Skip to content

ICE : Region parameter out of range when instantiating in region #124833

Closed
@Naserume

Description

@Naserume

Code

(reduced)

#![feature(generic_const_items)]

trait Trait {
    const C<'a>: &'a str;
}

impl Trait for () {
    const C<'a>:  = "C";
}

(original)

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

pub const K<'a, T: 'a + Copy, const N: usize>: Option<[T; N]> = None
where
    String: From<T>;

pub trait Trait<T: ?Sized> {
    const C<'a>: &'a T
    where
        T: 'a + Eq;
}

pub struct Implementor;

impl Trait<str> for Implementor {
    const C<'a>:  = "C"
    // In real code we could've left off this bound but adding it explicitly allows us to test if
    // we render where-clauses on associated consts inside impl blocks correctly.
    where
        str: 'a;
}

Note

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (7d83a4c13 2024-05-06)
binary: rustc
commit-hash: 7d83a4c131ab9ae81a74c6fd825c827d74a2881d
commit-date: 2024-05-06
host: x86_64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.4

Error output

warning: the feature `generic_const_items` is incomplete and may not be safe to use and/or cause compiler crashes
 --> ./331B_reduce.rs:1:12
  |
1 | #![feature(generic_const_items)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #113521 <https://github.com/rust-lang/rust/issues/113521> for more information
  = note: `#[warn(incomplete_features)]` on by default

error[E0601]: `main` function not found in crate `331B_reduce`
 --> ./331B_reduce.rs:9:2
  |
9 | }
  |  ^ consider adding a `main` function to `./331B_reduce.rs`
Backtrace

error: internal compiler error: compiler/rustc_middle/src/ty/generic_args.rs:827:13: Region parameter out of range when instantiating in region 'a (index=1, args = [()])

thread 'rustc' panicked at compiler/rustc_middle/src/ty/generic_args.rs:827:13:
Box<dyn Any>
stack backtrace:
   0:        0x1087a70e3 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb3c4fb7cad74ca73
   1:        0x1087f277b - core::fmt::write::h106c560ef213d39a
   2:        0x10879d2ce - std::io::Write::write_fmt::he202b330ae20a605
   3:        0x1087a6ed1 - std::sys_common::backtrace::print::h8f227787c7f1bbb9
   4:        0x1087a9bc9 - std::panicking::default_hook::{{closure}}::h332143d1af1e3900
   5:        0x1087a9910 - std::panicking::default_hook::hb3ef0e8c00f187cd
   6:        0x11145f88c - std[24c0137931bc3bdc]::panicking::update_hook::<alloc[b015eeca3045b8c7]::boxed::Box<rustc_driver_impl[c2d45e9fcab76dc2]::install_ice_hook::{closure#0}>>::{closure#0}
   7:        0x1087aa6c3 - std::panicking::rust_panic_with_hook::h3771356085505bd5
   8:        0x1114c817a - std[24c0137931bc3bdc]::panicking::begin_panic::<rustc_errors[49295634fe3a58f4]::ExplicitBug>::{closure#0}
   9:        0x1114c0469 - std[24c0137931bc3bdc]::sys_common::backtrace::__rust_end_short_backtrace::<std[24c0137931bc3bdc]::panicking::begin_panic<rustc_errors[49295634fe3a58f4]::ExplicitBug>::{closure#0}, !>
  10:        0x115c19009 - std[24c0137931bc3bdc]::panicking::begin_panic::<rustc_errors[49295634fe3a58f4]::ExplicitBug>
  11:        0x1114db366 - <rustc_errors[49295634fe3a58f4]::diagnostic::BugAbort as rustc_errors[49295634fe3a58f4]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:        0x111fb9f2e - rustc_middle[a7724b9a06509386]::util::bug::opt_span_bug_fmt::<rustc_span[ae9e312bf8f99328]::span_encoding::Span>::{closure#0}
  13:        0x111f6b3f7 - rustc_middle[a7724b9a06509386]::ty::context::tls::with_opt::<rustc_middle[a7724b9a06509386]::util::bug::opt_span_bug_fmt<rustc_span[ae9e312bf8f99328]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:        0x111f6aea5 - rustc_middle[a7724b9a06509386]::ty::context::tls::with_context_opt::<rustc_middle[a7724b9a06509386]::ty::context::tls::with_opt<rustc_middle[a7724b9a06509386]::util::bug::opt_span_bug_fmt<rustc_span[ae9e312bf8f99328]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:        0x115cdb9cb - rustc_middle[a7724b9a06509386]::util::bug::bug_fmt
  16:        0x115cdb534 - <rustc_middle[a7724b9a06509386]::ty::generic_args::ArgFolder as rustc_type_ir[8828e05372bf127c]::fold::TypeFolder<rustc_middle[a7724b9a06509386]::ty::context::TyCtxt>>::fold_region::region_param_out_of_range
  17:        0x111f97772 - <rustc_middle[a7724b9a06509386]::ty::generic_args::ArgFolder as rustc_type_ir[8828e05372bf127c]::fold::TypeFolder<rustc_middle[a7724b9a06509386]::ty::context::TyCtxt>>::fold_region
  18:        0x111f97ace - <rustc_middle[a7724b9a06509386]::ty::generic_args::ArgFolder as rustc_type_ir[8828e05372bf127c]::fold::TypeFolder<rustc_middle[a7724b9a06509386]::ty::context::TyCtxt>>::fold_ty
  19:        0x1119a658c - rustc_hir_typeck[a97cbdc6ab9526d5]::infer_type_if_missing
  20:        0x1119a4596 - rustc_hir_typeck[a97cbdc6ab9526d5]::diagnostic_only_typeck
  21:        0x1128c4efa - rustc_query_impl[fcf5f83184020037]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fcf5f83184020037]::query_impl::diagnostic_only_typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a7724b9a06509386]::query::erase::Erased<[u8; 8usize]>>
  22:        0x112745347 - rustc_query_system[c3abe97db1de196d]::query::plumbing::try_execute_query::<rustc_query_impl[fcf5f83184020037]::DynamicConfig<rustc_query_system[c3abe97db1de196d]::query::caches::VecCache<rustc_hir[640f0d9a5f60705a]::hir_id::OwnerId, rustc_middle[a7724b9a06509386]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[fcf5f83184020037]::plumbing::QueryCtxt, false>
  23:        0x1128e92ab - rustc_query_impl[fcf5f83184020037]::query_impl::diagnostic_only_typeck::get_query_non_incr::__rust_end_short_backtrace
  24:        0x11166c993 - rustc_middle[a7724b9a06509386]::query::plumbing::query_get_at::<rustc_query_system[c3abe97db1de196d]::query::caches::VecCache<rustc_hir[640f0d9a5f60705a]::hir_id::OwnerId, rustc_middle[a7724b9a06509386]::query::erase::Erased<[u8; 8usize]>>>
  25:        0x111783bd1 - rustc_hir_analysis[35b19c5979e9ecaf]::collect::type_of::infer_placeholder_type
  26:        0x111781a86 - rustc_hir_analysis[35b19c5979e9ecaf]::collect::type_of::type_of
  27:        0x1128c6a56 - rustc_query_impl[fcf5f83184020037]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fcf5f83184020037]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a7724b9a06509386]::query::erase::Erased<[u8; 8usize]>>
  28:        0x1126a1663 - rustc_query_system[c3abe97db1de196d]::query::plumbing::try_execute_query::<rustc_query_impl[fcf5f83184020037]::DynamicConfig<rustc_query_system[c3abe97db1de196d]::query::caches::DefIdCache<rustc_middle[a7724b9a06509386]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[fcf5f83184020037]::plumbing::QueryCtxt, false>
  29:        0x1128cf689 - rustc_query_impl[fcf5f83184020037]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  30:        0x11166bf3e - rustc_middle[a7724b9a06509386]::query::plumbing::query_get_at::<rustc_query_system[c3abe97db1de196d]::query::caches::DefIdCache<rustc_middle[a7724b9a06509386]::query::erase::Erased<[u8; 8usize]>>>
  31:        0x11170f7ea - rustc_hir_analysis[35b19c5979e9ecaf]::check::compare_impl_item::compare_impl_const_raw
  32:        0x1128c4182 - rustc_query_impl[fcf5f83184020037]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fcf5f83184020037]::query_impl::compare_impl_const::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a7724b9a06509386]::query::erase::Erased<[u8; 1usize]>>
  33:        0x112870eb5 - <rustc_query_impl[fcf5f83184020037]::query_impl::compare_impl_const::dynamic_query::{closure#2} as core[fca3941a4c8b7591]::ops::function::FnOnce<(rustc_middle[a7724b9a06509386]::ty::context::TyCtxt, (rustc_span[ae9e312bf8f99328]::def_id::LocalDefId, rustc_span[ae9e312bf8f99328]::def_id::DefId))>>::call_once
  34:        0x11271aa87 - rustc_query_system[c3abe97db1de196d]::query::plumbing::try_execute_query::<rustc_query_impl[fcf5f83184020037]::DynamicConfig<rustc_query_system[c3abe97db1de196d]::query::caches::DefaultCache<(rustc_span[ae9e312bf8f99328]::def_id::LocalDefId, rustc_span[ae9e312bf8f99328]::def_id::DefId), rustc_middle[a7724b9a06509386]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[fcf5f83184020037]::plumbing::QueryCtxt, false>
  35:        0x112934ebc - rustc_query_impl[fcf5f83184020037]::query_impl::compare_impl_const::get_query_non_incr::__rust_end_short_backtrace
  36:        0x1116f39f5 - rustc_hir_analysis[35b19c5979e9ecaf]::check::check::check_impl_items_against_trait
  37:        0x1116eb47b - rustc_hir_analysis[35b19c5979e9ecaf]::check::check::check_item_type
  38:        0x11172174a - rustc_hir_analysis[35b19c5979e9ecaf]::check::wfcheck::check_well_formed
  39:        0x1128c3c9a - rustc_query_impl[fcf5f83184020037]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fcf5f83184020037]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a7724b9a06509386]::query::erase::Erased<[u8; 1usize]>>
  40:        0x112742fac - rustc_query_system[c3abe97db1de196d]::query::plumbing::try_execute_query::<rustc_query_impl[fcf5f83184020037]::DynamicConfig<rustc_query_system[c3abe97db1de196d]::query::caches::VecCache<rustc_hir[640f0d9a5f60705a]::hir_id::OwnerId, rustc_middle[a7724b9a06509386]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[fcf5f83184020037]::plumbing::QueryCtxt, false>
  41:        0x11290a280 - rustc_query_impl[fcf5f83184020037]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  42:        0x11166cf42 - rustc_middle[a7724b9a06509386]::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system[c3abe97db1de196d]::query::caches::VecCache<rustc_hir[640f0d9a5f60705a]::hir_id::OwnerId, rustc_middle[a7724b9a06509386]::query::erase::Erased<[u8; 1usize]>>, ()>
  43:        0x1117304f1 - rustc_hir_analysis[35b19c5979e9ecaf]::check::wfcheck::check_mod_type_wf
  44:        0x1128c3c8a - rustc_query_impl[fcf5f83184020037]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fcf5f83184020037]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a7724b9a06509386]::query::erase::Erased<[u8; 1usize]>>
  45:        0x1126f0ab1 - rustc_query_system[c3abe97db1de196d]::query::plumbing::try_execute_query::<rustc_query_impl[fcf5f83184020037]::DynamicConfig<rustc_query_system[c3abe97db1de196d]::query::caches::DefaultCache<rustc_span[ae9e312bf8f99328]::def_id::LocalModDefId, rustc_middle[a7724b9a06509386]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[fcf5f83184020037]::plumbing::QueryCtxt, false>
  46:        0x1128e8380 - rustc_query_impl[fcf5f83184020037]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  47:        0x1117a64fc - rustc_hir_analysis[35b19c5979e9ecaf]::check_crate
  48:        0x111c1f1c6 - rustc_interface[aa7f650c50bbad27]::passes::run_required_analyses
  49:        0x111c21803 - rustc_interface[aa7f650c50bbad27]::passes::analysis
  50:        0x1128c6a6a - rustc_query_impl[fcf5f83184020037]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[fcf5f83184020037]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a7724b9a06509386]::query::erase::Erased<[u8; 1usize]>>
  51:        0x1126ac90e - rustc_query_system[c3abe97db1de196d]::query::plumbing::try_execute_query::<rustc_query_impl[fcf5f83184020037]::DynamicConfig<rustc_query_system[c3abe97db1de196d]::query::caches::SingleCache<rustc_middle[a7724b9a06509386]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[fcf5f83184020037]::plumbing::QueryCtxt, false>
  52:        0x1128d0bd7 - rustc_query_impl[fcf5f83184020037]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  53:        0x1114114e7 - <rustc_interface[aa7f650c50bbad27]::queries::QueryResult<&rustc_middle[a7724b9a06509386]::ty::context::GlobalCtxt>>::enter::<core[fca3941a4c8b7591]::result::Result<(), rustc_span[ae9e312bf8f99328]::ErrorGuaranteed>, rustc_driver_impl[c2d45e9fcab76dc2]::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  54:        0x1114667dd - rustc_interface[aa7f650c50bbad27]::interface::run_compiler::<core[fca3941a4c8b7591]::result::Result<(), rustc_span[ae9e312bf8f99328]::ErrorGuaranteed>, rustc_driver_impl[c2d45e9fcab76dc2]::run_compiler::{closure#0}>::{closure#1}
  55:        0x111452181 - std[24c0137931bc3bdc]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[aa7f650c50bbad27]::util::run_in_thread_with_globals<rustc_interface[aa7f650c50bbad27]::util::run_in_thread_pool_with_globals<rustc_interface[aa7f650c50bbad27]::interface::run_compiler<core[fca3941a4c8b7591]::result::Result<(), rustc_span[ae9e312bf8f99328]::ErrorGuaranteed>, rustc_driver_impl[c2d45e9fcab76dc2]::run_compiler::{closure#0}>::{closure#1}, core[fca3941a4c8b7591]::result::Result<(), rustc_span[ae9e312bf8f99328]::ErrorGuaranteed>>::{closure#0}, core[fca3941a4c8b7591]::result::Result<(), rustc_span[ae9e312bf8f99328]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[fca3941a4c8b7591]::result::Result<(), rustc_span[ae9e312bf8f99328]::ErrorGuaranteed>>
  56:        0x11146c406 - <<std[24c0137931bc3bdc]::thread::Builder>::spawn_unchecked_<rustc_interface[aa7f650c50bbad27]::util::run_in_thread_with_globals<rustc_interface[aa7f650c50bbad27]::util::run_in_thread_pool_with_globals<rustc_interface[aa7f650c50bbad27]::interface::run_compiler<core[fca3941a4c8b7591]::result::Result<(), rustc_span[ae9e312bf8f99328]::ErrorGuaranteed>, rustc_driver_impl[c2d45e9fcab76dc2]::run_compiler::{closure#0}>::{closure#1}, core[fca3941a4c8b7591]::result::Result<(), rustc_span[ae9e312bf8f99328]::ErrorGuaranteed>>::{closure#0}, core[fca3941a4c8b7591]::result::Result<(), rustc_span[ae9e312bf8f99328]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[fca3941a4c8b7591]::result::Result<(), rustc_span[ae9e312bf8f99328]::ErrorGuaranteed>>::{closure#2} as core[fca3941a4c8b7591]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  57:        0x1087b3d2b - std::sys::pal::unix::thread::Thread::new::thread_start::hd56fbab72a546733
  58:     0x7ff801f5318b - __pthread_start

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: please make sure that you have updated to the latest nightly

note: please attach the file at `/Users/sal/20240505/rustc-ice-2024-05-07T04_13_25-9328.txt` to your bug report

query stack during panic:
#0 [diagnostic_only_typeck] type-checking `<impl at ./331B_reduce.rs:7:1: 7:18>::C`
#1 [type_of] computing type of `<impl at ./331B_reduce.rs:7:1: 7:18>::C`
#2 [compare_impl_const] checking assoc const `<impl at ./331B_reduce.rs:7:1: 7:18>::C` has the same type as trait item
#3 [check_well_formed] checking that `<impl at ./331B_reduce.rs:7:1: 7:18>` is well-formed
#4 [check_mod_type_wf] checking that types are well-formed in top-level module
#5 [analysis] running analysis passes on this crate
end of query stack
error: missing type for `const` item
 --> ./331B_reduce.rs:8:17
  |
8 |     const C<'a>:  = "C";
  |                 ^ help: provide a type for the item: `<type>`

error: aborting due to 3 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0601`.

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-generic_const_items`#![feature(generic_const_items)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions