Skip to content

Commit

Permalink
nicer errors
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Mar 14, 2024
1 parent 003214e commit fd02409
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,14 +735,16 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> {

impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
fn visit_body(&mut self, body: &mir::Body<'tcx>) {
self.super_body(body);

// Go over `required_items` *after* body, so if an item appears in both we reach it the
// "normal" way, via the body.
for item in &body.required_items {
// All these also need monomorphization to ensure that if that leads to error, we find
// those errors.
let item = self.monomorphize(*item);
visit_required_item(self.tcx, item, self.output);
}

self.super_body(body);
}

fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: Location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ LL | const C: () = panic!();
= 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)

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

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ LL | const C: () = panic!();
= 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)

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

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ LL | const C: () = panic!();
= 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)

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

error: aborting due to 1 previous error

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

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

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

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

error: aborting due to 2 previous errors

Expand Down

0 comments on commit fd02409

Please sign in to comment.