-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 #95293 - compiler-errors:braces, r=davidtwco
suggest wrapping single-expr blocks in square brackets Suggests a fix in cases like: ```diff - const A: [i32; 1] = { 1 }; + const A: [i32; 1] = [ 1 ]; ^ ^ ``` Also edit the message for the same suggestion in the parser (e.g. `{ 1, 2 }`). Fixes #95289
- Loading branch information
Showing
8 changed files
with
222 additions
and
91 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
10 changes: 10 additions & 0 deletions
10
src/test/ui/did_you_mean/brackets-to-braces-single-element.rs
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,10 @@ | ||
const A: [&str; 1] = { "hello" }; | ||
//~^ ERROR mismatched types | ||
|
||
const B: &[u32] = &{ 1 }; | ||
//~^ ERROR mismatched types | ||
|
||
const C: &&[u32; 1] = &&{ 1 }; | ||
//~^ ERROR mismatched types | ||
|
||
fn main() {} |
38 changes: 38 additions & 0 deletions
38
src/test/ui/did_you_mean/brackets-to-braces-single-element.stderr
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,38 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/brackets-to-braces-single-element.rs:1:24 | ||
| | ||
LL | const A: [&str; 1] = { "hello" }; | ||
| ^^^^^^^ expected array `[&'static str; 1]`, found `&str` | ||
| | ||
help: to create an array, use square brackets instead of curly braces | ||
| | ||
LL | const A: [&str; 1] = [ "hello" ]; | ||
| ~ ~ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/brackets-to-braces-single-element.rs:4:19 | ||
| | ||
LL | const B: &[u32] = &{ 1 }; | ||
| ^^^^^^ expected slice `[u32]`, found integer | ||
| | ||
= note: expected reference `&'static [u32]` | ||
found reference `&{integer}` | ||
help: to create an array, use square brackets instead of curly braces | ||
| | ||
LL | const B: &[u32] = &[ 1 ]; | ||
| ~ ~ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/brackets-to-braces-single-element.rs:7:27 | ||
| | ||
LL | const C: &&[u32; 1] = &&{ 1 }; | ||
| ^ expected array `[u32; 1]`, found integer | ||
| | ||
help: to create an array, use square brackets instead of curly braces | ||
| | ||
LL | const C: &&[u32; 1] = &&[ 1 ]; | ||
| ~ ~ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
7 changes: 4 additions & 3 deletions
7
src/test/ui/did_you_mean/issue-87830-try-brackets-for-arrays.rs
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
Oops, something went wrong.