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_generics #73730

Closed
leonardo-m opened this issue Jun 25, 2020 · 3 comments · Fixed by #74392
Closed

[ICE] with const_generics #73730

leonardo-m opened this issue Jun 25, 2020 · 3 comments · 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

@leonardo-m
Copy link

#![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
@leonardo-m leonardo-m added the C-bug Category: This is a bug. label Jun 25, 2020
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) 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. labels Jun 25, 2020
@rustbot
Copy link
Collaborator

rustbot commented Jun 25, 2020

Error: Parsing glacier command in comment failed: ...'ground.rs"' | error: invalid link - must be from a playground gist at >| ''...

Please let @rust-lang/release know if you're having trouble with this bot.

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jun 27, 2020
@nbdd0121
Copy link
Contributor

nbdd0121 commented Jun 28, 2020

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

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

impl<A, I: ?Sized> Foo<'a, A> for I where I: Iterator<Item=A>  {
    fn bar<const N: usize>(&mut self) -> *const [A; N] {
        std::ptr::null()
    }
}

fn main() {
    (0_u8 .. 10).bar::<10_usize>();
}

A minimised example

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.

6 participants