1
Fork 0
rust/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.rs

31 lines
495 B
Rust
Raw Normal View History

#![feature(const_trait_impl)]
#![feature(const_fn_trait_bound)] // FIXME is this needed?
trait ConstDefaultFn: Sized {
fn b(self);
#[default_method_body_is_const]
fn a(self) {
self.b();
}
}
struct NonConstImpl;
struct ConstImpl;
impl ConstDefaultFn for NonConstImpl {
fn b(self) {}
}
impl const ConstDefaultFn for ConstImpl {
fn b(self) {}
}
const fn test() {
NonConstImpl.a();
2021-12-10 01:10:05 +08:00
//~^ ERROR cannot call non-const fn
ConstImpl.a();
}
fn main() {}