-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 dereference of Box
when inner type is expected
#90627
Conversation
This suggestion is already emitted in other situations, but not the situation described in the PR description:
|
src/test/ui/terr-sorts.stderr
Outdated
| ^ | ||
| | | ||
| expected struct `Foo`, found struct `Box` | ||
| help: try dereferencing the `Box` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I use span_suggestion_verbose
instead to improve cases like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, r=me after that.
src/test/ui/terr-sorts.stderr
Outdated
| ^ | ||
| | | ||
| expected struct `Foo`, found struct `Box` | ||
| help: try dereferencing the `Box` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, r=me after that.
26371aa
to
ab95e04
Compare
Thanks! @bors r=davidtwco rollup |
📌 Commit ab95e04e121af4bb1ff1c30e30b1f3ab77c507ef has been approved by |
For example: enum Ty { Unit, List(Box<Ty>), } fn foo(x: Ty) -> Ty { match x { Ty::Unit => Ty::Unit, Ty::List(elem) => foo(elem), } } Before, the only suggestion was to rewrap `elem` with `Ty::List`, which is unhelpful and confusing: error[E0308]: mismatched types --> src/test/ui/suggestions/boxed-variant-field.rs:9:31 | 9 | Ty::List(elem) => foo(elem), | ^^^^ | | | expected enum `Ty`, found struct `Box` | help: try using a variant of the expected enum: `Ty::List(elem)` | = note: expected enum `Ty` found struct `Box<Ty>` Now, rustc will first suggest dereferencing the `Box`, which is most likely what the user intended: error[E0308]: mismatched types --> src/test/ui/suggestions/boxed-variant-field.rs:9:31 | 9 | Ty::List(elem) => foo(elem), | ^^^^ expected enum `Ty`, found struct `Box` | = note: expected enum `Ty` found struct `Box<Ty>` help: try dereferencing the `Box` | 9 | Ty::List(elem) => foo(*elem), | + help: try using a variant of the expected enum | 9 | Ty::List(elem) => foo(Ty::List(elem)), | ~~~~~~~~~~~~~~
ab95e04
to
d93f7f9
Compare
(Fixed something confusing in the commit message) @bors r=davidtwco |
📌 Commit d93f7f9 has been approved by |
Suggest dereference of `Box` when inner type is expected For example: enum Ty { Unit, List(Box<Ty>), } fn foo(x: Ty) -> Ty { match x { Ty::Unit => Ty::Unit, Ty::List(elem) => foo(elem), } } Before, the only suggestion was to rewrap `inner` with `Ty::Wrapper`, which is unhelpful and confusing: error[E0308]: mismatched types --> src/test/ui/suggestions/boxed-variant-field.rs:9:31 | 9 | Ty::List(elem) => foo(elem), | ^^^^ | | | expected enum `Ty`, found struct `Box` | help: try using a variant of the expected enum: `Ty::List(elem)` | = note: expected enum `Ty` found struct `Box<Ty>` Now, rustc will first suggest dereferencing the `Box`, which is most likely what the user intended: error[E0308]: mismatched types --> src/test/ui/suggestions/boxed-variant-field.rs:9:31 | 9 | Ty::List(elem) => foo(elem), | ^^^^ expected enum `Ty`, found struct `Box` | = note: expected enum `Ty` found struct `Box<Ty>` help: try dereferencing the `Box` | 9 | Ty::List(elem) => foo(*elem), | + help: try using a variant of the expected enum | 9 | Ty::List(elem) => foo(Ty::List(elem)), | ~~~~~~~~~~~~~~ r? `@davidtwco`
…askrgr Rollup of 6 pull requests Successful merges: - rust-lang#90487 (Add a chapter on reading Rustdoc output) - rust-lang#90508 (Apply adjustments for field expression even if inaccessible) - rust-lang#90627 (Suggest dereference of `Box` when inner type is expected) - rust-lang#90642 (use matches!() macro in more places) - rust-lang#90646 (type error go brrrrrrrr) - rust-lang#90649 (Run reveal_all on MIR when inlining is activated.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…ef-suggestion, r=camelid Deduplicate box deref and regular deref suggestions Remove the suggestion code special-cased for Box deref. r? `@camelid` since you introduced the code in rust-lang#90627
…ef-suggestion, r=camelid Deduplicate box deref and regular deref suggestions Remove the suggestion code special-cased for Box deref. r? ``@camelid`` since you introduced the code in rust-lang#90627
…ef-suggestion, r=camelid Deduplicate box deref and regular deref suggestions Remove the suggestion code special-cased for Box deref. r? ```@camelid``` since you introduced the code in rust-lang#90627
For example:
Before, the only suggestion was to rewrap
inner
withTy::Wrapper
,which is unhelpful and confusing:
Now, rustc will first suggest dereferencing the
Box
, which is mostlikely what the user intended:
r? @davidtwco