@@ -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 ,
@@ -2270,6 +2271,33 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22702271 && item. path == sym:: reason
22712272 {
22722273 errors:: UnusedNote :: NoLints { name : attr. name_or_empty ( ) }
2274+ } else if matches ! (
2275+ attr. name_or_empty( ) ,
2276+ sym:: allow | sym:: warn | sym:: deny | sym:: forbid | sym:: expect
2277+ ) && let Some ( meta) = attr. meta_item_list ( )
2278+ && meta. iter ( ) . any ( |meta| {
2279+ meta. meta_item ( ) . map_or ( false , |item| item. path == sym:: linker_messages)
2280+ } )
2281+ {
2282+ if hir_id != CRATE_HIR_ID {
2283+ let err = match attr. style {
2284+ ast:: AttrStyle :: Outer => errors:: OuterCrateLevelAttr ,
2285+ ast:: AttrStyle :: Inner => errors:: OuterCrateLevelAttr ,
2286+ } ;
2287+ self . tcx . emit_node_span_lint ( UNUSED_ATTRIBUTES , hir_id, attr. span , err) ;
2288+ return ;
2289+ } else {
2290+ let never_needs_link = self
2291+ . tcx
2292+ . crate_types ( )
2293+ . iter ( )
2294+ . all ( |kind| matches ! ( kind, CrateType :: Rlib | CrateType :: Staticlib ) ) ;
2295+ if never_needs_link {
2296+ errors:: UnusedNote :: LinkerWarningsBinaryCrateOnly
2297+ } else {
2298+ return ;
2299+ }
2300+ }
22732301 } else if attr. name_or_empty ( ) == sym:: default_method_body_is_const {
22742302 errors:: UnusedNote :: DefaultMethodBodyConst
22752303 } else {
0 commit comments