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

ptr_arg triggers on &mut String despite clone_into #13308

Closed
ronnodas opened this issue Aug 26, 2024 · 3 comments · Fixed by #13313
Closed

ptr_arg triggers on &mut String despite clone_into #13308

ronnodas opened this issue Aug 26, 2024 · 3 comments · Fixed by #13313
Assignees
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

@ronnodas
Copy link

ronnodas commented Aug 26, 2024

Summary

If a &mut String argument is only used as the input to clone_into, then ptr_arg triggers erroneously.

Lint Name

ptr_arg

Reproducer

I tried this code:

fn foo(source: &str, destination: &mut String)  {
    source.clone_into(destination)
}

fn main() {
    foo("bar", &mut String::new());
}

I saw this happen:

warning: writing `&mut String` instead of `&mut str` involves a new object where a slice will do
 --> src/main.rs:1:35
  |
1 | fn foo(source: &str, destination: &mut String)  {
  |                                   ^^^^^^^^^^^ help: change this to: `&mut str`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
  = note: `#[warn(clippy::ptr_arg)]` on by default

I expected to see this happen:

Nothing

Version

rustc 1.80.1 (3f5fd8dd4 2024-08-06)
binary: rustc
commit-hash: 3f5fd8dd41153bc5fdca9427e9e05be2c767ba23
commit-date: 2024-08-06
host: x86_64-unknown-linux-gnu
release: 1.80.1
LLVM version: 18.1.7

Additional Labels

@rustbot label +I-suggestion-causes-error

@ronnodas ronnodas 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 Aug 26, 2024
@rustbot
Copy link
Collaborator

rustbot commented Aug 26, 2024

Error: Parsing relabel command in comment failed: ...' label +' | error: empty label at >| ' I-suggest'...

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Aug 26, 2024
@y21 y21 self-assigned this Aug 26, 2024
@bors bors closed this as completed in 2536745 Sep 13, 2024
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.

5 participants
@ronnodas @y21 @rustbot and others