]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_middle/src/lint.rs
Rollup merge of #102893 - TaKO8Ki:fix-102878, r=davidtwco
[rust.git] / compiler / rustc_middle / src / lint.rs
index 7b0054a96d3ea019ac202140712bbeb36bbe0562..d95c5cbd654cb1a48ec7920b5e19a17a7bb1d345 100644 (file)
@@ -350,7 +350,6 @@ fn struct_lint_level_impl(
             (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
@@ -375,6 +374,10 @@ fn struct_lint_level_impl(
             }
         }
 
+        // 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
@@ -443,7 +446,9 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
     match expn_data.kind {
         ExpnKind::Inlined
         | ExpnKind::Root
-        | ExpnKind::Desugaring(DesugaringKind::ForLoop | DesugaringKind::WhileLoop) => false,
+        | ExpnKind::Desugaring(
+            DesugaringKind::ForLoop | DesugaringKind::WhileLoop | DesugaringKind::OpaqueTy,
+        ) => false,
         ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => true, // well, it's "external"
         ExpnKind::Macro(MacroKind::Bang, _) => {
             // Dummy span for the `def_site` means it's an external macro.