Skip to content

Commit 8a36889

Browse files
committed
Auto merge of #2818 - saethlin:rustup, r=saethlin
rustup
2 parents 6a2eb72 + 2b223b8 commit 8a36889

File tree

213 files changed

+2111
-1291
lines changed

Some content is hidden

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

213 files changed

+2111
-1291
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ no_llvm_build
4242
/llvm/
4343
/mingw-build/
4444
build/
45+
!/compiler/rustc_mir_build/src/build/
4546
/build-rust-analyzer/
4647
/dist/
4748
/unicode-downloads

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,9 +1365,9 @@ dependencies = [
13651365

13661366
[[package]]
13671367
name = "ena"
1368-
version = "0.14.1"
1368+
version = "0.14.2"
13691369
source = "registry+https://github.com/rust-lang/crates.io-index"
1370-
checksum = "b2e5d13ca2353ab7d0230988629def93914a8c4015f621f9b13ed2955614731d"
1370+
checksum = "c533630cf40e9caa44bd91aadc88a75d75a4c3a12b4cfde353cbed41daa1e1f1"
13711371
dependencies = [
13721372
"log",
13731373
]

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,13 +1426,9 @@ pub enum ExprKind {
14261426
Block(P<Block>, Option<Label>),
14271427
/// An async block (`async move { ... }`).
14281428
///
1429-
/// The `NodeId` is the `NodeId` for the closure that results from
1430-
/// desugaring an async block, just like the NodeId field in the
1431-
/// `Async::Yes` variant. This is necessary in order to create a def for the
1432-
/// closure which can be used as a parent of any child defs. Defs
1433-
/// created during lowering cannot be made the parent of any other
1434-
/// preexisting defs.
1435-
Async(CaptureBy, NodeId, P<Block>),
1429+
/// The async block used to have a `NodeId`, which was removed in favor of
1430+
/// using the parent `NodeId` of the parent `Expr`.
1431+
Async(CaptureBy, P<Block>),
14361432
/// An await expression (`my_future.await`).
14371433
Await(P<Expr>),
14381434

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,8 +1407,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
14071407
vis.visit_block(blk);
14081408
visit_opt(label, |label| vis.visit_label(label));
14091409
}
1410-
ExprKind::Async(_capture_by, node_id, body) => {
1411-
vis.visit_id(node_id);
1410+
ExprKind::Async(_capture_by, body) => {
14121411
vis.visit_block(body);
14131412
}
14141413
ExprKind::Await(expr) => vis.visit_expr(expr),

compiler/rustc_ast/src/util/parser.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ pub enum ExprPrecedence {
259259
Assign,
260260
AssignOp,
261261

262-
Box,
263262
AddrOf,
264263
Let,
265264
Unary,
@@ -319,8 +318,7 @@ impl ExprPrecedence {
319318
ExprPrecedence::AssignOp => AssocOp::Assign.precedence() as i8,
320319

321320
// Unary, prefix
322-
ExprPrecedence::Box
323-
| ExprPrecedence::AddrOf
321+
ExprPrecedence::AddrOf
324322
// Here `let pats = expr` has `let pats =` as a "unary" prefix of `expr`.
325323
// However, this is not exactly right. When `let _ = a` is the LHS of a binop we
326324
// need parens sometimes. E.g. we can print `(let _ = a) && b` as `let _ = a && b`

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
860860
walk_list!(visitor, visit_label, opt_label);
861861
visitor.visit_block(block);
862862
}
863-
ExprKind::Async(_, _, body) => {
863+
ExprKind::Async(_, body) => {
864864
visitor.visit_block(body);
865865
}
866866
ExprKind::Await(expr) => visitor.visit_expr(expr),

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
6363
ExprKind::ForLoop(pat, head, body, opt_label) => {
6464
return self.lower_expr_for(e, pat, head, body, *opt_label);
6565
}
66-
// Similarly, async blocks do not use `e.id` but rather `closure_node_id`.
67-
ExprKind::Async(capture_clause, closure_node_id, block) => {
68-
let hir_id = self.lower_node_id(*closure_node_id);
69-
self.lower_attrs(hir_id, &e.attrs);
70-
return self.make_async_expr(
71-
*capture_clause,
72-
hir_id,
73-
*closure_node_id,
74-
None,
75-
e.span,
76-
hir::AsyncGeneratorKind::Block,
77-
|this| this.with_new_scopes(|this| this.lower_block_expr(block)),
78-
);
79-
}
8066
_ => (),
8167
}
8268

@@ -187,6 +173,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
187173
self.arena.alloc_from_iter(arms.iter().map(|x| self.lower_arm(x))),
188174
hir::MatchSource::Normal,
189175
),
176+
ExprKind::Async(capture_clause, block) => self.make_async_expr(
177+
*capture_clause,
178+
e.id,
179+
None,
180+
e.span,
181+
hir::AsyncGeneratorKind::Block,
182+
|this| this.with_new_scopes(|this| this.lower_block_expr(block)),
183+
),
190184
ExprKind::Await(expr) => {
191185
let dot_await_span = if expr.span.hi() < e.span.hi() {
192186
let span_with_whitespace = self
@@ -320,7 +314,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
320314
),
321315
ExprKind::Try(sub_expr) => self.lower_expr_try(e.span, sub_expr),
322316

323-
ExprKind::Paren(_) | ExprKind::ForLoop(..) | ExprKind::Async(..) => {
317+
ExprKind::Paren(_) | ExprKind::ForLoop(..) => {
324318
unreachable!("already handled")
325319
}
326320

@@ -591,13 +585,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
591585
pub(super) fn make_async_expr(
592586
&mut self,
593587
capture_clause: CaptureBy,
594-
outer_hir_id: hir::HirId,
595588
closure_node_id: NodeId,
596589
ret_ty: Option<hir::FnRetTy<'hir>>,
597590
span: Span,
598591
async_gen_kind: hir::AsyncGeneratorKind,
599592
body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
600-
) -> hir::Expr<'hir> {
593+
) -> hir::ExprKind<'hir> {
601594
let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span)));
602595

603596
// Resume argument type: `ResumeTy`
@@ -644,32 +637,36 @@ impl<'hir> LoweringContext<'_, 'hir> {
644637
});
645638

646639
// `static |_task_context| -> <ret_ty> { body }`:
647-
let generator_kind = {
648-
let c = self.arena.alloc(hir::Closure {
649-
def_id: self.local_def_id(closure_node_id),
650-
binder: hir::ClosureBinder::Default,
651-
capture_clause,
652-
bound_generic_params: &[],
653-
fn_decl,
654-
body,
655-
fn_decl_span: self.lower_span(span),
656-
fn_arg_span: None,
657-
movability: Some(hir::Movability::Static),
658-
constness: hir::Constness::NotConst,
659-
});
660-
661-
hir::ExprKind::Closure(c)
662-
};
640+
hir::ExprKind::Closure(self.arena.alloc(hir::Closure {
641+
def_id: self.local_def_id(closure_node_id),
642+
binder: hir::ClosureBinder::Default,
643+
capture_clause,
644+
bound_generic_params: &[],
645+
fn_decl,
646+
body,
647+
fn_decl_span: self.lower_span(span),
648+
fn_arg_span: None,
649+
movability: Some(hir::Movability::Static),
650+
constness: hir::Constness::NotConst,
651+
}))
652+
}
663653

664-
let hir_id = self.lower_node_id(closure_node_id);
654+
/// Forwards a possible `#[track_caller]` annotation from `outer_hir_id` to
655+
/// `inner_hir_id` in case the `closure_track_caller` feature is enabled.
656+
pub(super) fn maybe_forward_track_caller(
657+
&mut self,
658+
span: Span,
659+
outer_hir_id: hir::HirId,
660+
inner_hir_id: hir::HirId,
661+
) {
665662
if self.tcx.features().closure_track_caller
666663
&& let Some(attrs) = self.attrs.get(&outer_hir_id.local_id)
667664
&& attrs.into_iter().any(|attr| attr.has_name(sym::track_caller))
668665
{
669666
let unstable_span =
670667
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
671668
self.lower_attrs(
672-
hir_id,
669+
inner_hir_id,
673670
&[Attribute {
674671
kind: AttrKind::Normal(ptr::P(NormalAttr {
675672
item: AttrItem {
@@ -685,8 +682,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
685682
}],
686683
);
687684
}
688-
689-
hir::Expr { hir_id, kind: generator_kind, span: self.lower_span(span) }
690685
}
691686

692687
/// Desugar `<expr>.await` into:
@@ -1001,15 +996,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
1001996
None
1002997
};
1003998

1004-
this.make_async_expr(
999+
let async_body = this.make_async_expr(
10051000
capture_clause,
1006-
closure_hir_id,
10071001
inner_closure_id,
10081002
async_ret_ty,
10091003
body.span,
10101004
hir::AsyncGeneratorKind::Closure,
10111005
|this| this.with_new_scopes(|this| this.lower_expr_mut(body)),
1012-
)
1006+
);
1007+
let hir_id = this.lower_node_id(inner_closure_id);
1008+
this.maybe_forward_track_caller(body.span, closure_hir_id, hir_id);
1009+
hir::Expr { hir_id, kind: async_body, span: this.lower_span(body.span) }
10131010
});
10141011
body_id
10151012
});

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
11461146

11471147
let async_expr = this.make_async_expr(
11481148
CaptureBy::Value,
1149-
fn_id,
11501149
closure_id,
11511150
None,
11521151
body.span,
@@ -1180,7 +1179,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
11801179
},
11811180
);
11821181

1183-
(this.arena.alloc_from_iter(parameters), async_expr)
1182+
let hir_id = this.lower_node_id(closure_id);
1183+
this.maybe_forward_track_caller(body.span, fn_id, hir_id);
1184+
let expr = hir::Expr { hir_id, kind: async_expr, span: this.lower_span(body.span) };
1185+
1186+
(this.arena.alloc_from_iter(parameters), expr)
11841187
})
11851188
}
11861189

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl<'a> State<'a> {
439439
self.ibox(0);
440440
self.print_block_with_attrs(blk, attrs);
441441
}
442-
ast::ExprKind::Async(capture_clause, _, blk) => {
442+
ast::ExprKind::Async(capture_clause, blk) => {
443443
self.word_nbsp("async");
444444
self.print_capture_clause(*capture_clause);
445445
// cbox/ibox in analogy to the `ExprKind::Block` arm above

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ fn sccs_info<'cx, 'tcx>(
255255
let var_to_origin = infcx.reg_var_to_origin.borrow();
256256

257257
let mut var_to_origin_sorted = var_to_origin.clone().into_iter().collect::<Vec<_>>();
258-
var_to_origin_sorted.sort_by(|a, b| a.0.cmp(&b.0));
258+
var_to_origin_sorted.sort_by_key(|vto| vto.0);
259259
let mut debug_str = "region variables to origins:\n".to_string();
260260
for (reg_var, origin) in var_to_origin_sorted.into_iter() {
261261
debug_str.push_str(&format!("{:?}: {:?}\n", reg_var, origin));
@@ -2216,7 +2216,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22162216
// is in the same SCC or something. In that case, find what
22172217
// appears to be the most interesting point to report to the
22182218
// user via an even more ad-hoc guess.
2219-
categorized_path.sort_by(|p0, p1| p0.category.cmp(&p1.category));
2219+
categorized_path.sort_by_key(|p| p.category);
22202220
debug!("sorted_path={:#?}", categorized_path);
22212221

22222222
(categorized_path.remove(0), extra_info)

compiler/rustc_builtin_macros/src/assert/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
287287
// sync with the `rfc-2011-nicer-assert-messages/all-expr-kinds.rs` test.
288288
ExprKind::Assign(_, _, _)
289289
| ExprKind::AssignOp(_, _, _)
290-
| ExprKind::Async(_, _, _)
290+
| ExprKind::Async(_, _)
291291
| ExprKind::Await(_)
292292
| ExprKind::Block(_, _)
293293
| ExprKind::Break(_, _)

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
346346
crate::abi::codegen_return(fx);
347347
}
348348
TerminatorKind::Assert { cond, expected, msg, target, cleanup: _ } => {
349-
if !fx.tcx.sess.overflow_checks() {
350-
let overflow_not_to_check = match msg {
351-
AssertKind::OverflowNeg(..) => true,
352-
AssertKind::Overflow(op, ..) => op.is_checkable(),
353-
_ => false,
354-
};
355-
if overflow_not_to_check {
356-
let target = fx.get_block(*target);
357-
fx.bcx.ins().jump(target, &[]);
358-
continue;
359-
}
349+
if !fx.tcx.sess.overflow_checks() && msg.is_optional_overflow_check() {
350+
let target = fx.get_block(*target);
351+
fx.bcx.ins().jump(target, &[]);
352+
continue;
360353
}
361354
let cond = codegen_operand(fx, cond).load_scalar(fx);
362355

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,15 +1199,17 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
11991199
.and_then(|(lhs, rhs)| rhs.chars().all(char::is_numeric).then_some(lhs))
12001200
.unwrap_or(stem);
12011201

1202-
// GCC can have an optional target prefix.
1202+
// GCC/Clang can have an optional target prefix.
12031203
let flavor = if stem == "emcc" {
12041204
LinkerFlavor::EmCc
12051205
} else if stem == "gcc"
12061206
|| stem.ends_with("-gcc")
12071207
|| stem == "g++"
12081208
|| stem.ends_with("-g++")
12091209
|| stem == "clang"
1210+
|| stem.ends_with("-clang")
12101211
|| stem == "clang++"
1212+
|| stem.ends_with("-clang++")
12111213
{
12121214
LinkerFlavor::from_cli(LinkerFlavorCli::Gcc, &sess.target)
12131215
} else if stem == "wasm-ld" || stem.ends_with("-wasm-ld") {

compiler/rustc_codegen_ssa/src/glue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
4646
// NOTE: ideally, we want the effects of both `unchecked_smul` and `unchecked_umul`
4747
// (resulting in `mul nsw nuw` in LLVM IR), since we know that the multiplication
4848
// cannot signed wrap, and that both operands are non-negative. But at the time of writing,
49-
// `BuilderMethods` can't do this, and it doesn't seem to enable any further optimizations.
49+
// the `LLVM-C` binding can't do this, and it doesn't seem to enable any further optimizations.
5050
bx.unchecked_smul(info.unwrap(), bx.const_usize(unit.size.bytes())),
5151
bx.const_usize(unit.align.abi.bytes()),
5252
)

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -563,15 +563,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
563563
// with #[rustc_inherit_overflow_checks] and inlined from
564564
// another crate (mostly core::num generic/#[inline] fns),
565565
// while the current crate doesn't use overflow checks.
566-
if !bx.cx().check_overflow() {
567-
let overflow_not_to_check = match msg {
568-
AssertKind::OverflowNeg(..) => true,
569-
AssertKind::Overflow(op, ..) => op.is_checkable(),
570-
_ => false,
571-
};
572-
if overflow_not_to_check {
573-
const_cond = Some(expected);
574-
}
566+
if !bx.cx().check_overflow() && msg.is_optional_overflow_check() {
567+
const_cond = Some(expected);
575568
}
576569

577570
// Don't codegen the panic block if success if known.

compiler/rustc_const_eval/src/interpret/machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
155155

156156
/// Whether Assert(OverflowNeg) and Assert(Overflow) MIR terminators should actually
157157
/// check for overflow.
158-
fn ignore_checkable_overflow_assertions(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
158+
fn ignore_optional_overflow_checks(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
159159

160160
/// Entry point for obtaining the MIR of anything that should get evaluated.
161161
/// So not just functions and shims, but also const/static initializers, anonymous
@@ -474,7 +474,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
474474
}
475475

476476
#[inline(always)]
477-
fn ignore_checkable_overflow_assertions(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool {
477+
fn ignore_optional_overflow_checks(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool {
478478
false
479479
}
480480

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
138138
}
139139

140140
Assert { ref cond, expected, ref msg, target, cleanup } => {
141-
let ignored = M::ignore_checkable_overflow_assertions(self)
142-
&& match msg {
143-
mir::AssertKind::OverflowNeg(..) => true,
144-
mir::AssertKind::Overflow(op, ..) => op.is_checkable(),
145-
_ => false,
146-
};
141+
let ignored =
142+
M::ignore_optional_overflow_checks(self) && msg.is_optional_overflow_check();
147143
let cond_val = self.read_scalar(&self.eval_operand(cond, None)?)?.to_bool()?;
148144
if ignored || expected == cond_val {
149145
self.go_to_block(target);

compiler/rustc_data_structures/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ edition = "2021"
99
arrayvec = { version = "0.7", default-features = false }
1010
bitflags = "1.2.1"
1111
cfg-if = "1.0"
12-
ena = "0.14.1"
12+
ena = "0.14.2"
1313
indexmap = { version = "1.9.1" }
1414
jobserver_crate = { version = "0.1.13", package = "jobserver" }
1515
libc = "0.2"

0 commit comments

Comments
 (0)