Skip to content

Commit 8a0fda2

Browse files
authored
Rollup merge of #102567 - compiler-errors:issue-102561, r=davidtwco
Delay evaluating lint primary message until after it would be suppressed Fixes #102561 Fixes #102572
2 parents f333436 + f088e54 commit 8a0fda2

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

compiler/rustc_middle/src/lint.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ pub fn struct_lint_level(
350350
(Level::Deny | Level::Forbid, None) => sess.diagnostic().struct_err_lint(""),
351351
};
352352

353-
err.set_primary_message(msg);
354353
err.set_is_lint();
355354

356355
// If this code originates in a foreign macro, aka something that this crate
@@ -375,6 +374,10 @@ pub fn struct_lint_level(
375374
}
376375
}
377376

377+
// Delay evaluating and setting the primary message until after we've
378+
// suppressed the lint due to macros.
379+
err.set_primary_message(msg);
380+
378381
// Lint diagnostics that are covered by the expect level will not be emitted outside
379382
// the compiler. It is therefore not necessary to add any information for the user.
380383
// This will therefore directly call the decorate function which will in turn emit
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+
}

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)