-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Generic type alias fails to resolve fields #15943
Comments
This is the "actual Bevy" case I would like to resolve. I'm guessing this is resolved by fixing the simpler case, but I'll include it here for completeness. type Wrap<T> = T;
enum X {
A { cool: u32, stuff: u32 },
B,
}
enum XProps {
A { cool: u32, stuff: u32 },
B,
}
trait Schematic {
type Props;
}
impl Schematic for X {
type Props = XProps;
}
fn main() {
let wrapped = Wrap::<<X as Schematic>::Props>::A {
// autocomplete breaks here
cool: 100,
stuff: 100,
};
// RA resolves `cool` to unknown
if let Wrap::<<X as Schematic>::Props>::A { cool, .. } = &wrapped {}
} |
Relevant part for this should be here I think rust-analyzer/crates/hir-ty/src/infer.rs Lines 1154 to 1170 in 1a5cee1
Unsure why this fails though, since rust-analyzer/crates/hir-ty/src/infer.rs Lines 1220 to 1232 in 1a5cee1
|
I can confirm the first case now works on nightly. The second case (which is unfortunately my Bevy experiment use case) doesn't appear to be working. |
Can you extract what the proc-macro generates (by looking at the expansion or similar) somehow? It's difficult to figure out a concrete failing case here otherwise. We most likely fail to resolve |
type Wrap<T> = T;
struct S;
trait Schematic {
type Props;
}
impl Schematic for S {
type Props = X;
}
enum X {
A { cool: u32, stuff: u32 },
B,
}
fn main() {
let wrapped = Wrap::<<S as Schematic>::Props>::A {
cool: 100,
stuff: 100,
};
if let Wrap::<<S as Schematic>::Props>::A { cool, ..} = &wrapped {}
//^^^^ &u32
} fails to resolve when it should |
I'm not sure whats going on but our substitutions fall back to errors once we put them in the projection here (projection in question being rust-analyzer/crates/hir-ty/src/lower.rs Lines 513 to 524 in 2ee17bc
Debug printing the substitution on line 513 yields
whereas debug printing the projection right after yields
do you have any idea what could be going on there from a quick glance @flodiebold? Do we need to commit something somehow somewhere? |
If you mean the |
Thats what this chunk of code is. It looks like you either found it or reverse engineered the same thing though! |
Hmm. Let me try again. |
rust-analyzer version: 0.3.1740-standalone
rustc version: 1.73.0
And a screenshot of the failed type hint:
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 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.The text was updated successfully, but these errors were encountered: