Skip to content

Commit a27a6ef

Browse files
authored
Unrolled build for rust-lang#106893
Rollup merge of rust-lang#106893 - clubby789:struct-update-help, r=compiler-errors Explain base expression for struct update syntax Fixes rust-lang#106890 `@rustbot` label +A-diagnostics
2 parents 9273d63 + f1b8b7d commit a27a6ef

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

compiler/rustc_ast_lowering/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ast_lowering_bad_return_type_notation_output =
3535
3636
ast_lowering_base_expression_double_dot =
3737
base expression required after `..`
38-
.label = add a base expression here
38+
.suggestion = add a base expression here
3939
4040
ast_lowering_clobber_abi_not_supported =
4141
`clobber_abi` is not supported on this target

compiler/rustc_ast_lowering/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ pub struct UnderscoreExprLhsAssign {
114114
}
115115

116116
#[derive(Diagnostic, Clone, Copy)]
117-
#[diag(ast_lowering_base_expression_double_dot)]
117+
#[diag(ast_lowering_base_expression_double_dot, code = "E0797")]
118118
pub struct BaseExpressionDoubleDot {
119119
#[primary_span]
120-
#[label]
120+
#[suggestion(code = "/* expr */", applicability = "has-placeholders", style = "verbose")]
121121
pub span: Span,
122122
}
123123

compiler/rustc_error_codes/src/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ E0793: include_str!("./error_codes/E0793.md"),
516516
E0794: include_str!("./error_codes/E0794.md"),
517517
E0795: include_str!("./error_codes/E0795.md"),
518518
E0796: include_str!("./error_codes/E0796.md"),
519+
E0797: include_str!("./error_codes/E0797.md"),
519520
}
520521

521522
// Undocumented removed error codes. Note that many removed error codes are kept in the list above
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Struct update syntax was used without a base expression.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0797
6+
struct Foo {
7+
fizz: u8,
8+
buzz: u8
9+
}
10+
11+
let f1 = Foo { fizz: 10, buzz: 1};
12+
let f2 = Foo { fizz: 10, .. }; // error
13+
```
14+
15+
Using struct update syntax requires a 'base expression'.
16+
This will be used to fill remaining fields.
17+
18+
```
19+
struct Foo {
20+
fizz: u8,
21+
buzz: u8
22+
}
23+
24+
let f1 = Foo { fizz: 10, buzz: 1};
25+
let f2 = Foo { fizz: 10, ..f1 };
26+
```

tests/ui/destructuring-assignment/struct_destructure_fail.stderr

+8-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ error: functional record updates are not allowed in destructuring assignments
1212
LL | Struct { a, ..d } = Struct { a: 1, b: 2 };
1313
| ^ help: consider removing the trailing pattern
1414

15-
error: base expression required after `..`
15+
error[E0797]: base expression required after `..`
1616
--> $DIR/struct_destructure_fail.rs:15:19
1717
|
1818
LL | Struct { a, .. };
19-
| ^ add a base expression here
19+
| ^
20+
|
21+
help: add a base expression here
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
@@ -41,5 +46,5 @@ LL | Struct { a, .. } = Struct { a: 1, b: 2 };
4146

4247
error: aborting due to 5 previous errors
4348

44-
Some errors have detailed explanations: E0026, E0027.
49+
Some errors have detailed explanations: E0026, E0027, E0797.
4550
For more information about an error, try `rustc --explain E0026`.

0 commit comments

Comments
 (0)