Skip to content

Commit f088e54

Browse files
Delay evaluating lint primary message until after it would be suppressed
1 parent edadc7c commit f088e54

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Diff for: compiler/rustc_middle/src/lint.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ pub fn struct_lint_level<'s, 'd>(
354354
(Level::Deny | Level::Forbid, None) => sess.diagnostic().struct_err_lint(""),
355355
};
356356

357-
err.set_primary_message(msg);
358357
err.set_is_lint();
359358

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

381+
// Delay evaluating and setting the primary message until after we've
382+
// suppressed the lint due to macros.
383+
err.set_primary_message(msg);
384+
382385
// Lint diagnostics that are covered by the expect level will not be emitted outside
383386
// the compiler. It is therefore not necessary to add any information for the user.
384387
// This will therefore directly call the decorate function which will in turn emit

Diff for: src/test/ui/lint/auxiliary/trivial-cast-ice.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#[macro_export]
2+
macro_rules! foo {
3+
() => {
4+
let x: &Option<i32> = &Some(1);
5+
let _y = x as *const Option<i32>;
6+
}
7+
}

Diff for: src/test/ui/lint/trivial-cast-ice.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// aux-build:trivial-cast-ice.rs
2+
// check-pass
3+
4+
// Demonstrates the ICE in #102561
5+
6+
#![deny(trivial_casts)]
7+
8+
extern crate trivial_cast_ice;
9+
10+
fn main() {
11+
trivial_cast_ice::foo!();
12+
}

0 commit comments

Comments
 (0)