@@ -28,7 +28,7 @@ use rustc_hir as hir;
28
28
use rustc_hir:: def:: { DefKind , Res } ;
29
29
use rustc_hir:: def_id:: { CRATE_DEF_ID , DefId , LocalDefId } ;
30
30
use rustc_hir:: intravisit:: FnKind as HirFnKind ;
31
- use rustc_hir:: { Body , FnDecl , GenericParamKind , PatKind , PredicateOrigin } ;
31
+ use rustc_hir:: { Body , FnDecl , PatKind , PredicateOrigin } ;
32
32
use rustc_middle:: bug;
33
33
use rustc_middle:: lint:: LevelAndSource ;
34
34
use rustc_middle:: ty:: layout:: LayoutOf ;
@@ -952,36 +952,34 @@ declare_lint! {
952
952
953
953
declare_lint_pass ! ( InvalidNoMangleItems => [ NO_MANGLE_CONST_ITEMS , NO_MANGLE_GENERIC_ITEMS ] ) ;
954
954
955
+ impl InvalidNoMangleItems {
956
+ fn check_no_mangle_on_generic_fn (
957
+ & self ,
958
+ cx : & LateContext < ' _ > ,
959
+ attr_span : Span ,
960
+ def_id : LocalDefId ,
961
+ ) {
962
+ let generics = cx. tcx . generics_of ( def_id) ;
963
+ if generics. requires_monomorphization ( cx. tcx ) {
964
+ cx. emit_span_lint (
965
+ NO_MANGLE_GENERIC_ITEMS ,
966
+ cx. tcx . def_span ( def_id) ,
967
+ BuiltinNoMangleGeneric { suggestion : attr_span } ,
968
+ ) ;
969
+ }
970
+ }
971
+ }
972
+
955
973
impl < ' tcx > LateLintPass < ' tcx > for InvalidNoMangleItems {
956
974
fn check_item ( & mut self , cx : & LateContext < ' _ > , it : & hir:: Item < ' _ > ) {
957
975
let attrs = cx. tcx . hir_attrs ( it. hir_id ( ) ) ;
958
- let check_no_mangle_on_generic_fn = |attr_span : Span ,
959
- impl_generics : Option < & hir:: Generics < ' _ > > ,
960
- generics : & hir:: Generics < ' _ > ,
961
- span| {
962
- for param in
963
- generics. params . iter ( ) . chain ( impl_generics. map ( |g| g. params ) . into_iter ( ) . flatten ( ) )
964
- {
965
- match param. kind {
966
- GenericParamKind :: Lifetime { .. } => { }
967
- GenericParamKind :: Type { .. } | GenericParamKind :: Const { .. } => {
968
- cx. emit_span_lint (
969
- NO_MANGLE_GENERIC_ITEMS ,
970
- span,
971
- BuiltinNoMangleGeneric { suggestion : attr_span } ,
972
- ) ;
973
- break ;
974
- }
975
- }
976
- }
977
- } ;
978
976
match it. kind {
979
- hir:: ItemKind :: Fn { generics , .. } => {
977
+ hir:: ItemKind :: Fn { .. } => {
980
978
if let Some ( attr_span) =
981
979
find_attr ! ( attrs, AttributeKind :: ExportName { span, ..} => * span)
982
980
. or_else ( || find_attr ! ( attrs, AttributeKind :: NoMangle ( span) => * span) )
983
981
{
984
- check_no_mangle_on_generic_fn ( attr_span , None , generics , it. span ) ;
982
+ self . check_no_mangle_on_generic_fn ( cx , attr_span , it. owner_id . def_id ) ;
985
983
}
986
984
}
987
985
hir:: ItemKind :: Const ( ..) => {
@@ -1006,24 +1004,19 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
1006
1004
) ;
1007
1005
}
1008
1006
}
1009
- hir:: ItemKind :: Impl ( hir:: Impl { generics, items, .. } ) => {
1010
- for it in * items {
1011
- if let hir:: AssocItemKind :: Fn { .. } = it. kind {
1012
- let attrs = cx. tcx . hir_attrs ( it. id . hir_id ( ) ) ;
1013
- if let Some ( attr_span) =
1014
- find_attr ! ( attrs, AttributeKind :: ExportName { span, ..} => * span)
1015
- . or_else (
1016
- || find_attr ! ( attrs, AttributeKind :: NoMangle ( span) => * span) ,
1017
- )
1018
- {
1019
- check_no_mangle_on_generic_fn (
1020
- attr_span,
1021
- Some ( generics) ,
1022
- cx. tcx . hir_get_generics ( it. id . owner_id . def_id ) . unwrap ( ) ,
1023
- it. span ,
1024
- ) ;
1025
- }
1026
- }
1007
+ _ => { }
1008
+ }
1009
+ }
1010
+
1011
+ fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , it : & hir:: ImplItem < ' _ > ) {
1012
+ let attrs = cx. tcx . hir_attrs ( it. hir_id ( ) ) ;
1013
+ match it. kind {
1014
+ hir:: ImplItemKind :: Fn { .. } => {
1015
+ if let Some ( attr_span) =
1016
+ find_attr ! ( attrs, AttributeKind :: ExportName { span, ..} => * span)
1017
+ . or_else ( || find_attr ! ( attrs, AttributeKind :: NoMangle ( span) => * span) )
1018
+ {
1019
+ self . check_no_mangle_on_generic_fn ( cx, attr_span, it. owner_id . def_id ) ;
1027
1020
}
1028
1021
}
1029
1022
_ => { }
0 commit comments