@@ -666,6 +666,30 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
666666 ( Level :: Forbid , None ) => sess. struct_err ( msg) ,
667667 } ;
668668
669+ // Check for future incompatibility lints and issue a stronger warning.
670+ let lints = sess. lint_store . borrow ( ) ;
671+ let lint_id = LintId :: of ( lint) ;
672+ let future_incompatible = lints. future_incompatible ( lint_id) ;
673+
674+ // If this code originates in a foreign macro, aka something that this crate
675+ // did not itself author, then it's likely that there's nothing this crate
676+ // can do about it. We probably want to skip the lint entirely.
677+ if err. span . primary_spans ( ) . iter ( ) . any ( |s| in_external_macro ( sess, * s) ) {
678+ // Any suggestions made here are likely to be incorrect, so anything we
679+ // emit shouldn't be automatically fixed by rustfix.
680+ err. allow_suggestions ( false ) ;
681+
682+ // If this is a future incompatible lint it'll become a hard error, so
683+ // we have to emit *something*. Also allow lints to whitelist themselves
684+ // on a case-by-case basis for emission in a foreign macro.
685+ if future_incompatible. is_none ( ) && !lint. report_in_external_macro {
686+ err. cancel ( ) ;
687+ // Don't continue further, since we don't want to have
688+ // `diag_span_note_once` called for a diagnostic that isn't emitted.
689+ return err;
690+ }
691+ }
692+
669693 let name = lint. name_lower ( ) ;
670694 match src {
671695 LintSource :: Default => {
@@ -715,10 +739,6 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
715739
716740 err. code ( DiagnosticId :: Lint ( name) ) ;
717741
718- // Check for future incompatibility lints and issue a stronger warning.
719- let lints = sess. lint_store . borrow ( ) ;
720- let lint_id = LintId :: of ( lint) ;
721- let future_incompatible = lints. future_incompatible ( lint_id) ;
722742 if let Some ( future_incompatible) = future_incompatible {
723743 const STANDARD_MESSAGE : & str =
724744 "this was previously accepted by the compiler but is being phased out; \
@@ -743,22 +763,6 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
743763 err. note ( & citation) ;
744764 }
745765
746- // If this code originates in a foreign macro, aka something that this crate
747- // did not itself author, then it's likely that there's nothing this crate
748- // can do about it. We probably want to skip the lint entirely.
749- if err. span . primary_spans ( ) . iter ( ) . any ( |s| in_external_macro ( sess, * s) ) {
750- // Any suggestions made here are likely to be incorrect, so anything we
751- // emit shouldn't be automatically fixed by rustfix.
752- err. allow_suggestions ( false ) ;
753-
754- // If this is a future incompatible lint it'll become a hard error, so
755- // we have to emit *something*. Also allow lints to whitelist themselves
756- // on a case-by-case basis for emission in a foreign macro.
757- if future_incompatible. is_none ( ) && !lint. report_in_external_macro {
758- err. cancel ( )
759- }
760- }
761-
762766 return err
763767}
764768
0 commit comments