Auto merge of #93429 - fee1-dead-contrib:allow-super-trait-tilde-const, r=oli-obk

Allow `trait A: ~const B`

What's included: a minimal working change set for `~const` supertraits to work.

r? `@oli-obk`
This commit is contained in:
bors 2022-07-24 09:16:02 +00:00
commit b4151a41a0
9 changed files with 153 additions and 12 deletions

View file

@ -0,0 +1,14 @@
#![feature(const_trait_impl)]
trait Foo {
fn a(&self);
}
trait Bar: ~const Foo {}
const fn foo<T: Bar>(x: &T) {
x.a();
//~^ ERROR the trait bound
//~| ERROR cannot call
}
fn main() {}

View file

@ -0,0 +1,24 @@
error[E0277]: the trait bound `T: ~const Foo` is not satisfied
--> $DIR/super-traits-fail-2.rs:9:7
|
LL | x.a();
| ^^^ the trait `~const Foo` is not implemented for `T`
|
note: the trait `Foo` is implemented for `T`, but that implementation is not `const`
--> $DIR/super-traits-fail-2.rs:9:7
|
LL | x.a();
| ^^^
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
--> $DIR/super-traits-fail-2.rs:9:7
|
LL | x.a();
| ^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0015, E0277.
For more information about an error, try `rustc --explain E0015`.

View file

@ -0,0 +1,16 @@
#![feature(const_trait_impl)]
trait Foo {
fn a(&self);
}
trait Bar: ~const Foo {}
struct S;
impl Foo for S {
fn a(&self) {}
}
impl const Bar for S {}
//~^ ERROR the trait bound
fn main() {}

View file

@ -0,0 +1,24 @@
error[E0277]: the trait bound `S: ~const Foo` is not satisfied
--> $DIR/super-traits-fail.rs:13:12
|
LL | impl const Bar for S {}
| ^^^ the trait `~const Foo` is not implemented for `S`
|
note: the trait `Foo` is implemented for `S`, but that implementation is not `const`
--> $DIR/super-traits-fail.rs:13:12
|
LL | impl const Bar for S {}
| ^^^
note: required by a bound in `Bar`
--> $DIR/super-traits-fail.rs:6:12
|
LL | trait Bar: ~const Foo {}
| ^^^^^^^^^^ required by this bound in `Bar`
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
LL | impl const Bar for S where S: ~const Foo {}
| +++++++++++++++++++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -0,0 +1,22 @@
// check-pass
#![feature(const_trait_impl)]
trait Foo {
fn a(&self);
}
trait Bar: ~const Foo {}
struct S;
impl const Foo for S {
fn a(&self) {}
}
impl const Bar for S {}
const fn foo<T: ~const Bar>(t: &T) {
t.a();
}
const _: () = foo(&S);
fn main() {}