Skip to content

Commit 15665a4

Browse files
committed
nicer errors
1 parent bae65d0 commit 15665a4

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

Diff for: compiler/rustc_monomorphize/src/collector.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -735,14 +735,16 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> {
735735

736736
impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
737737
fn visit_body(&mut self, body: &mir::Body<'tcx>) {
738+
self.super_body(body);
739+
740+
// Go over `required_items` *after* body, so if an item appears in both we reach it the
741+
// "normal" way, via the body.
738742
for item in &body.required_items {
739743
// All these also need monomorphization to ensure that if that leads to error, we find
740744
// those errors.
741745
let item = self.monomorphize(*item);
742746
visit_required_item(self.tcx, item, self.output);
743747
}
744-
745-
self.super_body(body);
746748
}
747749

748750
fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: Location) {

Diff for: tests/ui/consts/required-consts/dead-code-in-called-fn.no-opt.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ LL | const C: () = panic!();
77
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
note: the above error was encountered while instantiating `fn called::<i32>`
10+
--> $DIR/dead-code-in-called-fn.rs:23:5
11+
|
12+
LL | called::<i32>();
13+
| ^^^^^^^^^^^^^^^
1014

1115
error: aborting due to 1 previous error
1216

Diff for: tests/ui/consts/required-consts/dead-code-in-called-fn.opt.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ LL | const C: () = panic!();
77
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
note: the above error was encountered while instantiating `fn called::<i32>`
10+
--> $DIR/dead-code-in-called-fn.rs:23:5
11+
|
12+
LL | called::<i32>();
13+
| ^^^^^^^^^^^^^^^
1014

1115
error: aborting due to 1 previous error
1216

Diff for: tests/ui/consts/required-consts/dead-code-in-dead-fn.no-opt.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ LL | const C: () = panic!();
77
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
note: the above error was encountered while instantiating `fn not_called::<i32>`
10+
--> $DIR/dead-code-in-dead-fn.rs:26:9
11+
|
12+
LL | not_called::<T>();
13+
| ^^^^^^^^^^^^^^^^^
1014

1115
error: aborting due to 1 previous error
1216

Diff for: tests/ui/generics/post_monomorphization_error_backtrace.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ LL | const V: () = assert!(std::mem::size_of::<T>() == 0);
77
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
note: the above error was encountered while instantiating `fn assert_zst::<u32>`
10+
--> $DIR/post_monomorphization_error_backtrace.rs:18:5
11+
|
12+
LL | assert_zst::<U>()
13+
| ^^^^^^^^^^^^^^^^^
1014

1115
error[E0080]: evaluation of `assert_zst::F::<i32>::V` failed
1216
--> $DIR/post_monomorphization_error_backtrace.rs:6:23
@@ -17,6 +21,10 @@ LL | const V: () = assert!(std::mem::size_of::<T>() == 0);
1721
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
1822

1923
note: the above error was encountered while instantiating `fn assert_zst::<i32>`
24+
--> $DIR/post_monomorphization_error_backtrace.rs:18:5
25+
|
26+
LL | assert_zst::<U>()
27+
| ^^^^^^^^^^^^^^^^^
2028

2129
error: aborting due to 2 previous errors
2230

0 commit comments

Comments
 (0)