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