Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,6 @@ impl<'a> Parser<'a> {
let mut err =
self.dcx().struct_span_err(span, format!("expected `;` or `]`, found {}", token_descr));
err.span_label(span, "expected `;` or `]`");
err.note("you might have meant to write a slice or array type");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is redondant with the suggestion, and otherwise not really helpful.


// If we cannot recover, return the error immediately.
if !self.may_recover() {
Expand All @@ -696,12 +695,10 @@ impl<'a> Parser<'a> {

let snapshot = self.create_snapshot_for_diagnostic();

let suggestion_span = if self.eat(exp!(Comma)) || self.eat(exp!(Star)) {
// Consume common erroneous separators.
self.prev_token.span
} else {
self.token.span.shrink_to_lo()
};
// Consume common erroneous separators.
let hi = self.prev_token.span.hi();
_ = self.eat(exp!(Comma)) || self.eat(exp!(Colon)) || self.eat(exp!(Star));
let suggestion_span = self.prev_token.span.with_lo(hi);

// we first try to parse pattern like `[u8 5]`
let length = match self.parse_expr_anon_const() {
Expand Down
5 changes: 2 additions & 3 deletions tests/ui/parser/better-expected.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ error: expected `;` or `]`, found `3`
LL | let x: [isize 3];
| ^ expected `;` or `]`
|
= note: you might have meant to write a slice or array type
help: you might have meant to use `;` as the separator
|
LL | let x: [isize ;3];
| +
LL | let x: [isize; 3];
| +

error: aborting due to 1 previous error

1 change: 0 additions & 1 deletion tests/ui/parser/issues/error-pattern-issue-50571.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ error: expected `;` or `]`, found `,`
LL | fn foo([a, b]: [i32; 2]) {}
| ^ expected `;` or `]`
|
= note: you might have meant to write a slice or array type
help: you might have meant to use `;` as the separator
|
LL - fn foo([a, b]: [i32; 2]) {}
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/parser/recover/array-type-no-semi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ fn main() {
//~| ERROR attempt to use a non-constant value in a constant [E0435]
let e: [i32 5];
//~^ ERROR expected `;` or `]`, found `5`
let f: [i32: 1 - 1];
//~^ ERROR expected `;` or `]`, found `:`
}
23 changes: 15 additions & 8 deletions tests/ui/parser/recover/array-type-no-semi.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ error: expected `;` or `]`, found `,`
LL | let b: [i32, 5];
| ^ expected `;` or `]`
|
= note: you might have meant to write a slice or array type
help: you might have meant to use `;` as the separator
|
LL - let b: [i32, 5];
Expand All @@ -19,16 +18,13 @@ LL | let a: [i32, ];
| |
| while parsing the type for `a`
| help: use `=` if you meant to assign
|
= note: you might have meant to write a slice or array type

error: expected `;` or `]`, found `,`
--> $DIR/array-type-no-semi.rs:12:16
|
LL | let c: [i32, x];
| ^ expected `;` or `]`
|
= note: you might have meant to write a slice or array type
help: you might have meant to use `;` as the separator
|
LL - let c: [i32, x];
Expand All @@ -41,11 +37,22 @@ error: expected `;` or `]`, found `5`
LL | let e: [i32 5];
| ^ expected `;` or `]`
|
= note: you might have meant to write a slice or array type
help: you might have meant to use `;` as the separator
|
LL | let e: [i32 ;5];
| +
LL | let e: [i32; 5];
| +

error: expected `;` or `]`, found `:`
--> $DIR/array-type-no-semi.rs:17:16
|
LL | let f: [i32: 1 - 1];
| ^ expected `;` or `]`
|
help: you might have meant to use `;` as the separator
|
LL - let f: [i32: 1 - 1];
LL + let f: [i32; 1 - 1];
|

error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/array-type-no-semi.rs:12:18
Expand All @@ -65,7 +72,7 @@ error[E0423]: expected value, found builtin type `i32`
LL | let a: [i32, ];
| ^^^ not a value

error: aborting due to 6 previous errors
error: aborting due to 7 previous errors

Some errors have detailed explanations: E0423, E0435.
For more information about an error, try `rustc --explain E0423`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ error: expected `;` or `]`, found `*`
LL | type v = [isize * 3];
| ^ expected `;` or `]`
|
= note: you might have meant to write a slice or array type
help: you might have meant to use `;` as the separator
|
LL - type v = [isize * 3];
LL + type v = [isize ; 3];
LL + type v = [isize; 3];
|

warning: type `v` should have an upper camel case name
Expand Down
Loading