Skip to content

Commit 9aea116

Browse files
committed
Auto merge of #60250 - Centril:rollup-d9tehhr, r=Centril
Rollup of 6 pull requests Successful merges: - #59560 (MIR generation cleanup) - #59697 (tweak unresolved label suggestion) - #60038 (Add codegen test for PGO instrumentation.) - #60160 (Fix #58270, fix off-by-one error in error diagnostics.) - #60185 (Reexport IntErrorKind in std) - #60243 (Add regression test for #53249.) Failed merges: r? @ghost
2 parents 3d21124 + 1443f3b commit 9aea116

File tree

40 files changed

+245
-101
lines changed

40 files changed

+245
-101
lines changed

src/bootstrap/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,11 +1268,11 @@ impl Step for Compiletest {
12681268
builder.add_rust_test_threads(&mut cmd);
12691269

12701270
if builder.config.sanitizers {
1271-
cmd.env("SANITIZER_SUPPORT", "1");
1271+
cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
12721272
}
12731273

12741274
if builder.config.profiler {
1275-
cmd.env("PROFILER_SUPPORT", "1");
1275+
cmd.env("RUSTC_PROFILER_SUPPORT", "1");
12761276
}
12771277

12781278
cmd.env("RUST_TEST_TMPDIR", builder.out.join("tmp"));

src/librustc_errors/emitter.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ impl EmitterWriter {
268268
// 6..7. This is degenerate input, but it's best to degrade
269269
// gracefully -- and the parser likes to supply a span like
270270
// that for EOF, in particular.
271+
271272
if lo.col_display == hi.col_display && lo.line == hi.line {
272273
hi.col_display += 1;
273274
}
@@ -547,6 +548,15 @@ impl EmitterWriter {
547548
&& j > i // multiline lines).
548549
&& p == 0 // We're currently on the first line, move the label one line down
549550
{
551+
// If we're overlapping with an un-labelled annotation with the same span
552+
// we can just merge them in the output
553+
if next.start_col == annotation.start_col
554+
&& next.end_col == annotation.end_col
555+
&& !next.has_label()
556+
{
557+
continue;
558+
}
559+
550560
// This annotation needs a new line in the output.
551561
p += 1;
552562
break;

src/librustc_mir/build/expr/as_rvalue.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
150150
let source = unpack!(block = this.as_operand(block, scope, source));
151151
block.and(Rvalue::Cast(CastKind::Misc, source, expr.ty))
152152
}
153-
ExprKind::Use { source } => {
154-
let source = unpack!(block = this.as_operand(block, scope, source));
155-
block.and(Rvalue::Use(source))
156-
}
157153
ExprKind::Pointer { cast, source } => {
158154
let source = unpack!(block = this.as_operand(block, scope, source));
159155
block.and(Rvalue::Cast(CastKind::Pointer(cast), source, expr.ty))
@@ -363,6 +359,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
363359
| ExprKind::Match { .. }
364360
| ExprKind::If { .. }
365361
| ExprKind::NeverToAny { .. }
362+
| ExprKind::Use { .. }
366363
| ExprKind::Loop { .. }
367364
| ExprKind::LogicalOp { .. }
368365
| ExprKind::Call { .. }

src/librustc_mir/build/expr/category.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl Category {
4848
| ExprKind::If { .. }
4949
| ExprKind::Match { .. }
5050
| ExprKind::NeverToAny { .. }
51+
| ExprKind::Use { .. }
5152
| ExprKind::Call { .. } => Some(Category::Rvalue(RvalueFunc::Into)),
5253

5354
ExprKind::Array { .. }
@@ -58,7 +59,6 @@ impl Category {
5859
| ExprKind::Binary { .. }
5960
| ExprKind::Box { .. }
6061
| ExprKind::Cast { .. }
61-
| ExprKind::Use { .. }
6262
| ExprKind::Pointer { .. }
6363
| ExprKind::Repeat { .. }
6464
| ExprKind::Borrow { .. }

src/librustc_mir/build/expr/into.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
327327
success.unit()
328328
}
329329
}
330+
ExprKind::Use { source } => {
331+
this.into(destination, block, source)
332+
}
330333

331334
// These cases don't actually need a destination
332335
ExprKind::Assign { .. }
@@ -379,7 +382,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
379382
| ExprKind::Binary { .. }
380383
| ExprKind::Box { .. }
381384
| ExprKind::Cast { .. }
382-
| ExprKind::Use { .. }
383385
| ExprKind::Pointer { .. }
384386
| ExprKind::Repeat { .. }
385387
| ExprKind::Borrow { .. }

src/librustc_mir/build/mod.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,21 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
147147
build::construct_fn(cx, id, arguments, safety, abi,
148148
return_ty, yield_ty, return_ty_span, body)
149149
} else {
150-
build::construct_const(cx, body_id, return_ty_span)
150+
// Get the revealed type of this const. This is *not* the adjusted
151+
// type of its body, which may be a subtype of this type. For
152+
// example:
153+
//
154+
// fn foo(_: &()) {}
155+
// static X: fn(&'static ()) = foo;
156+
//
157+
// The adjusted type of the body of X is `for<'a> fn(&'a ())` which
158+
// is not the same as the type of X. We need the type of the return
159+
// place to be the type of the constant because NLL typeck will
160+
// equate them.
161+
162+
let return_ty = cx.tables().node_type(id);
163+
164+
build::construct_const(cx, body_id, return_ty, return_ty_span)
151165
};
152166

153167
// Convert the Mir to global types.
@@ -730,16 +744,25 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
730744
fn construct_const<'a, 'gcx, 'tcx>(
731745
hir: Cx<'a, 'gcx, 'tcx>,
732746
body_id: hir::BodyId,
733-
ty_span: Span,
747+
const_ty: Ty<'tcx>,
748+
const_ty_span: Span,
734749
) -> Mir<'tcx> {
735750
let tcx = hir.tcx();
736-
let ast_expr = &tcx.hir().body(body_id).value;
737-
let ty = hir.tables().expr_ty_adjusted(ast_expr);
738751
let owner_id = tcx.hir().body_owner(body_id);
739752
let span = tcx.hir().span(owner_id);
740-
let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, ty_span, vec![], vec![]);
753+
let mut builder = Builder::new(
754+
hir,
755+
span,
756+
0,
757+
Safety::Safe,
758+
const_ty,
759+
const_ty_span,
760+
vec![],
761+
vec![],
762+
);
741763

742764
let mut block = START_BLOCK;
765+
let ast_expr = &tcx.hir().body(body_id).value;
743766
let expr = builder.hir.mirror(ast_expr);
744767
unpack!(block = builder.into_expr(&Place::RETURN_PLACE, block, expr));
745768

src/librustc_mir/interpret/step.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
259259
)?;
260260
}
261261

262-
Cast(kind, ref operand, cast_ty) => {
263-
debug_assert_eq!(self.monomorphize(cast_ty)?, dest.layout.ty);
262+
Cast(kind, ref operand, _) => {
264263
let src = self.eval_operand(operand, None)?;
265264
self.cast(src, kind, dest)?;
266265
}

src/librustc_resolve/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,12 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver<'_>,
364364
"use of undeclared label `{}`",
365365
name);
366366
if let Some(lev_candidate) = lev_candidate {
367-
err.span_label(span, format!("did you mean `{}`?", lev_candidate));
367+
err.span_suggestion(
368+
span,
369+
"a label with a similar name exists in this scope",
370+
lev_candidate.to_string(),
371+
Applicability::MaybeIncorrect,
372+
);
368373
} else {
369374
err.span_label(span, format!("undeclared label `{}`", name));
370375
}
@@ -4280,7 +4285,13 @@ impl<'a> Resolver<'a> {
42804285
// Picks the first label that is "close enough", which is not necessarily
42814286
// the closest match
42824287
let close_match = self.search_label(label.ident, |rib, ident| {
4283-
let names = rib.bindings.iter().map(|(id, _)| &id.name);
4288+
let names = rib.bindings.iter().filter_map(|(id, _)| {
4289+
if id.span.ctxt() == label.ident.span.ctxt() {
4290+
Some(&id.name)
4291+
} else {
4292+
None
4293+
}
4294+
});
42844295
find_best_match_for_name(names, &*ident.as_str(), None)
42854296
});
42864297
self.record_def(expr.id, err_path_resolution());

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,8 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
866866

867867
fcx.check_expr_coercable_to_type(&body.value, revealed_ty);
868868

869+
fcx.write_ty(id, revealed_ty);
870+
869871
fcx
870872
};
871873

src/librustc_typeck/check/writeback.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4242
for arg in &body.arguments {
4343
wbcx.visit_node_id(arg.pat.span, arg.hir_id);
4444
}
45+
// Type only exists for constants and statics, not functions.
46+
match self.tcx.hir().body_owner_kind(item_id) {
47+
hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => {
48+
let item_hir_id = self.tcx.hir().node_to_hir_id(item_id);
49+
wbcx.visit_node_id(body.value.span, item_hir_id);
50+
}
51+
hir::BodyOwnerKind::Closure | hir::BodyOwnerKind::Fn => (),
52+
}
4553
wbcx.visit_body(body);
4654
wbcx.visit_upvar_capture_map();
4755
wbcx.visit_upvar_list_map();

0 commit comments

Comments
 (0)