@@ -25,6 +25,7 @@ use rustc_middle::traits::ObligationCause;
25
25
use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
26
26
use rustc_middle:: ty:: { self , TyCtxt , TypingMode } ;
27
27
use rustc_middle:: { bug, span_bug} ;
28
+ use rustc_session:: config:: CrateType ;
28
29
use rustc_session:: lint:: builtin:: {
29
30
CONFLICTING_REPR_HINTS , INVALID_DOC_ATTRIBUTES , INVALID_MACRO_EXPORT_ARGUMENTS ,
30
31
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES , UNUSED_ATTRIBUTES ,
@@ -2328,6 +2329,33 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2328
2329
&& item. path == sym:: reason
2329
2330
{
2330
2331
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
+ }
2331
2359
} else if attr. name_or_empty ( ) == sym:: default_method_body_is_const {
2332
2360
errors:: UnusedNote :: DefaultMethodBodyConst
2333
2361
} else {
0 commit comments