-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
ptr_arg
does not recognize ToOwned::clone_into()
as a call that requires &mut String
or &mut Vec<T>
, and incorrectly suggests changing to &mut str
or &mut [T]
.
Lint Name
ptr_arg
Reproducer
I tried this code:
pub fn t1(mut_string: &mut String, ref_str: &str) {
ref_str.clone_into(mut_string);
}
pub fn t2(mut_vec: &mut Vec<u8>, ref_slice: &[u8]) {
ref_slice.clone_into(mut_vec);
}
I saw this happen:
warning: writing `&mut String` instead of `&mut str` involves a new object where a slice will do
--> src/lib.rs:1:23
|
1 | pub fn t1(mut_string: &mut String, ref_str: &str) {
| ^^^^^^^^^^^ 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
warning: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
--> src/lib.rs:4:20
|
4 | pub fn t2(mut_vec: &mut Vec<u8>, ref_slice: &[u8]) {
| ^^^^^^^^^^^^ help: change this to: `&mut [u8]`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
The suggestions do not compile.
I expected to see this happen: No warnings, since clone_into
requires a mutable reference to the owned and resizable type.
Version
Happens with 0.1.70 (2023-04-02 3a8a131) and also latest git 9818ad21678e5e71dcdfd3e3be5a348195e172e0
Additional Labels
@rustbot label +I-suggestion-causes-error
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