You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of rust-lang#139024 - compiler-errors:tweak-default-value-err, r=lcnr
Make error message for missing fields with `..` and without `..` more consistent
When `..` is not present, we say "missing field `bar` in initializer", but when it is present we say "missing mandatory field `bar`". I don't see why the primary error message should change, b/c the root cause is the same.
Let's harmonize these error messages and instead use a label to explain that `..` is required b/c it's not defaulted.
r? estebank
Copy file name to clipboardExpand all lines: tests/ui/structs/default-field-values/failures.stderr
+16-10
Original file line number
Diff line number
Diff line change
@@ -27,14 +27,20 @@ LL + #[derive(Default)]
27
27
LL | pub struct S;
28
28
|
29
29
30
-
error: missing mandatory field `bar`
31
-
--> $DIR/failures.rs:53:21
30
+
error: missing field `bar` in initializer
31
+
--> $DIR/failures.rs:53:19
32
32
|
33
33
LL | let _ = Bar { .. };
34
-
| ^
34
+
| ^ fields that do not have a defaulted value must be provided explicitly
35
+
36
+
error: missing field `bar` in initializer
37
+
--> $DIR/failures.rs:54:27
38
+
|
39
+
LL | let _ = Bar { baz: 0, .. };
40
+
| ^ fields that do not have a defaulted value must be provided explicitly
35
41
36
42
error[E0308]: mismatched types
37
-
--> $DIR/failures.rs:57:17
43
+
--> $DIR/failures.rs:58:17
38
44
|
39
45
LL | let _ = Rak(..);
40
46
| --- ^^ expected `i32`, found `RangeFull`
@@ -47,19 +53,19 @@ note: tuple struct defined here
47
53
LL | pub struct Rak(i32 = 42);
48
54
| ^^^
49
55
help: you might have meant to use `..` to skip providing a value for expected fields, but this is only supported on non-tuple struct literals; it is instead interpreted as a `std::ops::RangeFull` literal
50
-
--> $DIR/failures.rs:57:17
56
+
--> $DIR/failures.rs:58:17
51
57
|
52
58
LL | let _ = Rak(..);
53
59
| ^^
54
60
55
61
error[E0061]: this struct takes 1 argument but 2 arguments were supplied
56
-
--> $DIR/failures.rs:59:13
62
+
--> $DIR/failures.rs:60:13
57
63
|
58
64
LL | let _ = Rak(0, ..);
59
65
| ^^^ -- unexpected argument #2 of type `RangeFull`
60
66
|
61
67
help: you might have meant to use `..` to skip providing a value for expected fields, but this is only supported on non-tuple struct literals; it is instead interpreted as a `std::ops::RangeFull` literal
62
-
--> $DIR/failures.rs:59:20
68
+
--> $DIR/failures.rs:60:20
63
69
|
64
70
LL | let _ = Rak(0, ..);
65
71
| ^^
@@ -75,13 +81,13 @@ LL + let _ = Rak(0);
75
81
|
76
82
77
83
error[E0061]: this struct takes 1 argument but 2 arguments were supplied
78
-
--> $DIR/failures.rs:61:13
84
+
--> $DIR/failures.rs:62:13
79
85
|
80
86
LL | let _ = Rak(.., 0);
81
87
| ^^^ -- unexpected argument #1 of type `RangeFull`
82
88
|
83
89
help: you might have meant to use `..` to skip providing a value for expected fields, but this is only supported on non-tuple struct literals; it is instead interpreted as a `std::ops::RangeFull` literal
84
-
--> $DIR/failures.rs:61:17
90
+
--> $DIR/failures.rs:62:17
85
91
|
86
92
LL | let _ = Rak(.., 0);
87
93
| ^^
@@ -96,7 +102,7 @@ LL - let _ = Rak(.., 0);
96
102
LL + let _ = Rak(0);
97
103
|
98
104
99
-
error: aborting due to 7 previous errors
105
+
error: aborting due to 8 previous errors
100
106
101
107
Some errors have detailed explanations: E0061, E0277, E0308.
102
108
For more information about an error, try `rustc --explain E0061`.
0 commit comments