@@ -77,51 +77,49 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
7777 args : & [ Spanned < Operand < ' tcx > > ] ,
7878 source_info : SourceInfo ,
7979 ) {
80- let param_env = self . tcx . param_env ( def_id) ;
81- for bound in param_env. caller_bounds ( ) . all_clauses ( self . tcx ) . iter ( ) {
82- if let Some ( bound_ty) = self . is_pointer_trait ( bound) {
83- // Get the argument types as they appear in the function signature.
84- let arg_defs =
85- self . tcx . fn_sig ( def_id) . instantiate_identity ( ) . skip_binder ( ) . inputs ( ) ;
86- for ( arg_num, arg_def) in arg_defs. iter ( ) . enumerate ( ) {
87- // For all types reachable from the argument type in the fn sig
88- for inner_ty in arg_def. walk ( ) . filter_map ( |arg| arg. as_type ( ) ) {
89- // If the inner type matches the type bound by `Pointer`
90- if inner_ty == bound_ty {
91- // Do an instantiation using the parameters from the callsite
92- let instantiated_ty = EarlyBinder :: bind ( self . tcx , inner_ty)
93- . instantiate ( self . tcx , args_ref)
94- . skip_norm_wip ( ) ;
95- if let Some ( ( fn_id, fn_args) ) =
96- FunctionItemRefChecker :: is_fn_ref ( instantiated_ty)
97- {
98- let mut span = self . nth_arg_span ( args, arg_num) ;
99- if span. from_expansion ( ) {
100- // The operand's ctxt wouldn't display the lint since it's
101- // inside a macro so we have to use the callsite's ctxt.
102- let callsite_ctxt = span. source_callsite ( ) . ctxt ( ) ;
103- span = span. with_ctxt ( callsite_ctxt) ;
104- }
105- self . emit_lint ( fn_id, fn_args, source_info, span) ;
80+ let param_env: ty:: ParamEnv < ' tcx > = self . tcx . param_env ( def_id) ;
81+ let Some ( pointer_trait) = self . tcx . get_diagnostic_item ( sym:: Pointer ) else {
82+ return ;
83+ } ;
84+
85+ for bound in param_env
86+ . caller_bounds ( )
87+ . trait_clauses ( self . tcx )
88+ . with_polarity ( ty:: ClausePolarity :: Positive )
89+ . for_trait ( pointer_trait)
90+ . iter ( )
91+ {
92+ let bound_ty = bound. self_ty ( ) . skip_binder ( ) ;
93+
94+ // Get the argument types as they appear in the function signature.
95+ let arg_defs = self . tcx . fn_sig ( def_id) . instantiate_identity ( ) . skip_binder ( ) . inputs ( ) ;
96+ for ( arg_num, arg_def) in arg_defs. iter ( ) . enumerate ( ) {
97+ // For all types reachable from the argument type in the fn sig
98+ for inner_ty in arg_def. walk ( ) . filter_map ( |arg| arg. as_type ( ) ) {
99+ // If the inner type matches the type bound by `Pointer`
100+ if inner_ty == bound_ty {
101+ // Do an instantiation using the parameters from the callsite
102+ let instantiated_ty = EarlyBinder :: bind ( self . tcx , inner_ty)
103+ . instantiate ( self . tcx , args_ref)
104+ . skip_norm_wip ( ) ;
105+ if let Some ( ( fn_id, fn_args) ) =
106+ FunctionItemRefChecker :: is_fn_ref ( instantiated_ty)
107+ {
108+ let mut span = self . nth_arg_span ( args, arg_num) ;
109+ if span. from_expansion ( ) {
110+ // The operand's ctxt wouldn't display the lint since it's
111+ // inside a macro so we have to use the callsite's ctxt.
112+ let callsite_ctxt = span. source_callsite ( ) . ctxt ( ) ;
113+ span = span. with_ctxt ( callsite_ctxt) ;
106114 }
115+ self . emit_lint ( fn_id, fn_args, source_info, span) ;
107116 }
108117 }
109118 }
110119 }
111120 }
112121 }
113122
114- /// If the given predicate is the trait `fmt::Pointer`, returns the bound parameter type.
115- fn is_pointer_trait ( & self , bound : ty:: Clause < ' tcx > ) -> Option < Ty < ' tcx > > {
116- if let ty:: ClauseKind :: Trait ( predicate) = bound. kind ( ) . skip_binder ( ) {
117- self . tcx
118- . is_diagnostic_item ( sym:: Pointer , predicate. def_id ( ) )
119- . then ( || predicate. trait_ref . self_ty ( ) )
120- } else {
121- None
122- }
123- }
124-
125123 /// If a type is a reference or raw pointer to the anonymous type of a function definition,
126124 /// returns that function's `DefId` and `GenericArgs`.
127125 fn is_fn_ref ( ty : Ty < ' tcx > ) -> Option < ( DefId , GenericArgs < ' tcx > ) > {
0 commit comments