@@ -166,6 +166,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
166166 & Attribute :: Parsed ( AttributeKind :: MayDangle ( attr_span) ) => {
167167 self . check_may_dangle ( hir_id, attr_span)
168168 }
169+ Attribute :: Parsed ( AttributeKind :: NoMangle ( attr_span) ) => {
170+ self . check_no_mangle ( hir_id, * attr_span, span, target)
171+ }
169172 Attribute :: Unparsed ( _) => {
170173 match attr. path ( ) . as_slice ( ) {
171174 [ sym:: diagnostic, sym:: do_not_recommend, ..] => {
@@ -252,7 +255,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
252255 [ sym:: link, ..] => self . check_link ( hir_id, attr, span, target) ,
253256 [ sym:: link_name, ..] => self . check_link_name ( hir_id, attr, span, target) ,
254257 [ sym:: link_section, ..] => self . check_link_section ( hir_id, attr, span, target) ,
255- [ sym:: no_mangle, ..] => self . check_no_mangle ( hir_id, attr, span, target) ,
256258 [ sym:: macro_use, ..] | [ sym:: macro_escape, ..] => {
257259 self . check_macro_use ( hir_id, attr, target)
258260 }
@@ -690,6 +692,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
690692 AttributeKind :: Deprecation { .. }
691693 | AttributeKind :: Repr { .. }
692694 | AttributeKind :: Align { .. }
695+ | AttributeKind :: NoMangle ( ..)
693696 | AttributeKind :: Cold ( ..) ,
694697 ) => {
695698 continue ;
@@ -1938,7 +1941,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
19381941 }
19391942
19401943 /// Checks if `#[no_mangle]` is applied to a function or static.
1941- fn check_no_mangle ( & self , hir_id : HirId , attr : & Attribute , span : Span , target : Target ) {
1944+ fn check_no_mangle ( & self , hir_id : HirId , attr_span : Span , span : Span , target : Target ) {
19421945 match target {
19431946 Target :: Static | Target :: Fn => { }
19441947 Target :: Method ( ..) if self . is_impl_item ( hir_id) => { }
@@ -1947,7 +1950,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
19471950 // erroneously allowed it and some crates used it accidentally, to be compatible
19481951 // with crates depending on them, we can't throw an error here.
19491952 Target :: Field | Target :: Arm | Target :: MacroDef => {
1950- self . inline_attr_str_error_with_macro_def ( hir_id, attr . span ( ) , "no_mangle" ) ;
1953+ self . inline_attr_str_error_with_macro_def ( hir_id, attr_span , "no_mangle" ) ;
19511954 }
19521955 // FIXME: #[no_mangle] was previously allowed on non-functions/statics, this should be an error
19531956 // The error should specify that the item that is wrong is specifically a *foreign* fn/static
@@ -1961,8 +1964,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
19611964 self . tcx . emit_node_span_lint (
19621965 UNUSED_ATTRIBUTES ,
19631966 hir_id,
1964- attr . span ( ) ,
1965- errors:: NoMangleForeign { span, attr_span : attr . span ( ) , foreign_item_kind } ,
1967+ attr_span ,
1968+ errors:: NoMangleForeign { span, attr_span, foreign_item_kind } ,
19661969 ) ;
19671970 }
19681971 _ => {
@@ -1971,7 +1974,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
19711974 self . tcx . emit_node_span_lint (
19721975 UNUSED_ATTRIBUTES ,
19731976 hir_id,
1974- attr . span ( ) ,
1977+ attr_span ,
19751978 errors:: NoMangle { span } ,
19761979 ) ;
19771980 }
0 commit comments