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: const_generics: unexpected const parent in type_of_def_id() #73683

Closed
Boscop opened this issue Jun 24, 2020 · 4 comments
Closed

ICE: const_generics: unexpected const parent in type_of_def_id() #73683

Boscop opened this issue Jun 24, 2020 · 4 comments
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` 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

@Boscop
Copy link

Boscop commented Jun 24, 2020

Code

#[ext(pub, name = CollectArr)] // https://crates.io/crates/extend
impl<T: Iterator> T {
	fn collect_arr<const N: usize>(self) -> [T::Item; N]
	where
		[T::Item; N]: Array<Item = T::Item>,
		ArrayVec<[T::Item; N]>: Debug,
	{
		self.collect::<ArrayVec<[T::Item; N]>>().into_inner().expect("collect_arr")
	}
}

pub struct ChannelUsage(pub u16);

impl ChannelUsage {
	fn to_arr(&self) -> [bool; 16] {
		// self.iter().collect_arr() // works
		// self.iter().collect_arr::<16>() // error: cannot infer type for type `{integer}`
		self.iter().collect_arr::<16usize>() // ICE
	}
}

Meta

rustc --version --verbose:

rustc 1.46.0-nightly (ff5b446d2 2020-06-23)
binary: rustc
commit-hash: ff5b446d2fdbd898bc97a751f2f72858de185cf1
commit-date: 2020-06-23
host: x86_64-pc-windows-msvc
release: 1.46.0-nightly
LLVM version: 10.0

Error output

error: proj\src\lib.rs:1: unexpected const parent in type_of_def_id(): Expr(Expr { hir_id: HirId { owner: DefId(0:27 ~ vmidi[fa26]::chan_usage[0]::{{impl}}[1]::to_arr[0]), local_id: 10 }, kind: MethodCall(PathSegment { ident: collect_arr#0, hir_id: Some(HirId { owner: DefId(0:27 ~ vmidi[fa26]::chan_usage[0]::{{impl}}[1]::to_arr[0]), local_id: 5 }), res: Some(Err), args: Some(GenericArgs { args: [Const(ConstArg { value: AnonConst { hir_id: HirId { owner: DefId(0:27 ~ vmidi[fa26]::chan_usage[0]::{{impl}}[1]::to_arr[0]), local_id: 3 }, body: BodyId { hir_id: HirId { owner: DefId(0:27 ~ vmidi[fa26]::chan_usage[0]::{{impl}}[1]::to_arr[0]), local_id: 4 } } }, span: proj\src\chan_usage.rs:146:29: 146:36 (#0) })], bindings: [], parenthesized: false }), infer_args: false }, proj\src\chan_usage.rs:146:15: 146:26 (#0), [Expr { hir_id: HirId { owner: DefId(0:27 ~ vmidi[fa26]::chan_usage[0]::{{impl}}[1]::to_arr[0]), local_id: 9 }, kind: MethodCall(PathSegment { ident: iter#0, hir_id: Some(HirId { owner: DefId(0:27 ~ vmidi[fa26]::chan_usage[0]::{{impl}}[1]::to_arr[0]), local_id: 6 }), res: Some(Err), args: None, infer_args: true }, proj\src\chan_usage.rs:146:8: 146:12 (#0), [Expr { hir_id: HirId { owner: DefId(0:27 ~ vmidi[fa26]::chan_usage[0]::{{impl}}[1]::to_arr[0]), local_id: 8 }, kind: Path(Resolved(None, Path { span: proj\src\chan_usage.rs:146:3: 146:7 (#0), res: Local(HirId { owner: DefId(0:27 ~ vmidi[fa26]::chan_usage[0]::{{impl}}[1]::to_arr[0]), local_id: 1 }), segments: [PathSegment { ident: self#0, hir_id: Some(HirId { owner: DefId(0:27 ~ vmidi[fa26]::chan_usage[0]::{{impl}}[1]::to_arr[0]), local_id: 7 }), res: Some(Local(HirId { owner: DefId(0:27 ~ vmidi[fa26]::chan_usage[0]::{{impl}}[1]::to_arr[0]), local_id: 1 })), args: None, infer_args: true }] })), attrs: ThinVec(None), span: proj\src\chan_usage.rs:146:3: 146:7 (#0) }], proj\src\chan_usage.rs:146:8: 146:14 (#0)), attrs: ThinVec(None), span: proj\src\chan_usage.rs:146:3: 146:14 (#0) }], proj\src\chan_usage.rs:146:15: 146:39 (#0)), attrs: ThinVec(None), span: proj\src\chan_usage.rs:146:3: 146:39 (#0) })
note: proj\src\lib.rs:1: delayed at /rustc/ff5b446d2fdbd898bc97a751f2f72858de185cf1\src\librustc_session\session.rs:436:27
error: proj\src\chan_usage.rs:146: Const::from_anon_const: couldn't lit_to_const
note: proj\src\chan_usage.rs:146: delayed at /rustc/ff5b446d2fdbd898bc97a751f2f72858de185cf1\src\librustc_session\session.rs:436:27
error: proj\src\lib.rs:1: TyKind::Error constructed but no error reported
note: proj\src\lib.rs:1: delayed at /rustc/ff5b446d2fdbd898bc97a751f2f72858de185cf1\src\librustc_session\session.rs:436:27
error: proj\src\lib.rs:1: ty::ConstKind::Error constructed but no error reported.
note: proj\src\lib.rs:1: delayed at /rustc/ff5b446d2fdbd898bc97a751f2f72858de185cf1\src\librustc_session\session.rs:436:27
error: proj\src\chan_usage.rs:146: `ErrorReported` without an error
note: proj\src\chan_usage.rs:146: delayed at /rustc/ff5b446d2fdbd898bc97a751f2f72858de185cf1\src\librustc_session\session.rs:436:27
error: proj\src\chan_usage.rs:145: cat_expr Errd
note: proj\src\chan_usage.rs:145: delayed at /rustc/ff5b446d2fdbd898bc97a751f2f72858de185cf1\src\librustc_session\session.rs:436:27
error: proj\src\chan_usage.rs:146: cat_expr Errd
note: proj\src\chan_usage.rs:146: delayed at /rustc/ff5b446d2fdbd898bc97a751f2f72858de185cf1\src\librustc_session\session.rs:436:27
error: proj\src\chan_usage.rs:145: PromoteTemps: MIR had errors
note: proj\src\chan_usage.rs:145: delayed at /rustc/ff5b446d2fdbd898bc97a751f2f72858de185cf1\src\librustc_session\session.rs:436:27
error: proj\src\chan_usage.rs:145: broken MIR in DefId(0:27 ~ vmidi[fa26]::chan_usage[0]::{{impl}}[1]::to_arr[0]) ("return type"): bad type [type error]
note: proj\src\chan_usage.rs:145: delayed at src\librustc_mir\borrow_check\type_check\mod.rs:258:27
error: proj\src\chan_usage.rs:145: broken MIR in DefId(0:27 ~ vmidi[fa26]::chan_usage[0]::{{impl}}[1]::to_arr[0]) (LocalDecl { mutability: Mut, local_info: None, internal: false, is_block_tail: None, ty: [type error], user_ty: None, source_info: SourceInfo { span: proj\src\chan_usage.rs:145:2: 148:3 (#0), scope: scope[0] } }): bad type [type error]
note: proj\src\chan_usage.rs:145: delayed at src\librustc_mir\borrow_check\type_check\mod.rs:258:27
error: proj\src\chan_usage.rs:146: mir_const_qualif: MIR had errors
note: proj\src\chan_usage.rs:146: delayed at /rustc/ff5b446d2fdbd898bc97a751f2f72858de185cf1\src\librustc_session\session.rs:436:27
error: proj\src\chan_usage.rs:146: PromoteTemps: MIR had errors
note: proj\src\chan_usage.rs:146: delayed at /rustc/ff5b446d2fdbd898bc97a751f2f72858de185cf1\src\librustc_session\session.rs:436:27
error: proj\src\chan_usage.rs:146: broken MIR in DefId(0:29 ~ vmidi[fa26]::chan_usage[0]::{{impl}}[1]::to_arr[0]::{{constant}}[1]) ("return type"): bad type [type error]
note: proj\src\chan_usage.rs:146: delayed at src\librustc_mir\borrow_check\type_check\mod.rs:258:27
error: proj\src\chan_usage.rs:146: broken MIR in DefId(0:29 ~ vmidi[fa26]::chan_usage[0]::{{impl}}[1]::to_arr[0]::{{constant}}[1]) (LocalDecl { mutability: Mut, local_info: None, internal: false, is_block_tail: None, ty: [type error], user_ty: None, source_info: SourceInfo { span: proj\src\chan_usage.rs:146:29: 146:36 (#0), scope: scope[0] } }): bad type [type error]
note: proj\src\chan_usage.rs:146: 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_ast::ast::Item<rustc_ast::ast::ForeignItemKind> as rustc_ast::attr::HasAttrs>::attrs
  10: <rustc_ast::ast::Item<rustc_ast::ast::ForeignItemKind> as rustc_ast::attr::HasAttrs>::attrs
  11: <rustc_ast_passes::node_count::NodeCounter as rustc_ast::visit::Visitor>::visit_ident
  12: <rustc_metadata::foreign_modules::Collector as rustc_hir::itemlikevisit::ItemLikeVisitor>::visit_impl_item
  13: <rustc_driver::DEFAULT_HOOK as core::ops::deref::Deref>::deref
  14: <rustc_span::symbol::SymbolStr as core::fmt::Display>::fmt
  15: <i16 as petgraph::matrix_graph::Zero>::zero
  16: std::sys::windows::thread::Thread::new
  17: BaseThreadInitThunk
  18: 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 (ff5b446d2 2020-06-23) running on x86_64-pc-windows-msvc

note: compiler flags: -C opt-level=3 -C panic=abort -C embed-bitcode=no -C debuginfo=2 -C debug-assertions=on -C incremental --crate-type lib

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

query stack during panic:
end of query stack
@Boscop Boscop 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 Jun 24, 2020
@LeSeulArtichaut LeSeulArtichaut 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 Jun 24, 2020
@JohnTitor
Copy link
Member

It'd be great if we could drop external dependency, marking as E-needs-mcve.

@JohnTitor JohnTitor added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Jun 27, 2020
@connorskees
Copy link
Contributor

Slightly minified,

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

pub struct ChannelUsage;

impl ChannelUsage {
    fn collect_arr<const N: i32>() {}
}

fn foo() {
    ChannelUsage::collect_arr::<16i32>();
}
Error
rustc --version --verbose
rustc 1.46.0-nightly (a647c0cd6 2020-06-16)
binary: rustc
commit-hash: a647c0cd68bdd0f15081019f0b21bc31ae23f072
commit-date: 2020-06-16
host: x86_64-unknown-linux-gnu
release: 1.46.0-nightly
LLVM version: 10.0
error: internal compiler error: unexpected const parent path Expr(Expr { hir_id: HirId { owner: DefId(0:8 ~ ice[227a]::foo[0]), local_id: 6 }, kind: Path(TypeRelative(Ty { hir_id: HirId { owner: DefId(0:8 ~ ice[227a]::foo[0]), local_id: 2 }, kind: Path(Resolved(None, Path { span: src/lib.rs:11:5: 11:39 (#0), res: Def(Struct, DefId(0:3 ~ ice[227a]::ChannelUsage[0])), segments: [PathSegment { ident: ChannelUsage#0, hir_id: Some(HirId { owner: DefId(0:8 ~ ice[227a]::foo[0]), local_id: 1 }), res: Some(Err), args: None, infer_args: true }] })), span: src/lib.rs:11:5: 11:39 (#0) }, PathSegment { ident: collect_arr#0, hir_id: Some(HirId { owner: DefId(0:8 ~ ice[227a]::foo[0]), local_id: 5 }), res: Some(Err), args: Some(GenericArgs { args: [Const(ConstArg { value: AnonConst { hir_id: HirId { owner: DefId(0:8 ~ ice[227a]::foo[0]), local_id: 3 }, body: BodyId { hir_id: HirId { owner: DefId(0:8 ~ ice[227a]::foo[0]), local_id: 4 } } }, span: src/lib.rs:11:33: 11:38 (#0) })], bindings: [], parenthesized: false }), infer_args: false })), attrs: ThinVec(None), span: src/lib.rs:11:5: 11:39 (#0) })

error: internal compiler error: Const::from_anon_const: couldn't lit_to_const
  --> src/lib.rs:11:33
   |
11 |     ChannelUsage::collect_arr::<16i32>();
   |                                 ^^^^^

error: internal compiler error: `ErrorReported` without an error
  --> src/lib.rs:11:33
   |
11 |     ChannelUsage::collect_arr::<16i32>();
   |                                 ^^^^^

error: internal compiler error: cat_expr Errd
  --> src/lib.rs:10:10
   |
10 |   fn foo() {
   |  __________^
11 | |     ChannelUsage::collect_arr::<16i32>();
12 | | }
   | |_^

error: internal compiler error: cat_expr Errd
  --> src/lib.rs:11:5
   |
11 |     ChannelUsage::collect_arr::<16i32>();
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: PromoteTemps: MIR had errors
  --> src/lib.rs:10:1
   |
10 | / fn foo() {
11 | |     ChannelUsage::collect_arr::<16i32>();
12 | | }
   | |_^

error: internal compiler error: broken MIR in DefId(0:8 ~ ice[227a]::foo[0]) ("return type"): bad type [type error]
  --> src/lib.rs:10:1
   |
10 | / fn foo() {
11 | |     ChannelUsage::collect_arr::<16i32>();
12 | | }
   | |_^

error: internal compiler error: broken MIR in DefId(0:8 ~ ice[227a]::foo[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:10:1: 12:2 (#0), scope: scope[0] } }): bad type [type error]
  --> src/lib.rs:10:1
   |
10 | / fn foo() {
11 | |     ChannelUsage::collect_arr::<16i32>();
12 | | }
   | |_^

error: internal compiler error: mir_const_qualif: MIR had errors
  --> src/lib.rs:11:33
   |
11 |     ChannelUsage::collect_arr::<16i32>();
   |                                 ^^^^^

error: internal compiler error: PromoteTemps: MIR had errors
  --> src/lib.rs:11:33
   |
11 |     ChannelUsage::collect_arr::<16i32>();
   |                                 ^^^^^

error: internal compiler error: broken MIR in DefId(0:9 ~ ice[227a]::foo[0]::{{constant}}[0]) ("return type"): bad type [type error]
  --> src/lib.rs:11:33
   |
11 |     ChannelUsage::collect_arr::<16i32>();
   |                                 ^^^^^

error: internal compiler error: broken MIR in DefId(0:9 ~ ice[227a]::foo[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:11:33: 11:38 (#0), scope: scope[0] } }): bad type [type error]
  --> src/lib.rs:11:33
   |
11 |     ChannelUsage::collect_arr::<16i32>();
   |                                 ^^^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:366: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 (a647c0cd6 2020-06-16) running on x86_64-unknown-linux-gnu

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

playground

@lcnr
Copy link
Contributor

lcnr commented Jul 16, 2020

should be fixed by #74113 and we already have a nearly identical test to the mcve by @connorskees

@Boscop In case your original example is also fixed, please close this issue.

@lcnr lcnr removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Jul 16, 2020
@lcnr
Copy link
Contributor

lcnr commented Jul 31, 2020

Closing as I expect this to be fixed, in case the issue persists don't hesitate to open a new issue.

@lcnr lcnr closed this as completed Jul 31, 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)]` 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

No branches or pull requests

5 participants