Skip to content

[ICE] with const_generics  #73730

Closed
@leonardo-m

Description

@leonardo-m
#![feature(const_generics, in_band_lifetimes)]
#![allow(incomplete_features)]

use std::mem::MaybeUninit;

trait Foo<'a, A>: Iterator<Item=A> {
    fn bar<const N: usize>(&mut self) -> [A; N];

    fn foo<const N: usize>(&mut self) -> [A; N] {
        let result = self.bar();
        result
    }
}

impl<A, I: ?Sized> Foo<'a, A> for I where I: Iterator<Item=A>  {
    fn bar<const N: usize>(&mut self) -> [A; N] {
        let mut result: [MaybeUninit<A>; N] = unsafe {
            MaybeUninit::uninit().assume_init()
        };
        for (a, b) in result.iter_mut().zip(self) {
            *a = MaybeUninit::new(b);
        }
        let spam: *const [MaybeUninit<A>; N] = &result;
        unsafe { std::ptr::read(spam as *const [A; N]) }
    }
}

fn main() {
    let _: [u8; 10] = (0_u8 .. 10).foo::<10_usize>();
}

Gives:

error: internal compiler error: unexpected const parent in type_of_def_id(): Expr(Expr { hir_id: HirId { owner: DefId(0:22 ~ bug3b[317d]::main[0]), local_id: 19 }, kind: MethodCall(PathSegment { ident: foo#0, hir_id: Some(HirId { owner: DefId(0:22 ~ bug3b[317d]::main[0]), local_id: 9 }), res: Some(Err), args: Some(GenericArgs { args: [Const(ConstArg { value: AnonConst { hir_id: HirId { owner: DefId(0:22 ~ bug3b[317d]::main[0]), local_id: 7 }, body: BodyId { hir_id: HirId { owner: DefId(0:22 ~ bug3b[317d]::main[0]), local_id: 8 } } }, span: ...\test.rs:29:42: 29:50 (#0) })], bindings: [], parenthesized: false }), infer_args: false }, ...\test.rs:29:36: 29:39 (#0), [Expr { hir_id: HirId { owner: DefId(0:22 ~ bug3b[317d]::main[0]), local_id: 18 }, kind: Struct(Resolved(None, Path { span: ...\test.rs:29:24: 29:34 (#0), res: Def(Struct, DefId(2:28540 ~ core[dd24]::ops[0]::range[0]::Range[0])), segments: [PathSegment { ident: {{root}}#0, hir_id: Some(HirId { owner: DefId(0:22 ~ bug3b[317d]::main[0]), local_id: 14 }), res: Some(Err), args: None, infer_args: true }, PathSegment { ident: std#0, hir_id: Some(HirId { owner: DefId(0:22 ~ bug3b[317d]::main[0]), local_id: 15 }), res: Some(Def(Mod, DefId(1:0 ~ std[c173]))), args: None, infer_args: true }, PathSegment { ident: ops#0, hir_id: Some(HirId { owner: DefId(0:22 ~ bug3b[317d]::main[0]), local_id: 16 }), res: Some(Def(Mod, DefId(2:1980 ~ core[dd24]::ops[0]))), args: None, infer_args: true }, PathSegment { ident: Range#0, hir_id: Some(HirId { owner: DefId(0:22 ~ bug3b[317d]::main[0]), local_id: 17 }), res: Some(Err), args: None, infer_args: true }] }), [Field { hir_id: HirId { owner: DefId(0:22 ~ bug3b[317d]::main[0]), local_id: 11 }, ident: start#0, expr: Expr { hir_id: HirId { owner: DefId(0:22 ~ bug3b[317d]::main[0]), local_id: 10 }, kind: Lit(Spanned { node: Int(0, Unsigned(U8)), span: ...\test.rs:29:24: 29:28 (#0) }), attrs: ThinVec(None), span: ...\test.rs:29:24: 29:28 (#0) }, span: ...\test.rs:29:24: 29:28 (#0), is_shorthand: false }, Field { hir_id: HirId { owner: DefId(0:22 ~ bug3b[317d]::main[0]), local_id: 13 }, ident: end#0, expr: Expr { hir_id: HirId { owner: DefId(0:22 ~ bug3b[317d]::main[0]), local_id: 12 }, kind: Lit(Spanned { node: Int(10, Unsuffixed), span: ...\test.rs:29:32: 29:34 (#0) }), attrs: ThinVec(None), span: ...\test.rs:29:32: 29:34 (#0) }, span: ...\test.rs:29:32: 29:34 (#0), is_shorthand: false }], None), attrs: ThinVec(None), span: ...\test.rs:29:23: 29:35 (#0) }], ...\test.rs:29:36: 29:53 (#0)), attrs: ThinVec(None), span: ...\test.rs:29:23: 29:53 (#0) })
  |
  = note: delayed at /rustc/67100f61e62a86f2bf9e38552ee138e231eddc74\src\librustc_session\session.rs:436:27

error: internal compiler error: Const::from_anon_const: couldn't lit_to_const
  --> ...\test.rs:29:42
   |
29 |     let _: [u8; 10] = (0_u8 .. 10).foo::<10_usize>();
   |                                          ^^^^^^^^
   |
   = note: delayed at /rustc/67100f61e62a86f2bf9e38552ee138e231eddc74\src\librustc_session\session.rs:436:27

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

error: internal compiler error: `ErrorReported` without an error
  --> ...\test.rs:29:42
   |
29 |     let _: [u8; 10] = (0_u8 .. 10).foo::<10_usize>();
   |                                          ^^^^^^^^
   |
   = note: delayed at /rustc/67100f61e62a86f2bf9e38552ee138e231eddc74\src\librustc_session\session.rs:436:27

error: internal compiler error: cat_expr Errd
  --> ...\test.rs:28:11
   |
28 |   fn main() {
   |  ___________^
29 | |     let _: [u8; 10] = (0_u8 .. 10).foo::<10_usize>();
30 | | }
   | |_^
   |
   = note: delayed at /rustc/67100f61e62a86f2bf9e38552ee138e231eddc74\src\librustc_session\session.rs:436:27

error: internal compiler error: cat_expr Errd
  --> ...\test.rs:29:23
   |
29 |     let _: [u8; 10] = (0_u8 .. 10).foo::<10_usize>();
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at /rustc/67100f61e62a86f2bf9e38552ee138e231eddc74\src\librustc_session\session.rs:436:27

error: internal compiler error: PromoteTemps: MIR had errors
  --> ...\test.rs:28:1
   |
28 | / fn main() {
29 | |     let _: [u8; 10] = (0_u8 .. 10).foo::<10_usize>();
30 | | }
   | |_^
   |
   = note: delayed at /rustc/67100f61e62a86f2bf9e38552ee138e231eddc74\src\librustc_session\session.rs:436:27

error: internal compiler error: broken MIR in DefId(0:22 ~ bug3b[317d]::main[0]) ("return type"): bad type [type error]
  --> ...\test.rs:28:1
   |
28 | / fn main() {
29 | |     let _: [u8; 10] = (0_u8 .. 10).foo::<10_usize>();
30 | | }
   | |_^
   |
   = note: delayed at src\librustc_mir\borrow_check\type_check\mod.rs:258:27

error: internal compiler error: broken MIR in DefId(0:22 ~ bug3b[317d]::main[0]) (LocalDecl { mutability: Mut, local_info: None, internal: false, is_block_tail: None, ty: [type error], user_ty: None, source_info: SourceInfo { span: ...\test.rs:28:1: 30:2 (#0), scope: scope[0] } }): bad type [type error]
  --> ...\test.rs:28:1
   |
28 | / fn main() {
29 | |     let _: [u8; 10] = (0_u8 .. 10).foo::<10_usize>();
30 | | }
   | |_^
   |
   = note: delayed at src\librustc_mir\borrow_check\type_check\mod.rs:258:27

error: internal compiler error: mir_const_qualif: MIR had errors
  --> ...\test.rs:29:42
   |
29 |     let _: [u8; 10] = (0_u8 .. 10).foo::<10_usize>();
   |                                          ^^^^^^^^
   |
   = note: delayed at /rustc/67100f61e62a86f2bf9e38552ee138e231eddc74\src\librustc_session\session.rs:436:27

error: internal compiler error: PromoteTemps: MIR had errors
  --> ...\test.rs:29:42
   |
29 |     let _: [u8; 10] = (0_u8 .. 10).foo::<10_usize>();
   |                                          ^^^^^^^^
   |
   = note: delayed at /rustc/67100f61e62a86f2bf9e38552ee138e231eddc74\src\librustc_session\session.rs:436:27

error: internal compiler error: broken MIR in DefId(0:24 ~ bug3b[317d]::main[0]::{{constant}}[1]) ("return type"): bad type [type error]
  --> ...\test.rs:29:42
   |
29 |     let _: [u8; 10] = (0_u8 .. 10).foo::<10_usize>();
   |                                          ^^^^^^^^
   |
   = note: delayed at src\librustc_mir\borrow_check\type_check\mod.rs:258:27

error: internal compiler error: broken MIR in DefId(0:24 ~ bug3b[317d]::main[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: ...\test.rs:29:42: 29:50 (#0), scope: scope[0] } }): bad type [type error]
  --> ...\test.rs:29:42
   |
29 |     let _: [u8; 10] = (0_u8 .. 10).foo::<10_usize>();
   |                                          ^^^^^^^^
   |
   = 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: _dllonexit
   1: _dllonexit
   2: _dllonexit
   3: _dllonexit
   4: _dllonexit
   5: _dllonexit
   6: _dllonexit
   7: _dllonexit
   8: _dllonexit
   9: _dllonexit
  10: _dllonexit
  11: _dllonexit
  12: _dllonexit
  13: _dllonexit
  14: _dllonexit
  15: _dllonexit
  16: _dllonexit
  17: _dllonexit
  18: _dllonexit
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 (67100f61e 2020-06-24) running on x86_64-pc-windows-gnu

query stack during panic:
end of query stack

Tool completed with exit code 101

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-const_generics`#![feature(const_generics)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions