@@ -976,17 +976,21 @@ declare_lint! {
976976 /// ```rust
977977 /// #[unsafe(no_mangle)]
978978 /// fn foo<T>(t: T) {}
979+ ///
980+ /// #[unsafe(export_name = "bar")]
981+ /// fn bar<T>(t: T) {}
979982 /// ```
980983 ///
981984 /// {{produces}}
982985 ///
983986 /// ### Explanation
984987 ///
985988 /// A function with generics must have its symbol mangled to accommodate
986- /// the generic parameter. The [`no_mangle` attribute] has no effect in
987- /// this situation, and should be removed.
989+ /// the generic parameter. The [`no_mangle`] and [`export_name`] attributes
990+ /// have no effect in this situation, and should be removed.
988991 ///
989- /// [`no_mangle` attribute]: https://doc.rust-lang.org/reference/abi.html#the-no_mangle-attribute
992+ /// [`no_mangle`]: https://doc.rust-lang.org/reference/abi.html#the-no_mangle-attribute
993+ /// [`export_name`]: https://doc.rust-lang.org/reference/abi.html#the-export_name-attribute
990994 NO_MANGLE_GENERIC_ITEMS ,
991995 Warn ,
992996 "generic items must be mangled"
@@ -997,7 +1001,7 @@ declare_lint_pass!(InvalidNoMangleItems => [NO_MANGLE_CONST_ITEMS, NO_MANGLE_GEN
9971001impl < ' tcx > LateLintPass < ' tcx > for InvalidNoMangleItems {
9981002 fn check_item ( & mut self , cx : & LateContext < ' _ > , it : & hir:: Item < ' _ > ) {
9991003 let attrs = cx. tcx . hir_attrs ( it. hir_id ( ) ) ;
1000- let check_no_mangle_on_generic_fn = |no_mangle_attr : & hir:: Attribute ,
1004+ let check_no_mangle_on_generic_fn = |attr : & hir:: Attribute ,
10011005 impl_generics : Option < & hir:: Generics < ' _ > > ,
10021006 generics : & hir:: Generics < ' _ > ,
10031007 span| {
@@ -1010,7 +1014,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
10101014 cx. emit_span_lint (
10111015 NO_MANGLE_GENERIC_ITEMS ,
10121016 span,
1013- BuiltinNoMangleGeneric { suggestion : no_mangle_attr . span ( ) } ,
1017+ BuiltinNoMangleGeneric { suggestion : attr . span ( ) } ,
10141018 ) ;
10151019 break ;
10161020 }
@@ -1019,8 +1023,10 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
10191023 } ;
10201024 match it. kind {
10211025 hir:: ItemKind :: Fn { generics, .. } => {
1022- if let Some ( no_mangle_attr) = attr:: find_by_name ( attrs, sym:: no_mangle) {
1023- check_no_mangle_on_generic_fn ( no_mangle_attr, None , generics, it. span ) ;
1026+ if let Some ( attr) = attr:: find_by_name ( attrs, sym:: export_name)
1027+ . or_else ( || attr:: find_by_name ( attrs, sym:: no_mangle) )
1028+ {
1029+ check_no_mangle_on_generic_fn ( attr, None , generics, it. span ) ;
10241030 }
10251031 }
10261032 hir:: ItemKind :: Const ( ..) => {
@@ -1048,11 +1054,12 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
10481054 hir:: ItemKind :: Impl ( hir:: Impl { generics, items, .. } ) => {
10491055 for it in * items {
10501056 if let hir:: AssocItemKind :: Fn { .. } = it. kind {
1051- if let Some ( no_mangle_attr) =
1052- attr:: find_by_name ( cx. tcx . hir_attrs ( it. id . hir_id ( ) ) , sym:: no_mangle)
1057+ let attrs = cx. tcx . hir_attrs ( it. id . hir_id ( ) ) ;
1058+ if let Some ( attr) = attr:: find_by_name ( attrs, sym:: export_name)
1059+ . or_else ( || attr:: find_by_name ( attrs, sym:: no_mangle) )
10531060 {
10541061 check_no_mangle_on_generic_fn (
1055- no_mangle_attr ,
1062+ attr ,
10561063 Some ( generics) ,
10571064 cx. tcx . hir_get_generics ( it. id . owner_id . def_id ) . unwrap ( ) ,
10581065 it. span ,
0 commit comments