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 when running an associated function with a const generic parameter #74255

Closed
beepster4096 opened this issue Jul 11, 2020 · 1 comment · Fixed by #74392
Closed

ICE when running an associated function with a const generic parameter #74255

beepster4096 opened this issue Jul 11, 2020 · 1 comment · Fixed by #74392
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@beepster4096
Copy link
Contributor

Code

#![feature(const_generics)]
#![allow(dead_code, incomplete_features)]

#[derive(PartialEq, Eq)]
enum IceEnum {
    Variant
}

struct IceStruct;

impl IceStruct {
	fn ice_struct_fn<const I: IceEnum>() {}
}

fn ice_fn() {
	IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
}

Meta

rustc --version --verbose:

rustc 1.46.0-nightly (daecab3a7 2020-07-10)
binary: rustc
commit-hash: daecab3a784f28082df90cebb204998051f3557d
commit-date: 2020-07-10
host: x86_64-pc-windows-msvc
release: 1.46.0-nightly
LLVM version: 10.0

Error output

error: internal compiler error: unexpected const parent path Expr(Expr { hir_id: HirId { owner: DefId(0:8 ~ icetest[e2da]::ice_fn[0]), local_id: 10 }, kind: Path(TypeRelative(Ty { hir_id: HirId { owner: DefId(0:8 ~ icetest[e2da]::ice_fn[0]), local_id: 2 }, kind: Path(Resolved(None, Path { span: src\lib.rs:16:2: 16:48 (#0), res: 
Def(Struct, DefId(0:3 ~ icetest[e2da]::IceStruct[0])), segments: [PathSegment { ident: IceStruct#0, hir_id: Some(HirId { owner: DefId(0:8 ~ icetest[e2da]::ice_fn[0]), local_id: 1 }), res: Some(Err), args: None, infer_args: true }] })), span: src\lib.rs:16:2: 16:48 (#0) }, PathSegment { ident: ice_struct_fn#0, hir_id: Some(HirId 
{ owner: DefId(0:8 ~ icetest[e2da]::ice_fn[0]), local_id: 9 }), res: Some(Err), args: Some(GenericArgs { args: [Const(ConstArg { value: AnonConst { hir_id: HirId { owner: DefId(0:8 ~ icetest[e2da]::ice_fn[0]), local_id: 3 }, body: BodyId { hir_id: HirId { owner: DefId(0:8 ~ icetest[e2da]::ice_fn[0]), local_id: 8 } } }, span: src\lib.rs:16:29: 16:47 (#0) })], bindings: [], parenthesized: false }), infer_args: false })), attrs: ThinVec(None), span: src\lib.rs:16:2: 16:48 (#0) })
  |
  = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: cat_expr Errd
  --> src\lib.rs:16:29
   |
16 |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
   |                                ^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: `ErrorReported` without an error
  --> src\lib.rs:16:29
   |
16 |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
   |                                ^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: cat_expr Errd
  --> src\lib.rs:15:13
   |
15 |   fn ice_fn() {
   |  _____________^
16 | |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
17 | | }
   | |_^
   |
   = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: cat_expr Errd
  --> src\lib.rs:16:2
   |
16 |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: PromoteTemps: MIR had errors
  --> src\lib.rs:15:1
   |
15 | / fn ice_fn() {
16 | |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
17 | | }
   | |_^
   |
   = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: broken MIR in DefId(0:8 ~ icetest[e2da]::ice_fn[0]) ("return type"): bad type [type error]
  --> src\lib.rs:15:1
   |
15 | / fn ice_fn() {
16 | |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
17 | | }
   | |_^
   |
   = note: delayed at src\librustc_mir\borrow_check\type_check\mod.rs:258:27

error: internal compiler error: broken MIR in DefId(0:8 ~ icetest[e2da]::ice_fn[0]) (LocalDecl { mutability: Mut, local_info: None, internal: false, is_block_tail: None, ty: [type error], user_ty: None, source_info: SourceInfo { span: src\lib.rs:15:1: 17:2 (#0), scope: scope[0] } }): bad type [type error]
  --> src\lib.rs:15:1
   |
15 | / fn ice_fn() {
16 | |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
17 | | }
   | |_^
   |
   = note: delayed at src\librustc_mir\borrow_check\type_check\mod.rs:258:27

error: internal compiler error: mir_const_qualif: MIR had errors
  --> src\lib.rs:16:29
   |
16 |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
   |                                ^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: PromoteTemps: MIR had errors
  --> src\lib.rs:16:29
   |
16 |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
   |                                ^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: broken MIR in DefId(0:9 ~ icetest[e2da]::ice_fn[0]::{{constant}}[0]) ("return type"): bad type [type error]
  --> src\lib.rs:16:29
   |
16 |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
   |                                ^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at src\librustc_mir\borrow_check\type_check\mod.rs:258:27

error: internal compiler error: broken MIR in DefId(0:9 ~ icetest[e2da]::ice_fn[0]::{{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\lib.rs:16:29: 16:47 (#0), scope: scope[0] } }): bad type [type error]     
  --> src\lib.rs:16:29
   |
16 |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
   |                                ^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at src\librustc_mir\borrow_check\type_check\mod.rs:258:27

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src\librustc_errors\lib.rs:367:17
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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.46.0-nightly (daecab3a7 2020-07-10) running on x86_64-pc-windows-msvc

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

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

error: could not compile `icetest`.

To learn more, run the command again with --verbose.
Backtrace

error: internal compiler error: unexpected const parent path Expr(Expr { hir_id: HirId { owner: DefId(0:8 ~ icetest[e2da]::ice_fn[0]), local_id: 10 }, kind: Path(TypeRelative(Ty { hir_id: HirId { owner: DefId(0:8 ~ icetest[e2da]::ice_fn[0]), local_id: 2 }, kind: Path(Resolved(None, Path { span: src\lib.rs:16:2: 16:48 (#0), res: 
Def(Struct, DefId(0:3 ~ icetest[e2da]::IceStruct[0])), segments: [PathSegment { ident: IceStruct#0, hir_id: Some(HirId { owner: DefId(0:8 ~ icetest[e2da]::ice_fn[0]), local_id: 1 }), res: Some(Err), args: None, infer_args: true }] })), span: src\lib.rs:16:2: 16:48 (#0) }, PathSegment { ident: ice_struct_fn#0, hir_id: Some(HirId 
{ owner: DefId(0:8 ~ icetest[e2da]::ice_fn[0]), local_id: 9 }), res: Some(Err), args: Some(GenericArgs { args: [Const(ConstArg { value: AnonConst { hir_id: HirId { owner: DefId(0:8 ~ icetest[e2da]::ice_fn[0]), local_id: 3 }, body: BodyId { hir_id: HirId { owner: DefId(0:8 ~ icetest[e2da]::ice_fn[0]), local_id: 8 } } }, span: src\lib.rs:16:29: 16:47 (#0) })], bindings: [], parenthesized: false }), infer_args: false })), attrs: ThinVec(None), span: src\lib.rs:16:2: 16:48 (#0) })
  |
  = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: cat_expr Errd
  --> src\lib.rs:16:29
   |
16 |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
   |                                ^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: `ErrorReported` without an error
  --> src\lib.rs:16:29
   |
16 |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
   |                                ^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: cat_expr Errd
  --> src\lib.rs:15:13
   |
15 |   fn ice_fn() {
   |  _____________^
16 | |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
17 | | }
   | |_^
   |
   = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: cat_expr Errd
  --> src\lib.rs:16:2
   |
16 |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: PromoteTemps: MIR had errors
  --> src\lib.rs:15:1
   |
15 | / fn ice_fn() {
16 | |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
17 | | }
   | |_^
   |
   = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: broken MIR in DefId(0:8 ~ icetest[e2da]::ice_fn[0]) ("return type"): bad type [type error]
  --> src\lib.rs:15:1
   |
15 | / fn ice_fn() {
16 | |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
17 | | }
   | |_^
   |
   = note: delayed at src\librustc_mir\borrow_check\type_check\mod.rs:258:27

error: internal compiler error: broken MIR in DefId(0:8 ~ icetest[e2da]::ice_fn[0]) (LocalDecl { mutability: Mut, local_info: None, internal: false, is_block_tail: None, ty: [type error], user_ty: None, source_info: SourceInfo { span: src\lib.rs:15:1: 17:2 (#0), scope: scope[0] } }): bad type [type error]
  --> src\lib.rs:15:1
   |
15 | / fn ice_fn() {
16 | |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
17 | | }
   | |_^
   |
   = note: delayed at src\librustc_mir\borrow_check\type_check\mod.rs:258:27

error: internal compiler error: mir_const_qualif: MIR had errors
  --> src\lib.rs:16:29
   |
16 |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
   |                                ^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: PromoteTemps: MIR had errors
  --> src\lib.rs:16:29
   |
16 |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
   |                                ^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at /rustc/daecab3a784f28082df90cebb204998051f3557d\src\librustc_session\session.rs:436:27

error: internal compiler error: broken MIR in DefId(0:9 ~ icetest[e2da]::ice_fn[0]::{{constant}}[0]) ("return type"): bad type [type error]
  --> src\lib.rs:16:29
   |
16 |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
   |                                ^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at src\librustc_mir\borrow_check\type_check\mod.rs:258:27

error: internal compiler error: broken MIR in DefId(0:9 ~ icetest[e2da]::ice_fn[0]::{{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\lib.rs:16:29: 16:47 (#0), scope: scope[0] } }): bad type [type error]     
  --> src\lib.rs:16:29
   |
16 |     IceStruct::ice_struct_fn::<{IceEnum::Variant}>();
   |                                ^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at src\librustc_mir\borrow_check\type_check\mod.rs:258:27

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src\librustc_errors\lib.rs:367:17
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: <std::io::IoSliceMut as core::fmt::Debug>::fmt
   3: std::panicking::take_hook
   4: std::panicking::take_hook
   5: rustc_driver::report_ice
   6: std::panicking::rust_panic_with_hook
   7: <rustc_errors::styled_buffer::StyledBuffer as core::fmt::Debug>::fmt
   8: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
   9: <rustc_driver::DEFAULT_HOOK as core::ops::deref::Deref>::deref
  10: <rustc_driver::DEFAULT_HOOK as core::ops::deref::Deref>::deref
  11: <rustc_span::def_id::CrateNum as rustc_middle::ty::query::keys::Key>::default_span
  12: <rustc_expand::config::StripUnconfigured as rustc_ast::mut_visit::MutVisitor>::visit_mac
  13: <env_logger::filter::inner::Filter as core::fmt::Display>::fmt
  14: <rustc_driver::DEFAULT_HOOK as core::ops::deref::Deref>::deref
  15: <rustc_driver::DEFAULT_HOOK as core::ops::deref::Deref>::deref
  16: <rustc_span::def_id::CrateNum as rustc_middle::ty::query::keys::Key>::default_span
  17: std::sys::windows::thread::Thread::new
  18: BaseThreadInitThunk
  19: RtlUserThreadStart
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.46.0-nightly (daecab3a7 2020-07-10) running on x86_64-pc-windows-msvc

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

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

query stack during panic:
end of query stack
error: could not compile `icetest`.

To learn more, run the command again with --verbose.

@beepster4096 beepster4096 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 Jul 11, 2020
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. labels Jul 11, 2020
@beepster4096
Copy link
Contributor Author

Related error:

#![feature(const_generics)]
#![allow(dead_code, incomplete_features)]

struct IceStruct;

impl IceStruct {
	fn ice_struct_fn<const I: usize>() {}
}

fn ice_fn() {
	IceStruct::ice_struct_fn::<1>();
}

Gives

error[E0282]: type annotations needed
  --> src/lib.rs:11:29
   |
11 |     IceStruct::ice_struct_fn::<1>();
   |                                ^ cannot infer type for type `{integer}`

And replacing 1 with 1usize gives the same ICE

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jul 14, 2020
lcnr added a commit to lcnr/rust that referenced this issue Jul 16, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 16, 2020
const generics triage

I went through all const generics issues and closed all issues which are already fixed.

Some issues already have a regression test but were not closed. Also doing this as part of this PR.

uff r? @eddyb @varkor

closes rust-lang#61936
closes rust-lang#62878
closes rust-lang#63695
closes rust-lang#67144
closes rust-lang#68596
closes rust-lang#69816
closes rust-lang#70217
closes rust-lang#70507
closes rust-lang#70586
closes rust-lang#71348
closes rust-lang#71805
closes rust-lang#73120
closes rust-lang#73508
closes rust-lang#73730
closes rust-lang#74255
@bors bors closed this as completed in c354524 Jul 16, 2020
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-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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.

3 participants