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

Implement the min_const_generics feature gate #74877

Merged
merged 7 commits into from
Aug 8, 2020

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Jul 28, 2020

Implements both rust-lang/lang-team#37 and rust-lang/compiler-team#332.

Adds the new feature gate #![feature(min_const_generics)].
This feature gate adds the following limitations to using const generics:

  • generic parameters must only be used in types if they are trivial. (either N or { N })
  • generic parameters must be either integers, bool or char.

We do allow arbitrary expressions in associated consts though, meaning that the following is allowed,
even if <[u8; 0] as Foo>::ASSOC is not const evaluatable.

trait Foo {
    const ASSOC: usize;
}

impl<const N: usize> Foo for [u8; N] {
    const ASSOC: usize = 64 / N;
}

r? @varkor cc @eddyb @withoutboats

@rust-highfive

This comment has been minimized.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 28, 2020
@lcnr lcnr mentioned this pull request Jul 28, 2020
8 tasks
@petrochenkov petrochenkov self-assigned this Jul 28, 2020
@mark-i-m
Copy link
Member

@rustbot modify labels: +A-const-generics

@rustbot rustbot added the A-const-generics Area: const generics (parameters and arguments) label Jul 28, 2020
@petrochenkov petrochenkov removed their assignment Aug 2, 2020
@oli-obk
Copy link
Contributor

oli-obk commented Aug 5, 2020

r? @oli-obk

@rust-highfive rust-highfive assigned oli-obk and unassigned varkor Aug 5, 2020
Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

you got some submodule changes entangled in your PR

I think we should port all const_generics tests that can be ported to min_const_generics in order to have a good coverage of the behaviour that we're stabilizing. This may require splitting some tests into a min_const_generic test and a const_generic test.

src/librustc_ast_passes/feature_gate.rs Outdated Show resolved Hide resolved
src/librustc_typeck/collect/type_of.rs Show resolved Hide resolved
@nikomatsakis
Copy link
Contributor

nikomatsakis commented Aug 5, 2020

I don't think it should block this PR, but I would like to see us doing a better write-up of what is permitted and not permitted in the "min const generics" variant, and why, and where the tests are. I imagine this is the work we'll be doing in the project group though.

UPDATE: I realize there are a lot of write-ups already and I think other folks who are closer to what's going on have a clear picture. It's just that I feel like I don't have a 'canonical reference' to go and re-read each time I realize I'm a bit confused.

@lcnr
Copy link
Contributor Author

lcnr commented Aug 5, 2020

submodules should be fixed, I ported all type-dependent tests for now without any issues,

imo the remaining tests can be done in a separate PR.

@oli-obk
Copy link
Contributor

oli-obk commented Aug 6, 2020

These tests are copied from const_generics tests, right? Can we remove the original tests now? They don't really give us anything new.

@lcnr
Copy link
Contributor Author

lcnr commented Aug 6, 2020

These tests are copied from const_generics tests, right? Can we remove the original tests now? They don't really give us anything new.

They do, min const generics eagerly evaluates constants without supplying the parent generics, IMO this is different enough for us to consider running all tests both with min_const_generics and const_generics.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 7, 2020
@bors
Copy link
Contributor

bors commented Aug 7, 2020

⌛ Testing commit 644c894 with merge e4c1ad1de3ced21a64716504511e76edd7622162...

@bors
Copy link
Contributor

bors commented Aug 7, 2020

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 7, 2020
@lcnr
Copy link
Contributor Author

lcnr commented Aug 7, 2020

network failure

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 7, 2020
@bors
Copy link
Contributor

bors commented Aug 8, 2020

⌛ Testing commit 644c894 with merge f9c2177...

@bors
Copy link
Contributor

bors commented Aug 8, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: oli-obk
Pushing f9c2177 to master...

@@ -579,6 +579,9 @@ declare_features! (
/// Alloc calling `transmute` in const fn
(active, const_fn_transmute, "1.46.0", Some(53605), None),

/// The smallest useful subset of `const_generics`.
(active, min_const_generics, "1.46.0", Some(74878), None),
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be 1.47.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thx, opened #75290

JohnTitor added a commit to JohnTitor/rust that referenced this pull request Aug 8, 2020
…n, r=jonas-schievink

fix `min_const_generics` version

rust-lang#74877 (comment)

> This should be 1.47.0
@hudson-ayers hudson-ayers mentioned this pull request Aug 11, 2020
2 tasks
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.