@@ -42,54 +42,28 @@ impl<'tcx> Visitor<'tcx> for FunctionItemRefChecker<'_, 'tcx> {
42
42
} = & terminator. kind
43
43
{
44
44
let source_info = * self . body . source_info ( location) ;
45
- // Only handle function calls outside macros
46
- if !source_info. span . from_expansion ( ) {
47
- let func_ty = func. ty ( self . body , self . tcx ) ;
48
- if let ty:: FnDef ( def_id, substs_ref) = * func_ty. kind ( ) {
49
- // Handle calls to `transmute`
50
- if self . tcx . is_diagnostic_item ( sym:: transmute, def_id) {
51
- let arg_ty = args[ 0 ] . ty ( self . body , self . tcx ) ;
52
- for generic_inner_ty in arg_ty. walk ( ) {
53
- if let GenericArgKind :: Type ( inner_ty) = generic_inner_ty. unpack ( ) {
54
- if let Some ( ( fn_id, fn_substs) ) =
55
- FunctionItemRefChecker :: is_fn_ref ( inner_ty)
56
- {
57
- let span = self . nth_arg_span ( & args, 0 ) ;
58
- self . emit_lint ( fn_id, fn_substs, source_info, span) ;
59
- }
45
+ let func_ty = func. ty ( self . body , self . tcx ) ;
46
+ if let ty:: FnDef ( def_id, substs_ref) = * func_ty. kind ( ) {
47
+ // Handle calls to `transmute`
48
+ if self . tcx . is_diagnostic_item ( sym:: transmute, def_id) {
49
+ let arg_ty = args[ 0 ] . ty ( self . body , self . tcx ) ;
50
+ for generic_inner_ty in arg_ty. walk ( ) {
51
+ if let GenericArgKind :: Type ( inner_ty) = generic_inner_ty. unpack ( ) {
52
+ if let Some ( ( fn_id, fn_substs) ) =
53
+ FunctionItemRefChecker :: is_fn_ref ( inner_ty)
54
+ {
55
+ let span = self . nth_arg_span ( & args, 0 ) ;
56
+ self . emit_lint ( fn_id, fn_substs, source_info, span) ;
60
57
}
61
58
}
62
- } else {
63
- self . check_bound_args ( def_id, substs_ref, & args, source_info) ;
64
59
}
60
+ } else {
61
+ self . check_bound_args ( def_id, substs_ref, & args, source_info) ;
65
62
}
66
63
}
67
64
}
68
65
self . super_terminator ( terminator, location) ;
69
66
}
70
-
71
- /// Emits a lint for function references formatted with `fmt::Pointer::fmt` by macros. These
72
- /// cases are handled as operands instead of call terminators to avoid any dependence on
73
- /// unstable, internal formatting details like whether `fmt` is called directly or not.
74
- fn visit_operand ( & mut self , operand : & Operand < ' tcx > , location : Location ) {
75
- let source_info = * self . body . source_info ( location) ;
76
- if source_info. span . from_expansion ( ) {
77
- let op_ty = operand. ty ( self . body , self . tcx ) ;
78
- if let ty:: FnDef ( def_id, substs_ref) = * op_ty. kind ( ) {
79
- if self . tcx . is_diagnostic_item ( sym:: pointer_trait_fmt, def_id) {
80
- let param_ty = substs_ref. type_at ( 0 ) ;
81
- if let Some ( ( fn_id, fn_substs) ) = FunctionItemRefChecker :: is_fn_ref ( param_ty) {
82
- // The operand's ctxt wouldn't display the lint since it's inside a macro so
83
- // we have to use the callsite's ctxt.
84
- let callsite_ctxt = source_info. span . source_callsite ( ) . ctxt ( ) ;
85
- let span = source_info. span . with_ctxt ( callsite_ctxt) ;
86
- self . emit_lint ( fn_id, fn_substs, source_info, span) ;
87
- }
88
- }
89
- }
90
- }
91
- self . super_operand ( operand, location) ;
92
- }
93
67
}
94
68
95
69
impl < ' tcx > FunctionItemRefChecker < ' _ , ' tcx > {
@@ -119,7 +93,13 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
119
93
if let Some ( ( fn_id, fn_substs) ) =
120
94
FunctionItemRefChecker :: is_fn_ref ( subst_ty)
121
95
{
122
- let span = self . nth_arg_span ( args, arg_num) ;
96
+ let mut span = self . nth_arg_span ( args, arg_num) ;
97
+ if span. from_expansion ( ) {
98
+ // The operand's ctxt wouldn't display the lint since it's inside a macro so
99
+ // we have to use the callsite's ctxt.
100
+ let callsite_ctxt = span. source_callsite ( ) . ctxt ( ) ;
101
+ span = span. with_ctxt ( callsite_ctxt) ;
102
+ }
123
103
self . emit_lint ( fn_id, fn_substs, source_info, span) ;
124
104
}
125
105
}
0 commit comments