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

+2-2
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

+10
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

+1-4
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

+1-1
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

+3-1
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

+28-5
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

+1-2
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

+13-2
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

+2
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

+8
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();

src/libstd/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
#![feature(hash_raw_entry)]
268268
#![feature(hashmap_internals)]
269269
#![feature(int_error_internals)]
270+
#![feature(int_error_matching)]
270271
#![feature(integer_atomics)]
271272
#![feature(lang_items)]
272273
#![feature(libc)]

src/libstd/num.rs

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ pub use core::num::{NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU128,
1616
#[stable(feature = "signed_nonzero", since = "1.34.0")]
1717
pub use core::num::{NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI128, NonZeroIsize};
1818

19+
#[unstable(feature = "int_error_matching",
20+
reason = "it can be useful to match errors when making error messages \
21+
for integer parsing",
22+
issue = "22639")]
23+
pub use core::num::IntErrorKind;
24+
1925
#[cfg(test)] use crate::fmt;
2026
#[cfg(test)] use crate::ops::{Add, Sub, Mul, Div, Rem};
2127

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Test that `-Zpgo-gen` creates expected instrumentation artifacts in LLVM IR.
2+
3+
// needs-profiler-support
4+
// compile-flags: -Z pgo-gen -Ccodegen-units=1
5+
6+
// CHECK: @__llvm_profile_raw_version =
7+
// CHECK: @__profc_{{.*}}pgo_instrumentation{{.*}}some_function{{.*}} = private global
8+
// CHECK: @__profd_{{.*}}pgo_instrumentation{{.*}}some_function{{.*}} = private global
9+
// CHECK: @__profc_{{.*}}pgo_instrumentation{{.*}}main{{.*}} = private global
10+
// CHECK: @__profd_{{.*}}pgo_instrumentation{{.*}}main{{.*}} = private global
11+
// CHECK: @__llvm_profile_filename = {{.*}}"default_%m.profraw\00"{{.*}}
12+
13+
#[inline(never)]
14+
fn some_function() {
15+
16+
}
17+
18+
fn main() {
19+
some_function();
20+
}

src/test/mir-opt/array-index-is-temporary.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,24 @@ fn main() {
1818
// START rustc.main.EraseRegions.after.mir
1919
// bb0: {
2020
// ...
21-
// _6 = &mut _2;
22-
// _5 = &mut (*_6);
23-
// _4 = move _5 as *mut usize (Misc);
24-
// _3 = move _4;
21+
// _5 = &mut _2;
22+
// _4 = &mut (*_5);
23+
// _3 = move _4 as *mut usize (Misc);
2524
// ...
26-
// _8 = _3;
27-
// _7 = const foo(move _8) -> bb1;
25+
// _7 = _3;
26+
// _6 = const foo(move _7) -> bb1;
2827
// }
2928
//
3029
// bb1: {
3130
// ...
32-
// _9 = _2;
33-
// _10 = Len(_1);
34-
// _11 = Lt(_9, _10);
35-
// assert(move _11, "index out of bounds: the len is move _10 but the index is _9") -> bb2;
31+
// _8 = _2;
32+
// _9 = Len(_1);
33+
// _10 = Lt(_8, _9);
34+
// assert(move _10, "index out of bounds: the len is move _9 but the index is _8") -> bb2;
3635
// }
3736
//
3837
// bb2: {
39-
// _1[_9] = move _7;
38+
// _1[_8] = move _6;
4039
// ...
4140
// return;
4241
// }

src/test/mir-opt/retag.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,18 @@ fn main() {
7575
// _10 = move _8;
7676
// Retag(_10);
7777
// ...
78-
// _15 = &mut (*_10);
79-
// Retag(_15);
80-
// _14 = move _15 as *mut i32 (Misc);
81-
// Retag([raw] _14);
78+
// _13 = &mut (*_10);
79+
// Retag(_13);
80+
// _12 = move _13 as *mut i32 (Misc);
81+
// Retag([raw] _12);
8282
// ...
83-
// _18 = move _19(move _20) -> bb2;
83+
// _16 = move _17(move _18) -> bb2;
8484
// }
8585
//
8686
// bb2: {
87-
// Retag(_18);
87+
// Retag(_16);
8888
// ...
89-
// _22 = const Test::foo_shr(move _23, move _25) -> bb3;
89+
// _20 = const Test::foo_shr(move _21, move _23) -> bb3;
9090
// }
9191
//
9292
// bb3: {
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
# needs-profiler-support
2+
13
-include ../tools.mk
24

35
all:
4-
ifeq ($(PROFILER_SUPPORT),1)
56
$(RUSTC) -Copt-level=3 -Clto=fat -Z pgo-gen="$(TMPDIR)" test.rs
67
$(call RUN,test) || exit 1
78
[ -e "$(TMPDIR)"/default_*.profraw ] || (echo "No .profraw file"; exit 1)
8-
endif
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
# needs-profiler-support
2+
13
-include ../tools.mk
24

35
all:
4-
ifeq ($(PROFILER_SUPPORT),1)
5-
$(RUSTC) -O -Ccodegen-units=1 -Z pgo-gen="$(TMPDIR)/test.profraw" --emit=llvm-ir test.rs
6+
$(RUSTC) -O -Ccodegen-units=1 -Z pgo-gen="$(TMPDIR)" --emit=llvm-ir test.rs
67
# We expect symbols starting with "__llvm_profile_".
78
$(CGREP) "__llvm_profile_" < $(TMPDIR)/test.ll
89
# We do NOT expect the "__imp_" version of these symbols.
910
$(CGREP) -v "__imp___llvm_profile_" < $(TMPDIR)/test.ll # 64 bit
1011
$(CGREP) -v "__imp____llvm_profile_" < $(TMPDIR)/test.ll # 32 bit
11-
endif
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
# needs-profiler-support
2+
13
-include ../tools.mk
24

35
all:
4-
ifeq ($(PROFILER_SUPPORT),1)
56
$(RUSTC) -g -Z pgo-gen="$(TMPDIR)" test.rs
67
$(call RUN,test) || exit 1
78
[ -e "$(TMPDIR)"/default_*.profraw ] || (echo "No .profraw file"; exit 1)
8-
endif
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
# needs-profiler-support
2+
13
-include ../tools.mk
24

35
all:
4-
ifeq ($(PROFILER_SUPPORT),1)
56
$(RUSTC) -g -Z profile test.rs
67
$(call RUN,test) || exit 1
78
[ -e "$(TMPDIR)/test.gcno" ] || (echo "No .gcno file"; exit 1)
89
[ -e "$(TMPDIR)/test.gcda" ] || (echo "No .gcda file"; exit 1)
9-
endif

src/test/run-make-fulldeps/sanitizer-address/Makefile

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
# needs-sanitizer-support
2+
13
-include ../tools.mk
24

35
LOG := $(TMPDIR)/log.txt
46

57
# NOTE the address sanitizer only supports x86_64 linux and macOS
68

79
ifeq ($(TARGET),x86_64-apple-darwin)
8-
ASAN_SUPPORT=$(SANITIZER_SUPPORT)
910
EXTRA_RUSTFLAG=-C rpath
1011
else
1112
ifeq ($(TARGET),x86_64-unknown-linux-gnu)
12-
ASAN_SUPPORT=$(SANITIZER_SUPPORT)
1313

1414
# Apparently there are very specific Linux kernels, notably the one that's
1515
# currently on Travis CI, which contain a buggy commit that triggers failures in
@@ -23,7 +23,5 @@ endif
2323
endif
2424

2525
all:
26-
ifeq ($(ASAN_SUPPORT),1)
2726
$(RUSTC) -g -Z sanitizer=address -Z print-link-args $(EXTRA_RUSTFLAG) overflow.rs | $(CGREP) librustc_asan
2827
$(TMPDIR)/overflow 2>&1 | $(CGREP) stack-buffer-overflow
29-
endif

0 commit comments

Comments
 (0)