Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ pub fn struct_lint_level<'s, 'd>(
(Level::Deny | Level::Forbid, None) => sess.diagnostic().struct_err_lint(""),
};

err.set_primary_message(msg);
err.set_is_lint();

// If this code originates in a foreign macro, aka something that this crate
Expand All @@ -379,6 +378,10 @@ pub fn struct_lint_level<'s, 'd>(
}
}

// Delay evaluating and setting the primary message until after we've
// suppressed the lint due to macros.
err.set_primary_message(msg);

// Lint diagnostics that are covered by the expect level will not be emitted outside
// the compiler. It is therefore not necessary to add any information for the user.
// This will therefore directly call the decorate function which will in turn emit
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/lint/auxiliary/trivial-cast-ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[macro_export]
macro_rules! foo {
() => {
let x: &Option<i32> = &Some(1);
let _y = x as *const Option<i32>;
}
}
12 changes: 12 additions & 0 deletions src/test/ui/lint/trivial-cast-ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// aux-build:trivial-cast-ice.rs
// check-pass

// Demonstrates the ICE in #102561

#![deny(trivial_casts)]

extern crate trivial_cast_ice;

fn main() {
trivial_cast_ice::foo!();
}