-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #93429 - fee1-dead-contrib:allow-super-trait-tilde-cons…
…t, r=oli-obk Allow `trait A: ~const B` What's included: a minimal working change set for `~const` supertraits to work. r? `@oli-obk`
- Loading branch information
Showing
9 changed files
with
153 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
24 changes: 24 additions & 0 deletions
24
src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
16 changes: 16 additions & 0 deletions
16
src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
24 changes: 24 additions & 0 deletions
24
src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |