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

ICE with const-generic enum pattern #80531

Closed
CraftSpider opened this issue Dec 30, 2020 · 3 comments · Fixed by #80551
Closed

ICE with const-generic enum pattern #80531

CraftSpider opened this issue Dec 30, 2020 · 3 comments · Fixed by #80551
Assignees
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CraftSpider
Copy link
Contributor

CraftSpider commented Dec 30, 2020

Code

enum ConstGenericEnum<const N: usize> {
    Foo([i32; N]),
    Bar,
}

fn foo<const N: usize>(val: &ConstGenericEnum<N>) {
    if let ConstGenericEnum::<N>::Foo(field, ..) = val {
        // Do stuff
    } else {
        // Do other stuff
    }
}

Note: The actual variant matched seems to be irrelevant, the significant part is the ::<N>. This does not need any feature flags, and adding either min_const_generics or const_generics does not fix it.

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (158f8d034 2020-12-29)
binary: rustc
commit-hash: 158f8d034b15e65ba8dc0d066358dd0632bfcd6e
commit-date: 2020-12-29
host: x86_64-pc-windows-msvc
release: 1.51.0-nightly

Error output

error: internal compiler error: unexpected const parent in type_of_def_id(): Pat(Pat { hir_id: HirId { owner: DefId(0:11 ~ consts[4055]::foo), local_id: 15 }, kind: TupleStruct(Resolved(None, Path { span: src\main.rs:10:12: 10:38 (#0), res: Def(Ctor(Variant, Fn), DefId(0:6 ~ consts[4055]::ConstGenericEnum::Foo::{constructor#0})), segments: [PathSegment { ident: ConstGenericEnum#0, hir_id: Some(HirId { owner: DefId(0:11 ~ consts[4055]::foo), local_id: 12 }), res: Some(Def(Enum, DefId(0:3 ~ consts[4055]::ConstGenericEnum))), args: Some(GenericArgs { args: [Const(ConstArg { value: AnonConst { hir_id: HirId { owner: DefId(0:11 ~ consts[4055]::foo), local_id: 9 }, body: BodyId { hir_id: HirId { owner: DefId(0:11 ~ consts[4055]::foo), local_id: 11 } } }, span: src\main.rs:10:31: 10:32 (#0) })], bindings: [], parenthesized: false }), infer_args: false }, PathSegment { ident: Foo#0, hir_id: Some(HirId { owner: DefId(0:11 ~ consts[4055]::foo), local_id: 13 }), res: Some(Err), args: None, infer_args: true }] }), [Pat { hir_id: HirId { owner: DefId(0:11 ~ consts[4055]::foo), local_id: 14 }, kind: Binding(Unannotated, HirId { owner: DefId(0:11 ~ consts[4055]::foo), local_id: 14 }, field#0, None), span: src\main.rs:10:39: 10:44 (#0), default_binding_modes: true }], Some(1)), span: src\main.rs:10:12: 10:49 (#0), default_binding_modes: true })
  |
  = note: delayed at compiler\rustc_typeck\src\collect\type_of.rs:334:26


error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler\rustc_typeck\src\check\coercion.rs:153:49


error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler\rustc_mir_build\src\build\mod.rs:696:18


error: internal compiler error: mir_const_qualif: MIR had errors
  --> src\main.rs:10:31
   |
10 |     if let ConstGenericEnum::<N>::Foo(field, ..) = val {
   |                               ^
   |
   = note: delayed at compiler\rustc_mir\src\transform\mod.rs:230:18


error: internal compiler error: PromoteTemps: MIR had errors
  --> src\main.rs:10:31
   |
10 |     if let ConstGenericEnum::<N>::Foo(field, ..) = val {
   |                               ^
   |
   = note: delayed at compiler\rustc_mir\src\transform\promote_consts.rs:55:22


error: internal compiler error: broken MIR in DefId(0:14 ~ consts[4055]::foo::{constant#0}) ("return type"): bad type [type error]
  --> src\main.rs:10:31
   |
10 |     if let ConstGenericEnum::<N>::Foo(field, ..) = val {
   |                               ^
   |
   = note: delayed at compiler\rustc_mir\src\borrow_check\type_check\mod.rs:253:27


error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler\rustc_mir\src\borrow_check\type_check\mod.rs:715:20


error: internal compiler error: broken MIR in DefId(0:14 ~ consts[4055]::foo::{constant#0}) (LocalDecl { mutability: Mut, local_info: None, internal: false, is_block_tail: None, ty: [type error], user_ty: None, source_info: SourceInfo { span: src\main.rs:10:31: 10:32 (#0), scope: scope[0] } }): bad type [type error]
  --> src\main.rs:10:31
   |
10 |     if let ConstGenericEnum::<N>::Foo(field, ..) = val {
   |                               ^
   |
   = note: delayed at compiler\rustc_mir\src\borrow_check\type_check\mod.rs:253:27
Backtrace

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler\rustc_errors\src\lib.rs:974:13
stack backtrace:
   0:     0x7ff99bd2bcf5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h17841712fc816a42
   1:     0x7ff99bd584fb - core::fmt::write::ha3ea633b18d2da75
   2:     0x7ff99bd1d5dd - <std::io::IoSlice as core::fmt::Debug>::fmt::h9df41d37d9186c48
   3:     0x7ff99bd2fecd - std::panicking::take_hook::h78f8a454f3a4df82
   4:     0x7ff99bd2f9d3 - std::panicking::take_hook::h78f8a454f3a4df82
   5:     0x7ff960e6ff27 - rustc_driver::report_ice::h1d5c5221edf9c73d
   6:     0x7ff99bd309af - std::panicking::rust_panic_with_hook::h9fd6ff93f12148ea
   7:     0x7ff99bd304a1 - rust_begin_unwind
   8:     0x7ff99bd2c69f - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h17841712fc816a42
   9:     0x7ff99bd303f9 - rust_begin_unwind
  10:     0x7ff99bd303ac - std::panicking::begin_panic_fmt::h33e8bdfb545f007a
  11:     0x7ff96569f214 - rustc_errors::HandlerInner::delay_as_bug::h5a7d10ea72b1c82f
  12:     0x7ff96569a8f4 - <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop::hc04473ab921ca342
  13:     0x7ff960e90a47 - rustc_ast::util::parser::prec_let_scrutinee_needs_par::h0da38a96661182e5
  14:     0x7ff960e92eba - rustc_ast::util::parser::prec_let_scrutinee_needs_par::h0da38a96661182e5
  15:     0x7ff960e8dc6c - rustc_ast::util::parser::prec_let_scrutinee_needs_par::h0da38a96661182e5
  16:     0x7ff960e72304 - <rustc_driver::Compilation as core::fmt::Debug>::fmt::hc313d7aa265f4349
  17:     0x7ff960eac7ac - <(rustc_middle::ty::sty::TyVid,&rustc_middle::ty::TyS) as rustc_infer::infer::nll_relate::VidValuePair>::value_ty::h323810e86d8af813
  18:     0x7ff960e810ab - rustc_ast::util::parser::prec_let_scrutinee_needs_par::h0da38a96661182e5
  19:     0x7ff960e08cfd - <tracing_subscriber::util::TryInitError as core::fmt::Display>::fmt::hbce8757813226e4d
  20:     0x7ff99bd3ffd3 - std::sys::windows::thread::Thread::new::h0de7ecb752bc4a62
  21:     0x7ff9f0cb7034 - BaseThreadInitThunk
  22:     0x7ff9f159d0d1 - RtlUserThreadStart
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.51.0-nightly (158f8d034 2020-12-29) running on x86_64-pc-windows-msvc
note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
end of query stack

@CraftSpider CraftSpider 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 Dec 30, 2020
@camelid camelid added the A-const-generics Area: const generics (parameters and arguments) label Dec 30, 2020
@camelid
Copy link
Member

camelid commented Dec 30, 2020

This seems like it's part of min_const_generics – and enabling min_const_generics doesn't fix it – which is worrying.

@rustbot prioritize

@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Dec 30, 2020
@CraftSpider
Copy link
Contributor Author

Correct, I ran into this with no feature flag

@camelid camelid added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 30, 2020
@camelid
Copy link
Member

camelid commented Dec 30, 2020

Assigning P-high and removing I-prioritize as discussed in the prioritization working group.

@lcnr lcnr self-assigned this Dec 30, 2020
light4 added a commit to light4/glacier that referenced this issue Dec 31, 2020
light4 added a commit to light4/glacier that referenced this issue Dec 31, 2020
JohnTitor pushed a commit to rust-lang/glacier that referenced this issue Dec 31, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Dec 31, 2020
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Dec 31, 2020
support pattern as const parents in type_of

nice to know that there's still stuff about rust i didn't know about 😆

fixes rust-lang#80531

r? ``@varkor``
@bors bors closed this as completed in 96c11f9 Jan 1, 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. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants