forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest adding missing braces in
const
block pattern
Previously it would only suggest wrapping the code in braces in regular expressions; now it does it in patterns too. This is a squashed rebase of rust-lang#78173
- Loading branch information
1 parent
a772336
commit 4980b77
Showing
11 changed files
with
241 additions
and
26 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
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
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,29 @@ | ||
//@ run-pass | ||
|
||
#![feature(inline_const_pat)] | ||
|
||
fn if_let_1() -> i32 { | ||
let x = 2; | ||
const Y: i32 = 3; | ||
|
||
if let const { (Y + 1) / 2 } = x { | ||
x | ||
} else { | ||
0 | ||
} | ||
} | ||
|
||
fn if_let_2() -> i32 { | ||
let x = 2; | ||
|
||
if let const { 1 + 2 } = x { | ||
const { 1 + 2 } | ||
} else { | ||
0 | ||
} | ||
} | ||
|
||
fn main() { | ||
assert_eq!(if_let_1(), 2); | ||
assert_eq!(if_let_2(), 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//@ run-rustfix | ||
|
||
// See issue #78168. | ||
|
||
#![feature(inline_const_pat)] | ||
|
||
// FIXME(#78171): the lint has to be allowed because of a bug | ||
#[allow(dead_code)] | ||
const fn one() -> i32 { | ||
1 | ||
} | ||
|
||
fn foo() -> i32 { | ||
let x = 2; | ||
|
||
match x { | ||
const { 2 } => {} | ||
//~^ ERROR expected `{`, found `2` | ||
//~| HELP try placing this code inside a block | ||
_ => {} | ||
} | ||
|
||
match x { | ||
const { 1 + 2 * 3 / 4 } => {} | ||
//~^ ERROR expected `{`, found `1` | ||
//~| HELP try placing this code inside a block | ||
_ => {} | ||
} | ||
|
||
match x { | ||
const { one() } => {} | ||
//~^ ERROR expected `{`, found `one` | ||
//~| HELP try placing this code inside a block | ||
_ => {} | ||
} | ||
|
||
x | ||
} | ||
|
||
fn bar() -> i32 { | ||
let x = const { 2 }; | ||
//~^ ERROR expected `{`, found `2` | ||
//~| HELP try placing this code inside a block | ||
|
||
x | ||
} | ||
|
||
fn baz() -> i32 { | ||
let y = const { 1 + 2 * 3 / 4 }; | ||
//~^ ERROR expected `{`, found `1` | ||
//~| HELP try placing this code inside a block | ||
|
||
y | ||
} | ||
|
||
fn main() { | ||
foo(); | ||
bar(); | ||
baz(); | ||
} |
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,60 @@ | ||
//@ run-rustfix | ||
|
||
// See issue #78168. | ||
|
||
#![feature(inline_const_pat)] | ||
|
||
// FIXME(#78171): the lint has to be allowed because of a bug | ||
#[allow(dead_code)] | ||
const fn one() -> i32 { | ||
1 | ||
} | ||
|
||
fn foo() -> i32 { | ||
let x = 2; | ||
|
||
match x { | ||
const 2 => {} | ||
//~^ ERROR expected `{`, found `2` | ||
//~| HELP try placing this code inside a block | ||
_ => {} | ||
} | ||
|
||
match x { | ||
const 1 + 2 * 3 / 4 => {} | ||
//~^ ERROR expected `{`, found `1` | ||
//~| HELP try placing this code inside a block | ||
_ => {} | ||
} | ||
|
||
match x { | ||
const one() => {} | ||
//~^ ERROR expected `{`, found `one` | ||
//~| HELP try placing this code inside a block | ||
_ => {} | ||
} | ||
|
||
x | ||
} | ||
|
||
fn bar() -> i32 { | ||
let x = const 2; | ||
//~^ ERROR expected `{`, found `2` | ||
//~| HELP try placing this code inside a block | ||
|
||
x | ||
} | ||
|
||
fn baz() -> i32 { | ||
let y = const 1 + 2 * 3 / 4; | ||
//~^ ERROR expected `{`, found `1` | ||
//~| HELP try placing this code inside a block | ||
|
||
y | ||
} | ||
|
||
fn main() { | ||
foo(); | ||
bar(); | ||
baz(); | ||
} |
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,57 @@ | ||
error: expected `{`, found `2` | ||
--> $DIR/inline-const-without-block.rs:17:15 | ||
| | ||
LL | const 2 => {} | ||
| ^ expected `{` | ||
| | ||
help: try placing this code inside a block | ||
| | ||
LL | const { 2 } => {} | ||
| + + | ||
|
||
error: expected `{`, found `1` | ||
--> $DIR/inline-const-without-block.rs:24:15 | ||
| | ||
LL | const 1 + 2 * 3 / 4 => {} | ||
| ^ expected `{` | ||
| | ||
help: try placing this code inside a block | ||
| | ||
LL | const { 1 + 2 * 3 / 4 } => {} | ||
| + + | ||
|
||
error: expected `{`, found `one` | ||
--> $DIR/inline-const-without-block.rs:31:15 | ||
| | ||
LL | const one() => {} | ||
| ^^^ expected `{` | ||
| | ||
help: try placing this code inside a block | ||
| | ||
LL | const { one() } => {} | ||
| + + | ||
|
||
error: expected `{`, found `2` | ||
--> $DIR/inline-const-without-block.rs:41:19 | ||
| | ||
LL | let x = const 2; | ||
| ^ expected `{` | ||
| | ||
help: try placing this code inside a block | ||
| | ||
LL | let x = const { 2 }; | ||
| + + | ||
|
||
error: expected `{`, found `1` | ||
--> $DIR/inline-const-without-block.rs:49:19 | ||
| | ||
LL | let y = const 1 + 2 * 3 / 4; | ||
| ^ expected `{` | ||
| | ||
help: try placing this code inside a block | ||
| | ||
LL | let y = const { 1 + 2 * 3 / 4 }; | ||
| + + | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// This file was auto-generated using 'src/etc/generate-keyword-tests.py const' | ||
|
||
fn main() { | ||
let const = "foo"; //~ error: expected identifier, found keyword `const` | ||
let const = "foo"; | ||
//~^ ERROR expected `{`, found `=` | ||
//~| ERROR inline-const in pattern position is experimental [E0658] | ||
} |
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,13 +1,19 @@ | ||
error: expected identifier, found keyword `const` | ||
--> $DIR/keyword-const-as-identifier.rs:4:9 | ||
error: expected `{`, found `=` | ||
--> $DIR/keyword-const-as-identifier.rs:2:15 | ||
| | ||
LL | let const = "foo"; | ||
| ^^^^^ expected identifier, found keyword | ||
| ^ expected `{` | ||
|
||
error[E0658]: inline-const in pattern position is experimental | ||
--> $DIR/keyword-const-as-identifier.rs:2:9 | ||
| | ||
help: escape `const` to use it as an identifier | ||
LL | let const = "foo"; | ||
| ^^^^^ | ||
| | ||
LL | let r#const = "foo"; | ||
| ++ | ||
= note: see issue #76001 <https://github.com/rust-lang/rust/issues/76001> for more information | ||
= help: add `#![feature(inline_const_pat)]` 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 1 previous error | ||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |