rust/tests/ui/tuple/missing-field-access.rs
Esteban Küber dd3b8255ca Do not suggest pinning missing .get_ref()
When suggesting field access which would encounter a method not found, do not suggest pinning when those methods are on `impl Pin` itself.

```
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();
   |               ++
```
instead of
```
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();
   |
```
2025-08-07 21:39:00 +00:00

17 lines
708 B
Rust

// Ensure that suggestions to search for missing intermediary field accesses are available for both
// tuple structs *and* regular tuples.
// Ensure that we do not suggest pinning the expression just because `Pin::get_ref` exists.
// https://github.com/rust-lang/rust/issues/144602
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
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
}