@@ -25,6 +25,7 @@ use rustc_middle::traits::ObligationCause;
2525use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
2626use rustc_middle:: ty:: { self , TyCtxt , TypingMode } ;
2727use rustc_middle:: { bug, span_bug} ;
28+ use rustc_session:: config:: CrateType ;
2829use rustc_session:: lint:: builtin:: {
2930 CONFLICTING_REPR_HINTS , INVALID_DOC_ATTRIBUTES , INVALID_MACRO_EXPORT_ARGUMENTS ,
3031 UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES , UNUSED_ATTRIBUTES ,
@@ -2328,6 +2329,33 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23282329 && item. path == sym:: reason
23292330 {
23302331 errors:: UnusedNote :: NoLints { name : attr. name_or_empty ( ) }
2332+ } else if matches ! (
2333+ attr. name_or_empty( ) ,
2334+ sym:: allow | sym:: warn | sym:: deny | sym:: forbid | sym:: expect
2335+ ) && let Some ( meta) = attr. meta_item_list ( )
2336+ && meta. iter ( ) . any ( |meta| {
2337+ meta. meta_item ( ) . map_or ( false , |item| item. path == sym:: linker_messages)
2338+ } )
2339+ {
2340+ if hir_id != CRATE_HIR_ID {
2341+ let err = match attr. style {
2342+ ast:: AttrStyle :: Outer => errors:: OuterCrateLevelAttr ,
2343+ ast:: AttrStyle :: Inner => errors:: OuterCrateLevelAttr ,
2344+ } ;
2345+ self . tcx . emit_node_span_lint ( UNUSED_ATTRIBUTES , hir_id, attr. span , err) ;
2346+ return ;
2347+ } else {
2348+ let never_needs_link = self
2349+ . tcx
2350+ . crate_types ( )
2351+ . iter ( )
2352+ . all ( |kind| matches ! ( kind, CrateType :: Rlib | CrateType :: Staticlib ) ) ;
2353+ if never_needs_link {
2354+ errors:: UnusedNote :: LinkerWarningsBinaryCrateOnly
2355+ } else {
2356+ return ;
2357+ }
2358+ }
23312359 } else if attr. name_or_empty ( ) == sym:: default_method_body_is_const {
23322360 errors:: UnusedNote :: DefaultMethodBodyConst
23332361 } else {
0 commit comments