Skip to content

Const generics ICE ("unexpected const parent in type_of_def_id") on const param of method #68596

Closed
@qwerty19106

Description

@qwerty19106

The code:

#![feature(const_generics)]
#![feature(const_fn)]

pub struct S(u8);

impl S {
    pub fn get<const A: u8>(&self) -> &u8 {
        &self.0
    }
}

fn main() {
    const A: u8 = 5;
    let s = S(0);
    
    s.get::<A>();
}

cause ICE:

error: internal compiler error: unexpected const parent in type_of_def_id(): Expr(expr(HirId { owner: DefIndex(9), local_id: 15 }: s.get::<>()))

error: internal compiler error: mir_const_qualif: MIR had errors
  --> a.rs:16:13
   |
16 |     s.get::<A>();
   |             ^

error: internal compiler error: PromoteTemps: MIR had errors
  --> a.rs:16:13
   |
16 |     s.get::<A>();
   |             ^

error: internal compiler error: broken MIR in DefId(0:11 ~ a[317d]::main[0]::{{constant}}[0]) ("return type"): bad type [type error]
  --> a.rs:16:13
   |
16 |     s.get::<A>();
   |             ^

error: internal compiler error: broken MIR in DefId(0:11 ~ a[317d]::main[0]::{{constant}}[0]) (LocalDecl { mutability: Mut, local_info: Other, internal: false, is_block_tail: None, ty: [type error], user_ty: UserTypeProjections { contents: [] }, source_info: SourceInfo { span: a.rs:16:13: 16:14, scope: scope[0] } }): bad type [type error]
  --> a.rs:16:13
   |
16 |     s.get::<A>();
   |             ^

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

And this code variant also gives ICE:

s.get::<A>();

error: internal compiler error: broken MIR in DefId(0:9 ~ a[317d]::main[0]) (const S::get::<Scalar(<ZST>): [type error]>): bad type for<'r> fn(&'r S) -> &'r u8 {S::get::<Scalar(<ZST>): [type error]>}
  --> a.rs:16:7
   |
16 |     s.get();
   |       ^^^

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

Complied by:

note: rustc 1.42.0-nightly (8a79d08fa 2020-01-27) running on x86_64-unknown-linux-gnu

playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)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