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 bounds on non-const functions #102273

Merged
merged 1 commit into from
Sep 26, 2022
Merged

Allow ~const bounds on non-const functions #102273

merged 1 commit into from
Sep 26, 2022

Conversation

lilasta
Copy link
Contributor

@lilasta lilasta commented Sep 25, 2022

Makes the behavior of bound of trait-associated functions and non-associated functions consistent.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jackh726 (or someone else) soon.

Please see the contribution instructions for more information.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 25, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 25, 2022
@compiler-errors
Copy link
Member

FYI that merge commits are not allowed and you'll need to rebase that out

@fee1-dead
Copy link
Member

r? @fee1-dead
@rustbot author please rebase per compiler-errors above

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 26, 2022
@rust-highfive rust-highfive assigned fee1-dead and unassigned jackh726 Sep 26, 2022
@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 26, 2022
@lilasta
Copy link
Contributor Author

lilasta commented Sep 26, 2022

Rebased.

@fee1-dead
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Sep 26, 2022

📌 Commit e4b08ab has been approved by fee1-dead

It is now in the queue for this repository.

@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 Sep 26, 2022
fee1-dead added a commit to fee1-dead-contrib/rust that referenced this pull request Sep 26, 2022
…dead

Allow `~const` bounds on non-const functions

Makes the behavior of bound of trait-associated functions and non-associated functions consistent.
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 26, 2022
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#101875 (Allow more `!Copy` impls)
 - rust-lang#101996 (Don't duplicate region names for late-bound regions in print of Binder)
 - rust-lang#102181 (Add regression test)
 - rust-lang#102273 (Allow `~const` bounds on non-const functions)
 - rust-lang#102286 (Recover some items that expect braces and don't take semicolons)

Failed merges:

 - rust-lang#102314 (Add a label to struct/enum/union ident name)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e9bec2f into rust-lang:master Sep 26, 2022
@rustbot rustbot added this to the 1.66.0 milestone Sep 26, 2022
@lilasta lilasta deleted the relax_const_bound branch September 27, 2022 06:58
struct Foo<const N: usize>;

impl<const N: usize> Foo<N> {
fn add<A: ~const Add42>(self) -> Foo<{ A::add(N) }> {
Copy link
Member

Choose a reason for hiding this comment

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

This can't be sound. ~const explicitly mean const but ehh. So it could be not const. We need something like A: const Trait which is "always const" to make this work. I will open a revert PR shortly.

Copy link
Contributor Author

@lilasta lilasta Sep 28, 2022

Choose a reason for hiding this comment

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

As far as I recall, the following code was accepted before this PR (I changed only 'non-associated' non-const functions).

impl Type {
    fn function<T: ~const Trait>() {}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, so all cases like the following are currently unsound...?

somefunc<T: ~const Trait>() -> Foo<{ T::bar(value) }>

Copy link
Contributor

Choose a reason for hiding this comment

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

I just came here because I broke this test in #101900 😆

so yea, this is unsound or depending on the impl, very confusing, as making a function const fn will make it stop compiling

Copy link
Contributor

Choose a reason for hiding this comment

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

funky broken errors, but they point at the problem:

error[E0277]: the trait bound `A: Add42<_>` is not satisfied
  --> /home/ubuntu/rust2/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs:27:61
   |
LL | fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
   |                                                             ^^^^^^ the trait `Add42<_>` is not implemented for `A`
   |
help: consider further restricting this bound
   |
LL | fn bar<A: ~const Add42 + Add42<_>, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
   |                        ++++++++++

error[E0277]: the trait bound `A: Add42<_>` is not satisfied
  --> /home/ubuntu/rust2/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs:11:43
   |
LL |    fn add<A: ~const Add42>(self) -> Foo<{ A::add(N) }> {
   |                                           ^^^^^^ the trait `Add42<_>` is not implemented for `A`
   |
help: consider further restricting this bound
   |
LL |    fn add<A: ~const Add42 + Add42<_>>(self) -> Foo<{ A::add(N) }> {
   |                           ++++++++++

error: aborting due to 2 previous errors

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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants