Skip to content

Commit 775e287

Browse files
committed
Do not provide field typo suggestions for tuples and tuple structs
1 parent 53eb650 commit 775e287

File tree

7 files changed

+14
-50
lines changed

7 files changed

+14
-50
lines changed

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,6 +2745,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27452745
let available_field_names = self.available_field_names(variant, expr, skip_fields);
27462746
if let Some(field_name) =
27472747
find_best_match_for_name(&available_field_names, field.ident.name, None)
2748+
&& !(field.ident.name.as_str().parse::<usize>().is_ok()
2749+
&& field_name.as_str().parse::<usize>().is_ok())
27482750
{
27492751
err.span_label(field.ident.span, "unknown field");
27502752
err.span_suggestion_verbose(
@@ -3360,6 +3362,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33603362
);
33613363
} else if let Some(field_name) =
33623364
find_best_match_for_name(&field_names, field.name, None)
3365+
&& !(field.name.as_str().parse::<usize>().is_ok()
3366+
&& field_name.as_str().parse::<usize>().is_ok())
33633367
{
33643368
err.span_suggestion_verbose(
33653369
field.span,

tests/ui/consts/issue-19244-1.stderr

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ error[E0609]: no field `1` on type `(usize,)`
44
LL | let a: [isize; TUP.1];
55
| ^ unknown field
66
|
7-
help: a field with a similar name exists
8-
|
9-
LL - let a: [isize; TUP.1];
10-
LL + let a: [isize; TUP.0];
11-
|
7+
= note: available field is: `0`
128

139
error: aborting due to 1 previous error
1410

tests/ui/error-codes/ex-E0612.stderr

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ error[E0609]: no field `1` on type `Foo`
44
LL | y.1;
55
| ^ unknown field
66
|
7-
help: a field with a similar name exists
8-
|
9-
LL - y.1;
10-
LL + y.0;
11-
|
7+
= note: available field is: `0`
128

139
error: aborting due to 1 previous error
1410

tests/ui/issues/issue-47073-zero-padded-tuple-struct-indices.stderr

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ error[E0609]: no field `00` on type `Verdict`
44
LL | let _condemned = justice.00;
55
| ^^ unknown field
66
|
7-
help: a field with a similar name exists
8-
|
9-
LL - let _condemned = justice.00;
10-
LL + let _condemned = justice.0;
11-
|
7+
= note: available fields are: `0`, `1`
128

139
error[E0609]: no field `001` on type `Verdict`
1410
--> $DIR/issue-47073-zero-padded-tuple-struct-indices.rs:10:31

tests/ui/offset-of/offset-of-tuple-field.stderr

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ error[E0609]: no field `01` on type `(u8, u8)`
2828
LL | offset_of!((u8, u8), 01);
2929
| ^^
3030
|
31-
help: a field with a similar name exists
32-
|
33-
LL - offset_of!((u8, u8), 01);
34-
LL + offset_of!((u8, u8), 0);
35-
|
31+
= note: available fields are: `0`, `1`
3632

3733
error[E0609]: no field `1e2` on type `(u8, u8)`
3834
--> $DIR/offset-of-tuple-field.rs:8:26
@@ -80,11 +76,7 @@ error[E0609]: no field `01` on type `(u8, u8)`
8076
LL | builtin # offset_of((u8, u8), 01);
8177
| ^^
8278
|
83-
help: a field with a similar name exists
84-
|
85-
LL - builtin # offset_of((u8, u8), 01);
86-
LL + builtin # offset_of((u8, u8), 0);
87-
|
79+
= note: available fields are: `0`, `1`
8880

8981
error[E0609]: no field `1_` on type `(u8, u8)`
9082
--> $DIR/offset-of-tuple-field.rs:15:35
@@ -104,11 +96,7 @@ error[E0609]: no field `2` on type `(u8, u16)`
10496
LL | offset_of!(((u8, u16), (u32, u16, u8)), 0.2);
10597
| ^
10698
|
107-
help: a field with a similar name exists
108-
|
109-
LL - offset_of!(((u8, u16), (u32, u16, u8)), 0.2);
110-
LL + offset_of!(((u8, u16), (u32, u16, u8)), 0.0);
111-
|
99+
= note: available fields are: `0`, `1`
112100

113101
error[E0609]: no field `1e2` on type `(u8, u16)`
114102
--> $DIR/offset-of-tuple-field.rs:19:47

tests/ui/tuple/index-invalid.stderr

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,15 @@ error[E0609]: no field `1` on type `(((),),)`
44
LL | let _ = (((),),).1.0;
55
| ^ unknown field
66
|
7-
help: a field with a similar name exists
8-
|
9-
LL - let _ = (((),),).1.0;
10-
LL + let _ = (((),),).0.0;
11-
|
7+
= note: available field is: `0`
128

139
error[E0609]: no field `1` on type `((),)`
1410
--> $DIR/index-invalid.rs:4:24
1511
|
1612
LL | let _ = (((),),).0.1;
1713
| ^ unknown field
1814
|
19-
help: a field with a similar name exists
20-
|
21-
LL - let _ = (((),),).0.1;
22-
LL + let _ = (((),),).0.0;
23-
|
15+
= note: available field is: `0`
2416

2517
error[E0609]: no field `000` on type `(((),),)`
2618
--> $DIR/index-invalid.rs:6:22

tests/ui/tuple/tuple-index-out-of-bounds.stderr

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,15 @@ error[E0609]: no field `2` on type `Point`
44
LL | origin.2;
55
| ^ unknown field
66
|
7-
help: a field with a similar name exists
8-
|
9-
LL - origin.2;
10-
LL + origin.0;
11-
|
7+
= note: available fields are: `0`, `1`
128

139
error[E0609]: no field `2` on type `({integer}, {integer})`
1410
--> $DIR/tuple-index-out-of-bounds.rs:12:11
1511
|
1612
LL | tuple.2;
1713
| ^ unknown field
1814
|
19-
help: a field with a similar name exists
20-
|
21-
LL - tuple.2;
22-
LL + tuple.0;
23-
|
15+
= note: available fields are: `0`, `1`
2416

2517
error: aborting due to 2 previous errors
2618

0 commit comments

Comments
 (0)