Skip to content

[ICE] Compiler Panics Using Self::CONSTANT and Lifetimes in Struct #80168

Closed
@Soham3-1415

Description

@Soham3-1415

Code

The following code does produce an error:

pub struct Problem<'a> {
    pub dat: &'a [u8; Self::C],
}

impl<'a> Problem<'a> {
	const C: usize = 0;
}

fn main() {}

The following code does NOT produce an error:

pub struct Problem<'a> {
    pub dat: &'a [u8; Problem::C],
}

impl<'a> Problem<'a> {
	const C: usize = 0;
}

fn main() {}

The following code does NOT produce an error:

pub struct Problem {
    pub dat: [u8; Self::C],
}

impl Problem {
	const C: usize = 0;
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.48.0 (7eac88abb 2020-11-16)
binary: rustc
commit-hash: 7eac88abb2e57e752f3302f02be5f3ce3d7adfb4
commit-date: 2020-11-16
host: x86_64-unknown-linux-gnu
release: 1.48.0
LLVM version: 11.0

rustc --version --verbose:

rustc 1.49.0-beta.4 (877c7cbe1 2020-12-10)
binary: rustc
commit-hash: 877c7cbe142a373f93d38a23741dcc3a0a17a2af
commit-date: 2020-12-10
host: x86_64-unknown-linux-gnu
release: 1.49.0-beta.4

rustc --version --verbose:

rustc 1.50.0-nightly (eb4fc71dc 2020-12-17)
binary: rustc
commit-hash: eb4fc71dc9024f15a0c9cc44bcc10c861e9d585e
commit-date: 2020-12-17
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly

Error output

cargo build --verbose:

Compiling rustc_issue v0.1.0 (REDACTED/rustc_issue)
     Running `rustc --crate-name rustc_issue --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=3e20745af1633f84 -C extra-filename=-3e20745af1633f84 --out-dir REDACTED/rustc_issue/target/debug/deps -C incremental=REDACTED/rustc_issue/target/debug/incremental -L dependency=REDACTED/rustc_issue/target/debug/deps`
error: internal compiler error: compiler/rustc_mir/src/borrow_check/universal_regions.rs:768:36: cannot convert `ReEarlyBound(0, 'a)` to a region vid

thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:945: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.48.0 (7eac88abb 2020-11-16) running on x86_64-unknown-linux-gnu

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

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

error: aborting due to previous error

error: could not compile `rustc_issue`

Caused by:
  process didn't exit successfully: `rustc --crate-name rustc_issue --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=3e20745af1633f84 -C extra-filename=-3e20745af1633f84 --out-dir REDACTED/rustc_issue/target/debug/deps -C incremental=REDACTED/rustc_issue/target/debug/incremental -L dependency=REDACTED/rustc_issue/target/debug/deps` (exit code: 101)
Backtrace

thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:945:9
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::bug
   2: rustc_errors::Handler::bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   4: rustc_middle::ty::context::tls::with_opt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt
   6: rustc_middle::util::bug::opt_span_bug_fmt
   7: rustc_middle::util::bug::bug_fmt
   8: rustc_mir::borrow_check::universal_regions::UniversalRegionIndices::to_region_vid::{{closure}}
   9: rustc_mir::borrow_check::universal_regions::UniversalRegionIndices::to_region_vid
  10: rustc_mir::borrow_check::type_check::constraint_conversion::ConstraintConversion::convert_all
  11: rustc_mir::borrow_check::type_check::type_check
  12: rustc_mir::borrow_check::nll::compute_regions
  13: rustc_mir::borrow_check::do_mir_borrowck
  14: rustc_infer::infer::InferCtxtBuilder::enter
  15: rustc_mir::borrow_check::mir_borrowck
  16: core::ops::function::FnOnce::call_once
  17: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  18: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  19: rustc_data_structures::stack::ensure_sufficient_stack
  20: rustc_query_system::query::plumbing::force_query_impl
  21: rustc_middle::ty::query::force_from_dep_node
  22: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
  23: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_previous_green
  24: rustc_query_system::dep_graph::graph::DepGraph<K>::try_mark_green_and_read
  25: rustc_data_structures::stack::ensure_sufficient_stack
  26: rustc_query_system::query::plumbing::get_query_impl
  27: rustc_mir::interpret::eval_context::InterpCx<M>::load_mir
  28: rustc_mir::const_eval::eval_queries::eval_to_allocation_raw_provider
  29: 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
  30: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  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::get_query_impl
  34: rustc_mir::const_eval::eval_queries::eval_to_const_value_raw_provider
  35: 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
  36: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  37: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  38: rustc_data_structures::stack::ensure_sufficient_stack
  39: rustc_query_system::query::plumbing::get_query_impl
  40: rustc_mir::const_eval::eval_queries::eval_to_const_value_raw_provider
  41: 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
  42: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  43: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  44: rustc_data_structures::stack::ensure_sufficient_stack
  45: rustc_query_system::query::plumbing::get_query_impl
  46: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_global_id
  47: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_resolve
  48: rustc_middle::ty::consts::Const::eval
  49: rustc_middle::ty::structural_impls::<impl rustc_middle::ty::fold::TypeFoldable for &rustc_middle::ty::TyS>::super_fold_with
  50: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_ty
  51: rustc_middle::ty::structural_impls::<impl rustc_middle::ty::fold::TypeFoldable for &rustc_middle::ty::TyS>::super_fold_with
  52: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_ty
  53: rustc_data_structures::stack::ensure_sufficient_stack
  54: rustc_trait_selection::traits::project::normalize
  55: <rustc_infer::infer::InferCtxt as rustc_trait_selection::infer::InferCtxtExt>::partially_normalize_associated_types_in
  56: rustc_typeck::check::inherited::Inherited::normalize_associated_types_in
  57: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  58: rustc_infer::infer::InferCtxtBuilder::enter
  59: rustc_typeck::check::wfcheck::check_item_well_formed
  60: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::check_item_well_formed>::compute
  61: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  62: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  63: rustc_data_structures::stack::ensure_sufficient_stack
  64: rustc_query_system::query::plumbing::get_query_impl
  65: rustc_query_system::query::plumbing::ensure_query_impl
  66: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  67: rustc_hir::hir::Crate::par_visit_all_item_likes
  68: rustc_session::session::Session::track_errors
  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_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  73: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  74: rustc_data_structures::stack::ensure_sufficient_stack
  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: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions