You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
map_clone incorrectly suggests .cloned() for calls such as:
input.iter().map(|s:&&String| String::clone(s))
Here, String::clone coerces &&String to &String and returns String, while .cloned() returns &String.
Only lint when argument adjustments preserve its type. This fixes the false positive while retaining valid Option and Result diagnostics. Tests cover String::clone and <String as Clone>::clone.
@CommanderStorm
I checked #10278. This change doesn't affect that case: its reproducer uses method-call syntax (s.clone()), while this PR only changes the function-call path (String::clone(s)).
I also don't think it is a false positive. The suggested .cloned() replacement compiles and still produces a Vec<String>. The compilation error in the issue comes from applying .clone() instead of the suggested .cloned(), as Alexendoo pointed out in the first comment. The equivalent case is already covered as an intended lint in tests/ui/map_clone.rs:14, and the test passes.
rustbot has assigned @llogiq for the project review.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
map_cloneincorrectly suggests.cloned()for calls such as:Here,
String::clonecoerces&&Stringto&Stringand returnsString, while.cloned()returns&String.Only lint when argument adjustments preserve its type. This fixes the false positive while retaining valid
OptionandResultdiagnostics. Tests coverString::cloneand<String as Clone>::clone.Fixes #17550
changelog: Fix [
map_clone] false positive for clone calls using deref coercion