@@ -27,6 +27,7 @@ use rustc_middle::traits::ObligationCause;
2727use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
2828use rustc_middle:: ty:: { self , TyCtxt , TypingMode } ;
2929use rustc_middle:: { bug, span_bug} ;
30+ use rustc_session:: config:: CrateType ;
3031use rustc_session:: lint:: builtin:: {
3132 CONFLICTING_REPR_HINTS , INVALID_DOC_ATTRIBUTES , INVALID_MACRO_EXPORT_ARGUMENTS ,
3233 UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES , UNUSED_ATTRIBUTES ,
@@ -2271,6 +2272,33 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22712272 && item. path == sym:: reason
22722273 {
22732274 errors:: UnusedNote :: NoLints { name : attr. name_or_empty ( ) }
2275+ } else if matches ! (
2276+ attr. name_or_empty( ) ,
2277+ sym:: allow | sym:: warn | sym:: deny | sym:: forbid | sym:: expect
2278+ ) && let Some ( meta) = attr. meta_item_list ( )
2279+ && meta. iter ( ) . any ( |meta| {
2280+ meta. meta_item ( ) . map_or ( false , |item| item. path == sym:: linker_messages)
2281+ } )
2282+ {
2283+ if hir_id != CRATE_HIR_ID {
2284+ let err = match attr. style {
2285+ ast:: AttrStyle :: Outer => errors:: OuterCrateLevelAttr ,
2286+ ast:: AttrStyle :: Inner => errors:: OuterCrateLevelAttr ,
2287+ } ;
2288+ self . tcx . emit_node_span_lint ( UNUSED_ATTRIBUTES , hir_id, attr. span , err) ;
2289+ return ;
2290+ } else {
2291+ let never_needs_link = self
2292+ . tcx
2293+ . crate_types ( )
2294+ . iter ( )
2295+ . all ( |kind| matches ! ( kind, CrateType :: Rlib | CrateType :: Staticlib ) ) ;
2296+ if never_needs_link {
2297+ errors:: UnusedNote :: LinkerWarningsBinaryCrateOnly
2298+ } else {
2299+ return ;
2300+ }
2301+ }
22742302 } else if attr. name_or_empty ( ) == sym:: default_method_body_is_const {
22752303 errors:: UnusedNote :: DefaultMethodBodyConst
22762304 } else {
0 commit comments