forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#67500 - JohnTitor:non-shorthand-field-patte…
…rns, r=Centril Tweak non_shorthand_field_patterns' suggestion Fixes rust-lang#66434 r? @estebank
- Loading branch information
Showing
6 changed files
with
129 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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 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,70 @@ | ||
// run-rustfix | ||
|
||
#![allow(nonstandard_style, unused_variables, unused_mut)] | ||
#![deny(non_shorthand_field_patterns)] | ||
|
||
struct Foo { | ||
x: isize, | ||
y: isize, | ||
} | ||
|
||
fn main() { | ||
{ | ||
let Foo { | ||
x, //~ ERROR the `x:` in this pattern is redundant | ||
ref y, //~ ERROR the `y:` in this pattern is redundant | ||
} = Foo { x: 0, y: 0 }; | ||
|
||
let Foo { | ||
x, | ||
ref y, | ||
} = Foo { x: 0, y: 0 }; | ||
} | ||
|
||
{ | ||
const x: isize = 1; | ||
|
||
match (Foo { x: 1, y: 1 }) { | ||
Foo { x: x, ..} => {}, | ||
_ => {}, | ||
} | ||
} | ||
|
||
{ | ||
struct Bar { | ||
x: x, | ||
} | ||
|
||
struct x; | ||
|
||
match (Bar { x: x }) { | ||
Bar { x: x } => {}, | ||
} | ||
} | ||
|
||
{ | ||
struct Bar { | ||
x: Foo, | ||
} | ||
|
||
enum Foo { x } | ||
|
||
match (Bar { x: Foo::x }) { | ||
Bar { x: Foo::x } => {}, | ||
} | ||
} | ||
|
||
{ | ||
struct Baz { | ||
x: isize, | ||
y: isize, | ||
z: isize, | ||
} | ||
|
||
let Baz { | ||
mut x, //~ ERROR the `x:` in this pattern is redundant | ||
ref y, //~ ERROR the `y:` in this pattern is redundant | ||
ref mut z, //~ ERROR the `z:` in this pattern is redundant | ||
} = Baz { x: 0, y: 0, z: 0 }; | ||
} | ||
} |
This file contains 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 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 |
---|---|---|
@@ -1,24 +1,38 @@ | ||
error: the `x:` in this pattern is redundant | ||
--> $DIR/lint-shorthand-field.rs:12:13 | ||
--> $DIR/lint-shorthand-field.rs:14:13 | ||
| | ||
LL | x: x, | ||
| --^^ | ||
| | | ||
| help: remove this | ||
| ^^^^ help: use shorthand field pattern: `x` | ||
| | ||
note: lint level defined here | ||
--> $DIR/lint-shorthand-field.rs:2:9 | ||
--> $DIR/lint-shorthand-field.rs:4:9 | ||
| | ||
LL | #![deny(non_shorthand_field_patterns)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: the `y:` in this pattern is redundant | ||
--> $DIR/lint-shorthand-field.rs:13:13 | ||
--> $DIR/lint-shorthand-field.rs:15:13 | ||
| | ||
LL | y: ref y, | ||
| --^^^^^^ | ||
| | | ||
| help: remove this | ||
| ^^^^^^^^ help: use shorthand field pattern: `ref y` | ||
|
||
error: aborting due to 2 previous errors | ||
error: the `x:` in this pattern is redundant | ||
--> $DIR/lint-shorthand-field.rs:65:13 | ||
| | ||
LL | x: mut x, | ||
| ^^^^^^^^ help: use shorthand field pattern: `mut x` | ||
|
||
error: the `y:` in this pattern is redundant | ||
--> $DIR/lint-shorthand-field.rs:66:13 | ||
| | ||
LL | y: ref y, | ||
| ^^^^^^^^ help: use shorthand field pattern: `ref y` | ||
|
||
error: the `z:` in this pattern is redundant | ||
--> $DIR/lint-shorthand-field.rs:67:13 | ||
| | ||
LL | z: ref mut z, | ||
| ^^^^^^^^^^^^ help: use shorthand field pattern: `ref mut z` | ||
|
||
error: aborting due to 5 previous errors | ||
|
This file contains 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 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