Allow ~const bounds on non-const functions#102273
Allow ~const bounds on non-const functions#102273bors merged 1 commit intorust-lang:masterfrom lilasta:relax_const_bound
~const bounds on non-const functions#102273Conversation
|
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. |
|
FYI that merge commits are not allowed and you'll need to rebase that out |
|
r? @fee1-dead |
|
Rebased. |
|
@bors r+ rollup |
…dead Allow `~const` bounds on non-const functions Makes the behavior of bound of trait-associated functions and non-associated functions consistent.
…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
| struct Foo<const N: usize>; | ||
|
|
||
| impl<const N: usize> Foo<N> { | ||
| fn add<A: ~const Add42>(self) -> Foo<{ A::add(N) }> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>() {}
}There was a problem hiding this comment.
Oh, so all cases like the following are currently unsound...?
somefunc<T: ~const Trait>() -> Foo<{ T::bar(value) }>There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Makes the behavior of bound of trait-associated functions and non-associated functions consistent.