diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2025-07-30 16:21:40 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2025-08-07 21:39:00 +0000 |
| commit | a17e8cfe8f64ed8c14ffa44081f518b617bfbe35 (patch) | |
| tree | 395338287778e922074b0d5fcb6977a74f3c6a96 | |
| parent | dd3b8255ca6215b5129181ceb6912aed1370bdce (diff) | |
| download | rust-a17e8cfe8f64ed8c14ffa44081f518b617bfbe35.tar.gz rust-a17e8cfe8f64ed8c14ffa44081f518b617bfbe35.zip | |
Do not provide field typo suggestions for tuples and tuple structs
| -rw-r--r-- | compiler/rustc_hir_typeck/src/expr.rs | 4 | ||||
| -rw-r--r-- | tests/ui/consts/issue-19244-1.stderr | 6 | ||||
| -rw-r--r-- | tests/ui/error-codes/ex-E0612.stderr | 6 | ||||
| -rw-r--r-- | tests/ui/offset-of/offset-of-tuple-field.stderr | 18 | ||||
| -rw-r--r-- | tests/ui/structs/tuple-struct-field-naming-47073.stderr | 6 | ||||
| -rw-r--r-- | tests/ui/tuple/index-invalid.stderr | 12 | ||||
| -rw-r--r-- | tests/ui/tuple/tuple-index-out-of-bounds.stderr | 12 |
7 files changed, 14 insertions, 50 deletions
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 7ec9e7a19ba..edb497b763a 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -2745,6 +2745,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let available_field_names = self.available_field_names(variant, expr, skip_fields); if let Some(field_name) = find_best_match_for_name(&available_field_names, field.ident.name, None) + && !(field.ident.name.as_str().parse::<usize>().is_ok() + && field_name.as_str().parse::<usize>().is_ok()) { err.span_label(field.ident.span, "unknown field"); err.span_suggestion_verbose( @@ -3360,6 +3362,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); } else if let Some(field_name) = find_best_match_for_name(&field_names, field.name, None) + && !(field.name.as_str().parse::<usize>().is_ok() + && field_name.as_str().parse::<usize>().is_ok()) { err.span_suggestion_verbose( field.span, diff --git a/tests/ui/consts/issue-19244-1.stderr b/tests/ui/consts/issue-19244-1.stderr index 7d78f954efe..98a33817b4c 100644 --- a/tests/ui/consts/issue-19244-1.stderr +++ b/tests/ui/consts/issue-19244-1.stderr @@ -4,11 +4,7 @@ error[E0609]: no field `1` on type `(usize,)` LL | let a: [isize; TUP.1]; | ^ unknown field | -help: a field with a similar name exists - | -LL - let a: [isize; TUP.1]; -LL + let a: [isize; TUP.0]; - | + = note: available field is: `0` error: aborting due to 1 previous error diff --git a/tests/ui/error-codes/ex-E0612.stderr b/tests/ui/error-codes/ex-E0612.stderr index 54451d3d452..e6062f6061d 100644 --- a/tests/ui/error-codes/ex-E0612.stderr +++ b/tests/ui/error-codes/ex-E0612.stderr @@ -4,11 +4,7 @@ error[E0609]: no field `1` on type `Foo` LL | y.1; | ^ unknown field | -help: a field with a similar name exists - | -LL - y.1; -LL + y.0; - | + = note: available field is: `0` error: aborting due to 1 previous error diff --git a/tests/ui/offset-of/offset-of-tuple-field.stderr b/tests/ui/offset-of/offset-of-tuple-field.stderr index e4a5ed09e13..01622c5fa2d 100644 --- a/tests/ui/offset-of/offset-of-tuple-field.stderr +++ b/tests/ui/offset-of/offset-of-tuple-field.stderr @@ -28,11 +28,7 @@ error[E0609]: no field `01` on type `(u8, u8)` LL | offset_of!((u8, u8), 01); | ^^ | -help: a field with a similar name exists - | -LL - offset_of!((u8, u8), 01); -LL + offset_of!((u8, u8), 0); - | + = note: available fields are: `0`, `1` error[E0609]: no field `1e2` on type `(u8, u8)` --> $DIR/offset-of-tuple-field.rs:8:26 @@ -80,11 +76,7 @@ error[E0609]: no field `01` on type `(u8, u8)` LL | builtin # offset_of((u8, u8), 01); | ^^ | -help: a field with a similar name exists - | -LL - builtin # offset_of((u8, u8), 01); -LL + builtin # offset_of((u8, u8), 0); - | + = note: available fields are: `0`, `1` error[E0609]: no field `1_` on type `(u8, u8)` --> $DIR/offset-of-tuple-field.rs:15:35 @@ -104,11 +96,7 @@ error[E0609]: no field `2` on type `(u8, u16)` LL | offset_of!(((u8, u16), (u32, u16, u8)), 0.2); | ^ | -help: a field with a similar name exists - | -LL - offset_of!(((u8, u16), (u32, u16, u8)), 0.2); -LL + offset_of!(((u8, u16), (u32, u16, u8)), 0.0); - | + = note: available fields are: `0`, `1` error[E0609]: no field `1e2` on type `(u8, u16)` --> $DIR/offset-of-tuple-field.rs:19:47 diff --git a/tests/ui/structs/tuple-struct-field-naming-47073.stderr b/tests/ui/structs/tuple-struct-field-naming-47073.stderr index efbdaeca4ea..09ba2fb406a 100644 --- a/tests/ui/structs/tuple-struct-field-naming-47073.stderr +++ b/tests/ui/structs/tuple-struct-field-naming-47073.stderr @@ -4,11 +4,7 @@ error[E0609]: no field `00` on type `Verdict` LL | let _condemned = justice.00; | ^^ unknown field | -help: a field with a similar name exists - | -LL - let _condemned = justice.00; -LL + let _condemned = justice.0; - | + = note: available fields are: `0`, `1` error[E0609]: no field `001` on type `Verdict` --> $DIR/tuple-struct-field-naming-47073.rs:11:31 diff --git a/tests/ui/tuple/index-invalid.stderr b/tests/ui/tuple/index-invalid.stderr index acc4134d1a6..fee09b7947c 100644 --- a/tests/ui/tuple/index-invalid.stderr +++ b/tests/ui/tuple/index-invalid.stderr @@ -4,11 +4,7 @@ error[E0609]: no field `1` on type `(((),),)` LL | let _ = (((),),).1.0; | ^ unknown field | -help: a field with a similar name exists - | -LL - let _ = (((),),).1.0; -LL + let _ = (((),),).0.0; - | + = note: available field is: `0` error[E0609]: no field `1` on type `((),)` --> $DIR/index-invalid.rs:4:24 @@ -16,11 +12,7 @@ error[E0609]: no field `1` on type `((),)` LL | let _ = (((),),).0.1; | ^ unknown field | -help: a field with a similar name exists - | -LL - let _ = (((),),).0.1; -LL + let _ = (((),),).0.0; - | + = note: available field is: `0` error[E0609]: no field `000` on type `(((),),)` --> $DIR/index-invalid.rs:6:22 diff --git a/tests/ui/tuple/tuple-index-out-of-bounds.stderr b/tests/ui/tuple/tuple-index-out-of-bounds.stderr index 72827690909..2be9d5631f7 100644 --- a/tests/ui/tuple/tuple-index-out-of-bounds.stderr +++ b/tests/ui/tuple/tuple-index-out-of-bounds.stderr @@ -4,11 +4,7 @@ error[E0609]: no field `2` on type `Point` LL | origin.2; | ^ unknown field | -help: a field with a similar name exists - | -LL - origin.2; -LL + origin.0; - | + = note: available fields are: `0`, `1` error[E0609]: no field `2` on type `({integer}, {integer})` --> $DIR/tuple-index-out-of-bounds.rs:12:11 @@ -16,11 +12,7 @@ error[E0609]: no field `2` on type `({integer}, {integer})` LL | tuple.2; | ^ unknown field | -help: a field with a similar name exists - | -LL - tuple.2; -LL + tuple.0; - | + = note: available fields are: `0`, `1` error: aborting due to 2 previous errors |
