Skip to content

"Broken MIR" ICE when trying to use const generics #60923

Closed
@est31

Description

@est31

Code like this

#![feature(const_generics)]
pub trait Foo {
    fn foo(&self);
}


impl<T, const N: usize> Foo for [T; N] {
    fn foo(&self) {
        let _ = &self;
    }
}

Gives ICE errors like this:


error: internal compiler error: cat_expr Errd
  --> src/lib.rs:9:19
   |
9  |       fn foo(&self) {
   |  ___________________^
10 | |         let _ = &self;
11 | |     }
   | |_____^

error: internal compiler error: cat_expr Errd
  --> src/lib.rs:10:17
   |
10 |         let _ = &self;
   |                 ^^^^^

error: internal compiler error: cat_expr Errd
  --> src/lib.rs:10:18
   |
10 |         let _ = &self;
   |                  ^^^^

error: internal compiler error: QualifyAndPromoteConstants: Mir had errors
  --> src/lib.rs:9:5
   |
9  | /     fn foo(&self) {
10 | |         let _ = &self;
11 | |     }
   | |_____^

error: internal compiler error: broken MIR in DefId(0:18 ~ playground[4a30]::{{impl}}[0]::foo[0]) ("return type"): bad type [type error]
  --> src/lib.rs:9:5
   |
9  | /     fn foo(&self) {
10 | |         let _ = &self;
11 | |     }
   | |_____^

error: internal compiler error: broken MIR in DefId(0:18 ~ playground[4a30]::{{impl}}[0]::foo[0]) (LocalDecl { mutability: Mut, is_user_variable: None, internal: false, is_block_tail: None, ty: [type error], user_ty: UserTypeProjections { contents: [] }, name: None, source_info: SourceInfo { span: src/lib.rs:9:5: 11:6, scope: scope[0] }, visibility_scope: scope[0] }): bad type [type error]
  --> src/lib.rs:9:5
   |
9  | /     fn foo(&self) {
10 | |         let _ = &self;
11 | |     }
   | |_____^

Metadata

Metadata

Assignees

Labels

A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions