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 and specified constant #71805

Closed
leonardo-m opened this issue May 2, 2020 · 1 comment · Fixed by #74392
Closed

[ICE] with const generics and specified constant #71805

leonardo-m opened this issue May 2, 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

@leonardo-m
Copy link

Related to ER #71387

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

use std::mem::MaybeUninit;

trait CollectSlice<'a>: Iterator {
    fn inner_array<const N: usize>(&mut self) -> [Self::Item; N];

    fn collect_array<const N: usize>(&mut self) -> [Self::Item; N] {
        let result = self.inner_array();
        assert!(self.next().is_none());
        result
    }
}

impl<'a, I: ?Sized> CollectSlice<'a> for I where I: Iterator {
    fn inner_array<const N: usize>(&mut self) -> [Self::Item; N] {
        let mut result: [MaybeUninit<Self::Item>; N] = unsafe {
            MaybeUninit::uninit().assume_init()
        };

        let mut count = 0;
        for (dest, item) in result.iter_mut().zip(self) {
            *dest = MaybeUninit::new(item);
            count += 1;
        }

        assert_eq!(N, count);

        let temp_ptr: *const [MaybeUninit<Self::Item>; N] = &result;
        unsafe { std::ptr::read(temp_ptr as *const [Self::Item; N]) }
    }
}

fn main() {
    let foos = [0_u64; 9].iter().cloned();
    let _bar: [u64; 9] = foos.collect_array::<9_usize>();
}

Gives:

error: internal compiler error: unexpected const parent in type_of_def_id(): Expr(Expr { hir_id: HirId { owner: DefId(0:21 ~ bug[317d]::main[0]), local_id: 23 }, kind: MethodCall(PathSegment { ident: collect_array#0, hir_id: Some(HirId { owner: DefId(0:21 ~ bug[317d]::main[0]), local_id: 20 }), res: Some(Err), args: Some(GenericArgs { args: [Const(ConstArg { value: AnonConst { hir_id: HirId { owner: DefId(0:21 ~ bug[317d]::main[0]), local_id: 18 }, body: BodyId { hir_id: HirId { owner: DefId(0:21 ~ bug[317d]::main[0]), local_id: 19 } } }, span: ...\bug.rs:37:47: 37:54 })], bindings: [], parenthesized: false }), infer_args: false }, ...\bug.rs:37:31: 37:44, [Expr { hir_id: HirId { owner: DefId(0:21 ~ bug[317d]::main[0]), local_id: 22 }, kind: Path(Resolved(None, Path { span: ...\bug.rs:37:26: 37:30, res: Local(HirId { owner: DefId(0:21 ~ bug[317d]::main[0]), local_id: 1 }), segments: [PathSegment { ident: foos#0, hir_id: Some(HirId { owner: DefId(0:21 ~ bug[317d]::main[0]), local_id: 21 }), res: Some(Local(HirId { owner: DefId(0:21 ~ bug[317d]::main[0]), local_id: 1 })), args: None, infer_args: true }] })), attrs: ThinVec(None), span: ...\bug.rs:37:26: 37:30 }]), attrs: ThinVec(None), span: ...\bug.rs:37:26: 37:57 })

error: internal compiler error: Const::from_anon_const: couldn't lit_to_const
  --> ...\bug.rs:37:47
   |
37 |     let _bar: [u64; 9] = foos.collect_array::<9_usize>();
   |                                               ^^^^^^^

error: internal compiler error: `ErrorReported` without an error
  --> ...\bug.rs:37:47
   |
37 |     let _bar: [u64; 9] = foos.collect_array::<9_usize>();
   |                                               ^^^^^^^

error: internal compiler error: cat_expr Errd
  --> ...\bug.rs:35:11
   |
35 |   fn main() {
   |  ___________^
36 | |     let foos = [0_u64; 9].iter().cloned();
37 | |     let _bar: [u64; 9] = foos.collect_array::<9_usize>();
38 | | }
   | |_^

error: internal compiler error: cat_expr Errd
  --> ...\bug.rs:37:26
   |
37 |     let _bar: [u64; 9] = foos.collect_array::<9_usize>();
   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: PromoteTemps: MIR had errors
  --> ...\bug.rs:35:1
   |
35 | / fn main() {
36 | |     let foos = [0_u64; 9].iter().cloned();
37 | |     let _bar: [u64; 9] = foos.collect_array::<9_usize>();
38 | | }
   | |_^

error: internal compiler error: broken MIR in DefId(0:21 ~ bug[317d]::main[0]) ("return type"): bad type [type error]
  --> ...\bug.rs:35:1
   |
35 | / fn main() {
36 | |     let foos = [0_u64; 9].iter().cloned();
37 | |     let _bar: [u64; 9] = foos.collect_array::<9_usize>();
38 | | }
   | |_^

error: internal compiler error: broken MIR in DefId(0:21 ~ bug[317d]::main[0]) (LocalDecl { mutability: Mut, local_info: Other, internal: false, is_block_tail: None, ty: [type error], user_ty: UserTypeProjections { contents: [] }, source_info: SourceInfo { span: ...\bug.rs:35:1: 38:2, scope: scope[0] } }): bad type [type error]
  --> ...\bug.rs:35:1
   |
35 | / fn main() {
36 | |     let foos = [0_u64; 9].iter().cloned();
37 | |     let _bar: [u64; 9] = foos.collect_array::<9_usize>();
38 | | }
   | |_^

error: internal compiler error: mir_const_qualif: MIR had errors
  --> ...\bug.rs:37:47
   |
37 |     let _bar: [u64; 9] = foos.collect_array::<9_usize>();
   |                                               ^^^^^^^

error: internal compiler error: PromoteTemps: MIR had errors
  --> ...\bug.rs:37:47
   |
37 |     let _bar: [u64; 9] = foos.collect_array::<9_usize>();
   |                                               ^^^^^^^

error: internal compiler error: broken MIR in DefId(0:24 ~ bug[317d]::main[0]::{{constant}}[2]) ("return type"): bad type [type error]
  --> ...\bug.rs:37:47
   |
37 |     let _bar: [u64; 9] = foos.collect_array::<9_usize>();
   |                                               ^^^^^^^

error: internal compiler error: broken MIR in DefId(0:24 ~ bug[317d]::main[0]::{{constant}}[2]) (LocalDecl { mutability: Mut, local_info: Other, internal: false, is_block_tail: None, ty: [type error], user_ty: UserTypeProjections { contents: [] }, source_info: SourceInfo { span: ...\bug.rs:37:47: 37:54, scope: scope[0] } }): bad type [type error]
  --> ...\bug.rs:37:47
   |
37 |     let _bar: [u64; 9] = foos.collect_array::<9_usize>();
   |                                               ^^^^^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src\librustc_errors\lib.rs:366:17

note: rustc 1.45.0-nightly (7f65393b9 2020-05-01) running on x86_64-pc-windows-gnu
@leonardo-m leonardo-m 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 May 2, 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 May 2, 2020
@lcnr
Copy link
Contributor

lcnr commented May 2, 2020

Probably related to #70507 (comment)

cc @varkor

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label May 6, 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.

4 participants