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

ICE: cannot convert ReErased to a region vid #81857

Closed
ZhangZhuoSJTU opened this issue Feb 7, 2021 · 4 comments · Fixed by #89561
Closed

ICE: cannot convert ReErased to a region vid #81857

ZhangZhuoSJTU opened this issue Feb 7, 2021 · 4 comments · Fixed by #89561
Labels
A-borrow-checker Area: The borrow checker A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) 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

@ZhangZhuoSJTU
Copy link

It seems like a duplicate of #78174. But it is, on the other hand, an invalid statements instead of a nightly-only feature (inline_const). So I open this issue.

I will try to understand whether it is indeed a duplicate. But it would be very appreciated if someone can figure it out, so that we do not bother so much. Thanks!

Code

#[c=""]

fn e()->i {{""]const{""

md5: fef99e2b36eeaaa4fe32447f7ff03c9c

Meta

It is on nightly, beta, and stable versions.

rustc --version --verbose:

rustc 1.52.0-nightly (a73c2e555 2021-02-06)
binary: rustc
commit-hash: a73c2e555c26ef0c8b98c91c97a7d24b7017267f
commit-date: 2021-02-06
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1

rustc 1.50.0-beta.8 (1cd030396 2021-01-20)
binary: rustc
commit-hash: 1cd0303963629f317a08e7e52162ccca7232ae7f
commit-date: 2021-01-20
host: x86_64-unknown-linux-gnu
release: 1.50.0-beta.8

rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-unknown-linux-gnu
release: 1.49.0

Error output

The output is from nightly.

➜  playground rustc poc.rs
error: this file contains an unclosed delimiter
 --> poc.rs:3:25
  |
3 | fn e()->i {{""]const{""
  |           -         -   ^
  |           |         |
  |           |         unclosed delimiter
  |           unclosed delimiter

error: mismatched closing delimiter: `]`
 --> poc.rs:3:15
  |
3 | fn e()->i {{""]const{""
  |            -  ^ mismatched closing delimiter
  |            |
  |            unclosed delimiter

error: cannot find attribute `c` in this scope
 --> poc.rs:1:3
  |
1 | #[c=""]
  |   ^

error[E0412]: cannot find type `i` in this scope
 --> poc.rs:3:9
  |
3 | fn e()->i {{""]const{""
  |         ^ help: a builtin type with a similar name exists: `i8`

error[E0658]: inline-const is experimental
 --> poc.rs:3:16
  |
3 | fn e()->i {{""]const{""
  |                ^^^^^
  |
  = note: see issue #76001 <https://github.com/rust-lang/rust/issues/76001> for more information
  = help: add `#![feature(inline_const)]` to the crate attributes to enable

warning: unnecessary braces around block return value
 --> poc.rs:3:12
  |
3 | fn e()->i {{""]const{""
  |            ^^^^ help: remove these braces
  |
  = note: `#[warn(unused_braces)]` on by default

error[E0308]: mismatched types
 --> poc.rs:3:13
  |
3 | fn e()->i {{""]const{""
  |             ^^ expected `()`, found `&str`

error: internal compiler error: compiler/rustc_mir/src/borrow_check/universal_regions.rs:768:36: cannot convert `ReErased` to a region vid

thread 'rustc' panicked at 'Box<Any>', /rustc/a73c2e555c26ef0c8b98c91c97a7d24b7017267f/library/std/src/panic.rs:59:5
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.52.0-nightly (a73c2e555 2021-02-06) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking `e::{constant#0}`
#1 [mir_drops_elaborated_and_const_checked] elaborating drops for `e::{constant#0}`
end of query stack
error: aborting due to 7 previous errors; 1 warning emitted

Some errors have detailed explanations: E0308, E0412, E0658.
For more information about an error, try `rustc --explain E0308`.
Backtrace

thread 'rustc' panicked at 'Box<Any>', /rustc/a73c2e555c26ef0c8b98c91c97a7d24b7017267f/library/std/src/panic.rs:59:5
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_mir::borrow_check::universal_regions::UniversalRegionIndices::to_region_vid
   8: rustc_mir::borrow_check::universal_regions::UniversalRegionIndices::fold_to_region_vids::{{closure}}
   9: rustc_middle::ty::structural_impls::<impl rustc_middle::ty::fold::TypeFoldable for &rustc_middle::ty::TyS>::super_fold_with
  10: rustc_mir::borrow_check::universal_regions::UniversalRegions::new
  11: rustc_mir::borrow_check::nll::replace_regions_in_mir
  12: rustc_mir::borrow_check::do_mir_borrowck
  13: rustc_infer::infer::InferCtxtBuilder::enter
  14: rustc_mir::borrow_check::mir_borrowck
  15: core::ops::function::FnOnce::call_once
  16: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_borrowck>::compute
  17: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  18: rustc_data_structures::stack::ensure_sufficient_stack
  19: rustc_query_system::query::plumbing::force_query_with_job
  20: rustc_query_system::query::plumbing::get_query_impl
  21: rustc_query_system::query::plumbing::ensure_query_impl
  22: rustc_mir::transform::mir_drops_elaborated_and_const_checked
  23: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_drops_elaborated_and_const_checked>::compute
  24: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  25: rustc_data_structures::stack::ensure_sufficient_stack
  26: rustc_query_system::query::plumbing::force_query_with_job
  27: rustc_query_system::query::plumbing::get_query_impl
  28: rustc_mir::transform::inner_mir_for_ctfe
  29: rustc_mir::transform::mir_for_ctfe
  30: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_for_ctfe>::compute
  31: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  32: rustc_data_structures::stack::ensure_sufficient_stack
  33: rustc_query_system::query::plumbing::force_query_with_job
  34: rustc_query_system::query::plumbing::get_query_impl
  35: <rustc_mir::const_eval::machine::CompileTimeInterpreter as rustc_mir::interpret::machine::Machine>::load_mir
  36: rustc_mir::interpret::eval_context::InterpCx<M>::load_mir
  37: rustc_mir::const_eval::eval_queries::eval_to_allocation_raw_provider
  38: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::eval_to_allocation_raw>::compute
  39: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  40: rustc_data_structures::stack::ensure_sufficient_stack
  41: rustc_query_system::query::plumbing::force_query_with_job
  42: rustc_query_system::query::plumbing::get_query_impl
  43: rustc_mir::const_eval::eval_queries::eval_to_const_value_raw_provider
  44: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::eval_to_const_value_raw>::compute
  45: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  46: rustc_data_structures::stack::ensure_sufficient_stack
  47: rustc_query_system::query::plumbing::force_query_with_job
  48: rustc_query_system::query::plumbing::get_query_impl
  49: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_resolve
  50: rustc_infer::infer::InferCtxt::const_eval_resolve
  51: rustc_trait_selection::traits::const_evaluatable::is_const_evaluatable
  52: rustc_trait_selection::traits::fulfill::FulfillProcessor::progress_changed_obligations
  53: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_where_possible
  54: rustc_typeck::check::fn_ctxt::_impl::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::select_obligations_where_possible
  55: rustc_infer::infer::InferCtxtBuilder::enter
  56: rustc_typeck::check::typeck
  57: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck>::compute
  58: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  59: rustc_data_structures::stack::ensure_sufficient_stack
  60: rustc_query_system::query::plumbing::force_query_with_job
  61: rustc_query_system::query::plumbing::get_query_impl
  62: rustc_query_system::query::plumbing::ensure_query_impl
  63: rustc_typeck::check::typeck_item_bodies
  64: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck_item_bodies>::compute
  65: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  66: rustc_data_structures::stack::ensure_sufficient_stack
  67: rustc_query_system::query::plumbing::force_query_with_job
  68: rustc_query_system::query::plumbing::get_query_impl
  69: rustc_typeck::check_crate
  70: rustc_interface::passes::analysis
  71: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  72: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  73: rustc_data_structures::stack::ensure_sufficient_stack
  74: rustc_query_system::query::plumbing::force_query_with_job
  75: rustc_query_system::query::plumbing::get_query_impl
  76: rustc_interface::passes::QueryContext::enter
  77: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  78: rustc_span::with_source_map
  79: rustc_interface::interface::create_compiler_and_run
  80: rustc_span::with_session_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@ZhangZhuoSJTU ZhangZhuoSJTU 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 Feb 7, 2021
@jonas-schievink jonas-schievink added A-borrow-checker Area: The borrow checker A-lifetimes Area: Lifetimes / regions F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) labels Feb 7, 2021
@dillona
Copy link
Contributor

dillona commented Feb 8, 2021

searched nightlies: from nightly-2020-10-11 to nightly-2021-02-08
regressed nightly: nightly-2020-10-18
searched commits: from e3051d8 to 043eca7
regressed commit: 6af9846

bisected with cargo-bisect-rustc v0.6.0

Host triple: aarch64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --regress ice

@ZhangZhuoSJTU
Copy link
Author

ZhangZhuoSJTU commented Feb 9, 2021

Another test-case.

fn main() {
  const {
    ""
  }
}

@osa1
Copy link
Contributor

osa1 commented Feb 11, 2021

This seems to be a bad interaction between constant evaluation and region erasing. It's not specific to string literals, same thing happens with e.g.

#![feature(inline_const)]
#![allow(incomplete_features)]

fn main() {
    const { &[1usize] };
}

Basically returning a &'static value seems to be enough to trigger this.

I'd like to debug this but I'm not sure where to start. Where can I learn more about the handling of regions in constant evaluation?

@adamgemmell
Copy link
Contributor

This example used to ICE but is now picked up by E308, at least on x86_64/aarch64-unknown-linux-gnu

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 8, 2021
Type inference for inline consts

Fixes rust-lang#78132
Fixes rust-lang#78174
Fixes rust-lang#81857
Fixes rust-lang#89964

Perform type checking/inference of inline consts in the same context as the outer def, similar to what is currently done to closure.

Doing so would require `closure_base_def_id` of the inline const to return the outer def, and since `closure_base_def_id` can be called on non-local crate (and thus have no HIR available), a new `DefKind` is created for inline consts.

The type of the generated anon const can capture lifetime of outer def, so we couldn't just use the typeck result as the type of the inline const's def. Closure has a similar issue, and it uses extra type params `CK, CS, U` to capture closure kind, input/output signature and upvars. I use a similar approach for inline consts, letting it have an extra type param `R`, and then `typeof(InlineConst<[paremt generics], R>)` would just be `R`. In borrowck region requirements are also propagated to the outer MIR body just like it's currently done for closure.

With this PR, inline consts in expression position are quitely usable now; however the usage in pattern position is still incomplete -- since those does not remain in the MIR borrowck couldn't verify the lifetime there. I have left an ignored test as a FIXME.

Some disucssions can be found on [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck).
cc `@spastorino` `@lcnr`
r? `@nikomatsakis`

`@rustbot` label A-inference F-inline_const T-compiler
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 8, 2021
Type inference for inline consts

Fixes rust-lang#78132
Fixes rust-lang#78174
Fixes rust-lang#81857
Fixes rust-lang#89964

Perform type checking/inference of inline consts in the same context as the outer def, similar to what is currently done to closure.

Doing so would require `closure_base_def_id` of the inline const to return the outer def, and since `closure_base_def_id` can be called on non-local crate (and thus have no HIR available), a new `DefKind` is created for inline consts.

The type of the generated anon const can capture lifetime of outer def, so we couldn't just use the typeck result as the type of the inline const's def. Closure has a similar issue, and it uses extra type params `CK, CS, U` to capture closure kind, input/output signature and upvars. I use a similar approach for inline consts, letting it have an extra type param `R`, and then `typeof(InlineConst<[paremt generics], R>)` would just be `R`. In borrowck region requirements are also propagated to the outer MIR body just like it's currently done for closure.

With this PR, inline consts in expression position are quitely usable now; however the usage in pattern position is still incomplete -- since those does not remain in the MIR borrowck couldn't verify the lifetime there. I have left an ignored test as a FIXME.

Some disucssions can be found on [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck).
cc ``@spastorino`` ``@lcnr``
r? ``@nikomatsakis``

``@rustbot`` label A-inference F-inline_const T-compiler
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 8, 2021
Type inference for inline consts

Fixes rust-lang#78132
Fixes rust-lang#78174
Fixes rust-lang#81857
Fixes rust-lang#89964

Perform type checking/inference of inline consts in the same context as the outer def, similar to what is currently done to closure.

Doing so would require `closure_base_def_id` of the inline const to return the outer def, and since `closure_base_def_id` can be called on non-local crate (and thus have no HIR available), a new `DefKind` is created for inline consts.

The type of the generated anon const can capture lifetime of outer def, so we couldn't just use the typeck result as the type of the inline const's def. Closure has a similar issue, and it uses extra type params `CK, CS, U` to capture closure kind, input/output signature and upvars. I use a similar approach for inline consts, letting it have an extra type param `R`, and then `typeof(InlineConst<[paremt generics], R>)` would just be `R`. In borrowck region requirements are also propagated to the outer MIR body just like it's currently done for closure.

With this PR, inline consts in expression position are quitely usable now; however the usage in pattern position is still incomplete -- since those does not remain in the MIR borrowck couldn't verify the lifetime there. I have left an ignored test as a FIXME.

Some disucssions can be found on [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck).
cc ```@spastorino``` ```@lcnr```
r? ```@nikomatsakis```

```@rustbot``` label A-inference F-inline_const T-compiler
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 8, 2021
Type inference for inline consts

Fixes rust-lang#78132
Fixes rust-lang#78174
Fixes rust-lang#81857
Fixes rust-lang#89964

Perform type checking/inference of inline consts in the same context as the outer def, similar to what is currently done to closure.

Doing so would require `closure_base_def_id` of the inline const to return the outer def, and since `closure_base_def_id` can be called on non-local crate (and thus have no HIR available), a new `DefKind` is created for inline consts.

The type of the generated anon const can capture lifetime of outer def, so we couldn't just use the typeck result as the type of the inline const's def. Closure has a similar issue, and it uses extra type params `CK, CS, U` to capture closure kind, input/output signature and upvars. I use a similar approach for inline consts, letting it have an extra type param `R`, and then `typeof(InlineConst<[paremt generics], R>)` would just be `R`. In borrowck region requirements are also propagated to the outer MIR body just like it's currently done for closure.

With this PR, inline consts in expression position are quitely usable now; however the usage in pattern position is still incomplete -- since those does not remain in the MIR borrowck couldn't verify the lifetime there. I have left an ignored test as a FIXME.

Some disucssions can be found on [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck).
cc ````@spastorino```` ````@lcnr````
r? ````@nikomatsakis````

````@rustbot```` label A-inference F-inline_const T-compiler
@bors bors closed this as completed in fd74c93 Nov 9, 2021
flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 23, 2021
Type inference for inline consts

Fixes rust-lang#78132
Fixes rust-lang#78174
Fixes rust-lang#81857
Fixes rust-lang#89964

Perform type checking/inference of inline consts in the same context as the outer def, similar to what is currently done to closure.

Doing so would require `closure_base_def_id` of the inline const to return the outer def, and since `closure_base_def_id` can be called on non-local crate (and thus have no HIR available), a new `DefKind` is created for inline consts.

The type of the generated anon const can capture lifetime of outer def, so we couldn't just use the typeck result as the type of the inline const's def. Closure has a similar issue, and it uses extra type params `CK, CS, U` to capture closure kind, input/output signature and upvars. I use a similar approach for inline consts, letting it have an extra type param `R`, and then `typeof(InlineConst<[paremt generics], R>)` would just be `R`. In borrowck region requirements are also propagated to the outer MIR body just like it's currently done for closure.

With this PR, inline consts in expression position are quitely usable now; however the usage in pattern position is still incomplete -- since those does not remain in the MIR borrowck couldn't verify the lifetime there. I have left an ignored test as a FIXME.

Some disucssions can be found on [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck).
cc `````@spastorino````` `````@lcnr`````
r? `````@nikomatsakis`````

`````@rustbot````` label A-inference F-inline_const T-compiler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) 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
5 participants