@@ -3,7 +3,7 @@ use rustc_errors::Applicability;
33use rustc_hir:: def_id:: DefId ;
44use rustc_middle:: mir:: visit:: Visitor ;
55use 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 } ;
77use rustc_session:: lint:: builtin:: FUNCTION_ITEM_REFERENCES ;
88use rustc_span:: { symbol:: sym, Span } ;
99use rustc_target:: spec:: abi:: Abi ;
@@ -45,14 +45,12 @@ impl<'tcx> Visitor<'tcx> for FunctionItemRefChecker<'_, 'tcx> {
4545 // Handle calls to `transmute`
4646 if self . tcx . is_diagnostic_item ( sym:: transmute, def_id) {
4747 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. unpack ( ) . 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) ;
5654 }
5755 }
5856 } else {
@@ -82,24 +80,22 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
8280 let arg_defs = self . tcx . fn_sig ( def_id) . subst_identity ( ) . skip_binder ( ) . inputs ( ) ;
8381 for ( arg_num, arg_def) in arg_defs. iter ( ) . enumerate ( ) {
8482 // 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. unpack ( ) . 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) ;
10297 }
98+ self . emit_lint ( fn_id, fn_substs, source_info, span) ;
10399 }
104100 }
105101 }
0 commit comments