Skip to content

Commit ee20c86

Browse files
committed
Auto merge of rust-lang#3902 - RalfJung:rustup, r=RalfJung
Rustup
2 parents a3fea24 + d877ec2 commit ee20c86

File tree

191 files changed

+2412
-746
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+2412
-746
lines changed

compiler/rustc_abi/src/lib.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -337,23 +337,21 @@ impl TargetDataLayout {
337337
Ok(dl)
338338
}
339339

340-
/// Returns exclusive upper bound on object size.
340+
/// Returns **exclusive** upper bound on object size in bytes.
341341
///
342342
/// The theoretical maximum object size is defined as the maximum positive `isize` value.
343343
/// This ensures that the `offset` semantics remain well-defined by allowing it to correctly
344344
/// index every address within an object along with one byte past the end, along with allowing
345345
/// `isize` to store the difference between any two pointers into an object.
346346
///
347-
/// The upper bound on 64-bit currently needs to be lower because LLVM uses a 64-bit integer
348-
/// to represent object size in bits. It would need to be 1 << 61 to account for this, but is
349-
/// currently conservatively bounded to 1 << 47 as that is enough to cover the current usable
350-
/// address space on 64-bit ARMv8 and x86_64.
347+
/// LLVM uses a 64-bit integer to represent object size in *bits*, but we care only for bytes,
348+
/// so we adopt such a more-constrained size bound due to its technical limitations.
351349
#[inline]
352350
pub fn obj_size_bound(&self) -> u64 {
353351
match self.pointer_size.bits() {
354352
16 => 1 << 15,
355353
32 => 1 << 31,
356-
64 => 1 << 47,
354+
64 => 1 << 61,
357355
bits => panic!("obj_size_bound: unknown pointer bit size {bits}"),
358356
}
359357
}

compiler/rustc_ast/src/ast.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1187,8 +1187,8 @@ impl Expr {
11871187
/// `min_const_generics` as more complex expressions are not supported.
11881188
///
11891189
/// Does not ensure that the path resolves to a const param, the caller should check this.
1190-
pub fn is_potential_trivial_const_arg(&self) -> bool {
1191-
let this = self.maybe_unwrap_block();
1190+
pub fn is_potential_trivial_const_arg(&self, strip_identity_block: bool) -> bool {
1191+
let this = if strip_identity_block { self.maybe_unwrap_block().1 } else { self };
11921192

11931193
if let ExprKind::Path(None, path) = &this.kind
11941194
&& path.is_potential_trivial_const_arg()
@@ -1199,14 +1199,15 @@ impl Expr {
11991199
}
12001200
}
12011201

1202-
pub fn maybe_unwrap_block(&self) -> &Expr {
1202+
/// Returns an expression with (when possible) *one* outter brace removed
1203+
pub fn maybe_unwrap_block(&self) -> (bool, &Expr) {
12031204
if let ExprKind::Block(block, None) = &self.kind
12041205
&& let [stmt] = block.stmts.as_slice()
12051206
&& let StmtKind::Expr(expr) = &stmt.kind
12061207
{
1207-
expr
1208+
(true, expr)
12081209
} else {
1209-
self
1210+
(false, self)
12101211
}
12111212
}
12121213

compiler/rustc_ast_lowering/src/asm.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use super::errors::{
2020
};
2121
use super::LoweringContext;
2222
use crate::{
23-
fluent_generated as fluent, ImplTraitContext, ImplTraitPosition, ParamMode,
24-
ResolverAstLoweringExt,
23+
fluent_generated as fluent, AllowReturnTypeNotation, ImplTraitContext, ImplTraitPosition,
24+
ParamMode, ResolverAstLoweringExt,
2525
};
2626

2727
impl<'a, 'hir> LoweringContext<'a, 'hir> {
@@ -201,6 +201,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
201201
&sym.qself,
202202
&sym.path,
203203
ParamMode::Optional,
204+
AllowReturnTypeNotation::No,
204205
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
205206
None,
206207
);
@@ -220,7 +221,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
220221
let parent_def_id = self.current_def_id_parent;
221222
let node_id = self.next_node_id();
222223
// HACK(min_generic_const_args): see lower_anon_const
223-
if !expr.is_potential_trivial_const_arg() {
224+
if !expr.is_potential_trivial_const_arg(true) {
224225
self.create_def(
225226
parent_def_id,
226227
node_id,

compiler/rustc_ast_lowering/src/delegation.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use rustc_target::spec::abi;
5252
use {rustc_ast as ast, rustc_hir as hir};
5353

5454
use super::{GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode};
55-
use crate::{ImplTraitPosition, ResolverAstLoweringExt};
55+
use crate::{AllowReturnTypeNotation, ImplTraitPosition, ResolverAstLoweringExt};
5656

5757
pub(crate) struct DelegationResults<'hir> {
5858
pub body_id: hir::BodyId,
@@ -340,6 +340,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
340340
&delegation.qself,
341341
&delegation.path,
342342
ParamMode::Optional,
343+
AllowReturnTypeNotation::No,
343344
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
344345
None,
345346
);

compiler/rustc_ast_lowering/src/expr.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use super::{
2323
GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode, ResolverAstLoweringExt,
2424
};
2525
use crate::errors::YieldInClosure;
26-
use crate::{fluent_generated, FnDeclKind, ImplTraitPosition};
26+
use crate::{fluent_generated, AllowReturnTypeNotation, FnDeclKind, ImplTraitPosition};
2727

2828
impl<'hir> LoweringContext<'_, 'hir> {
2929
fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> &'hir [hir::Expr<'hir>] {
@@ -281,6 +281,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
281281
qself,
282282
path,
283283
ParamMode::Optional,
284+
AllowReturnTypeNotation::No,
284285
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
285286
None,
286287
);
@@ -328,6 +329,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
328329
&se.qself,
329330
&se.path,
330331
ParamMode::Optional,
332+
AllowReturnTypeNotation::No,
331333
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
332334
None,
333335
)),
@@ -387,7 +389,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
387389
let node_id = self.next_node_id();
388390

389391
// HACK(min_generic_const_args): see lower_anon_const
390-
if !arg.is_potential_trivial_const_arg() {
392+
if !arg.is_potential_trivial_const_arg(true) {
391393
// Add a definition for the in-band const def.
392394
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, f.span);
393395
}
@@ -1291,6 +1293,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
12911293
qself,
12921294
path,
12931295
ParamMode::Optional,
1296+
AllowReturnTypeNotation::No,
12941297
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
12951298
None,
12961299
);
@@ -1311,6 +1314,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13111314
qself,
13121315
path,
13131316
ParamMode::Optional,
1317+
AllowReturnTypeNotation::No,
13141318
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
13151319
None,
13161320
);
@@ -1336,6 +1340,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13361340
&se.qself,
13371341
&se.path,
13381342
ParamMode::Optional,
1343+
AllowReturnTypeNotation::No,
13391344
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
13401345
None,
13411346
);

compiler/rustc_ast_lowering/src/lib.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,23 @@ enum ParamMode {
485485
Optional,
486486
}
487487

488+
#[derive(Copy, Clone, Debug)]
489+
enum AllowReturnTypeNotation {
490+
/// Only in types, since RTN is denied later during HIR lowering.
491+
Yes,
492+
/// All other positions (path expr, method, use tree).
493+
No,
494+
}
495+
488496
enum GenericArgsMode {
497+
/// Allow paren sugar, don't allow RTN.
489498
ParenSugar,
499+
/// Allow RTN, don't allow paren sugar.
500+
ReturnTypeNotation,
501+
// Error if parenthesized generics or RTN are encountered.
490502
Err,
503+
/// Silence errors when lowering generics. Only used with `Res::Err`.
504+
Silence,
491505
}
492506

493507
impl<'a, 'hir> LoweringContext<'a, 'hir> {
@@ -1226,7 +1240,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12261240
}
12271241

12281242
let id = self.lower_node_id(t.id);
1229-
let qpath = self.lower_qpath(t.id, qself, path, param_mode, itctx, None);
1243+
let qpath = self.lower_qpath(
1244+
t.id,
1245+
qself,
1246+
path,
1247+
param_mode,
1248+
AllowReturnTypeNotation::Yes,
1249+
itctx,
1250+
None,
1251+
);
12301252
self.ty_path(id, t.span, qpath)
12311253
}
12321254

@@ -2203,6 +2225,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22032225
&None,
22042226
&p.path,
22052227
ParamMode::Explicit,
2228+
AllowReturnTypeNotation::No,
22062229
itctx,
22072230
Some(modifiers),
22082231
) {
@@ -2341,6 +2364,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23412364
&None,
23422365
path,
23432366
ParamMode::Optional,
2367+
AllowReturnTypeNotation::No,
23442368
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
23452369
None,
23462370
);
@@ -2419,6 +2443,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24192443
qself,
24202444
path,
24212445
ParamMode::Optional,
2446+
AllowReturnTypeNotation::No,
24222447
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
24232448
None,
24242449
);
@@ -2441,7 +2466,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24412466
/// See [`hir::ConstArg`] for when to use this function vs
24422467
/// [`Self::lower_anon_const_to_const_arg`].
24432468
fn lower_anon_const_to_anon_const(&mut self, c: &AnonConst) -> &'hir hir::AnonConst {
2444-
if c.value.is_potential_trivial_const_arg() {
2469+
if c.value.is_potential_trivial_const_arg(true) {
24452470
// HACK(min_generic_const_args): see DefCollector::visit_anon_const
24462471
// Over there, we guess if this is a bare param and only create a def if
24472472
// we think it's not. However we may can guess wrong (see there for example)

compiler/rustc_ast_lowering/src/pat.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use super::errors::{
1111
ArbitraryExpressionInPattern, ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding,
1212
};
1313
use super::{ImplTraitContext, LoweringContext, ParamMode, ResolverAstLoweringExt};
14-
use crate::ImplTraitPosition;
14+
use crate::{AllowReturnTypeNotation, ImplTraitPosition};
1515

1616
impl<'a, 'hir> LoweringContext<'a, 'hir> {
1717
pub(crate) fn lower_pat(&mut self, pattern: &Pat) -> &'hir hir::Pat<'hir> {
@@ -38,6 +38,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
3838
qself,
3939
path,
4040
ParamMode::Optional,
41+
AllowReturnTypeNotation::No,
4142
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
4243
None,
4344
);
@@ -55,6 +56,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
5556
qself,
5657
path,
5758
ParamMode::Optional,
59+
AllowReturnTypeNotation::No,
5860
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
5961
None,
6062
);
@@ -66,6 +68,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
6668
qself,
6769
path,
6870
ParamMode::Optional,
71+
AllowReturnTypeNotation::No,
6972
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
7073
None,
7174
);

0 commit comments

Comments
 (0)