Rollup merge of #82287 - r00ster91:field_name_and, r=petrochenkov
Make "missing field" error message more natural
```rust
struct A {
x: i32,
y: i32,
z: i32,
}
fn main() {
A { };
}
```
```
error[E0063]: missing fields `x`, `y`, `z` in initializer of `A`
--> src/main.rs:8:5
|
8 | A { };
| ^ missing `x`, `y`, `z`
```
This error is now:
```
error[E0063]: missing fields `x`, `y` and `z` in initializer of `A`
--> src/main.rs:8:5
|
8 | A { };
| ^ missing `x`, `y` and `z`
```
I thought it looked nicer and more natural this way. Also, if there is >3 fields missing, there is an "and" as well ("missing \`x\`, \`y\`, \`z\` *and* 1 other field"), but for <=3 there is not. As such it improves consistency too.
As for the implementation, originally I ended up with a chunky `push_str` algorithm but then I figured I could just do the formatting manually since it's just 3 field names at maximum. It is comparatively readable.
As a sidenote, one thing I was wondering about is, isn't there more cases where you have a list of things like field names? Maybe this whole thing can at some point later be made into a more general function to be used in multiple areas.
This commit is contained in:
commit
20c1fa1770
9 changed files with 29 additions and 26 deletions
|
|
@ -23,7 +23,7 @@ fn wrong() {
|
|||
foo::Enum::Variant { x: () };
|
||||
//~^ ERROR missing field `y` in initializer of `Enum`
|
||||
foo::Enum::Variant { };
|
||||
//~^ ERROR missing fields `x`, `y` in initializer of `Enum`
|
||||
//~^ ERROR missing fields `x` and `y` in initializer of `Enum`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@ error[E0063]: missing field `y` in initializer of `Enum`
|
|||
LL | foo::Enum::Variant { x: () };
|
||||
| ^^^^^^^^^^^^^^^^^^ missing `y`
|
||||
|
||||
error[E0063]: missing fields `x`, `y` in initializer of `Enum`
|
||||
error[E0063]: missing fields `x` and `y` in initializer of `Enum`
|
||||
--> $DIR/issue-79593.rs:25:5
|
||||
|
|
||||
LL | foo::Enum::Variant { };
|
||||
| ^^^^^^^^^^^^^^^^^^ missing `x`, `y`
|
||||
| ^^^^^^^^^^^^^^^^^^ missing `x` and `y`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue