@@ -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 ,
@@ -2313,6 +2314,33 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23132314 && item. path == sym:: reason
23142315 {
23152316 errors:: UnusedNote :: NoLints { name : attr. name_or_empty ( ) }
2317+ } else if matches ! (
2318+ attr. name_or_empty( ) ,
2319+ sym:: allow | sym:: warn | sym:: deny | sym:: forbid | sym:: expect
2320+ ) && let Some ( meta) = attr. meta_item_list ( )
2321+ && meta. iter ( ) . any ( |meta| {
2322+ meta. meta_item ( ) . map_or ( false , |item| item. path == sym:: linker_messages)
2323+ } )
2324+ {
2325+ if hir_id != CRATE_HIR_ID {
2326+ let err = match attr. style {
2327+ ast:: AttrStyle :: Outer => errors:: OuterCrateLevelAttr ,
2328+ ast:: AttrStyle :: Inner => errors:: OuterCrateLevelAttr ,
2329+ } ;
2330+ self . tcx . emit_node_span_lint ( UNUSED_ATTRIBUTES , hir_id, attr. span , err) ;
2331+ return ;
2332+ } else {
2333+ let never_needs_link = self
2334+ . tcx
2335+ . crate_types ( )
2336+ . iter ( )
2337+ . all ( |kind| matches ! ( kind, CrateType :: Rlib | CrateType :: Staticlib ) ) ;
2338+ if never_needs_link {
2339+ errors:: UnusedNote :: LinkerWarningsBinaryCrateOnly
2340+ } else {
2341+ return ;
2342+ }
2343+ }
23162344 } else if attr. name_or_empty ( ) == sym:: default_method_body_is_const {
23172345 errors:: UnusedNote :: DefaultMethodBodyConst
23182346 } else {
0 commit comments