Skip to content

Commit 2415a64

Browse files
committed
Improve error message for struct expression missing a base expression after ..
1 parent 1f65f5d commit 2415a64

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,7 @@ impl<'a> Parser<'a> {
21082108
// AST lowering will then report an error if it's not on the LHS of an assignment.
21092109
if self.token == token::CloseDelim(token::Brace) {
21102110
base = Some(self.mk_expr(
2111-
self.prev_token.span,
2111+
self.prev_token.span.shrink_to_hi(),
21122112
ExprKind::Underscore,
21132113
AttrVec::new(),
21142114
));

src/test/ui/destructuring-assignment/struct_destructure_fail.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ fn main() {
1212
Struct { a, _ } = Struct { a: 1, b: 2 }; //~ ERROR pattern does not mention field `b`
1313
//~| ERROR expected identifier, found reserved identifier `_`
1414
Struct { a, ..d } = Struct { a: 1, b: 2 }; //~ ERROR base expression not allowed here
15+
Struct { a, .. }; //~ ERROR base expression required after `..`
1516
}

src/test/ui/destructuring-assignment/struct_destructure_fail.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ error: base expression not allowed here
1212
LL | Struct { a, ..d } = Struct { a: 1, b: 2 };
1313
| ^ help: consider removing this
1414

15+
error: base expression required after `..`
16+
--> $DIR/struct_destructure_fail.rs:15:19
17+
|
18+
LL | Struct { a, .. };
19+
| ^ add the base expression here
20+
1521
error[E0026]: struct `Struct` does not have a field named `c`
1622
--> $DIR/struct_destructure_fail.rs:11:20
1723
|
@@ -24,7 +30,7 @@ error[E0027]: pattern does not mention field `b`
2430
LL | Struct { a, _ } = Struct { a: 1, b: 2 };
2531
| ^^^^^^^^^^^^^^^ missing field `b`
2632

27-
error: aborting due to 4 previous errors
33+
error: aborting due to 5 previous errors
2834

2935
Some errors have detailed explanations: E0026, E0027.
3036
For more information about an error, try `rustc --explain E0026`.

0 commit comments

Comments
 (0)