Skip to content
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

Add support for trait aliases #2773

Open
weiznich opened this issue Jan 8, 2020 · 2 comments
Open

Add support for trait aliases #2773

weiznich opened this issue Jan 8, 2020 · 2 comments
Assignees
Labels
A-rustc issues regarding the rustc codebase and rustc private crates A-ty type system / type inference / traits / method resolution B-unstable unstable feature C-feature Category: feature request

Comments

@weiznich
Copy link
Contributor

weiznich commented Jan 8, 2020

Trait aliases are currently a nightly feature.

Example code:

pub trait ValidGrouping<G> {
    type IsAggregate;
}

pub trait MixedAggregates {
    type Output;
}

mod is_aggregate {
    pub struct No;
}

pub trait NonAggregate = ValidGrouping<()>
where
    <Self as ValidGrouping<()>>::IsAggregate:
        MixedAggregates<is_aggregate::No, Output = is_aggregate::No>;

rust_analyzer seems not to be able to parse this correctly and returns a bunch of syntax errors:

383: rust-analyzer: Syntax Error: expected `{`
383: rust-analyzer: Syntax Error: expected an item
383: rust-analyzer: Syntax Error: expected EXCL
383: rust-analyzer: Syntax Error: expected `{`, `[`, `(`
383: rust-analyzer: Syntax Error: expected SEMI
383: rust-analyzer: Syntax Error: expected an item
383: rust-analyzer: Syntax Error: expected an item
383: rust-analyzer: Syntax Error: expected an item
383: rust-analyzer: Syntax Error: expected an item
384: rust-analyzer: Syntax Error: expected an item
385: rust-analyzer: Syntax Error: expected an item
385: rust-analyzer: Syntax Error: expected EXCL
385: rust-analyzer: Syntax Error: expected `{`, `[`, `(`
385: rust-analyzer: Syntax Error: expected SEMI
385: rust-analyzer: Syntax Error: expected an item
385: rust-analyzer: Syntax Error: expected EXCL
385: rust-analyzer: Syntax Error: expected `{`, `[`, `(`
385: rust-analyzer: Syntax Error: expected SEMI
385: rust-analyzer: Syntax Error: expected an item
385: rust-analyzer: Syntax Error: expected an item
385: rust-analyzer: Syntax Error: expected an item
385: rust-analyzer: Syntax Error: expected an item
385: rust-analyzer: Syntax Error: expected an item
385: rust-analyzer: Syntax Error: expected EXCL
385: rust-analyzer: Syntax Error: expected `{`, `[`, `(`
385: rust-analyzer: Syntax Error: expected SEMI
385: rust-analyzer: Syntax Error: expected an item
386: rust-analyzer: Syntax Error: expected EXCL
386: rust-analyzer: Syntax Error: expected `{`, `[`, `(`
386: rust-analyzer: Syntax Error: expected SEMI
386: rust-analyzer: Syntax Error: expected an item
386: rust-analyzer: Syntax Error: expected EXCL
386: rust-analyzer: Syntax Error: expected `{`, `[`, `(`
386: rust-analyzer: Syntax Error: expected SEMI
386: rust-analyzer: Syntax Error: expected an item
386: rust-analyzer: Syntax Error: expected EXCL
386: rust-analyzer: Syntax Error: expected `{`, `[`, `(`
386: rust-analyzer: Syntax Error: expected SEMI
386: rust-analyzer: Syntax Error: expected an item
386: rust-analyzer: Syntax Error: expected EXCL
386: rust-analyzer: Syntax Error: expected `{`, `[`, `(`
386: rust-analyzer: Syntax Error: expected SEMI
386: rust-analyzer: Syntax Error: expected an item
386: rust-analyzer: Syntax Error: expected an item
@kiljacken
Copy link
Contributor

kiljacken commented Jan 9, 2020

Parsing gets implemented in #2779.

It currently just gets mashed into the existing AST format so:

trait Z<U> = T<U> where Self: Debug + U: Clone;

is stored as:

trait Z<U>: T<U> where Self: Debug + U: Clone {}

I haven't read the RFC in detail apart from the parsing section, so I'm pretty sure more work need to be done to handle some of the special semantics trait aliases seems to introduce.

If the semantics differ from the above, we'd probably need a way to distinguish the two in the AST.

@weiznich
Copy link
Contributor Author

weiznich commented Jan 9, 2020

Thanks for the fast fix. For my current use case it's sufficient to just not generate any parser errors and otherwise ignore the alias. (It's just an unused unstable feature deep in a crate…)

@lnicola lnicola added the S-actionable Someone could pick this issue up and work on it right now label Jan 25, 2021
@Veykril Veykril added A-assists C-feature Category: feature request labels Jan 25, 2023
@lowr lowr added A-ty type system / type inference / traits / method resolution A-hir hir and hir-def related A-rustc issues regarding the rustc codebase and rustc private crates and removed A-assists labels Feb 21, 2023
@lowr lowr self-assigned this Mar 1, 2023
bors added a commit that referenced this issue Mar 3, 2023
Handle trait alias definitions

Part of #2773

This PR adds a bunch of structs and enum variants for trait aliases. Trait aliases should be handled as an independent item because they are semantically distinct from traits.

I basically started by adding `TraitAlias{Id, Loc}` to `hir_def::item_tree` and iterated adding necessary stuffs until compiler stopped complaining what's missing. Let me know if there's still anything I need to add.

I'm opening up this PR for early review and stuff. I'm planning to add tests for IDE functionalities in this PR, but not type-related support, for which I put FIXME notes.
@lowr lowr removed S-actionable Someone could pick this issue up and work on it right now A-hir hir and hir-def related labels Mar 4, 2023
@lowr lowr added the B-unstable unstable feature label May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustc issues regarding the rustc codebase and rustc private crates A-ty type system / type inference / traits / method resolution B-unstable unstable feature C-feature Category: feature request
Projects
None yet
Development

No branches or pull requests

5 participants