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

"escaping late-bound region during canonicalization" ICE when returning DST #91803

Closed
5225225 opened this issue Dec 11, 2021 · 4 comments · Fixed by #95603
Closed

"escaping late-bound region during canonicalization" ICE when returning DST #91803

5225225 opened this issue Dec 11, 2021 · 4 comments · Fixed by #95603
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@5225225
Copy link
Contributor

5225225 commented Dec 11, 2021

Code

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=681b7aa5ba07fe30593b61e77e3d3b03

trait Foo<'a> {}

fn or<'a>(first: &'static dyn Foo<'a>) -> dyn Foo<'a> {
    return Box::new(panic!());
}

Happens on stable, beta, and nightly.

Error output

   Compiling playground v0.0.1 (/playground)
warning: unreachable call
 --> src/lib.rs:4:12
  |
4 |     return Box::new(panic!());
  |            ^^^^^^^^ -------- any code following this expression is unreachable
  |            |
  |            unreachable call
  |
  = note: `#[warn(unreachable_code)]` on by default

error: internal compiler error: compiler/rustc_infer/src/infer/canonical/canonicalizer.rs:295:21: escaping late-bound region during canonicalization

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1170:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.59.0-nightly (0b42deacc 2021-12-09) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [typeck] type-checking `or`
#1 [typeck_item_bodies] type-checking all item bodies
end of query stack
warning: `playground` (lib) generated 1 warning
error: could not compile `playground`; 1 warning emitted
@5225225 5225225 added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 11, 2021
@5225225
Copy link
Contributor Author

5225225 commented Dec 11, 2021

Regression in 2020-04-23 apparently.

found 7 bors merge commits in the specified range
  commit[0] 2020-04-21UTC: Auto merge of #71170 - spastorino:dyn-fnonce-alignment, r=nikomatsakis
  commit[1] 2020-04-22UTC: Auto merge of #71402 - ehuss:update-cargo, r=ehuss
  commit[2] 2020-04-22UTC: Auto merge of #71410 - JohnTitor:rollup-vh6dut5, r=JohnTitor
  commit[3] 2020-04-22UTC: Auto merge of #71323 - nnethercote:bitcode-in-rlib, r=alexcrichton
  commit[4] 2020-04-22UTC: Auto merge of #71424 - Dylan-DPC:rollup-iunh61a, r=Dylan-DPC
  commit[5] 2020-04-22UTC: Auto merge of #71374 - nnethercote:alphabetize-C-and-Z-options, r=petrochenkov
  commit[6] 2020-04-22UTC: Auto merge of #71431 - Dylan-DPC:rollup-rvm6tfy, r=Dylan-DPC
ERROR: no CI builds available between 45d050cde277b22a755847338f2acc2c7b834141 and b2e36e6c2d229126b59e892c9147fbb68115d292 within last 167 days

@terrarier2111
Copy link
Contributor

@rustbot claim

@rustbot
Copy link
Collaborator

rustbot commented Dec 12, 2021

Error: Malformed triagebot.toml in master branch.
missing field trigger_labels for key autolabel at line 156 column 1

Please let @rust-lang/release know if you're having trouble with this bot.

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Dec 13, 2021
@terrarier2111
Copy link
Contributor

I found a fix for this and #91801 i will open a pr in the next few days.

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue 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 issue 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 bors closed this as completed in 92e53f5 Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
4 participants