-
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
Fix late-bound ICE #92289
Fix late-bound ICE #92289
Conversation
r? @wesleywiser (rust-highfive has picked a reviewer for you, use r? to override) |
I am not sure tho if the long "FIXME" comment is still correct after this or if this is even the correct way to fix the issue, as one test changed significantly with this fix applied. |
@wesleywiser Could you take a look at this? |
fcx.require_type_is_sized(declared_ret_ty, decl.output.span(), traits::SizedReturnType); | ||
fcx.check_expr(&body.value); |
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.
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.
@wesleywiser correct, before my change this was branchless code. I want it to return to being branchless code while also supporting the improved diagnostics.
= note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types> | ||
= note: if all the returned values were of the same type you could use `impl std::fmt::Display` as the return type | ||
= note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits> | ||
= note: you can create a new `enum` with a variant for each returned type |
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.
cc @estebank This PR resolves an ICE but causes some changes to diagnostics. Most of the notes appear to be more or less present as help messages instead but this note about creating a new enum is missing. Do you have concerns with merging this PR?
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.
Given this fixes an ICE, lets merge, but I at least I would open a ticket pointing at this PR about getting these back :-/
63a5634
to
42b26cd
Compare
Apologies for the delays in getting back to this. @terrarier2111 if you have a bit of time, would it be possible to see how removing the fixme |
LL ~ fn pug() -> Box<dyn std::fmt::Display> { | ||
LL | match 13 { | ||
LL ~ 0 => Box::new(0i32), | ||
LL ~ 1 => Box::new(1u32), | ||
LL ~ _ => Box::new(2u32), | ||
| | ||
|
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 guess this is the only output we'd lose, right? Can we check whether this suggestion in particular still triggers anywhere else?
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.
At least the help "return a boxed trait object instead" triggers in dyn-trait-return-should-be-impl-trait
The " |
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. Fixes rust-lang#91801 Fixes rust-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#92289
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. Fixes rust-lang#91801 Fixes rust-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#92289
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. Fixes rust-lang#91801 Fixes rust-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#92289
☔ The latest upstream changes (presumably #95662) made this pull request unmergeable. Please resolve the merge conflicts. |
Visiting at T-compiler triage meeting. We believe the root cause (of the issues addressed by this PR, namely #91803 and #91801) has since been independently addressed by PR #95603. Therefore, we are closing this PR as no longer necessary. Thank you so much for your contribution, @terrarier2111 ! and also, if this summary is incorrect, and this PR is providing new value that is not addressed by PR #95603, please do feel free to reopen this PR! |
This fixes #91803 and #91801