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

Suggest field typo through derefs #117110

Merged
merged 6 commits into from
Nov 18, 2023
Merged

Conversation

estebank
Copy link
Contributor

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 #78374 (comment)

@rustbot
Copy link
Collaborator

rustbot commented Oct 24, 2023

r? @b-naber

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 24, 2023
@estebank estebank force-pushed the deref-field-suggestion branch 2 times, most recently from 5e56fb2 to d3ceb6c Compare October 24, 2023 23:31
}
ty::Alias(ty::Opaque, _) => {
self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you please extract this whole block to a function and not make suggest_await_on_field_access return a value, but instead put the functionality in suggest_await_on_field_access, that is responsible for the return value, in this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean that you should get rid of the has_label block, just that you either move the functionality that calculates has_label to its own function. As an alternative you could also just put the logic that was responsible for calculating the return value of suggest_await_on_field_access directly into the "has_label block" instead of making suggest_await_on_field_access have a return value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of the last commit instead? There's some duplication of the setting of the label, but less state to keep track of.

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)
When encountering a `Result<T, _>` or `Option<T>` where `T` has a field
that's being accessed, suggest calling `.unwrap()` to get to the field.
@b-naber
Copy link
Contributor

b-naber commented Nov 18, 2023

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 18, 2023

📌 Commit 289ce57 has been approved by b-naber

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 18, 2023
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this pull request 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 pull request 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)
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 18, 2023
Rollup of 6 pull requests

Successful merges:

 - rust-lang#116446 (Yeet `mir::Const::from_anon_const`)
 - rust-lang#116750 (Add Seek::seek_relative)
 - rust-lang#117110 (Suggest field typo through derefs)
 - rust-lang#117961 (Add `x suggest` entries for testing `mir-opt` and `coverage`)
 - rust-lang#118020 (Fix links to `From<{OwnedHandle, OwnedFd}> for std::process::Child{Stdin, Stdout, Stderr}` in 1.74 release notes)
 - rust-lang#118034 (bump few deps to fix unsoundness and drop few dup deps)

r? `@ghost`
`@rustbot` modify labels: rollup
compiler-errors added a commit to compiler-errors/rust that referenced this pull request 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)
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 18, 2023
Rollup of 5 pull requests

Successful merges:

 - rust-lang#116750 (Add Seek::seek_relative)
 - rust-lang#117110 (Suggest field typo through derefs)
 - rust-lang#117961 (Add `x suggest` entries for testing `mir-opt` and `coverage`)
 - rust-lang#118020 (Fix links to `From<{OwnedHandle, OwnedFd}> for std::process::Child{Stdin, Stdout, Stderr}` in 1.74 release notes)
 - rust-lang#118034 (bump few deps to fix unsoundness and drop few dup deps)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9e84f6d into rust-lang:master Nov 18, 2023
11 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Nov 18, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request 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
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants