diff options
| author | Michael Goulet <michael@errs.io> | 2022-10-02 06:30:49 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2022-10-02 06:32:40 +0000 |
| commit | f088e543cb51afa12c05097c131969d7962eca36 (patch) | |
| tree | 60772197fa49fe9a3a9f0f3be40422f943469198 | |
| parent | edadc7ccdda644ef8149869d2f24018a1dac202a (diff) | |
| download | rust-f088e543cb51afa12c05097c131969d7962eca36.tar.gz rust-f088e543cb51afa12c05097c131969d7962eca36.zip | |
Delay evaluating lint primary message until after it would be suppressed
| -rw-r--r-- | compiler/rustc_middle/src/lint.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/lint/auxiliary/trivial-cast-ice.rs | 7 | ||||
| -rw-r--r-- | src/test/ui/lint/trivial-cast-ice.rs | 12 |
3 files changed, 23 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index 328b7ad6a49..41b8aeb4852 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -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 @@ -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 diff --git a/src/test/ui/lint/auxiliary/trivial-cast-ice.rs b/src/test/ui/lint/auxiliary/trivial-cast-ice.rs new file mode 100644 index 00000000000..ab2332d0656 --- /dev/null +++ b/src/test/ui/lint/auxiliary/trivial-cast-ice.rs @@ -0,0 +1,7 @@ +#[macro_export] +macro_rules! foo { + () => { + let x: &Option<i32> = &Some(1); + let _y = x as *const Option<i32>; + } +} diff --git a/src/test/ui/lint/trivial-cast-ice.rs b/src/test/ui/lint/trivial-cast-ice.rs new file mode 100644 index 00000000000..f781fab2212 --- /dev/null +++ b/src/test/ui/lint/trivial-cast-ice.rs @@ -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!(); +} |
