Skip to content

Commit 71cde38

Browse files
committed
Improve error for missing expression in struct update syntax
1 parent 1221e43 commit 71cde38

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

compiler/rustc_ast_lowering/messages.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ ast_lowering_bad_return_type_notation_output =
4040
ast_lowering_base_expression_double_dot =
4141
base expression required after `..`
4242
.label = add a base expression here
43+
.suggestion = using struct update syntax requires a base expression of the same type
4344
4445
ast_lowering_clobber_abi_not_supported =
4546
`clobber_abi` is not supported on this target

compiler/rustc_ast_lowering/src/errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub struct UnderscoreExprLhsAssign {
100100
pub struct BaseExpressionDoubleDot {
101101
#[primary_span]
102102
#[label]
103+
#[suggestion(code = "/* expr */", applicability = "has-placeholders", style = "verbose")]
103104
pub span: Span,
104105
}
105106

tests/ui/destructuring-assignment/struct_destructure_fail.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ error: base expression required after `..`
1717
|
1818
LL | Struct { a, .. };
1919
| ^ add a base expression here
20+
|
21+
help: using struct update syntax requires a base expression of the same type
22+
|
23+
LL | Struct { a, ../* expr */ };
24+
| ++++++++++
2025

2126
error[E0026]: struct `Struct` does not have a field named `c`
2227
--> $DIR/struct_destructure_fail.rs:10:20

0 commit comments

Comments
 (0)