-
Notifications
You must be signed in to change notification settings - Fork 1.8k
unnecessary_operation
: don't suggest autofixes on composite types with fields of uncertain types
#15460
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
ada4a
wants to merge
6
commits into
rust-lang:master
Choose a base branch
from
ada4a:unnecessary-operation-uncertain-exprs
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
unnecessary_operation
: don't suggest autofixes on composite types with fields of uncertain types
#15460
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
be7e3ce
add failing test
ada4a 6251b69
don't allow fields whose types are uncertain
ada4a 81e72cc
special-case ranges
ada4a a6be4c5
reduce `applicability` when finding exprs with uncertain types
ada4a f381fbc
do the same for `Call`s
ada4a dff9f73
do the same for `Array`s
ada4a File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//@no-rustfix | ||
#![expect(unused)] | ||
#![warn(clippy::unnecessary_operation)] | ||
|
||
// don't lint if any of the fields has an ambiguous type when used by themselves | ||
fn issue15381() { | ||
struct DescriptorSet { | ||
slots: Vec<u32>, | ||
} | ||
|
||
// the repro | ||
DescriptorSet { slots: Vec::new() }; | ||
//~^ unnecessary_operation | ||
|
||
// other cases | ||
enum E { | ||
Foo { f: Vec<u32> }, | ||
Bar(Vec<u32>), | ||
} | ||
E::Foo { f: Vec::new() }; | ||
//~^ unnecessary_operation | ||
E::Bar(Vec::new()); | ||
//~^ unnecessary_operation | ||
|
||
struct Tuple(Vec<u32>); | ||
Tuple(Vec::new()); | ||
//~^ unnecessary_operation | ||
|
||
// the type of the second slice gets inferred based on it needing to be the same to that of the | ||
// first one, but that doesn't happen when they're outside the array | ||
[[1, 2, 3].as_slice(), [].as_slice()]; | ||
//~^ unnecessary_operation | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
error: unnecessary operation | ||
--> tests/ui/unnecessary_operation_unfixable.rs:12:5 | ||
| | ||
LL | DescriptorSet { slots: Vec::new() }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `Vec::new();` | ||
| | ||
= note: `-D clippy::unnecessary-operation` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_operation)]` | ||
|
||
error: unnecessary operation | ||
--> tests/ui/unnecessary_operation_unfixable.rs:20:5 | ||
| | ||
LL | E::Foo { f: Vec::new() }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `Vec::new();` | ||
|
||
error: unnecessary operation | ||
--> tests/ui/unnecessary_operation_unfixable.rs:22:5 | ||
| | ||
LL | E::Bar(Vec::new()); | ||
| ^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `Vec::new();` | ||
|
||
error: unnecessary operation | ||
--> tests/ui/unnecessary_operation_unfixable.rs:26:5 | ||
| | ||
LL | Tuple(Vec::new()); | ||
| ^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `Vec::new();` | ||
|
||
error: unnecessary operation | ||
--> tests/ui/unnecessary_operation_unfixable.rs:31:5 | ||
| | ||
LL | [[1, 2, 3].as_slice(), [].as_slice()]; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: statement can be reduced to: `[1, 2, 3].as_slice();[].as_slice();` | ||
|
||
error: aborting due to 5 previous errors | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of off-topic: I was forced to use the more verbose
Vec::new()
syntax in all the tests because, when I usedvec![]
, this check would prevent the lint from firing. That doesn't sound quite right to me?