Skip to content

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

Closed
@Naserume

Description

@Naserume

Code

(reduced)

trait Trait<T: ?Sized> {
    const C<'a>: &'a T
}

struct Implementor;

impl Trait<str> for Implementor {
    const C<>: &'a str = "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 str = "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;
}

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (9d5cdf75a 2024-04-07)
binary: rustc
commit-hash: 9d5cdf75aa42faaf0b58ba21a510117e8d0051a3
commit-date: 2024-04-07
host: x86_64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.3

Error output

error: expected `;`, found `}`
 --> ./743F0725FEABD9E7F4F5425F8913337F0F0429BC495C842AFD6DCFB4EE1922E0.rs:2:23
  |
2 |     const C<'a>: &'a T
  |                       ^ help: add `;` here
3 | }
  | - unexpected token

error: expected `;`, found `}`
 --> ./743F0725FEABD9E7F4F5425F8913337F0F0429BC495C842AFD6DCFB4EE1922E0.rs:8:29
  |
8 |     const C<>: &'a str = "C"
  |                             ^ help: add `;` here
9 | }
  | - unexpected token

error[E0261]: use of undeclared lifetime name `'a`
 --> ./743F0725FEABD9E7F4F5425F8913337F0F0429BC495C842AFD6DCFB4EE1922E0.rs:8:17
  |
7 | impl Trait<str> for Implementor {
  |     - help: consider introducing lifetime `'a` here: `<'a>`
8 |     const C<>: &'a str = "C"
  |                 ^^ undeclared lifetime

error[E0658]: generic const items are experimental
 --> ./743F0725FEABD9E7F4F5425F8913337F0F0429BC495C842AFD6DCFB4EE1922E0.rs:2:12
  |
2 |     const C<'a>: &'a T
  |            ^^^^
  |
  = note: see issue #113521 <https://github.com/rust-lang/rust/issues/113521> for more information
  = help: add `#![feature(generic_const_items)]` to the crate attributes to enable
  = note: this compiler was built on 2024-04-11; consider upgrading it if it is out of date

error[E0658]: generic const items are experimental
 --> ./743F0725FEABD9E7F4F5425F8913337F0F0429BC495C842AFD6DCFB4EE1922E0.rs:8:12
  |
8 |     const C<>: &'a str = "C"
  |            ^^
  |
  = note: see issue #113521 <https://github.com/rust-lang/rust/issues/113521> for more information
  = help: add `#![feature(generic_const_items)]` to the crate attributes to enable
  = note: this compiler was built on 2024-04-11; consider upgrading it if it is out of date

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

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

thread 'rustc' panicked at compiler/rustc_middle/src/ty/generic_args.rs:825:13:
Box<dyn Any>
stack backtrace:
   0:        0x1030abe13 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hcb82b7434a7ad069
   1:        0x1030f7a8b - core::fmt::write::h20ce779d62646bbc
   2:        0x1030a1f5e - std::io::Write::write_fmt::hc9677006e9d09a01
   3:        0x1030abc01 - std::sys_common::backtrace::print::h574caf35b482d642
   4:        0x1030aea69 - std::panicking::default_hook::{{closure}}::hd4be3fc55f74a05f
   5:        0x1030ae7b0 - std::panicking::default_hook::h2f05dfe1d561d141
   6:        0x10bd0728c - std[49a09ef43dd137fc]::panicking::update_hook::<alloc[5c0aec220d3fb6dd]::boxed::Box<rustc_driver_impl[9cc6f343bed42afe]::install_ice_hook::{closure#0}>>::{closure#0}
   7:        0x1030af58c - std::panicking::rust_panic_with_hook::hf0bdb32e38a98365
   8:        0x10bd72e8a - std[49a09ef43dd137fc]::panicking::begin_panic::<rustc_errors[eb8a5b66a8ece974]::ExplicitBug>::{closure#0}
   9:        0x10bd6b3b9 - std[49a09ef43dd137fc]::sys_common::backtrace::__rust_end_short_backtrace::<std[49a09ef43dd137fc]::panicking::begin_panic<rustc_errors[eb8a5b66a8ece974]::ExplicitBug>::{closure#0}, !>
  10:        0x11049f6a9 - std[49a09ef43dd137fc]::panicking::begin_panic::<rustc_errors[eb8a5b66a8ece974]::ExplicitBug>
  11:        0x10bd865d6 - <rustc_errors[eb8a5b66a8ece974]::diagnostic::BugAbort as rustc_errors[eb8a5b66a8ece974]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:        0x10c86250e - rustc_middle[86d1f27645b76717]::util::bug::opt_span_bug_fmt::<rustc_span[c866a394ab29ee91]::span_encoding::Span>::{closure#0}
  13:        0x10c812a67 - rustc_middle[86d1f27645b76717]::ty::context::tls::with_opt::<rustc_middle[86d1f27645b76717]::util::bug::opt_span_bug_fmt<rustc_span[c866a394ab29ee91]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:        0x10c8124d5 - rustc_middle[86d1f27645b76717]::ty::context::tls::with_context_opt::<rustc_middle[86d1f27645b76717]::ty::context::tls::with_opt<rustc_middle[86d1f27645b76717]::util::bug::opt_span_bug_fmt<rustc_span[c866a394ab29ee91]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:        0x11055e13b - rustc_middle[86d1f27645b76717]::util::bug::bug_fmt
  16:        0x11055dca4 - <rustc_middle[86d1f27645b76717]::ty::generic_args::ArgFolder as rustc_type_ir[8aa2137bd864a930]::fold::TypeFolder<rustc_middle[86d1f27645b76717]::ty::context::TyCtxt>>::fold_region::region_param_out_of_range
  17:        0x10c840ff2 - <rustc_middle[86d1f27645b76717]::ty::generic_args::ArgFolder as rustc_type_ir[8aa2137bd864a930]::fold::TypeFolder<rustc_middle[86d1f27645b76717]::ty::context::TyCtxt>>::fold_region
  18:        0x10c84cec1 - <rustc_middle[86d1f27645b76717]::ty::Ty as rustc_type_ir[8aa2137bd864a930]::fold::TypeSuperFoldable<rustc_middle[86d1f27645b76717]::ty::context::TyCtxt>>::try_super_fold_with::<rustc_middle[86d1f27645b76717]::ty::generic_args::ArgFolder>
  19:        0x10bfb59e2 - rustc_hir_analysis[90609d44e62386d1]::check::compare_impl_item::compare_impl_const_raw
  20:        0x10d15c2c2 - rustc_query_impl[16231b3ed4d194e2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[16231b3ed4d194e2]::query_impl::compare_impl_const::dynamic_query::{closure#2}::{closure#0}, rustc_middle[86d1f27645b76717]::query::erase::Erased<[u8; 1usize]>>
  21:        0x10d1089c5 - <rustc_query_impl[16231b3ed4d194e2]::query_impl::compare_impl_const::dynamic_query::{closure#2} as core[75211c3caa4ba820]::ops::function::FnOnce<(rustc_middle[86d1f27645b76717]::ty::context::TyCtxt, (rustc_span[c866a394ab29ee91]::def_id::LocalDefId, rustc_span[c866a394ab29ee91]::def_id::DefId))>>::call_once
  22:        0x10cfbf8d7 - rustc_query_system[acfab0ae1d333eea]::query::plumbing::try_execute_query::<rustc_query_impl[16231b3ed4d194e2]::DynamicConfig<rustc_query_system[acfab0ae1d333eea]::query::caches::DefaultCache<(rustc_span[c866a394ab29ee91]::def_id::LocalDefId, rustc_span[c866a394ab29ee91]::def_id::DefId), rustc_middle[86d1f27645b76717]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[16231b3ed4d194e2]::plumbing::QueryCtxt, false>
  23:        0x10d1ce84c - rustc_query_impl[16231b3ed4d194e2]::query_impl::compare_impl_const::get_query_non_incr::__rust_end_short_backtrace
  24:        0x10bf999e3 - rustc_hir_analysis[90609d44e62386d1]::check::check::check_impl_items_against_trait
  25:        0x10bf925ab - rustc_hir_analysis[90609d44e62386d1]::check::check::check_item_type
  26:        0x10bfca9b4 - rustc_hir_analysis[90609d44e62386d1]::check::wfcheck::check_well_formed
  27:        0x10d15bdfa - rustc_query_impl[16231b3ed4d194e2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[16231b3ed4d194e2]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[86d1f27645b76717]::query::erase::Erased<[u8; 1usize]>>
  28:        0x10cfdd77c - rustc_query_system[acfab0ae1d333eea]::query::plumbing::try_execute_query::<rustc_query_impl[16231b3ed4d194e2]::DynamicConfig<rustc_query_system[acfab0ae1d333eea]::query::caches::VecCache<rustc_hir[427244ed39142342]::hir_id::OwnerId, rustc_middle[86d1f27645b76717]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[16231b3ed4d194e2]::plumbing::QueryCtxt, false>
  29:        0x10d1a3ca0 - rustc_query_impl[16231b3ed4d194e2]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  30:        0x10bf1c612 - rustc_middle[86d1f27645b76717]::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system[acfab0ae1d333eea]::query::caches::VecCache<rustc_hir[427244ed39142342]::hir_id::OwnerId, rustc_middle[86d1f27645b76717]::query::erase::Erased<[u8; 1usize]>>, ()>
  31:        0x10bfd8781 - rustc_hir_analysis[90609d44e62386d1]::check::wfcheck::check_mod_type_wf
  32:        0x10d15bdea - rustc_query_impl[16231b3ed4d194e2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[16231b3ed4d194e2]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[86d1f27645b76717]::query::erase::Erased<[u8; 1usize]>>
  33:        0x10cf90da1 - rustc_query_system[acfab0ae1d333eea]::query::plumbing::try_execute_query::<rustc_query_impl[16231b3ed4d194e2]::DynamicConfig<rustc_query_system[acfab0ae1d333eea]::query::caches::DefaultCache<rustc_span[c866a394ab29ee91]::def_id::LocalModDefId, rustc_middle[86d1f27645b76717]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[16231b3ed4d194e2]::plumbing::QueryCtxt, false>
  34:        0x10d180d70 - rustc_query_impl[16231b3ed4d194e2]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  35:        0x10c05269c - rustc_hir_analysis[90609d44e62386d1]::check_crate
  36:        0x10c4c5672 - rustc_interface[6612d49bd5b18005]::passes::run_required_analyses
  37:        0x10c4c7c90 - rustc_interface[6612d49bd5b18005]::passes::analysis
  38:        0x10d15eb6a - rustc_query_impl[16231b3ed4d194e2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[16231b3ed4d194e2]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[86d1f27645b76717]::query::erase::Erased<[u8; 1usize]>>
  39:        0x10cf4405e - rustc_query_system[acfab0ae1d333eea]::query::plumbing::try_execute_query::<rustc_query_impl[16231b3ed4d194e2]::DynamicConfig<rustc_query_system[acfab0ae1d333eea]::query::caches::SingleCache<rustc_middle[86d1f27645b76717]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[16231b3ed4d194e2]::plumbing::QueryCtxt, false>
  40:        0x10d168f37 - rustc_query_impl[16231b3ed4d194e2]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  41:        0x10bcb93b7 - <rustc_interface[6612d49bd5b18005]::queries::QueryResult<&rustc_middle[86d1f27645b76717]::ty::context::GlobalCtxt>>::enter::<core[75211c3caa4ba820]::result::Result<(), rustc_span[c866a394ab29ee91]::ErrorGuaranteed>, rustc_driver_impl[9cc6f343bed42afe]::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  42:        0x10bd0e52f - rustc_interface[6612d49bd5b18005]::interface::run_compiler::<core[75211c3caa4ba820]::result::Result<(), rustc_span[c866a394ab29ee91]::ErrorGuaranteed>, rustc_driver_impl[9cc6f343bed42afe]::run_compiler::{closure#0}>::{closure#0}
  43:        0x10bcfa2cd - std[49a09ef43dd137fc]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[6612d49bd5b18005]::util::run_in_thread_with_globals<rustc_interface[6612d49bd5b18005]::util::run_in_thread_pool_with_globals<rustc_interface[6612d49bd5b18005]::interface::run_compiler<core[75211c3caa4ba820]::result::Result<(), rustc_span[c866a394ab29ee91]::ErrorGuaranteed>, rustc_driver_impl[9cc6f343bed42afe]::run_compiler::{closure#0}>::{closure#0}, core[75211c3caa4ba820]::result::Result<(), rustc_span[c866a394ab29ee91]::ErrorGuaranteed>>::{closure#0}, core[75211c3caa4ba820]::result::Result<(), rustc_span[c866a394ab29ee91]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[75211c3caa4ba820]::result::Result<(), rustc_span[c866a394ab29ee91]::ErrorGuaranteed>>
  44:        0x10bd143e6 - <<std[49a09ef43dd137fc]::thread::Builder>::spawn_unchecked_<rustc_interface[6612d49bd5b18005]::util::run_in_thread_with_globals<rustc_interface[6612d49bd5b18005]::util::run_in_thread_pool_with_globals<rustc_interface[6612d49bd5b18005]::interface::run_compiler<core[75211c3caa4ba820]::result::Result<(), rustc_span[c866a394ab29ee91]::ErrorGuaranteed>, rustc_driver_impl[9cc6f343bed42afe]::run_compiler::{closure#0}>::{closure#0}, core[75211c3caa4ba820]::result::Result<(), rustc_span[c866a394ab29ee91]::ErrorGuaranteed>>::{closure#0}, core[75211c3caa4ba820]::result::Result<(), rustc_span[c866a394ab29ee91]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[75211c3caa4ba820]::result::Result<(), rustc_span[c866a394ab29ee91]::ErrorGuaranteed>>::{closure#1} as core[75211c3caa4ba820]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  45:        0x1030b8ccb - std::sys::pal::unix::thread::Thread::new::thread_start::h6978137b7cf37fba
  46:     0x7ff818270202 - __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/Documents/240410버전(240412검토)/rustc-ice-2024-04-12T01_35_50-84190.txt` to your bug report

query stack during panic:
#0 [compare_impl_const] checking assoc const `<impl at ./743F0725FEABD9E7F4F5425F8913337F0F0429BC495C842AFD6DCFB4EE1922E0.rs:7:1: 7:32>::C` has the same type as trait item
#1 [check_well_formed] checking that `<impl at ./743F0725FEABD9E7F4F5425F8913337F0F0429BC495C842AFD6DCFB4EE1922E0.rs:7:1: 7:32>` is well-formed
#2 [check_mod_type_wf] checking that types are well-formed in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 7 previous errors

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) ❄️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