-
Notifications
You must be signed in to change notification settings - Fork 2k
ptr_arg triggers on &mut String despite clone_into #13308
Copy link
Copy link
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Type
Fields
Give feedbackNo fields configured for issues without a type.