granite-rust/tests/ui/traits/const-traits/const-opaque.rs
2024-11-19 20:31:05 +00:00

38 lines
659 B
Rust

//@ revisions: yes no
//@ compile-flags: -Znext-solver
//@[yes] check-pass
#![feature(const_trait_impl)]
#[const_trait]
trait Foo {
fn method(&self);
}
impl<T: ~const Foo> const Foo for (T,) {
fn method(&self) {}
}
#[cfg(yes)]
impl const Foo for () {
fn method(&self) {}
}
#[cfg(no)]
impl Foo for () {
fn method(&self) {}
}
const fn bar<T: ~const Foo>(t: T) -> impl ~const Foo {
(t,)
}
const _: () = {
let opaque = bar(());
//[no]~^ ERROR the trait bound `(): const Foo` is not satisfied
opaque.method();
//[no]~^ ERROR the trait bound `(): const Foo` is not satisfied
std::mem::forget(opaque);
};
fn main() {}