Skip to content

ICE: range start index 1 out of range for slice of length 1 in rustc_const_eval/src/interpret/terminator.rs #127304

Closed
@Naserume

Description

@Naserume

Code

trait Trait<T> {}
impl Trait<u16> for () {}

#![feature(adt_const_params)]

struct MyStr(str);
impl std::marker::ConstParamTy for MyStr {}

fn function_with_my_str<const S: &'static MyStr>() -> &'static MyStr {
    S
}

impl MyStr {
    const fn new(s: &Trait str) -> &'static MyStr {}
}

pub fn main() {
    let f = function_with_my_str::<{ MyStr::new("hello") }>();
}

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (6292b2af6 2024-07-02)
binary: rustc
commit-hash: 6292b2af620dbd771ebb687c3a93c69ba8f97268
commit-date: 2024-07-02
host: x86_64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7

Error output

error: an inner attribute is not permitted in this context
 --> ./2F705.rs:4:1
  |
4 | #![feature(adt_const_params)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
7 | struct MyStr(str);
  | ------------------ the inner attribute doesn't annotate this struct
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
help: to annotate the struct, change the attribute from inner to outer style
  |
4 - #![feature(adt_const_params)]
4 + #[feature(adt_const_params)]
  |

error: expected one of `:`, `@`, or `|`, found `)`
  --> ./2F705.rs:15:31
   |
15 |     const fn new(s: &Trait str) -> &'static MyStr {}
   |                               ^ expected one of `:`, `@`, or `|`
   |
   = note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
help: if this is a parameter name, give it a type
   |
15 |     const fn new(s: &Trait str: TypeName) -> &'static MyStr {}
   |                               ++++++++++
help: if this is a type, explicitly ignore the parameter name
   |
15 |     const fn new(s: &Trait _: str) -> &'static MyStr {}
   |                            ++

error: expected one of `!`, `(`, `)`, `,`, `::`, or `<`, found `str`
  --> ./2F705.rs:15:28
   |
15 |     const fn new(s: &Trait str) -> &'static MyStr {}
   |                           -^^^ expected one of `!`, `(`, `)`, `,`, `::`, or `<`
   |                           |
   |                           help: missing `,`

error[E0658]: use of unstable library feature 'adt_const_params'
 --> ./2F705.rs:8:6
  |
8 | impl std::marker::ConstParamTy for MyStr {}
  |      ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
  = help: add `#![feature(adt_const_params)]` to the crate attributes to enable
  = note: this compiler was built on 2024-07-02; consider upgrading it if it is out of date

error[E0277]: the trait bound `MyStr: Eq` is not satisfied
   --> ./2F705.rs:8:36
    |
8   | impl std::marker::ConstParamTy for MyStr {}
    |                                    ^^^^^ the trait `Eq` is not implemented for `MyStr`
    |
note: required by a bound in `ConstParamTy`
   --> /Users/sal/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/marker.rs:981:47
    |
981 | pub trait ConstParamTy: StructuralPartialEq + Eq {}
    |                                               ^^ required by this bound in `ConstParamTy`
help: consider annotating `MyStr` with `#[derive(Eq)]`
    |
7   + #[derive(Eq)]
8   | struct MyStr(str);
    |

error[E0277]: the type `MyStr` does not `#[derive(PartialEq)]`
   --> ./2F705.rs:8:36
    |
8   | impl std::marker::ConstParamTy for MyStr {}
    |                                    ^^^^^ the trait `StructuralPartialEq` is not implemented for `MyStr`
    |
note: required by a bound in `ConstParamTy`
   --> /Users/sal/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/marker.rs:981:25
    |
981 | pub trait ConstParamTy: StructuralPartialEq + Eq {}
    |                         ^^^^^^^^^^^^^^^^^^^ required by this bound in `ConstParamTy`

error: `&'static MyStr` is forbidden as the type of a const generic parameter
  --> ./2F705.rs:10:34
   |
10 | fn function_with_my_str<const S: &'static MyStr>() -> &'static MyStr {
   |                                  ^^^^^^^^^^^^^^
   |
   = note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
   |
1  + #![feature(adt_const_params)]
   |

warning: trait objects without an explicit `dyn` are deprecated
  --> ./2F705.rs:15:22
   |
15 |     const fn new(s: &Trait str) -> &'static MyStr {}
   |                      ^^^^^
   |
   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
   = note: `#[warn(bare_trait_objects)]` on by default
help: if this is an object-safe trait, use `dyn`
   |
15 |     const fn new(s: &dyn Trait str) -> &'static MyStr {}
   |                      +++

error[E0107]: missing generics for trait `Trait`
  --> ./2F705.rs:15:22
   |
15 |     const fn new(s: &Trait str) -> &'static MyStr {}
   |                      ^^^^^ expected 1 generic argument
   |
note: trait defined here, with 1 generic parameter: `T`
  --> ./2F705.rs:1:7
   |
1  | trait Trait<T> {}
   |       ^^^^^ -
help: add missing generic argument
   |
15 |     const fn new(s: &Trait<T> str) -> &'static MyStr {}
   |                           +++

error[E0308]: mismatched types
  --> ./2F705.rs:15:36
   |
15 |     const fn new(s: &Trait str) -> &'static MyStr {}
   |              ---                   ^^^^^^^^^^^^^^ expected `&MyStr`, found `()`
   |              |
   |              implicitly returns `()` as its body has no tail or `return` expression

Backtrace

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/terminator.rs:133:39:
range start index 2 out of range for slice of length 1
stack backtrace:
   0:        0x1091f2d93 - <std::sys::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h9393e218f71d31cf
   1:        0x10923e17b - core::fmt::write::h1271a75a7bae980c
   2:        0x1091e8c3e - std::io::Write::write_fmt::h8270e961acbabe61
   3:        0x1091f2b81 - std::sys::backtrace::print::h04e4916ebe343f6e
   4:        0x1091f5959 - std::panicking::default_hook::{{closure}}::hc9df26d29e0f9e5a
   5:        0x1091f56da - std::panicking::default_hook::h1026261fa8b9d0a8
   6:        0x1124dd0ac - std[26270defc80edaa9]::panicking::update_hook::<alloc[98df03226deedbda]::boxed::Box<rustc_driver_impl[708b2ec565622c48]::install_ice_hook::{closure#0}>>::{closure#0}
   7:        0x1091f6699 - std::panicking::rust_panic_with_hook::hf72d729757d375cc
   8:        0x1091f5ed5 - std::panicking::begin_panic_handler::{{closure}}::h5eb191147adf0e0d
   9:        0x1091f3269 - std::sys::backtrace::__rust_end_short_backtrace::he8eea0af09eba22f
  10:        0x1091f5aec - _rust_begin_unwind
  11:        0x1092594ca - core::panicking::panic_fmt::h403139b1d3f51ed8
  12:        0x109259b36 - core::slice::index::slice_start_index_len_fail::h58e498803150e5af
  13:        0x11244b12a - <rustc_const_eval[396cbee6e07433a6]::interpret::eval_context::InterpCx<rustc_const_eval[396cbee6e07433a6]::const_eval::machine::CompileTimeMachine>>::terminator
  14:        0x112462f56 - rustc_const_eval[396cbee6e07433a6]::const_eval::eval_queries::eval_to_allocation_raw_provider
  15:        0x113b9aaec - rustc_query_impl[36fa5edae9172c7f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[36fa5edae9172c7f]::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8094f41c293b336b]::query::erase::Erased<[u8; 24usize]>>
  16:        0x113b4fbae - <rustc_query_impl[36fa5edae9172c7f]::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2} as core[c342ec502b95801]::ops::function::FnOnce<(rustc_middle[8094f41c293b336b]::ty::context::TyCtxt, rustc_middle[8094f41c293b336b]::ty::ParamEnvAnd<rustc_middle[8094f41c293b336b]::mir::interpret::GlobalId>)>>::call_once
  17:        0x1139b3c0d - rustc_query_system[16c7cab3586fd5d4]::query::plumbing::try_execute_query::<rustc_query_impl[36fa5edae9172c7f]::DynamicConfig<rustc_query_system[16c7cab3586fd5d4]::query::caches::DefaultCache<rustc_middle[8094f41c293b336b]::ty::ParamEnvAnd<rustc_middle[8094f41c293b336b]::mir::interpret::GlobalId>, rustc_middle[8094f41c293b336b]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[36fa5edae9172c7f]::plumbing::QueryCtxt, false>
  18:        0x113bc59dc - rustc_query_impl[36fa5edae9172c7f]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace
  19:        0x112393752 - rustc_middle[8094f41c293b336b]::query::plumbing::query_get_at::<rustc_query_system[16c7cab3586fd5d4]::query::caches::DefaultCache<rustc_middle[8094f41c293b336b]::ty::ParamEnvAnd<rustc_middle[8094f41c293b336b]::mir::interpret::GlobalId>, rustc_middle[8094f41c293b336b]::query::erase::Erased<[u8; 24usize]>>>
  20:        0x11240f281 - rustc_const_eval[396cbee6e07433a6]::const_eval::valtrees::eval_to_valtree
  21:        0x112e34fe3 - <rustc_const_eval[396cbee6e07433a6]::provide::{closure#0} as core[c342ec502b95801]::ops::function::FnOnce<(rustc_middle[8094f41c293b336b]::ty::context::TyCtxt, rustc_middle[8094f41c293b336b]::ty::ParamEnvAnd<rustc_middle[8094f41c293b336b]::mir::interpret::GlobalId>)>>::call_once
  22:        0x113b97d6c - rustc_query_impl[36fa5edae9172c7f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[36fa5edae9172c7f]::query_impl::eval_to_valtree::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8094f41c293b336b]::query::erase::Erased<[u8; 24usize]>>
  23:        0x113b329de - <rustc_query_impl[36fa5edae9172c7f]::query_impl::eval_to_valtree::dynamic_query::{closure#2} as core[c342ec502b95801]::ops::function::FnOnce<(rustc_middle[8094f41c293b336b]::ty::context::TyCtxt, rustc_middle[8094f41c293b336b]::ty::ParamEnvAnd<rustc_middle[8094f41c293b336b]::mir::interpret::GlobalId>)>>::call_once
  24:        0x1139b3c0d - rustc_query_system[16c7cab3586fd5d4]::query::plumbing::try_execute_query::<rustc_query_impl[36fa5edae9172c7f]::DynamicConfig<rustc_query_system[16c7cab3586fd5d4]::query::caches::DefaultCache<rustc_middle[8094f41c293b336b]::ty::ParamEnvAnd<rustc_middle[8094f41c293b336b]::mir::interpret::GlobalId>, rustc_middle[8094f41c293b336b]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[36fa5edae9172c7f]::plumbing::QueryCtxt, false>
  25:        0x113bc671c - rustc_query_impl[36fa5edae9172c7f]::query_impl::eval_to_valtree::get_query_non_incr::__rust_end_short_backtrace
  26:        0x11321df16 - rustc_middle[8094f41c293b336b]::query::plumbing::query_get_at::<rustc_query_system[16c7cab3586fd5d4]::query::caches::DefaultCache<rustc_middle[8094f41c293b336b]::ty::ParamEnvAnd<rustc_middle[8094f41c293b336b]::mir::interpret::GlobalId>, rustc_middle[8094f41c293b336b]::query::erase::Erased<[u8; 24usize]>>>
  27:        0x113222208 - <rustc_middle[8094f41c293b336b]::ty::context::TyCtxt>::const_eval_global_id_for_typeck
  28:        0x113221bc2 - <rustc_middle[8094f41c293b336b]::ty::context::TyCtxt>::const_eval_resolve_for_typeck
  29:        0x1140b4f71 - <rustc_middle[8094f41c293b336b]::ty::consts::Const>::eval
  30:        0x114174e82 - rustc_trait_selection[e5babfdcefab668e]::traits::util::with_replaced_escaping_bound_vars::<rustc_middle[8094f41c293b336b]::ty::consts::Const, rustc_middle[8094f41c293b336b]::ty::consts::Const, <rustc_trait_selection[e5babfdcefab668e]::traits::normalize::AssocTypeNormalizer as rustc_type_ir[52f1f4e14ae618a5]::fold::TypeFolder<rustc_middle[8094f41c293b336b]::ty::context::TyCtxt>>::fold_const::{closure#0}>
  31:        0x1129c8d78 - <&rustc_middle[8094f41c293b336b]::ty::list::RawList<(), rustc_middle[8094f41c293b336b]::ty::generic_args::GenericArg> as rustc_type_ir[52f1f4e14ae618a5]::fold::TypeFoldable<rustc_middle[8094f41c293b336b]::ty::context::TyCtxt>>::try_fold_with::<rustc_trait_selection[e5babfdcefab668e]::traits::normalize::AssocTypeNormalizer>
  32:        0x1129e8f72 - rustc_trait_selection[e5babfdcefab668e]::traits::normalize::normalize_with_depth_to::<&rustc_middle[8094f41c293b336b]::ty::list::RawList<(), rustc_middle[8094f41c293b336b]::ty::generic_args::GenericArg>>::{closure#0}
  33:        0x112abd06a - <rustc_hir_typeck[83a831c03ea981a4]::fn_ctxt::FnCtxt>::normalize::<&rustc_middle[8094f41c293b336b]::ty::list::RawList<(), rustc_middle[8094f41c293b336b]::ty::generic_args::GenericArg>>
  34:        0x112b82dfd - <rustc_hir_typeck[83a831c03ea981a4]::fn_ctxt::FnCtxt>::instantiate_value_path
  35:        0x112a97dc5 - <rustc_hir_typeck[83a831c03ea981a4]::fn_ctxt::FnCtxt>::check_expr_path
  36:        0x112a9718e - <rustc_hir_typeck[83a831c03ea981a4]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  37:        0x112b67f45 - <rustc_hir_typeck[83a831c03ea981a4]::fn_ctxt::FnCtxt>::check_expr_kind
  38:        0x112a972aa - <rustc_hir_typeck[83a831c03ea981a4]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  39:        0x112ad6930 - <rustc_hir_typeck[83a831c03ea981a4]::fn_ctxt::FnCtxt>::check_decl
  40:        0x112ad738c - <rustc_hir_typeck[83a831c03ea981a4]::fn_ctxt::FnCtxt>::check_block_with_expected
  41:        0x112a972aa - <rustc_hir_typeck[83a831c03ea981a4]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  42:        0x112a993b4 - <rustc_hir_typeck[83a831c03ea981a4]::fn_ctxt::FnCtxt>::check_return_expr
  43:        0x112b56b3a - rustc_hir_typeck[83a831c03ea981a4]::check::check_fn
  44:        0x112b522e1 - rustc_hir_typeck[83a831c03ea981a4]::typeck
  45:        0x113b9d43c - rustc_query_impl[36fa5edae9172c7f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[36fa5edae9172c7f]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8094f41c293b336b]::query::erase::Erased<[u8; 8usize]>>
  46:        0x113a210fe - rustc_query_system[16c7cab3586fd5d4]::query::plumbing::try_execute_query::<rustc_query_impl[36fa5edae9172c7f]::DynamicConfig<rustc_query_system[16c7cab3586fd5d4]::query::caches::VecCache<rustc_span[2de937bbddea0bd8]::def_id::LocalDefId, rustc_middle[8094f41c293b336b]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[36fa5edae9172c7f]::plumbing::QueryCtxt, false>
  47:        0x113bc0abb - rustc_query_impl[36fa5edae9172c7f]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  48:        0x112756fd6 - <rustc_middle[8094f41c293b336b]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[af0a509199b1bc4b]::check_crate::{closure#4}>::{closure#0}
  49:        0x1128ac55c - rustc_hir_analysis[af0a509199b1bc4b]::check_crate
  50:        0x112e53df7 - rustc_interface[eab3c32d3b591e25]::passes::run_required_analyses
  51:        0x112e563a0 - rustc_interface[eab3c32d3b591e25]::passes::analysis
  52:        0x113b9d4ec - rustc_query_impl[36fa5edae9172c7f]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[36fa5edae9172c7f]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8094f41c293b336b]::query::erase::Erased<[u8; 1usize]>>
  53:        0x11397bfbe - rustc_query_system[16c7cab3586fd5d4]::query::plumbing::try_execute_query::<rustc_query_impl[36fa5edae9172c7f]::DynamicConfig<rustc_query_system[16c7cab3586fd5d4]::query::caches::SingleCache<rustc_middle[8094f41c293b336b]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[36fa5edae9172c7f]::plumbing::QueryCtxt, false>
  54:        0x113ba7a47 - rustc_query_impl[36fa5edae9172c7f]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  55:        0x112486857 - <rustc_interface[eab3c32d3b591e25]::queries::QueryResult<&rustc_middle[8094f41c293b336b]::ty::context::GlobalCtxt>>::enter::<core[c342ec502b95801]::result::Result<(), rustc_span[2de937bbddea0bd8]::ErrorGuaranteed>, rustc_driver_impl[708b2ec565622c48]::run_compiler::{closure#0}::{closure#1}::{closure#5}>
  56:        0x1124e4465 - rustc_interface[eab3c32d3b591e25]::interface::run_compiler::<core[c342ec502b95801]::result::Result<(), rustc_span[2de937bbddea0bd8]::ErrorGuaranteed>, rustc_driver_impl[708b2ec565622c48]::run_compiler::{closure#0}>::{closure#1}
  57:        0x1124caee1 - std[26270defc80edaa9]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[eab3c32d3b591e25]::util::run_in_thread_with_globals<rustc_interface[eab3c32d3b591e25]::util::run_in_thread_pool_with_globals<rustc_interface[eab3c32d3b591e25]::interface::run_compiler<core[c342ec502b95801]::result::Result<(), rustc_span[2de937bbddea0bd8]::ErrorGuaranteed>, rustc_driver_impl[708b2ec565622c48]::run_compiler::{closure#0}>::{closure#1}, core[c342ec502b95801]::result::Result<(), rustc_span[2de937bbddea0bd8]::ErrorGuaranteed>>::{closure#0}, core[c342ec502b95801]::result::Result<(), rustc_span[2de937bbddea0bd8]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c342ec502b95801]::result::Result<(), rustc_span[2de937bbddea0bd8]::ErrorGuaranteed>>
  58:        0x1124eaff6 - <<std[26270defc80edaa9]::thread::Builder>::spawn_unchecked_<rustc_interface[eab3c32d3b591e25]::util::run_in_thread_with_globals<rustc_interface[eab3c32d3b591e25]::util::run_in_thread_pool_with_globals<rustc_interface[eab3c32d3b591e25]::interface::run_compiler<core[c342ec502b95801]::result::Result<(), rustc_span[2de937bbddea0bd8]::ErrorGuaranteed>, rustc_driver_impl[708b2ec565622c48]::run_compiler::{closure#0}>::{closure#1}, core[c342ec502b95801]::result::Result<(), rustc_span[2de937bbddea0bd8]::ErrorGuaranteed>>::{closure#0}, core[c342ec502b95801]::result::Result<(), rustc_span[2de937bbddea0bd8]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c342ec502b95801]::result::Result<(), rustc_span[2de937bbddea0bd8]::ErrorGuaranteed>>::{closure#2} as core[c342ec502b95801]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  59:        0x1091ff83b - std::sys::pal::unix::thread::Thread::new::thread_start::hfcd29f6cc9954faa
  60:     0x7ff801f5318b - __pthread_start

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

note: please attach the file at `/Users/240701-nightly/rustc-ice-2024-07-04T07_01_14-84256.txt` to your bug report

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `main::{constant#0}`
#1 [eval_to_valtree] evaluating type-level constant
end of query stack
error: aborting due to 9 previous errors; 1 warning emitted

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

Note

Ice location:

let fn_sig_binder = func.layout.ty.fn_sig(*self.tcx);
let fn_sig =
self.tcx.normalize_erasing_late_bound_regions(self.param_env, fn_sig_binder);
let extra_args = &args[fn_sig.inputs().len()..];
let extra_args =
self.tcx.mk_type_list_from_iter(extra_args.iter().map(|arg| arg.layout().ty));

@rustbot label +F-adt_const_params

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-adt_const_params`#![feature(adt_const_params)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityS-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

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions