diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2025-07-29 18:39:16 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2025-08-07 21:39:00 +0000 |
| commit | 26c12c746296e01c2dc13d8078b0a2f1569fcb1c (patch) | |
| tree | d985e0de99807696015bc4724270eafeefa0d8b7 /tests/ui/tuple | |
| parent | 2fd855fbfc8239285aa2d596f76a8cc75e17ce02 (diff) | |
| download | rust-26c12c746296e01c2dc13d8078b0a2f1569fcb1c.tar.gz rust-26c12c746296e01c2dc13d8078b0a2f1569fcb1c.zip | |
Account for bare tuples in field searching logic
When looking for the field names and types of a given type, account for tuples. This allows suggestions for incorrectly nested field accesses and field name typos to trigger as intended. Previously these suggestions only worked on `ty::Adt`, including tuple structs which are no different to tuples, so they should behave the same in suggestions. ``` error[E0599]: no method named `get_ref` found for tuple `(BufReader<File>,)` in the current scope --> $DIR/missing-field-access.rs:11:15 | LL | let x = f.get_ref(); | ^^^^^^^ method not found in `(BufReader<File>,)` | help: one of the expressions' fields has a method of the same name | LL | let x = f.0.get_ref(); | ++ ```
Diffstat (limited to 'tests/ui/tuple')
| -rw-r--r-- | tests/ui/tuple/index-invalid.stderr | 14 | ||||
| -rw-r--r-- | tests/ui/tuple/missing-field-access.rs | 17 | ||||
| -rw-r--r-- | tests/ui/tuple/missing-field-access.stderr | 38 | ||||
| -rw-r--r-- | tests/ui/tuple/tuple-index-out-of-bounds.stderr | 6 |
4 files changed, 75 insertions, 0 deletions
diff --git a/tests/ui/tuple/index-invalid.stderr b/tests/ui/tuple/index-invalid.stderr index ae2c275f52c..acc4134d1a6 100644 --- a/tests/ui/tuple/index-invalid.stderr +++ b/tests/ui/tuple/index-invalid.stderr @@ -3,18 +3,32 @@ 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; + | error[E0609]: no field `1` on type `((),)` --> $DIR/index-invalid.rs:4:24 | LL | let _ = (((),),).0.1; | ^ unknown field + | +help: a field with a similar name exists + | +LL - let _ = (((),),).0.1; +LL + let _ = (((),),).0.0; + | error[E0609]: no field `000` on type `(((),),)` --> $DIR/index-invalid.rs:6:22 | LL | let _ = (((),),).000.000; | ^^^ unknown field + | + = note: available field is: `0` error: aborting due to 3 previous errors diff --git a/tests/ui/tuple/missing-field-access.rs b/tests/ui/tuple/missing-field-access.rs new file mode 100644 index 00000000000..4ccd759ccd2 --- /dev/null +++ b/tests/ui/tuple/missing-field-access.rs @@ -0,0 +1,17 @@ +use std::{fs::File, io::BufReader}; + +struct F(BufReader<File>); + +fn main() { + let f = F(BufReader::new(File::open("x").unwrap())); + let x = f.get_ref(); //~ ERROR E0599 + //~^ HELP one of the expressions' fields has a method of the same name + //~| HELP consider pinning the expression + let f = (BufReader::new(File::open("x").unwrap()), ); + let x = f.get_ref(); //~ ERROR E0599 + //~^ HELP one of the expressions' fields has a method of the same name + //~| HELP consider pinning the expression + + // FIXME(estebank): the pinning suggestion should not be included in either case. + // https://github.com/rust-lang/rust/issues/144602 +} diff --git a/tests/ui/tuple/missing-field-access.stderr b/tests/ui/tuple/missing-field-access.stderr new file mode 100644 index 00000000000..711a8906d62 --- /dev/null +++ b/tests/ui/tuple/missing-field-access.stderr @@ -0,0 +1,38 @@ +error[E0599]: no method named `get_ref` found for struct `F` in the current scope + --> $DIR/missing-field-access.rs:7:15 + | +LL | struct F(BufReader<File>); + | -------- method `get_ref` not found for this struct +... +LL | let x = f.get_ref(); + | ^^^^^^^ method not found in `F` + | +help: one of the expressions' fields has a method of the same name + | +LL | let x = f.0.get_ref(); + | ++ +help: consider pinning the expression + | +LL ~ let mut pinned = std::pin::pin!(f); +LL ~ let x = pinned.as_ref().get_ref(); + | + +error[E0599]: no method named `get_ref` found for tuple `(BufReader<File>,)` in the current scope + --> $DIR/missing-field-access.rs:11:15 + | +LL | let x = f.get_ref(); + | ^^^^^^^ method not found in `(BufReader<File>,)` + | +help: one of the expressions' fields has a method of the same name + | +LL | let x = f.0.get_ref(); + | ++ +help: consider pinning the expression + | +LL ~ let mut pinned = std::pin::pin!(f); +LL ~ let x = pinned.as_ref().get_ref(); + | + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/tuple/tuple-index-out-of-bounds.stderr b/tests/ui/tuple/tuple-index-out-of-bounds.stderr index 8b3c835c3e3..72827690909 100644 --- a/tests/ui/tuple/tuple-index-out-of-bounds.stderr +++ b/tests/ui/tuple/tuple-index-out-of-bounds.stderr @@ -15,6 +15,12 @@ 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; + | error: aborting due to 2 previous errors |
