Skip to content

[ICE] in \ty\subst.rs with wrongly posioned use statement #80077

Closed
@leonardo-m

Description

@leonardo-m

Recently I've reported a bug similar to this, and it was closed down as duplicate, so I am not sure if this is novel (this is wrong code because of that import inside the feature):

#![feature(
    const_assume,
    const_evaluatable_checked,
    const_generics,
    use std::intrinsics::assume;
)]
#![allow(incomplete_features)]

const fn foo(n: usize) -> usize { n }

pub struct Bar<const N: usize>(usize);

impl<const N: usize> Bar<N> where [(); foo(N)]: {
    fn spam(i: usize) { }
}

fn main() {}

It gave:

error: expected identifier, found keyword `use`
 --> ...\test.rs:5:5
  |
5 |     use std::intrinsics::assume;
  |     ^^^ expected identifier, found keyword

error: expected one of `(`, `,`, `::`, or `=`, found `std`
 --> ...\test.rs:5:9
  |
5 |     use std::intrinsics::assume;
  |         ^^^ expected one of `(`, `,`, `::`, or `=`

error[E0658]: const generics are unstable
  --> ...\test.rs:11:22
   |
11 | pub struct Bar<const N: usize>(usize);
   |                      ^
   |
   = note: see issue #74878 <https://github.com/rust-lang/rust/issues/74878> for more information
   = help: add `#![feature(min_const_generics)]` to the crate attributes to enable

error[E0658]: const generics are unstable
  --> ...\test.rs:13:12
   |
13 | impl<const N: usize> Bar<N> where [(); foo(N)]: {
   |            ^
   |
   = note: see issue #74878 <https://github.com/rust-lang/rust/issues/74878> for more information
   = help: add `#![feature(min_const_generics)]` to the crate attributes to enable

error: internal compiler error: compiler\rustc_middle\src\ty\subst.rs:568:17: const parameter `N/#0` (Const { ty: usize, val: Param(N/#0) }/0) out of range when substituting substs=[]

thread 'rustc' panicked at 'Box<Any>', /rustc/f76ecd0668fcdb289456cdc72a39ad15467cc454\compiler\rustc_errors\src\lib.rs:904:9
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::span_bug
   2: rustc_errors::Handler::span_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::span_bug_fmt
   8: <rustc_middle::ty::subst::SubstFolder as rustc_middle::ty::fold::TypeFolder>::fold_const
   9: rustc_middle::ty::normalize_erasing_regions::<impl rustc_middle::ty::context::TyCtxt>::subst_and_normalize_erasing_regions
  10: rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_operand
  11: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::try_fold
  12: <alloc::vec::Vec<T> as alloc::vec::SpecFromIter<T,I>>::from_iter
  13: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::run
  14: rustc_mir::const_eval::eval_queries::eval_to_allocation_raw_provider
  15: 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
  16: rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}::{{closure}}
  17: rustc_query_system::query::plumbing::get_query_impl
  18: rustc_mir::const_eval::eval_queries::eval_to_const_value_raw_provider
  19: 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
  20: rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}::{{closure}}
  21: rustc_query_system::query::plumbing::get_query_impl
  22: rustc_mir::const_eval::eval_queries::eval_to_const_value_raw_provider
  23: 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
  24: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  25: rustc_data_structures::stack::ensure_sufficient_stack
  26: rustc_query_system::query::plumbing::get_query_impl
  27: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_global_id
  28: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_resolve
  29: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_const
  30: rustc_middle::ty::structural_impls::<impl rustc_middle::ty::fold::TypeFoldable for &rustc_middle::ty::TyS>::super_fold_with
  31: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_ty
  32: rustc_middle::ty::fold::TypeFoldable::fold_with
  33: rustc_middle::ty::fold::TypeFoldable::fold_with
  34: rustc_trait_selection::traits::project::AssocTypeNormalizer::fold
  35: rustc_trait_selection::traits::project::normalize
  36: rustc_trait_selection::traits::fully_normalize
  37: rustc_infer::infer::InferCtxtBuilder::enter
  38: rustc_trait_selection::traits::do_normalize_predicates
  39: rustc_trait_selection::traits::normalize_param_env_or_error
  40: rustc_ty_utils::ty::param_env
  41: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::param_env>::compute
  42: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  43: rustc_data_structures::stack::ensure_sufficient_stack
  44: rustc_query_system::query::plumbing::get_query_impl
  45: rustc_typeck::check::wfcheck::check_item_well_formed
  46: 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
  47: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  48: rustc_data_structures::stack::ensure_sufficient_stack
  49: rustc_query_system::query::plumbing::get_query_impl
  50: rustc_query_system::query::plumbing::ensure_query_impl
  51: rustc_data_structures::sync::par_for_each_in
  52: rustc_hir::hir::Crate::par_visit_all_item_likes
  53: rustc_session::session::Session::track_errors
  54: rustc_typeck::check_crate
  55: rustc_interface::passes::analysis
  56: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  57: rustc_query_system::dep_graph::graph::DepGraph<K>::with_eval_always_task
  58: rustc_data_structures::stack::ensure_sufficient_stack
  59: rustc_query_system::query::plumbing::get_query_impl
  60: rustc_interface::passes::QueryContext::enter
  61: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  62: rustc_span::with_source_map
  63: rustc_interface::interface::create_compiler_and_run
  64: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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.50.0-nightly (f76ecd066 2020-12-15) running on x86_64-pc-windows-gnu

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `Bar::<N>::{constant#0}`
#1 [eval_to_const_value_raw] simplifying constant for the type system `Bar::<N>::{constant#0}`
#2 [eval_to_const_value_raw] simplifying constant for the type system `Bar::<N>::{constant#0}`
#3 [param_env] computing normalized predicates of `Bar<N>`
#4 [check_item_well_formed] checking that `Bar<N>` is well-formed
#5 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 5 previous errors

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)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.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions