-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow trait method paths to satisfy const Fn bounds
- Loading branch information
Showing
6 changed files
with
100 additions
and
13 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
19 changes: 19 additions & 0 deletions
19
src/test/ui/rfc-2632-const-trait-impl/const-closure-trait-method-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,19 @@ | ||
#![feature(const_trait_impl)] | ||
|
||
#[const_trait] | ||
trait Tr { | ||
fn a(self) -> i32; | ||
} | ||
|
||
impl Tr for () { | ||
fn a(self) -> i32 { 42 } | ||
} | ||
|
||
const fn need_const_closure<T: ~const FnOnce(()) -> i32>(x: T) -> i32 { | ||
x(()) | ||
} | ||
|
||
const _: () = assert!(need_const_closure(Tr::a) == 42); | ||
//~^ ERROR: the trait bound | ||
|
||
fn main() {} |
23 changes: 23 additions & 0 deletions
23
src/test/ui/rfc-2632-const-trait-impl/const-closure-trait-method-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,23 @@ | ||
error[E0277]: the trait bound `(): ~const Tr` is not satisfied in `fn(()) -> i32 {<() as Tr>::a}` | ||
--> $DIR/const-closure-trait-method-fail.rs:16:42 | ||
| | ||
LL | const _: () = assert!(need_const_closure(Tr::a) == 42); | ||
| ------------------ ^^^^^ within `fn(()) -> i32 {<() as Tr>::a}`, the trait `~const Tr` is not implemented for `()` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: the trait `Tr` is implemented for `()`, but that implementation is not `const` | ||
--> $DIR/const-closure-trait-method-fail.rs:16:42 | ||
| | ||
LL | const _: () = assert!(need_const_closure(Tr::a) == 42); | ||
| ^^^^^ | ||
= note: required because it appears within the type `fn(()) -> i32 {<() as Tr>::a}` | ||
note: required by a bound in `need_const_closure` | ||
--> $DIR/const-closure-trait-method-fail.rs:12:32 | ||
| | ||
LL | const fn need_const_closure<T: ~const FnOnce(()) -> i32>(x: T) -> i32 { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `need_const_closure` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
19 changes: 19 additions & 0 deletions
19
src/test/ui/rfc-2632-const-trait-impl/const-closure-trait-method.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,19 @@ | ||
// check-pass | ||
#![feature(const_trait_impl)] | ||
|
||
#[const_trait] | ||
trait Tr { | ||
fn a(self) -> i32; | ||
} | ||
|
||
impl const Tr for () { | ||
fn a(self) -> i32 { 42 } | ||
} | ||
|
||
const fn need_const_closure<T: ~const FnOnce(()) -> i32>(x: T) -> i32 { | ||
x(()) | ||
} | ||
|
||
const _: () = assert!(need_const_closure(Tr::a) == 42); | ||
|
||
fn main() {} |