Skip to content

Generic type alias fails to resolve fields  #15943

@cart

Description

@cart

rust-analyzer version: 0.3.1740-standalone
rustc version: 1.73.0

type Wrap<T> = T;

enum X {
    A { cool: u32, stuff: u32 },
    B,
}

fn main() {
    let wrapped = Wrap::<X>::A {
        // autocomplete for fields breaks here
        cool: 100,
        stuff: 100,
    };

    // autocomplete for fields breaks here
    // RA fails to resolve `cool`'s type (lists as unknown)
    if let Wrap::<X>::A { cool, .. } = &wrapped {}
}

And a screenshot of the failed type hint:
image

Context

I'm building a DSL for Bevy Scenes with the goal of supporting as many RA niceties as possible (ex: autocomplete, go to definition, etc). I created a discussion here a few months ago and got very helpful advice, which has generally worked!

However when building support for enums in my DSL, I encountered a limitation in the Rust type system that required the use of this type alias wrapper workaround (or an experimental feature ... which isn't an option for us).

The actual proc_macro code in my impl looks like this:

 if let Wrap::<<#path as Schematic>::Props>::#variant { #(#fields,)* .. } = &mut props {
 }

If I replace Wrap::<<#path as Schematic>::Props> with the "actual" type, RA field autocomplete does work for the enum in my DSL. Sadly, I cannot name the type in the macro (as it is defined outside of the macro), so I need to rely on the type system to resolve this.

Given that RA fails to resolve the fields in the simplified if let Wrap::<X>::A { cool, .. } = &wrapped {}, I'm assuming that if RA can handle autocomplete for this case, it can probably handle autocompletion in the Bevy DSL proc_macro as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tytype system / type inference / traits / method resolutionC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions