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

Do not allow const generics to depend on type parameters #60284

Merged
merged 5 commits into from
Apr 26, 2019

Conversation

varkor
Copy link
Member

@varkor varkor commented Apr 25, 2019

Fixes #60264. In https://github.com/rust-lang/rust/pull/58191/files/b534cf992d0189032207f395c27ed092c89b40c7#diff-aeb0880081a991f34aef2ab889e1fb7a, it was suggested that there might be a better place for this error, but as this bug already affects stable, it's probably worth merging this now, and refactoring afterwards (I can open an issue for this).

@rust-highfive
Copy link
Collaborator

r? @cramertj

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 25, 2019
@cramertj
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Apr 25, 2019

📌 Commit 908a639 has been approved by cramertj

@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 Apr 25, 2019
@varkor
Copy link
Member Author

varkor commented Apr 25, 2019

See #60286 for the follow up.

Centril added a commit to Centril/rust that referenced this pull request Apr 25, 2019
…=cramertj

Do not allow const generics to depend on type parameters

Fixes rust-lang#60264. In https://github.com/rust-lang/rust/pull/58191/files/b534cf992d0189032207f395c27ed092c89b40c7#diff-aeb0880081a991f34aef2ab889e1fb7a, it was suggested that there might be a better place for this error, but as this bug already affects stable, it's probably worth merging this now, and refactoring afterwards (I can open an issue for this).
@Pratyush
Copy link
Contributor

Is there a type theoretic reason why we want to disallow this?

@varkor
Copy link
Member Author

varkor commented Apr 25, 2019

@Pratyush: no, we're just being conservative at this point with the types we allow to be used in const generics (see the RFC for more details). I would expect this constraint to be relaxed in the future.

@rust-highfive

This comment has been minimized.

@Pratyush
Copy link
Contributor

Ahh I see the structural match requirement now. Thanks!

@varkor
Copy link
Member Author

varkor commented Apr 26, 2019

@bors r=cramertj

@bors
Copy link
Contributor

bors commented Apr 26, 2019

📌 Commit 6d7c794 has been approved by cramertj

Centril added a commit to Centril/rust that referenced this pull request Apr 26, 2019
…=cramertj

Do not allow const generics to depend on type parameters

Fixes rust-lang#60264. In https://github.com/rust-lang/rust/pull/58191/files/b534cf992d0189032207f395c27ed092c89b40c7#diff-aeb0880081a991f34aef2ab889e1fb7a, it was suggested that there might be a better place for this error, but as this bug already affects stable, it's probably worth merging this now, and refactoring afterwards (I can open an issue for this).
bors added a commit that referenced this pull request Apr 26, 2019
Rollup of 12 pull requests

Successful merges:

 - #59734 (Prevent failure in case no space left on device in rustdoc)
 - #59940 (Set cfg(test) when rustdoc is running with --test option)
 - #60134 (Fix index-page generation)
 - #60165 (Add Pin::{into_inner,into_inner_unchecked})
 - #60183 (Chalkify: Add builtin Copy/Clone)
 - #60225 (Introduce hir::ExprKind::Use and employ in for loop desugaring.)
 - #60247 (Implement Debug for Place using Place::iterate)
 - #60259 (Derive Default instead of new in applicable lint)
 - #60267 (Add feature-gate for f16c target feature)
 - #60284 (Do not allow const generics to depend on type parameters)
 - #60285 (Do not ICE when checking types against foreign fn)
 - #60289 (Make `-Z allow-features` work for stdlib features)

Failed merges:

r? @ghost
@bors bors merged commit 6d7c794 into rust-lang:master Apr 26, 2019
@astrojhgu
Copy link

astrojhgu commented Oct 14, 2020

Is there a plan to allow const generics to depend on type parameters in the (near) future?
I find the following code cannot be compiled:

#![feature(const_generics)]
#![feature(specialization)]

struct S<const ND:usize>{}

trait Type{
    type tt;
}

default impl<const ND:usize> Type for SSS<ND>{
    type tt=<SSS<{ND-1}> as Type>::tt;
}

impl Type for SSS<0>{
    type tt=i32;
}


fn main() {
    let a=SSS::<3>{};
}

@varkor
Copy link
Member Author

varkor commented Oct 21, 2020

Is there a plan to allow const generics to depend on type parameters in the (near) future?

Not in the near future, but it's something we'd like to support eventually. It's not in the original RFC, though, so will require some design discussion.

@varkor varkor deleted the const-param-of-type-param branch October 21, 2020 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Const generic ICE on stable, beta and nightly
6 participants