@@ -153,7 +153,9 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
153
153
cx. tcx . fn_sig ( item. def_id ) . skip_binder ( ) . inputs ( ) ,
154
154
sig. decl . inputs ,
155
155
& [ ] ,
156
- ) {
156
+ )
157
+ . filter ( |arg| arg. mutability ( ) == Mutability :: Not )
158
+ {
157
159
span_lint_and_sugg (
158
160
cx,
159
161
PTR_ARG ,
@@ -170,10 +172,10 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
170
172
fn check_body ( & mut self , cx : & LateContext < ' tcx > , body : & ' tcx Body < ' _ > ) {
171
173
let hir = cx. tcx . hir ( ) ;
172
174
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 ( ) {
174
176
Some ( ( _, Node :: Item ( i) ) ) => {
175
177
if let ItemKind :: Fn ( sig, ..) = & i. kind {
176
- ( i. def_id , sig. decl )
178
+ ( i. def_id , sig. decl , false )
177
179
} else {
178
180
return ;
179
181
}
@@ -185,14 +187,14 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
185
187
return ;
186
188
}
187
189
if let ImplItemKind :: Fn ( sig, _) = & i. kind {
188
- ( i. def_id , sig. decl )
190
+ ( i. def_id , sig. decl , false )
189
191
} else {
190
192
return ;
191
193
}
192
194
} ,
193
195
Some ( ( _, Node :: TraitItem ( i) ) ) => {
194
196
if let TraitItemKind :: Fn ( sig, _) = & i. kind {
195
- ( i. def_id , sig. decl )
197
+ ( i. def_id , sig. decl , true )
196
198
} else {
197
199
return ;
198
200
}
@@ -202,7 +204,9 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
202
204
203
205
check_mut_from_ref ( cx, decl) ;
204
206
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 ( ) ;
206
210
let results = check_ptr_arg_usage ( cx, body, & lint_args) ;
207
211
208
212
for ( result, args) in results. iter ( ) . zip ( lint_args. iter ( ) ) . filter ( |( r, _) | !r. skip ) {
@@ -318,6 +322,10 @@ impl PtrArg<'_> {
318
322
self . deref_ty. argless_str( ) ,
319
323
)
320
324
}
325
+
326
+ fn mutability ( & self ) -> Mutability {
327
+ self . ref_prefix . mutability
328
+ }
321
329
}
322
330
323
331
struct RefPrefix {
0 commit comments