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 const generics #11688

Merged
merged 1 commit into from
Mar 14, 2022
Merged

Add const generics #11688

merged 1 commit into from
Mar 14, 2022

Conversation

HKalbasi
Copy link
Member

#7434 is not in this PR, so there is no evaluation of constants and no default const argument. But the rest (type inference and method resolution with chalk) should work.

Chalk is pedantic about kind of generic arguments, and will panic in case of mixing type and const arguments. I tried to add test that, but I'm not sure if it covers all cases.

crates/hir/src/display.rs Outdated Show resolved Hide resolved
crates/hir/src/lib.rs Outdated Show resolved Hide resolved
crates/hir_ty/src/consteval.rs Show resolved Hide resolved
crates/hir_ty/src/consteval.rs Outdated Show resolved Hide resolved
crates/hir_ty/src/infer/expr.rs Outdated Show resolved Hide resolved
crates/hir_ty/src/infer/expr.rs Outdated Show resolved Hide resolved
crates/hir_ty/src/lower.rs Outdated Show resolved Hide resolved
crates/hir_ty/src/lower.rs Outdated Show resolved Hide resolved
crates/hir_ty/src/tests/regression.rs Outdated Show resolved Hide resolved
crates/hir_ty/src/tests/regression.rs Outdated Show resolved Hide resolved
Copy link
Member

@flodiebold flodiebold left a comment

Choose a reason for hiding this comment

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

Looks mostly good. If you haven't done so, maybe try running rust-analyzer analysis-stats on some const-generics-heavy codebases? (nalgebra?)

bors d+

@bors
Copy link
Contributor

bors bot commented Mar 12, 2022

✌️ 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.

bors added a commit to rust-lang/chalk that referenced this pull request Mar 12, 2022
Add missing fold_free_var_const

This causes panic in rust-lang/rust-analyzer#11688 when `Sized` trait is in tests.
@HKalbasi HKalbasi force-pushed the const_generic branch 3 times, most recently from 1f450d9 to 765593b Compare March 14, 2022 10:51
@HKalbasi
Copy link
Member Author

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 14, 2022

@bors bors bot merged commit 20fa7cb into rust-lang:master Mar 14, 2022
@jonas-schievink
Copy link
Contributor

This seems to have broken analysis-stats on r-a itself: https://github.com/rust-analyzer/rust-analyzer/runs/5536316191?check_suite_focus=true

bors bot added a commit that referenced this pull request Mar 15, 2022
11718: Fix const generic panic r=lnicola a=HKalbasi

fix #11688 (comment)

Co-authored-by: hkalbasi <hamidrezakalbasi@protonmail.com>
impl std::fmt::Display for ConstScalarOrPath {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ConstScalarOrPath::Scalar(s) => write!(f, "{}", s),
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
ConstScalarOrPath::Scalar(s) => write!(f, "{}", s),
ConstScalarOrPath::Scalar(s) => s.fmt(f),
ConstScalarOrPath::Path(n) => n.fmt(f),

Copy link
Member

@lnicola lnicola Mar 21, 2022

Choose a reason for hiding this comment

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

Ah, sorry, this was already merged 🤦. I'll file a PR to clean these up.

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