diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-04-01 06:59:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-01 06:59:42 +0200 |
| commit | 8f493fd46a99c1c9255b684d8a7e61991e59a923 (patch) | |
| tree | 6189e7050d91ec0572ee8b54fb98f11aa3f5be25 /compiler/rustc_parse/src/parser | |
| parent | 94b1960535b79bc211a1a9c9967a972e8306e7ae (diff) | |
| parent | 91ac9cf5952ef00218c215c564ec7f56c479019d (diff) | |
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
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index a970d180b1a..20d035fba19 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1919,17 +1919,13 @@ impl<'a> Parser<'a> { match snapshot.parse_array_or_repeat_expr(attrs, token::Brace) { Ok(arr) => { let hi = snapshot.prev_token.span; - self.struct_span_err( - arr.span, - "this code is interpreted as a block expression, not an array", - ) - .multipart_suggestion( - "try using [] instead of {}", - vec![(lo, "[".to_owned()), (hi, "]".to_owned())], - Applicability::MaybeIncorrect, - ) - .note("to define an array, one would use square brackets instead of curly braces") - .emit(); + self.struct_span_err(arr.span, "this is a block expression, not an array") + .multipart_suggestion( + "to make an array, use square brackets instead of curly braces", + vec![(lo, "[".to_owned()), (hi, "]".to_owned())], + Applicability::MaybeIncorrect, + ) + .emit(); self.restore_snapshot(snapshot); Some(self.mk_expr_err(arr.span)) |
