Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Const Default with generic_const_exprs & super trait #93182

Closed
Tracked by #106994
mriise opened this issue Jan 22, 2022 · 2 comments
Closed
Tracked by #106994

Const Default with generic_const_exprs & super trait #93182

mriise opened this issue Jan 22, 2022 · 2 comments
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mriise
Copy link

mriise commented Jan 22, 2022

Code

// must be enabled
#![feature(generic_const_exprs)]

// this causes an ICE!!!
pub const CONST: usize = 64;
pub trait Tr<const S: usize = CONST>: Foo<A<S>> {}

// no ICE
// pub trait Digest<const S: usize = 64>: FromH<A<S>> {} 

struct St ();

struct A<const S: usize> ([u8; S]);

pub trait Foo<T> {
    fn foo(_: T);
}

impl<const S: usize> Foo<A<S>> for St {
    fn foo(_: A<S>) {
        todo!()
    }
}

pub trait FooBar {
    type Tr: Tr;
}

playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=1a8997314db8560b8723adc2af0c07a3

Meta

rustc --version --verbose:

rustc 1.60.0-nightly (777bb86bc 2022-01-20) running on x86_64-unknown-linux-gnu

Error output

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:588:17: const parameter `S/#1` (Const { ty: usize, val: Param(S/#1) }/1) out of range when substituting substs=[<Self as FooBar>::Tr]

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/777bb86bcdbc568be7cff6eeeaaf81a89b4aa50b/compiler/rustc_errors/src/lib.rs:1115: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.60.0-nightly (777bb86bc 2022-01-20) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

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

query stack during panic:
#0 [check_trait_item_well_formed] checking that `FooBar::Tr` is well-formed
#1 [analysis] running analysis passes on this crate
end of query stack

Backtrace

Compiling playground v0.0.1 (/playground)
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:2:12
  |
2 | #![feature(generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information

error[E0601]: `main` function not found in crate `playground`
  --> src/main.rs:2:1
   |
2  | / #![feature(generic_const_exprs)]
3  | |
4  | | // this causes an ICE!!!
5  | | pub const CONST: usize = 64;
...  |
25 | |     type Tr: Tr;
26 | | }
   | |_^ consider adding a `main` function to `src/main.rs`

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:588:17: const parameter `S/#1` (Const { ty: usize, val: Param(S/#1) }/1) out of range when substituting substs=[<Self as FooBar>::Tr]

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/777bb86bcdbc568be7cff6eeeaaf81a89b4aa50b/compiler/rustc_errors/src/lib.rs:1115:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::span_bug::<rustc_span::span_encoding::Span>
   3: <rustc_errors::Handler>::span_bug::<rustc_span::span_encoding::Span>
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   7: <&rustc_middle::ty::consts::Const as rustc_middle::ty::fold::TypeFoldable>::try_fold_with::<rustc_middle::ty::subst::SubstFolder>
   8: <&rustc_middle::ty::TyS as rustc_middle::ty::fold::TypeFoldable>::super_fold_with::<rustc_middle::ty::subst::SubstFolder>
   9: <alloc::vec::Vec<rustc_middle::ty::Predicate> as alloc::vec::spec_extend::SpecExtend<rustc_middle::ty::Predicate, core::iter::adapters::map::Map<core::slice::iter::Iter<(rustc_middle::ty::Predicate, rustc_span::span_encoding::Span)>, <rustc_middle::ty::generics::GenericPredicates>::instantiate_into::{closure#0}>>>::spec_extend
  10: <rustc_middle::ty::generics::GenericPredicates>::instantiate_into
  11: <rustc_middle::ty::generics::GenericPredicates>::instantiate
  12: <rustc_trait_selection::traits::wf::WfPredicates>::nominal_obligations
  13: <rustc_trait_selection::traits::wf::WfPredicates>::compute
  14: <rustc_trait_selection::traits::fulfill::FulfillProcessor>::progress_changed_obligations
  15: <rustc_data_structures::obligation_forest::ObligationForest<rustc_trait_selection::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection::traits::fulfill::FulfillProcessor, rustc_data_structures::obligation_forest::Outcome<rustc_trait_selection::traits::fulfill::PendingPredicateObligation, rustc_infer::traits::FulfillmentErrorCode>>
  16: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_all_or_error
  17: <rustc_infer::infer::InferCtxtBuilder>::enter::<(), <rustc_typeck::check::inherited::InheritedBuilder>::enter<<rustc_typeck::check::wfcheck::CheckWfFcxBuilder>::with_fcx<rustc_typeck::check::wfcheck::check_associated_item::{closure#0}>::{closure#0}, ()>::{closure#0}>
  18: rustc_typeck::check::wfcheck::check_associated_item
  19: rustc_typeck::check::wfcheck::check_trait_item
  20: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, ()>>
  21: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::check_trait_item_well_formed, rustc_query_impl::plumbing::QueryCtxt>
  22: rustc_data_structures::sync::par_for_each_in::<&alloc::vec::Vec<core::option::Option<rustc_hir::hir::OwnerInfo>>, <rustc_middle::hir::map::Map>::par_visit_all_item_likes<rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor>::{closure#0}>
  23: <rustc_session::session::Session>::track_errors::<rustc_typeck::check_crate::{closure#5}, ()>
  24: rustc_typeck::check_crate
  25: rustc_interface::passes::analysis
  26: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorReported>>>
  27: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  28: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
  29: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  30: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>
  31: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
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.60.0-nightly (777bb86bc 2022-01-20) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin

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

query stack during panic:
#0 [check_trait_item_well_formed] checking that `FooBar::Tr` is well-formed
#1 [analysis] running analysis passes on this crate
end of query stack
For more information about this error, try `rustc --explain E0601`.
warning: `playground` (bin "playground") generated 1 warning
error: could not compile `playground` due to previous error; 1 warning emitted

@mriise mriise added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 22, 2022
@mriise mriise changed the title Const Default with generic_const_exprs & super trait Const Default with generic_const_exprs & super trait Jan 22, 2022
@BoxyUwU BoxyUwU added A-const-generics Area: const generics (parameters and arguments) F-generic_const_exprs `#![feature(generic_const_exprs)]` labels Jan 22, 2022
@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 22, 2022

I think this ICE is the same as what was mentioned in the description of #86580

trait Foo<const N: usize> {}
struct Bar<const N: usize = { 2 + 3 }> where (): Foo<N>;

This code also ICEs under this PR because instantiating the default's predicates causes an ICE as predicates_of contains predicates with fwd declared params

@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 17, 2023

closing in favor of #106994

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants