Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Reach into" Result/Option to look for expected methods in error messages #78374

Open
qrnch-jan opened this issue Oct 25, 2020 · 2 comments
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@qrnch-jan
Copy link

Sometimes it would be really helpful if the compiler could "reach into" a Result or Option. Say one forgets to ? or even .unwrap(), the compiler currently says something like "no method named get_ref found for enum std::result::Result<tokio_rustls::client::TlsStream<tokio::net::TcpStream>, std::io::Error> in the current scope". It would be helpful if it would say something along the line of ".. but contained type T contains the requested method".

@estebank

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 25, 2020
@estebank
Copy link
Contributor

estebank commented Oct 25, 2020

We already special case errors for Option and Result, and provide similar suggestions to await Futures. I think this is worthwhile.

Edit: thinking about this a bit more it would be great if we could do this for arbitrary container types by checking all variants with single fields on enums for types that would match the expected type or have the desired field or method.

@camelid camelid changed the title "Reach into" to Result/Option to look for expected methods in error messages "Reach into" Result/Option to look for expected methods in error messages Oct 26, 2020
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Oct 26, 2020
@jyn514
Copy link
Member

jyn514 commented Oct 30, 2020

I have a similar request:

error[E0609]: no field `include_default_target` on type `std::sync::Arc<config::Config>`
   --> src/docbuilder/rustwide_builder.rs:325:50
    |
325 |                 } = metadata.targets(self.config.include_default_target);
    |                                                  ^^^^^^^^^^^^^^^^^^^^^^ unknown field

error: aborting due to previous error

Normally rust would suggest the typo include_default_target -> include_default_targets. But since it's behind an Arc, the compiler only looks on fields on the Arc itself. It would nice to follow deref coercion for suggestions.

estebank added a commit to estebank/rust that referenced this issue Oct 24, 2023
Take into account implicit dereferences when suggesting fields.

```
error[E0609]: no field `longname` on type `Arc<S>`
  --> $DIR/suggest-field-through-deref.rs:10:15
   |
LL |     let _ = x.longname;
   |               ^^^^^^^^ help: a field with a similar name exists: `long_name`
```

CC rust-lang#78374 (comment)
estebank added a commit to estebank/rust that referenced this issue Oct 24, 2023
Take into account implicit dereferences when suggesting fields.

```
error[E0609]: no field `longname` on type `Arc<S>`
  --> $DIR/suggest-field-through-deref.rs:10:15
   |
LL |     let _ = x.longname;
   |               ^^^^^^^^ help: a field with a similar name exists: `long_name`
```

CC rust-lang#78374 (comment)
estebank added a commit to estebank/rust that referenced this issue Oct 24, 2023
Take into account implicit dereferences when suggesting fields.

```
error[E0609]: no field `longname` on type `Arc<S>`
  --> $DIR/suggest-field-through-deref.rs:10:15
   |
LL |     let _ = x.longname;
   |               ^^^^^^^^ help: a field with a similar name exists: `long_name`
```

CC rust-lang#78374 (comment)
estebank added a commit to estebank/rust that referenced this issue Nov 9, 2023
Take into account implicit dereferences when suggesting fields.

```
error[E0609]: no field `longname` on type `Arc<S>`
  --> $DIR/suggest-field-through-deref.rs:10:15
   |
LL |     let _ = x.longname;
   |               ^^^^^^^^ help: a field with a similar name exists: `long_name`
```

CC rust-lang#78374 (comment)
estebank added a commit to estebank/rust that referenced this issue Nov 15, 2023
Take into account implicit dereferences when suggesting fields.

```
error[E0609]: no field `longname` on type `Arc<S>`
  --> $DIR/suggest-field-through-deref.rs:10:15
   |
LL |     let _ = x.longname;
   |               ^^^^^^^^ help: a field with a similar name exists: `long_name`
```

CC rust-lang#78374 (comment)
estebank added a commit to estebank/rust that referenced this issue Nov 16, 2023
Take into account implicit dereferences when suggesting fields.

```
error[E0609]: no field `longname` on type `Arc<S>`
  --> $DIR/suggest-field-through-deref.rs:10:15
   |
LL |     let _ = x.longname;
   |               ^^^^^^^^ help: a field with a similar name exists: `long_name`
```

CC rust-lang#78374 (comment)
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Nov 18, 2023
…=b-naber

Suggest field typo through derefs

Take into account implicit dereferences when suggesting fields.

```
error[E0609]: no field `longname` on type `Arc<S>`
  --> $DIR/suggest-field-through-deref.rs:10:15
   |
LL |     let _ = x.longname;
   |               ^^^^^^^^ help: a field with a similar name exists: `long_name`
```

CC rust-lang#78374 (comment)
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Nov 18, 2023
…=b-naber

Suggest field typo through derefs

Take into account implicit dereferences when suggesting fields.

```
error[E0609]: no field `longname` on type `Arc<S>`
  --> $DIR/suggest-field-through-deref.rs:10:15
   |
LL |     let _ = x.longname;
   |               ^^^^^^^^ help: a field with a similar name exists: `long_name`
```

CC rust-lang#78374 (comment)
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Nov 18, 2023
…=b-naber

Suggest field typo through derefs

Take into account implicit dereferences when suggesting fields.

```
error[E0609]: no field `longname` on type `Arc<S>`
  --> $DIR/suggest-field-through-deref.rs:10:15
   |
LL |     let _ = x.longname;
   |               ^^^^^^^^ help: a field with a similar name exists: `long_name`
```

CC rust-lang#78374 (comment)
compiler-errors added a commit to compiler-errors/rust that referenced this issue Nov 18, 2023
…=b-naber

Suggest field typo through derefs

Take into account implicit dereferences when suggesting fields.

```
error[E0609]: no field `longname` on type `Arc<S>`
  --> $DIR/suggest-field-through-deref.rs:10:15
   |
LL |     let _ = x.longname;
   |               ^^^^^^^^ help: a field with a similar name exists: `long_name`
```

CC rust-lang#78374 (comment)
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 18, 2023
Rollup merge of rust-lang#117110 - estebank:deref-field-suggestion, r=b-naber

Suggest field typo through derefs

Take into account implicit dereferences when suggesting fields.

```
error[E0609]: no field `longname` on type `Arc<S>`
  --> $DIR/suggest-field-through-deref.rs:10:15
   |
LL |     let _ = x.longname;
   |               ^^^^^^^^ help: a field with a similar name exists: `long_name`
```

CC rust-lang#78374 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants