diff options
| author | bors <bors@rust-lang.org> | 2022-12-30 01:09:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-12-30 01:09:31 +0000 |
| commit | 973a4db8d590d1ddfa4d07bd216aeffd28ba354e (patch) | |
| tree | 4ad2aa5b9738da23077665fb818fa462630e8003 /src/test | |
| parent | 2c7536eaae59b44ff5259183ca98384129d69dd0 (diff) | |
| parent | 983606d3676c967e79a94b74b890bfb02367b608 (diff) | |
| download | rust-973a4db8d590d1ddfa4d07bd216aeffd28ba354e.tar.gz rust-973a4db8d590d1ddfa4d07bd216aeffd28ba354e.zip | |
Auto merge of #106210 - fee1-dead-contrib:const-closure-trait-method, r=compiler-errors
Allow trait method paths to satisfy const Fn bounds r? `@oli-obk`
Diffstat (limited to 'src/test')
3 files changed, 61 insertions, 0 deletions
diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-closure-trait-method-fail.rs b/src/test/ui/rfc-2632-const-trait-impl/const-closure-trait-method-fail.rs new file mode 100644 index 00000000000..b5f19e40c03 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/const-closure-trait-method-fail.rs @@ -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() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-closure-trait-method-fail.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-closure-trait-method-fail.stderr new file mode 100644 index 00000000000..4470e287cc3 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/const-closure-trait-method-fail.stderr @@ -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`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-closure-trait-method.rs b/src/test/ui/rfc-2632-const-trait-impl/const-closure-trait-method.rs new file mode 100644 index 00000000000..3e6d1908848 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/const-closure-trait-method.rs @@ -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() {} |
