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: lifetime in type in const-expr in len of array-type [T; len]: cannot convert ReEarlyBound #66152

Closed
lambinoo opened this issue Nov 6, 2019 · 6 comments · Fixed by #96730
Assignees
Labels
A-borrow-checker Area: The borrow checker A-const-generics Area: const generics (parameters and arguments) A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lambinoo
Copy link
Contributor

lambinoo commented Nov 6, 2019

When trying to compile the following code, a panic occurs on librustc_mir:

use core::mem::size_of;    
    
struct Foo<'a> {    
    foo0: Option<Foo<'a>>,    
    foo1: Option<Foo<'a>>,    
    lots_of_foos: [u64; size_of::<Option<Foo<'a>>>()]    
}    
fn main() {} 

Backtrace

RUST_BACKTRACE=1 cargo run +stable --verbose

   Compiling compiler_panic v0.1.0 (/rust/compiler_panic)
     Running `rustc --edition=2018 --crate-name compiler_panic src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=74430e226fab29eb -C extra-filename=-74430e226fab29eb --out-dir /rust/compiler_panic/target/debug/deps -C incremental=/rust/compiler_panic/target/debug/incremental -L dependency=/rust/compiler_panic/target/debug/deps`
error: internal compiler error: src/librustc_mir/borrow_check/nll/universal_regions.rs:741: cannot convert `ReEarlyBound(0, 'a)` to a region vid

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:644:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.34/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.34/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:47
   3: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:36
   4: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:200
   5: std::panicking::default_hook
             at src/libstd/panicking.rs:214
   6: rustc::util::common::panic_hook
   7: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:481
   8: std::panicking::begin_panic
   9: rustc_errors::Handler::bug
  10: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  11: rustc::ty::context::tls::with_opt::{{closure}}
  12: rustc::ty::context::tls::with_context_opt
  13: rustc::ty::context::tls::with_opt
  14: rustc::util::bug::opt_span_bug_fmt
  15: rustc::util::bug::bug_fmt
  16: rustc_mir::borrow_check::nll::universal_regions::UniversalRegionIndices::to_region_vid::{{closure}}
  17: rustc_mir::borrow_check::nll::type_check::constraint_conversion::ConstraintConversion::to_region_vid
  18: rustc_mir::borrow_check::nll::type_check::constraint_conversion::ConstraintConversion::convert_all
  19: rustc_mir::borrow_check::nll::type_check::TypeChecker::fully_perform_op
  20: rustc_mir::borrow_check::nll::type_check::type_check
  21: rustc_mir::borrow_check::nll::compute_regions
  22: rustc_mir::borrow_check::do_mir_borrowck
  23: rustc::ty::context::GlobalCtxt::enter_local
  24: rustc_mir::borrow_check::mir_borrowck
  25: rustc::ty::query::__query_compute::mir_borrowck
  26: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_borrowck>::compute
  27: rustc::dep_graph::graph::DepGraph::with_task_impl
  28: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::ensure_query
  30: rustc_mir::transform::optimized_mir
  31: rustc::ty::query::__query_compute::optimized_mir
  32: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute
  33: rustc::dep_graph::graph::DepGraph::with_task_impl
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  35: rustc_mir::interpret::eval_context::InterpCx<M>::load_mir
  36: rustc_mir::const_eval::const_eval_raw_provider
  37: rustc::ty::query::__query_compute::const_eval_raw
  38: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_raw>::compute
  39: rustc::dep_graph::graph::DepGraph::with_task_impl
  40: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  41: rustc_mir::const_eval::const_eval_provider
  42: rustc::ty::query::__query_compute::const_eval
  43: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval>::compute
  44: rustc::dep_graph::graph::DepGraph::with_task_impl
  45: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  46: <rustc::traits::project::AssocTypeNormalizer as rustc::ty::fold::TypeFolder>::fold_const
  47: <rustc::traits::project::AssocTypeNormalizer as rustc::ty::fold::TypeFolder>::fold_ty
  48: rustc::traits::project::normalize
  49: rustc_typeck::check::FnCtxt::normalize_associated_types_in
  50: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  51: rustc::ty::context::GlobalCtxt::enter_local
  52: rustc_typeck::check::wfcheck::check_item_well_formed
  53: rustc::ty::query::__query_compute::check_item_well_formed
  54: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::check_item_well_formed>::compute
  55: rustc::dep_graph::graph::DepGraph::with_task_impl
  56: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  57: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  58: std::panicking::try::do_call
  59: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:80
  60: rustc_data_structures::sync::par_for_each_in
  61: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:80
  62: rustc::hir::Crate::par_visit_all_item_likes
  63: rustc::util::common::time
  64: rustc_typeck::check_crate
  65: rustc_interface::passes::analysis
  66: rustc::ty::query::__query_compute::analysis
  67: rustc::dep_graph::graph::DepGraph::with_task_impl
  68: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  69: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  70: rustc_interface::passes::create_global_ctxt::{{closure}}
  71: rustc_interface::interface::run_compiler_in_existing_thread_pool
  72: std::thread::local::LocalKey<T>::with
  73: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
#0 [mir_borrowck] processing `Foo::lots_of_foos::{{constant}}#0`
#1 [optimized_mir] processing `Foo::lots_of_foos::{{constant}}#0`
 --> src/main.rs:6:25
  |
6 |     lots_of_foos: [u64; size_of::<Option<Foo<'a>>>()]
  |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#2 [const_eval_raw] const-evaluating `Foo::lots_of_foos::{{constant}}#0`
#3 [const_eval] const-evaluating + checking `Foo::lots_of_foos::{{constant}}#0`
#4 [check_item_well_formed] processing `Foo`
#5 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error


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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.38.0 (625451e37 2019-09-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

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

error: Could not compile `compiler_panic`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name compiler_panic src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=74430e226fab29eb -C extra-filename=-74430e226fab29eb --out-dir /rust/compiler_panic/target/debug/deps -C incremental=/rust/compiler_panic/target/debug/incremental -L dependency=/rust/compiler_panic/target/debug/deps` (exit code: 101)
@lambinoo lambinoo changed the title librustc_mir panics on structu:re definition librustc_mir panics on structure Nov 6, 2019
@jonas-schievink jonas-schievink added A-borrow-checker Area: The borrow checker C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-NLL Area: Non-lexical lifetimes (NLL) labels Nov 6, 2019
@jonas-schievink
Copy link
Contributor

Also happens on nightly

@Centril
Copy link
Contributor

Centril commented Nov 6, 2019

ICE reproduces all the way back to 1.36.0; before that, it still ICEs but in a different place.

@Centril
Copy link
Contributor

Centril commented Nov 6, 2019

Maximal reduction:

fn main() {}

const fn foo<T>() -> usize { 0 }

struct S<'a> {
    beta: [(); foo::<&'a ()>()],
}

ICE arises in:

.unwrap_or_else(|| bug!("cannot convert `{:?}` to a region vid", r))

Blame: @nikomatsakis
cc @matthewjasper

@pnkfelix pnkfelix changed the title librustc_mir panics on structure ICE: lifetime in type in const-expr in len of array-type [T; len]: cannot convert ReEarlyBound Nov 7, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Nov 7, 2019

I suspect this is a duplicate of #64173. But the test case is slightly different so I'll leave it open for now

@pnkfelix
Copy link
Member

pnkfelix commented Nov 7, 2019

triage: P-medium (via analogy with priority on #64173), removing nomination label.

@JohnTitor
Copy link
Member

Triage:
This is no longer ICE with the latest nightly: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=2350135dbdd5165a3f4d0ef1ac8cfd38

@JohnTitor JohnTitor added A-const-generics Area: const generics (parameters and arguments) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Dec 30, 2020
JohnTitor added a commit to JohnTitor/rust that referenced this issue May 5, 2022
compiler-errors added a commit to compiler-errors/rust that referenced this issue May 5, 2022
…=compiler-errors

Add a regression test for rust-lang#64173 and rust-lang#66152

Closes rust-lang#64173
Closes rust-lang#66152

Mixed the code as the root cause seems the same.
compiler-errors added a commit to compiler-errors/rust that referenced this issue May 6, 2022
…=compiler-errors

Add a regression test for rust-lang#64173 and rust-lang#66152

Closes rust-lang#64173
Closes rust-lang#66152

Mixed the code as the root cause seems the same.
bors added a commit to rust-lang-ci/rust that referenced this issue May 6, 2022
…piler-errors

Rollup of 7 pull requests

Successful merges:

 - rust-lang#96174 (mark ptr-int-transmute test as no_run)
 - rust-lang#96639 (Fix typo in `offset_from` documentation)
 - rust-lang#96704 (Add rotation animation on settings button when loading)
 - rust-lang#96730 (Add a regression test for rust-lang#64173 and rust-lang#66152)
 - rust-lang#96741 (Improve settings loading strategy)
 - rust-lang#96744 (Implement [OsStr]::join)
 - rust-lang#96747 (Add `track_caller` to `DefId::expect_local()`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in b78179e May 6, 2022
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-const-generics Area: const generics (parameters and arguments) A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants