Uh oh!
There was an error while loading. Please reload this page.
Fix late-bound ICE in dyn return type suggestion - #95603
Merged
Merged
Conversation
rust-highfive
commented
Apr 2, 2022
Contributor
(rust-highfive has picked a reviewer for you, use r? to override) |
cjgillot
reviewed
Apr 2, 2022
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
michaelwoerister
commented
Apr 4, 2022
Member
Thanks for the PR, @compiler-errors! This looks like r? rust-lang/diagnostics to me. |
oli-obk
commented
Apr 4, 2022
Contributor
oooh nice @bors r+ |
bors
commented
Apr 4, 2022
Collaborator
📌 Commit b899251 has been approved by |
Dylan-DPC added a commit
to Dylan-DPC/rust
that referenced
this pull request
Apr 4, 2022
Fix late-bound ICE in `dyn` return type suggestion
This fixes the root-cause of the attached issues -- the root problem is that we're using the return type from a signature with late-bound instead of early-bound regions. The change on line 1087 (`let Some(liberated_sig) = typeck_results.liberated_fn_sigs().get(fn_hir_id) else { return false; };`) makes sure we're grabbing the _right_ return type for this suggestion to check the `dyn` predicates with.
Fixesrust-lang#91801Fixesrust-lang#91803
This fix also includes some drive-by changes, specifically:
1. Don't suggest boxing when we have `-> dyn Trait` and are already returning `Box<T>` where `T: Trait` (before we always boxed the value).
2. Suggestion applies even when the return type is a type alias (e.g. `type Foo = dyn Trait`). This does cause the suggestion to expand to the aliased type, but I think it's still beneficial.
3. Split up the multipart suggestion because there's a 6-line max in the printed output...
I am open to splitting out the above changes, if we just want to fix the ICE first.
cc: `@terrarier2111` and rust-lang#92289Dylan-DPC added a commit
to Dylan-DPC/rust
that referenced
this pull request
Apr 4, 2022
Fix late-bound ICE in `dyn` return type suggestion
This fixes the root-cause of the attached issues -- the root problem is that we're using the return type from a signature with late-bound instead of early-bound regions. The change on line 1087 (`let Some(liberated_sig) = typeck_results.liberated_fn_sigs().get(fn_hir_id) else { return false; };`) makes sure we're grabbing the _right_ return type for this suggestion to check the `dyn` predicates with.
Fixesrust-lang#91801Fixesrust-lang#91803
This fix also includes some drive-by changes, specifically:
1. Don't suggest boxing when we have `-> dyn Trait` and are already returning `Box<T>` where `T: Trait` (before we always boxed the value).
2. Suggestion applies even when the return type is a type alias (e.g. `type Foo = dyn Trait`). This does cause the suggestion to expand to the aliased type, but I think it's still beneficial.
3. Split up the multipart suggestion because there's a 6-line max in the printed output...
I am open to splitting out the above changes, if we just want to fix the ICE first.
cc: ``@terrarier2111`` and rust-lang#92289bors added a commit
to rust-lang-ci/rust
that referenced
this pull request
Apr 5, 2022
Rollup of 7 pull requests Successful merges: - rust-lang#91873 (Mention implementers of unsatisfied trait) - rust-lang#95588 (explicitly distinguish pointer::addr and pointer::expose_addr) - rust-lang#95603 (Fix late-bound ICE in `dyn` return type suggestion) - rust-lang#95620 (interpret: remove MemoryExtra in favor of giving access to the Machine) - rust-lang#95630 (Update `NonNull` pointer provenance methods' documentation) - rust-lang#95631 (Refactor: remove unnecessary nested blocks) - rust-lang#95642 (`CandidateSource::XCandidate` -> `CandidateSource::X`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes the root-cause of the attached issues -- the root problem is that we're using the return type from a signature with late-bound instead of early-bound regions. The change on line 1087 (
let Some(liberated_sig) = typeck_results.liberated_fn_sigs().get(fn_hir_id) else { return false; };) makes sure we're grabbing the right return type for this suggestion to check thedynpredicates with.Fixes#91801
Fixes#91803
This fix also includes some drive-by changes, specifically:
-> dyn Traitand are already returningBox<T>whereT: Trait(before we always boxed the value).type Foo = dyn Trait). This does cause the suggestion to expand to the aliased type, but I think it's still beneficial.I am open to splitting out the above changes, if we just want to fix the ICE first.
cc: @terrarier2111 and #92289