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

allow const generics in const fn #71109

Merged
merged 1 commit into from
Apr 14, 2020
Merged

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Apr 13, 2020

This was explicitly forbidden before. As we were unable to think of a reason
why this should still be the case, this check has been removed.

r? @eddyb
cc @varkor @Centril

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

eddyb commented Apr 13, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Apr 13, 2020

📌 Commit 50eb397 has been approved by eddyb

@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 13, 2020
@varkor
Copy link
Member

varkor commented Apr 13, 2020

@bors r-

This was a deliberate decision. The interactions with const fn and const generics are unclear, as it can lead to a form of dependent typing that we need to carefully examine before permitting. In addition, the const generics RFC did not permit const generics to be specified on const fn.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 13, 2020
/// as this is tantamount to allowing compile-time dependent typing.
///
/// FIXME(const_generics): Is this really true / necessary? Discuss with @varkor.
/// At any rate, the restriction feels too syntactic. Consider moving it to e.g. typeck.
Copy link
Member

Choose a reason for hiding this comment

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

We could certainly move it elsewhere, but there are definitely still concerns with its interactions with const fn. At any rate, I don't see that there's any urgent need to combine the two features at present anyway.

@eddyb
Copy link
Member

eddyb commented Apr 13, 2020

@varkor I've never heard of this and it doesn't make sense to me.
A link to prior discussion would be helpful.

You can already do everything const fn with generic parameters can, using this construction:

struct Foo<const X: u32, const Y: u32>;
impl<const X: u32, const Y: u32> Foo<X, Y> {
    const OUTPUT: u32 = X + Y;
}

@varkor
Copy link
Member

varkor commented Apr 13, 2020

This was discussed on Discord during implementation; I may be able to find a link if Discord has recorded this much history. I need to think about the example, as I haven't thought about this in a long time.

@varkor
Copy link
Member

varkor commented Apr 13, 2020

(We're discussing this on Zulip. If it's a false alarm, I'll re-approve shortly.)

@varkor
Copy link
Member

varkor commented Apr 13, 2020

After discussing this, we agreed that allowing this case should not be a concern: I was worrying about calling const fn inside const arguments and the implications for const unification, but this is a separate concern that we should be able to deal with when we consider more advanced forms of unification than identity-checking. Here is a link to the relevant discussion on Zulip.

@bors r=eddyb

@bors
Copy link
Contributor

bors commented Apr 13, 2020

📌 Commit 50eb397 has been approved by eddyb

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 13, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 13, 2020
Rollup of 4 pull requests

Successful merges:

 - rust-lang#70654 (Explain how to work with subtree)
 - rust-lang#71092 (Remove some usage of `DUMMY_HIR_ID`)
 - rust-lang#71103 (Add test case for type aliasing `impl Sized`)
 - rust-lang#71109 (allow const generics in const fn)

Failed merges:

r? @ghost
@bors bors merged commit dd27462 into rust-lang:master Apr 14, 2020
@lcnr lcnr deleted the generics_in_const_fn branch June 13, 2023 12:58
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.

5 participants