Skip to content

Regression in ptr_arg on &mut Vec in trait #8366

Closed
@dtolnay

Description

@dtolnay

Summary

&mut Vec<T> in a trait method signature used to correctly not trigger ptr_arg. As of the most recent nightly, it's started falsely positiving. The same type in a non-trait function does not seem to be affected.

Lint Name

ptr_arg

Reproducer

trait Trait {
    fn f(vec: &mut Vec<i32>);
}

impl Trait for i32 {
    fn f(vec: &mut Vec<i32>) {
        vec.push(2);
    }
}

fn main() {
    let mut vec = Vec::new();
    i32::f(&mut vec);
    println!("{:?}", vec);
}
warning: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
 --> src/main.rs:2:15
  |
2 |     fn f(vec: &mut Vec<i32>);
  |               ^^^^^^^^^^^^^ help: change this to: `&mut [i32]`
  |
  = note: `#[warn(clippy::ptr_arg)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

Version

rustc 1.60.0-nightly (e0a55f449 2022-01-28)
binary: rustc
commit-hash: e0a55f4491a729bffc63b402ba903d90858c806b
commit-date: 2022-01-28
host: x86_64-unknown-linux-gnu
release: 1.60.0-nightly
LLVM version: 13.0.0

Additional Labels

@rustbot label +I-suggestion-causes-error

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions