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

Fix late-bound ICE #92289

Closed

Conversation

terrarier2111
Copy link
Contributor

This fixes #91803 and #91801

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 26, 2021
@rust-highfive
Copy link
Collaborator

r? @wesleywiser

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 26, 2021
@terrarier2111
Copy link
Contributor Author

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.

@terrarier2111
Copy link
Contributor Author

@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);
Copy link
Member

Choose a reason for hiding this comment

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

@estebank I see you added this branch in e536257 including the FIXME. Did you add the FIXME because it would be great to unify the ty::Dynamic case with all the others and remove the check or for another reason? Just trying to figure out what we'd like to have fixed. 🙂

Copy link
Contributor

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
Copy link
Member

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?

Copy link
Contributor

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 :-/

@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 27, 2022
@wesleywiser
Copy link
Member

Since this is waiting on @estebank to take a look, I'm going to reassign.

r? @estebank

@estebank
Copy link
Contributor

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 if/else and instead do what we used to do (just what is in the else branch) affects the diagnostics?

Comment on lines -277 to -283
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),
|

Copy link
Contributor

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?

Copy link
Contributor Author

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

@terrarier2111
Copy link
Contributor Author

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 if/else and instead do what we used to do (just what is in the else branch) affects the diagnostics?

The "match arms have incompatible types" and "if and else have incompatible types" warnings in "point-to-type-err-cause-on-impl-trait-return" go away and the "if and else have incompatible types" warning in "dyn-trait-return-should-be-impl-trait" goes away, everything else stays as-is.

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.

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
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.

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
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.

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
@bors
Copy link
Contributor

bors commented Apr 5, 2022

☔ The latest upstream changes (presumably #95662) made this pull request unmergeable. Please resolve the merge conflicts.

@pnkfelix
Copy link
Member

pnkfelix commented Apr 14, 2022

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!

@pnkfelix pnkfelix closed this Apr 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"escaping late-bound region during canonicalization" ICE when returning DST
8 participants