Skip to content

ICE: Default type parameter that references Self in an object type #18956

Closed
@nikomatsakis

Description

@nikomatsakis

This example causes an ICE:

#![feature(default_type_params)]

trait Foo<T=Self> {
    fn method(&self);
}

fn foo(x: &Foo) { }

fn main() { }

yields

<anon>:7:12: 7:15 error: internal compiler error: Type parameter `Self/SelfSpace.0` (Self/SelfSpace/0) out of range when substituting (root type=Self) substs=Substs[types=[[];[];[];[]], regions=[[];[];[];[]]]

This is because, in an object type, the self parameter slot is empty, so the substitution of the default fails. I'm not 100% sure what's the best way to fix this. We could make the substitution report a proper error rather than ICE; perhaps that's best.

It is debatable whether such a trait ought to be object safe, but it seems harmless, if pointless, since the Self type winds up being revealed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions