-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add needless_conversion_for_trait
lint
#15451
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
Open
smoelius
wants to merge
6
commits into
rust-lang:master
Choose a base branch
from
smoelius:needless-conversion-for-trait
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+2,467
−949
Conversation
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
Lintcheck changes for b6b7409
This comment will be updated if you push new changes |
This comment has been minimized.
This comment has been minimized.
ac3f154
to
5e295a3
Compare
This comment has been minimized.
This comment has been minimized.
5e295a3
to
388dbe0
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
388dbe0
to
f02a065
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
f02a065
to
f4a9a2f
Compare
This comment has been minimized.
This comment has been minimized.
f4a9a2f
to
3500a56
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
3500a56
to
b6b7409
Compare
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-lint
Area: New lints
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties
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.
Adds a lint to flag trait-behavior preserving calls where the receiver/argument could be used directly. For example, the lint flags the call to
as_path
in the following code, because&lint_file_path
could be used instead:rust-clippy/clippy_dev/src/new_lint.rs
Line 436 in 14dfc03
Organization
The PR is currently organized as five commits:
DisallowedPath
->ConfPath
;REPLACEMENTS_ALLOWED
->REPLACEABLE
: Shorten some configuration-related names for types used by this lint.clippy_utils::ty
: Move some functions fromunnecessary_to_owned
andneedless_conversion_for_generic_args
(cc: @Jarcho) into theclippy_utils::ty
module.replace_types
: Emphasize thatreplace_types
cannot change a function's output type (see below).needless_conversion_for_trait
lint; getuitest
to pass: The PR's main commit.Relationship to
unnecessary_to_owned
Some of
unnecessary_to_owned
's functionality is subsumed by this lint. However,replace_types
, whichneedless_conversion_for_trait
uses, does not allow a function's output type to change.unnecessary_to_owned
does not have this restriction. So, to ensure the two lints do not flag the same code,unnecessary_to_owned
now requires that a function's output type contain the type to be replaced. Note that someunnecessary_to_owned
tests contain a function whose output type is changed by the lint's suggestion:rust-clippy/tests/ui/unnecessary_to_owned.rs
Line 460 in 14dfc03
rust-clippy/tests/ui/unnecessary_to_owned.rs
Line 604 in 14dfc03
Also,
unnecessary_to_owned
will not eliminate a call toToString::to_string
unless the receiver implementsDeref<Target = str>
orAsRef<str>
.needless_conversion_for_trait
incorporates this restriction as well.check_inherent_functions
The lint includes a
check_crate_post
check that runs when Clippy is compiled in debug mode. The check looks for functions the lint should either warn about, or should explicitly ignore. For example, while preparing this PR, the check flaggedVec::into_chunks
, which was added to the list of explicitly ignored functions.False positive in
clippy_utils
There are three false positives in
clippy_utils
that I do not know how best to resolve. They concern the implementations of the three functions forDiagExt
:rust-clippy/clippy_utils/src/sugg.rs
Lines 702 to 715 in 14dfc03
needless_conversion_for_trait
reports thatmsg.to_string()
could be replaced withmsg
. However, making this change causes the borrow checker to thinkmsg
's reference flows into&mut self
. I haveallow
ed the lint for the trait implementation, but I am open to suggestions for eliminating this class of false positives.changelog: Add
needless_conversion_for_trait
lintSummary Notes
Managed by
@rustbot
—see help for details