rust/tests/ui/traits/const-traits/const-opaque.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
659 B
Rust
Raw Normal View History

2024-11-19 20:29:01 +00:00
//@ 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() {}