@@ -153,7 +153,9 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
153153 cx. tcx . fn_sig ( item. def_id ) . skip_binder ( ) . inputs ( ) ,
154154 sig. decl . inputs ,
155155 & [ ] ,
156- ) {
156+ )
157+ . filter ( |arg| arg. mutability ( ) == Mutability :: Not )
158+ {
157159 span_lint_and_sugg (
158160 cx,
159161 PTR_ARG ,
@@ -170,10 +172,10 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
170172 fn check_body ( & mut self , cx : & LateContext < ' tcx > , body : & ' tcx Body < ' _ > ) {
171173 let hir = cx. tcx . hir ( ) ;
172174 let mut parents = hir. parent_iter ( body. value . hir_id ) ;
173- let ( item_id, decl) = match parents. next ( ) {
175+ let ( item_id, decl, is_trait_item ) = match parents. next ( ) {
174176 Some ( ( _, Node :: Item ( i) ) ) => {
175177 if let ItemKind :: Fn ( sig, ..) = & i. kind {
176- ( i. def_id , sig. decl )
178+ ( i. def_id , sig. decl , false )
177179 } else {
178180 return ;
179181 }
@@ -185,14 +187,14 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
185187 return ;
186188 }
187189 if let ImplItemKind :: Fn ( sig, _) = & i. kind {
188- ( i. def_id , sig. decl )
190+ ( i. def_id , sig. decl , false )
189191 } else {
190192 return ;
191193 }
192194 } ,
193195 Some ( ( _, Node :: TraitItem ( i) ) ) => {
194196 if let TraitItemKind :: Fn ( sig, _) = & i. kind {
195- ( i. def_id , sig. decl )
197+ ( i. def_id , sig. decl , true )
196198 } else {
197199 return ;
198200 }
@@ -202,7 +204,9 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
202204
203205 check_mut_from_ref ( cx, decl) ;
204206 let sig = cx. tcx . fn_sig ( item_id) . skip_binder ( ) ;
205- let lint_args: Vec < _ > = check_fn_args ( cx, sig. inputs ( ) , decl. inputs , body. params ) . collect ( ) ;
207+ let lint_args: Vec < _ > = check_fn_args ( cx, sig. inputs ( ) , decl. inputs , body. params )
208+ . filter ( |arg| !is_trait_item || arg. mutability ( ) == Mutability :: Not )
209+ . collect ( ) ;
206210 let results = check_ptr_arg_usage ( cx, body, & lint_args) ;
207211
208212 for ( result, args) in results. iter ( ) . zip ( lint_args. iter ( ) ) . filter ( |( r, _) | !r. skip ) {
@@ -318,6 +322,10 @@ impl PtrArg<'_> {
318322 self . deref_ty. argless_str( ) ,
319323 )
320324 }
325+
326+ fn mutability ( & self ) -> Mutability {
327+ self . ref_prefix . mutability
328+ }
321329}
322330
323331struct RefPrefix {
0 commit comments