-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Fix unused_parens for pinned reference patterns #156089
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
P8L1
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
P8L1:fix-unused-parens-pinned-patterns
base: main
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
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions
9
tests/ui/lint/unused-parens-pinned-reference-patterns-no-feature.rs
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,9 @@ | ||
| #![feature(mut_ref)] | ||
| #![warn(unused_parens)] | ||
|
|
||
| fn main() { | ||
| let pin_const: &pin const i32 = todo!(); | ||
| //~^ ERROR pinned reference syntax is experimental | ||
| let &pin const (_x) = pin_const; | ||
| //~^ ERROR pinned reference syntax is experimental | ||
| } |
23 changes: 23 additions & 0 deletions
23
tests/ui/lint/unused-parens-pinned-reference-patterns-no-feature.stderr
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,23 @@ | ||
| error[E0658]: pinned reference syntax is experimental | ||
| --> $DIR/unused-parens-pinned-reference-patterns-no-feature.rs:5:21 | ||
| | | ||
| LL | let pin_const: &pin const i32 = todo!(); | ||
| | ^^^ | ||
| | | ||
| = note: see issue #130494 <https://github.com/rust-lang/rust/issues/130494> for more information | ||
| = help: add `#![feature(pin_ergonomics)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error[E0658]: pinned reference syntax is experimental | ||
| --> $DIR/unused-parens-pinned-reference-patterns-no-feature.rs:7:10 | ||
| | | ||
| LL | let &pin const (_x) = pin_const; | ||
| | ^^^ | ||
| | | ||
| = note: see issue #130494 <https://github.com/rust-lang/rust/issues/130494> for more information | ||
| = help: add `#![feature(pin_ergonomics)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error: aborting due to 2 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0658`. |
56 changes: 56 additions & 0 deletions
56
tests/ui/lint/unused-parens-pinned-reference-patterns.fixed
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,56 @@ | ||
| //@ run-rustfix | ||
| //@ check-pass | ||
| //@ normalize-stderr: "warning: 9 warnings emitted\n\n" -> "warning: 9 warnings emitted\n" | ||
| #![feature(pin_ergonomics, mut_ref)] | ||
| #![allow(dead_code)] | ||
| #![warn(unused_parens)] | ||
|
|
||
| fn pinned_reference_patterns( | ||
| pin_const: &pin const i32, | ||
| pin_mut: &pin mut i32, | ||
| nested_pin_const: &pin const &pin const i32, | ||
| ) { | ||
| let &pin const _x = pin_const; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
|
|
||
| let &pin const mut _x = pin_const; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
|
|
||
| let &pin const mut _x @ _ = pin_const; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
|
|
||
| let &pin mut mut _x = pin_mut; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
|
|
||
| let &pin const &pin const _x = nested_pin_const; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
|
|
||
| let &pin const ref pin const _x = pin_const; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
|
|
||
| let &pin mut ref pin mut _x = pin_mut; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
|
|
||
| let &pin const mut ref pin const _x = pin_const; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
|
|
||
| let &pin mut mut ref pin mut _x = pin_mut; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
| } | ||
|
|
||
| fn pinned_or_patterns_are_still_ambiguous(pin_const: &pin const i32) { | ||
| match pin_const { | ||
| &pin const (0 | 1) => {} | ||
| _ => {} | ||
| } | ||
| } | ||
|
|
||
| fn plain_shared_reference_patterns_still_need_parens(shared: &i32) { | ||
| let &(mut _x) = shared; | ||
|
|
||
| let &(mut ref _x) = shared; | ||
|
|
||
| let &(mut ref pin const _x) = shared; | ||
| } | ||
|
|
||
| fn main() {} |
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,56 @@ | ||
| //@ run-rustfix | ||
| //@ check-pass | ||
| //@ normalize-stderr: "warning: 9 warnings emitted\n\n" -> "warning: 9 warnings emitted\n" | ||
| #![feature(pin_ergonomics, mut_ref)] | ||
| #![allow(dead_code)] | ||
| #![warn(unused_parens)] | ||
|
|
||
| fn pinned_reference_patterns( | ||
| pin_const: &pin const i32, | ||
| pin_mut: &pin mut i32, | ||
| nested_pin_const: &pin const &pin const i32, | ||
| ) { | ||
| let &pin const (_x) = pin_const; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
|
|
||
| let &pin const (mut _x) = pin_const; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
|
|
||
| let &pin const (mut _x @ _) = pin_const; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
|
|
||
| let &pin mut (mut _x) = pin_mut; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
|
|
||
| let &pin const (&pin const _x) = nested_pin_const; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
|
|
||
| let &pin const (ref pin const _x) = pin_const; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
|
|
||
| let &pin mut (ref pin mut _x) = pin_mut; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
|
|
||
| let &pin const (mut ref pin const _x) = pin_const; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
|
|
||
| let &pin mut (mut ref pin mut _x) = pin_mut; | ||
| //~^ WARN unnecessary parentheses around pattern | ||
| } | ||
|
|
||
| fn pinned_or_patterns_are_still_ambiguous(pin_const: &pin const i32) { | ||
| match pin_const { | ||
| &pin const (0 | 1) => {} | ||
| _ => {} | ||
| } | ||
| } | ||
|
|
||
| fn plain_shared_reference_patterns_still_need_parens(shared: &i32) { | ||
| let &(mut _x) = shared; | ||
|
|
||
| let &(mut ref _x) = shared; | ||
|
|
||
| let &(mut ref pin const _x) = shared; | ||
| } | ||
|
|
||
| fn main() {} |
114 changes: 114 additions & 0 deletions
114
tests/ui/lint/unused-parens-pinned-reference-patterns.stderr
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,114 @@ | ||
| warning: unnecessary parentheses around pattern | ||
| --> $DIR/unused-parens-pinned-reference-patterns.rs:13:20 | ||
| | | ||
| LL | let &pin const (_x) = pin_const; | ||
| | ^ ^ | ||
| | | ||
| note: the lint level is defined here | ||
| --> $DIR/unused-parens-pinned-reference-patterns.rs:6:9 | ||
| | | ||
| LL | #![warn(unused_parens)] | ||
| | ^^^^^^^^^^^^^ | ||
| help: remove these parentheses | ||
| | | ||
| LL - let &pin const (_x) = pin_const; | ||
| LL + let &pin const _x = pin_const; | ||
| | | ||
|
|
||
| warning: unnecessary parentheses around pattern | ||
| --> $DIR/unused-parens-pinned-reference-patterns.rs:16:20 | ||
| | | ||
| LL | let &pin const (mut _x) = pin_const; | ||
| | ^ ^ | ||
| | | ||
| help: remove these parentheses | ||
| | | ||
| LL - let &pin const (mut _x) = pin_const; | ||
| LL + let &pin const mut _x = pin_const; | ||
| | | ||
|
|
||
| warning: unnecessary parentheses around pattern | ||
| --> $DIR/unused-parens-pinned-reference-patterns.rs:19:20 | ||
| | | ||
| LL | let &pin const (mut _x @ _) = pin_const; | ||
| | ^ ^ | ||
| | | ||
| help: remove these parentheses | ||
| | | ||
| LL - let &pin const (mut _x @ _) = pin_const; | ||
| LL + let &pin const mut _x @ _ = pin_const; | ||
| | | ||
|
|
||
| warning: unnecessary parentheses around pattern | ||
| --> $DIR/unused-parens-pinned-reference-patterns.rs:22:18 | ||
| | | ||
| LL | let &pin mut (mut _x) = pin_mut; | ||
| | ^ ^ | ||
| | | ||
| help: remove these parentheses | ||
| | | ||
| LL - let &pin mut (mut _x) = pin_mut; | ||
| LL + let &pin mut mut _x = pin_mut; | ||
| | | ||
|
|
||
| warning: unnecessary parentheses around pattern | ||
| --> $DIR/unused-parens-pinned-reference-patterns.rs:25:20 | ||
| | | ||
| LL | let &pin const (&pin const _x) = nested_pin_const; | ||
| | ^ ^ | ||
| | | ||
| help: remove these parentheses | ||
| | | ||
| LL - let &pin const (&pin const _x) = nested_pin_const; | ||
| LL + let &pin const &pin const _x = nested_pin_const; | ||
| | | ||
|
|
||
| warning: unnecessary parentheses around pattern | ||
| --> $DIR/unused-parens-pinned-reference-patterns.rs:28:20 | ||
| | | ||
| LL | let &pin const (ref pin const _x) = pin_const; | ||
| | ^ ^ | ||
| | | ||
| help: remove these parentheses | ||
| | | ||
| LL - let &pin const (ref pin const _x) = pin_const; | ||
| LL + let &pin const ref pin const _x = pin_const; | ||
| | | ||
|
|
||
| warning: unnecessary parentheses around pattern | ||
| --> $DIR/unused-parens-pinned-reference-patterns.rs:31:18 | ||
| | | ||
| LL | let &pin mut (ref pin mut _x) = pin_mut; | ||
| | ^ ^ | ||
| | | ||
| help: remove these parentheses | ||
| | | ||
| LL - let &pin mut (ref pin mut _x) = pin_mut; | ||
| LL + let &pin mut ref pin mut _x = pin_mut; | ||
| | | ||
|
|
||
| warning: unnecessary parentheses around pattern | ||
| --> $DIR/unused-parens-pinned-reference-patterns.rs:34:20 | ||
| | | ||
| LL | let &pin const (mut ref pin const _x) = pin_const; | ||
| | ^ ^ | ||
| | | ||
| help: remove these parentheses | ||
| | | ||
| LL - let &pin const (mut ref pin const _x) = pin_const; | ||
| LL + let &pin const mut ref pin const _x = pin_const; | ||
| | | ||
|
|
||
| warning: unnecessary parentheses around pattern | ||
| --> $DIR/unused-parens-pinned-reference-patterns.rs:37:18 | ||
| | | ||
| LL | let &pin mut (mut ref pin mut _x) = pin_mut; | ||
| | ^ ^ | ||
| | | ||
| help: remove these parentheses | ||
| | | ||
| LL - let &pin mut (mut ref pin mut _x) = pin_mut; | ||
| LL + let &pin mut mut ref pin mut _x = pin_mut; | ||
| | | ||
|
|
||
| warning: 9 warnings emitted |
Oops, something went wrong.
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.