Skip to content

Preserve order of generic args#11140

Merged
bors[bot] merged 2 commits into
rust-lang:masterfrom
hkalbasi:const_generic
Mar 4, 2022
Merged

Preserve order of generic args#11140
bors[bot] merged 2 commits into
rust-lang:masterfrom
hkalbasi:const_generic

Conversation

@hkalbasi

Copy link
Copy Markdown
Member

rust-lang/rust#90207 removed order restriction of generic args, i.e. const generics can now become before of type generics. We need to preserve this order to analyze correctly, and this PR does that.

It also simplifies implementation of const generics a bit IMO.

Implementing default generics the same problem of #7434, we need lower them to body and then evaluate them.

Comment thread crates/hir/src/has_source.rs Outdated
Comment thread crates/hir/src/lib.rs Outdated
Comment thread crates/hir/src/lib.rs
}

impl ConstParam {
pub fn merge(self) -> TypeOrConstParam {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this should be just a plain From impl?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I guess the benefit here is in not having a generic output type involved, the name merge feels wrong though since we don't merge anything

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge is reverse of split on the TypeOrConstParam. Suggestion for better name? generalize?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have better names either, so keeping it as merge or generalize is fine

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also expect this to just be a From impl, is that not possible?

Comment thread crates/hir/src/semantics.rs Outdated
Comment thread crates/hir_def/src/attr.rs Outdated
Comment thread crates/hir_def/src/attr.rs Outdated
Comment thread crates/ide/src/navigation_target.rs Outdated
Comment thread crates/ide/src/navigation_target.rs Outdated
Comment thread crates/ide/src/syntax_highlighting/inject.rs

@Veykril Veykril left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good in my eyes now, but since there is a lot of type stuff involved @flodiebold should take a look at this as well once they have time since I don't feel comfortable about that part of the codebase

@lnicola

lnicola commented Jan 17, 2022

Copy link
Copy Markdown
Member

@hkalbasi can you please rebase?

@hkalbasi hkalbasi force-pushed the const_generic branch 2 times, most recently from d3c35f0 to f4918a4 Compare March 1, 2022 09:11
@hkalbasi

hkalbasi commented Mar 1, 2022

Copy link
Copy Markdown
Member Author

@flodiebold Can you please review this PR? It touches too many files so it conflicts with master frequently.

@flodiebold flodiebold left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems ok to me, though I wonder whether if we still have TypeParamId and ConstParamId we should still be using them in some places that explicitly expect a type/const param.

Comment thread crates/hir_def/src/lib.rs Outdated
Comment thread crates/hir_def/src/resolver.rs Outdated
pub enum TypeNs {
SelfType(ImplId),
GenericParam(TypeParamId),
GenericParam(TypeOrConstParamId),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in type ns, this has to be a type, doesn't it? so why can't this stay a TypeParamId?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test hover_const_param fails if I change it. Seems I have broken something.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment thread crates/hir_def/src/resolver.rs Outdated
Comment thread crates/hir_ty/src/db.rs Outdated
Comment thread crates/hir_def/src/lib.rs Outdated
@hkalbasi hkalbasi force-pushed the const_generic branch 4 times, most recently from c3f3605 to c334e92 Compare March 4, 2022 08:09
@flodiebold

Copy link
Copy Markdown
Member

bors d+

@bors

bors Bot commented Mar 4, 2022

Copy link
Copy Markdown
Contributor

✌️ HKalbasi can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@hkalbasi

hkalbasi commented Mar 4, 2022

Copy link
Copy Markdown
Member Author

bors r+

@bors

bors Bot commented Mar 4, 2022

Copy link
Copy Markdown
Contributor

@bors bors Bot merged commit f8329ba into rust-lang:master Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants