Skip to content

Commit c17cf1d

Browse files
Rollup merge of #132025 - duncpro:E0027, r=compiler-errors
fix suggestion for diagnostic error E0027 Closes #132008
2 parents 972fef2 + 10b60eb commit c17cf1d

11 files changed

+95
-0
lines changed

Diff for: compiler/rustc_hir_typeck/src/pat.rs

+19
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20712071
s = pluralize!(len),
20722072
them = if len == 1 { "it" } else { "them" },
20732073
),
2074+
format!(
2075+
"{}{}{}{}",
2076+
prefix,
2077+
unmentioned_fields
2078+
.iter()
2079+
.map(|(_, name)| {
2080+
let field_name = name.to_string();
2081+
format!("{field_name}: _")
2082+
})
2083+
.collect::<Vec<_>>()
2084+
.join(", "),
2085+
if have_inaccessible_fields { ", .." } else { "" },
2086+
postfix,
2087+
),
2088+
Applicability::MachineApplicable,
2089+
);
2090+
err.span_suggestion(
2091+
sp,
2092+
"or always ignore missing fields here",
20742093
format!("{prefix}..{postfix}"),
20752094
Applicability::MachineApplicable,
20762095
);

Diff for: tests/ui/destructuring-assignment/struct_destructure_fail.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ LL | Struct { a, b } = Struct { a: 1, b: 2 };
4141
| ~~~~~
4242
help: if you don't care about this missing field, you can explicitly ignore it
4343
|
44+
LL | Struct { a, b: _ } = Struct { a: 1, b: 2 };
45+
| ~~~~~~~~
46+
help: or always ignore missing fields here
47+
|
4448
LL | Struct { a, .. } = Struct { a: 1, b: 2 };
4549
| ~~~~~~
4650

Diff for: tests/ui/error-codes/E0027.stderr

+16
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ LL | Dog { age: x, name } => {}
1010
| ~~~~~~~~
1111
help: if you don't care about this missing field, you can explicitly ignore it
1212
|
13+
LL | Dog { age: x, name: _ } => {}
14+
| ~~~~~~~~~~~
15+
help: or always ignore missing fields here
16+
|
1317
LL | Dog { age: x, .. } => {}
1418
| ~~~~~~
1519

@@ -25,6 +29,10 @@ LL | Dog { name: x, age } => {}
2529
| ~~~~~~~
2630
help: if you don't care about this missing field, you can explicitly ignore it
2731
|
32+
LL | Dog { name: x, age: _ } => {}
33+
| ~~~~~~~~~~
34+
help: or always ignore missing fields here
35+
|
2836
LL | Dog { name: x, .. } => {}
2937
| ~~~~~~
3038

@@ -40,6 +48,10 @@ LL | Dog { name: x, age } => {}
4048
| ~~~~~~~
4149
help: if you don't care about this missing field, you can explicitly ignore it
4250
|
51+
LL | Dog { name: x, age: _ } => {}
52+
| ~~~~~~~~~~
53+
help: or always ignore missing fields here
54+
|
4355
LL | Dog { name: x, .. } => {}
4456
| ~~~~~~
4557

@@ -55,6 +67,10 @@ LL | Dog { name, age } => {}
5567
| ~~~~~~~~~~~~~
5668
help: if you don't care about these missing fields, you can explicitly ignore them
5769
|
70+
LL | Dog { name: _, age: _ } => {}
71+
| ~~~~~~~~~~~~~~~~~~~
72+
help: or always ignore missing fields here
73+
|
5874
LL | Dog { .. } => {}
5975
| ~~~~~~
6076

Diff for: tests/ui/pattern/usefulness/doc-hidden-fields.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ LL | let HiddenStruct { one, two, .. } = HiddenStruct::default();
2121
| ~~~~~~~~~~~
2222
help: if you don't care about this missing field, you can explicitly ignore it
2323
|
24+
LL | let HiddenStruct { one, two: _, .. } = HiddenStruct::default();
25+
| ~~~~~~~~~~~~~~
26+
help: or always ignore missing fields here
27+
|
2428
LL | let HiddenStruct { one, .. } = HiddenStruct::default();
2529
| ~~~~~~
2630

@@ -36,6 +40,10 @@ LL | let HiddenStruct { one, hide, two } = HiddenStruct::default();
3640
| ~~~~~~~
3741
help: if you don't care about this missing field, you can explicitly ignore it
3842
|
43+
LL | let HiddenStruct { one, hide, two: _ } = HiddenStruct::default();
44+
| ~~~~~~~~~~
45+
help: or always ignore missing fields here
46+
|
3947
LL | let HiddenStruct { one, hide, .. } = HiddenStruct::default();
4048
| ~~~~~~
4149

@@ -51,6 +59,10 @@ LL | let InCrate { a, b, im_hidden } = InCrate { a: 0, b: false, im_hidden:
5159
| ~~~~~~~~~~~~~
5260
help: if you don't care about this missing field, you can explicitly ignore it
5361
|
62+
LL | let InCrate { a, b, im_hidden: _ } = InCrate { a: 0, b: false, im_hidden: 0 };
63+
| ~~~~~~~~~~~~~~~~
64+
help: or always ignore missing fields here
65+
|
5466
LL | let InCrate { a, b, .. } = InCrate { a: 0, b: false, im_hidden: 0 };
5567
| ~~~~~~
5668

Diff for: tests/ui/pattern/usefulness/stable-gated-fields.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ LL | let UnstableStruct { stable, stable2, .. } = UnstableStruct::default();
1010
| ~~~~~~~~~~~~~~~
1111
help: if you don't care about this missing field, you can explicitly ignore it
1212
|
13+
LL | let UnstableStruct { stable, stable2: _, .. } = UnstableStruct::default();
14+
| ~~~~~~~~~~~~~~~~~~
15+
help: or always ignore missing fields here
16+
|
1317
LL | let UnstableStruct { stable, .. } = UnstableStruct::default();
1418
| ~~~~~~
1519

Diff for: tests/ui/pattern/usefulness/unstable-gated-fields.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ LL | let UnstableStruct { stable, stable2, unstable } = UnstableStruct::defa
1010
| ~~~~~~~~~~~~
1111
help: if you don't care about this missing field, you can explicitly ignore it
1212
|
13+
LL | let UnstableStruct { stable, stable2, unstable: _ } = UnstableStruct::default();
14+
| ~~~~~~~~~~~~~~~
15+
help: or always ignore missing fields here
16+
|
1317
LL | let UnstableStruct { stable, stable2, .. } = UnstableStruct::default();
1418
| ~~~~~~
1519

@@ -25,6 +29,10 @@ LL | let UnstableStruct { stable, unstable, stable2 } = UnstableStruct::defa
2529
| ~~~~~~~~~~~
2630
help: if you don't care about this missing field, you can explicitly ignore it
2731
|
32+
LL | let UnstableStruct { stable, unstable, stable2: _ } = UnstableStruct::default();
33+
| ~~~~~~~~~~~~~~
34+
help: or always ignore missing fields here
35+
|
2836
LL | let UnstableStruct { stable, unstable, .. } = UnstableStruct::default();
2937
| ~~~~~~
3038

Diff for: tests/ui/structs/struct-field-cfg.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ LL | let Foo { present } = foo;
2424
| ~~~~~~~~~~~
2525
help: if you don't care about this missing field, you can explicitly ignore it
2626
|
27+
LL | let Foo { present: _ } = foo;
28+
| ~~~~~~~~~~~~~~
29+
help: or always ignore missing fields here
30+
|
2731
LL | let Foo { .. } = foo;
2832
| ~~~~~~
2933

Diff for: tests/ui/structs/struct-pat-derived-error.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ LL | let A { x, y, b, c } = self.d;
2727
| ~~~~~~~~
2828
help: if you don't care about these missing fields, you can explicitly ignore them
2929
|
30+
LL | let A { x, y, b: _, c: _ } = self.d;
31+
| ~~~~~~~~~~~~~~
32+
help: or always ignore missing fields here
33+
|
3034
LL | let A { x, y, .. } = self.d;
3135
| ~~~~~~
3236

Diff for: tests/ui/structs/struct-tuple-field-names.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ LL | if let E::S { 0: a, 1: _ } = x {
3232
| ~~~~~~~~
3333
help: if you don't care about this missing field, you can explicitly ignore it
3434
|
35+
LL | if let E::S { 0: a, 1: _ } = x {
36+
| ~~~~~~~~
37+
help: or always ignore missing fields here
38+
|
3539
LL | if let E::S { 0: a, .. } = x {
3640
| ~~~~~~
3741

Diff for: tests/ui/structs/suggest-replacing-field-when-specifying-same-type.stderr

+16
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ LL | Foo::Bar { a, aa: 1, c, b } => (),
1919
| ~~~~~
2020
help: if you don't care about this missing field, you can explicitly ignore it
2121
|
22+
LL | Foo::Bar { a, aa: 1, c, b: _ } => (),
23+
| ~~~~~~~~
24+
help: or always ignore missing fields here
25+
|
2226
LL | Foo::Bar { a, aa: 1, c, .. } => (),
2327
| ~~~~~~
2428

@@ -43,6 +47,10 @@ LL | Foo::Baz { bb: 1.0, a } => (),
4347
| ~~~~~
4448
help: if you don't care about this missing field, you can explicitly ignore it
4549
|
50+
LL | Foo::Baz { bb: 1.0, a: _ } => (),
51+
| ~~~~~~~~
52+
help: or always ignore missing fields here
53+
|
4654
LL | Foo::Baz { bb: 1.0, .. } => (),
4755
| ~~~~~~
4856

@@ -64,6 +72,10 @@ LL | Foo::Bar { a, aa: "", c, b } => (),
6472
| ~~~~~
6573
help: if you don't care about this missing field, you can explicitly ignore it
6674
|
75+
LL | Foo::Bar { a, aa: "", c, b: _ } => (),
76+
| ~~~~~~~~
77+
help: or always ignore missing fields here
78+
|
6779
LL | Foo::Bar { a, aa: "", c, .. } => (),
6880
| ~~~~~~
6981

@@ -85,6 +97,10 @@ LL | Foo::Baz { bb: "", a } => (),
8597
| ~~~~~
8698
help: if you don't care about this missing field, you can explicitly ignore it
8799
|
100+
LL | Foo::Baz { bb: "", a: _ } => (),
101+
| ~~~~~~~~
102+
help: or always ignore missing fields here
103+
|
88104
LL | Foo::Baz { bb: "", .. } => (),
89105
| ~~~~~~
90106

Diff for: tests/ui/typeck/issue-87872-missing-inaccessible-field-pattern.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ LL | let foo::Foo { visible, .. } = foo::Foo::default();
1010
| ~~~~~~~~~~~~~~~
1111
help: if you don't care about this missing field, you can explicitly ignore it
1212
|
13+
LL | let foo::Foo { visible: _, .. } = foo::Foo::default();
14+
| ~~~~~~~~~~~~~~~~~~
15+
help: or always ignore missing fields here
16+
|
1317
LL | let foo::Foo { .. } = foo::Foo::default();
1418
| ~~~~~~
1519

0 commit comments

Comments
 (0)