Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in ptr_arg on &mut Vec in trait #8366

Closed
dtolnay opened this issue Jan 29, 2022 · 1 comment · Fixed by #8369
Closed

Regression in ptr_arg on &mut Vec in trait #8366

dtolnay opened this issue Jan 29, 2022 · 1 comment · Fixed by #8369
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@dtolnay
Copy link
Member

dtolnay commented Jan 29, 2022

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

@dtolnay dtolnay added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jan 29, 2022
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Jan 29, 2022
@dtolnay
Copy link
Member Author

dtolnay commented Jan 29, 2022

Mentioning @Jarcho @flip1995 because you touched this lint recently.

dtolnay added a commit to serde-rs/json that referenced this issue Jan 29, 2022
rust-lang/rust-clippy#8366

    error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
      --> src/read.rs:65:45
       |
    65 |     fn parse_str<'s>(&'s mut self, scratch: &'s mut Vec<u8>) -> Result<Reference<'de, 's, str>>;
       |                                             ^^^^^^^^^^^^^^^ help: change this to: `&'s mut [u8]`
       |
       = note: `-D clippy::ptr-arg` implied by `-D clippy::all`
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

    error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
      --> src/read.rs:76:18
       |
    76 |         scratch: &'s mut Vec<u8>,
       |                  ^^^^^^^^^^^^^^^ help: change this to: `&'s mut [u8]`
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
@bors bors closed this as completed in 7bb69c0 Jan 31, 2022
ronaldslc pushed a commit to ronaldslc/serde-json that referenced this issue Dec 3, 2022
rust-lang/rust-clippy#8366

    error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
      --> src/read.rs:65:45
       |
    65 |     fn parse_str<'s>(&'s mut self, scratch: &'s mut Vec<u8>) -> Result<Reference<'de, 's, str>>;
       |                                             ^^^^^^^^^^^^^^^ help: change this to: `&'s mut [u8]`
       |
       = note: `-D clippy::ptr-arg` implied by `-D clippy::all`
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

    error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
      --> src/read.rs:76:18
       |
    76 |         scratch: &'s mut Vec<u8>,
       |                  ^^^^^^^^^^^^^^^ help: change this to: `&'s mut [u8]`
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants