Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

generic_const_exprs ICE with const N: T #90364

Closed
theo-lw opened this issue Oct 28, 2021 · 1 comment · Fixed by #90396
Closed

generic_const_exprs ICE with const N: T #90364

theo-lw opened this issue Oct 28, 2021 · 1 comment · Fixed by #90396
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)]` 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

@theo-lw
Copy link
Contributor

theo-lw commented Oct 28, 2021

Code

 ! [ feature ( generic_const_exprs ) ]
pub struct Grid < T , const W : usize , const H :
T > where [ ( ) ; W * H ] : Sized , { array : [ T ; W * H ] , } impl < T , const W : usize , const H : usize > Default for Grid < T , W , H > where [ ( ) ; W * H ] : Sized , T : Default + Copy , { fn default ( ) -> Self { Self { array : [ T :: default ( ) ; W * H ] ,
}
}
}
fn main ( ) {
}

Meta

rustc --version --verbose:

rustc 1.58.0-nightly (91b931926 2021-10-23)
binary: rustc
commit-hash: 91b931926fd49fc97d1e39f2b8206abf1d77ce7d
commit-date: 2021-10-23
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

Error output

$ rustc --crate-type staticlib -C debuginfo=2 -C opt-level=3 -Z mir-opt-level=3 -Z new-llvm-pass-manager=yes -Z unsound-mir-opts=yes -Z polonius=yes -Z polymorphize=yes mutant.rs
error[E0770]: the type of const parameters must not depend on other generic parameters
 --> mutant.rs:3:1
  |
3 | T > where [ ( ) ; W * H ] : Sized , { array : [ T ; W * H ] , } impl < T , const W : usize , const H : usize > Default for Grid < T , W , H > where [ ( ) ; W * H ] : Sized , T : Defaul...
  | ^ the type must not depend on the parameter `T`

warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> mutant.rs:1:17
  |
1 | # ! [ 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

thread 'rustc' panicked at 'assertion failed: !arg.has_type_flags(!allowed_flags)', compiler/rustc_typeck/src/collect/type_of.rs:296:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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.58.0-nightly (91b931926 2021-10-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=3 -Z new-llvm-pass-manager=yes -Z unsound-mir-opts=yes -Z polonius=yes -Z polymorphize=yes -C debuginfo=2 -C opt-level=3 --crate-type staticlib

query stack during panic:
#0 [default_anon_const_substs] computing the default generic arguments for `Grid::{constant#0}`
#1 [param_env] computing normalized predicates of `Grid`
end of query stack
error: aborting due to previous error; 1 warning emitted

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

thread 'rustc' panicked at 'assertion failed: !arg.has_type_flags(!allowed_flags)', compiler/rustc_typeck/src/collect/type_of.rs:296:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/91b931926fd49fc97d1e39f2b8206abf1d77ce7d/library/std/src/panicking.rs:495:5
   1: core::panicking::panic_fmt
             at /rustc/91b931926fd49fc97d1e39f2b8206abf1d77ce7d/library/core/src/panicking.rs:107:14
   2: core::panicking::panic
             at /rustc/91b931926fd49fc97d1e39f2b8206abf1d77ce7d/library/core/src/panicking.rs:50:5
   3: rustc_typeck::collect::type_of::default_anon_const_substs
   4: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, &rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg>>>
   5: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::default_anon_const_substs, rustc_query_impl::plumbing::QueryCtxt>
   6: <rustc_middle::ty::consts::kind::Unevaluated<()>>::substs
   7: <rustc_middle::ty::Predicate as rustc_middle::ty::fold::TypeFoldable>::super_fold_with::<rustc_trait_selection::traits::project::AssocTypeNormalizer>
   8: <rustc_infer::infer::InferCtxtBuilder>::enter::<core::result::Result<alloc::vec::Vec<rustc_middle::ty::Predicate>, rustc_errors::ErrorReported>, rustc_trait_selection::traits::do_normalize_predicates::{closure#0}>
   9: rustc_trait_selection::traits::normalize_param_env_or_error
  10: rustc_ty_utils::ty::param_env
  11: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::param_env
  12: rustc_typeck::check::wfcheck::for_id
  13: rustc_typeck::check::wfcheck::check_item_well_formed
  14: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, ()>>
  15: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_item_well_formed
  16: 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}>
  17: <rustc_session::session::Session>::track_errors::<rustc_typeck::check_crate::{closure#5}, ()>
  18: rustc_typeck::check_crate
  19: rustc_interface::passes::analysis
  20: 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>>>
  21: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  22: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorReported>>
  23: <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>>
  24: 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#0}>
  25: <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.

@theo-lw theo-lw 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 Oct 28, 2021
@theo-lw theo-lw changed the title ICE when compiling with --crate-type staticlib -C debuginfo=2 -C opt-level=3 -Z mir-opt-level=3 -Z new-llvm-pass-manager=yes -Z unsound-mir-opts=yes -Z polonius=yes -Z polymorphize=yes ICE with generic_const_exprs when compiling with --crate-type staticlib -C debuginfo=2 -C opt-level=3 -Z mir-opt-level=3 -Z new-llvm-pass-manager=yes -Z unsound-mir-opts=yes -Z polonius=yes -Z polymorphize=yes Oct 28, 2021
@BoxyUwU BoxyUwU changed the title ICE with generic_const_exprs when compiling with --crate-type staticlib -C debuginfo=2 -C opt-level=3 -Z mir-opt-level=3 -Z new-llvm-pass-manager=yes -Z unsound-mir-opts=yes -Z polonius=yes -Z polymorphize=yes generic_const_exprs ICE with const N: T Oct 28, 2021
@BoxyUwU BoxyUwU added A-const-generics Area: const generics (parameters and arguments) F-generic_const_exprs `#![feature(generic_const_exprs)]` labels Oct 28, 2021
@BoxyUwU
Copy link
Member

BoxyUwU commented Oct 28, 2021

minimal:

#![feature(generic_const_exprs)]
pub struct Foo<T, const H: T>(T)
where
    [(); {1}]:;

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 30, 2021
…n_consts, r=lcnr

Prevent type flags assertions being thrown in default_anon_const_substs if errors occurred

Fixes rust-lang#90364
Fixes rust-lang#88997

r? `@lcnr`
@bors bors closed this as completed in d99dc7a Oct 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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)]` 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
2 participants