@@ -3,7 +3,7 @@ use rustc_errors::Applicability;
3
3
use rustc_hir:: def_id:: DefId ;
4
4
use rustc_middle:: mir:: visit:: Visitor ;
5
5
use rustc_middle:: mir:: * ;
6
- use rustc_middle:: ty:: { self , EarlyBinder , GenericArgKind , PredicateKind , SubstsRef , Ty , TyCtxt } ;
6
+ use rustc_middle:: ty:: { self , EarlyBinder , PredicateKind , SubstsRef , Ty , TyCtxt } ;
7
7
use rustc_session:: lint:: builtin:: FUNCTION_ITEM_REFERENCES ;
8
8
use rustc_span:: { symbol:: sym, Span } ;
9
9
use rustc_target:: spec:: abi:: Abi ;
@@ -45,14 +45,12 @@ impl<'tcx> Visitor<'tcx> for FunctionItemRefChecker<'_, 'tcx> {
45
45
// Handle calls to `transmute`
46
46
if self . tcx . is_diagnostic_item ( sym:: transmute, def_id) {
47
47
let arg_ty = args[ 0 ] . ty ( self . body , self . tcx ) ;
48
- for generic_inner_ty in arg_ty. walk ( ) {
49
- if let GenericArgKind :: Type ( inner_ty) = generic_inner_ty. unpack ( ) {
50
- if let Some ( ( fn_id, fn_substs) ) =
51
- FunctionItemRefChecker :: is_fn_ref ( inner_ty)
52
- {
53
- let span = self . nth_arg_span ( & args, 0 ) ;
54
- self . emit_lint ( fn_id, fn_substs, source_info, span) ;
55
- }
48
+ for inner_ty in arg_ty. walk ( ) . filter_map ( |arg| arg. as_type ( ) ) {
49
+ if let Some ( ( fn_id, fn_substs) ) =
50
+ FunctionItemRefChecker :: is_fn_ref ( inner_ty)
51
+ {
52
+ let span = self . nth_arg_span ( & args, 0 ) ;
53
+ self . emit_lint ( fn_id, fn_substs, source_info, span) ;
56
54
}
57
55
}
58
56
} else {
@@ -82,24 +80,22 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
82
80
let arg_defs = self . tcx . fn_sig ( def_id) . subst_identity ( ) . skip_binder ( ) . inputs ( ) ;
83
81
for ( arg_num, arg_def) in arg_defs. iter ( ) . enumerate ( ) {
84
82
// For all types reachable from the argument type in the fn sig
85
- for generic_inner_ty in arg_def. walk ( ) {
86
- if let GenericArgKind :: Type ( inner_ty) = generic_inner_ty. unpack ( ) {
87
- // If the inner type matches the type bound by `Pointer`
88
- if inner_ty == bound_ty {
89
- // Do a substitution using the parameters from the callsite
90
- let subst_ty = EarlyBinder ( inner_ty) . subst ( self . tcx , substs_ref) ;
91
- if let Some ( ( fn_id, fn_substs) ) =
92
- FunctionItemRefChecker :: is_fn_ref ( subst_ty)
93
- {
94
- let mut span = self . nth_arg_span ( args, arg_num) ;
95
- if span. from_expansion ( ) {
96
- // The operand's ctxt wouldn't display the lint since it's inside a macro so
97
- // we have to use the callsite's ctxt.
98
- let callsite_ctxt = span. source_callsite ( ) . ctxt ( ) ;
99
- span = span. with_ctxt ( callsite_ctxt) ;
100
- }
101
- self . emit_lint ( fn_id, fn_substs, source_info, span) ;
83
+ for inner_ty in arg_def. walk ( ) . filter_map ( |arg| arg. as_type ( ) ) {
84
+ // If the inner type matches the type bound by `Pointer`
85
+ if inner_ty == bound_ty {
86
+ // Do a substitution using the parameters from the callsite
87
+ let subst_ty = EarlyBinder ( inner_ty) . subst ( self . tcx , substs_ref) ;
88
+ if let Some ( ( fn_id, fn_substs) ) =
89
+ FunctionItemRefChecker :: is_fn_ref ( subst_ty)
90
+ {
91
+ let mut span = self . nth_arg_span ( args, arg_num) ;
92
+ if span. from_expansion ( ) {
93
+ // The operand's ctxt wouldn't display the lint since it's inside a macro so
94
+ // we have to use the callsite's ctxt.
95
+ let callsite_ctxt = span. source_callsite ( ) . ctxt ( ) ;
96
+ span = span. with_ctxt ( callsite_ctxt) ;
102
97
}
98
+ self . emit_lint ( fn_id, fn_substs, source_info, span) ;
103
99
}
104
100
}
105
101
}
0 commit comments