Add #[default_method_body_is_const]

This commit is contained in:
Deadbeef 2021-07-04 12:24:20 +08:00
parent a84d1b21ae
commit 2db927d8d8
No known key found for this signature in database
GPG key ID: 6525773485376D92
5 changed files with 82 additions and 22 deletions

View file

@ -8,13 +8,31 @@ trait Tr {
println!("lul");
self.req();
}
#[default_method_body_is_const]
fn default() {}
}
struct S;
impl const Tr for S {
fn req(&self) {}
} //~^^ ERROR const trait implementations may not use non-const default functions
impl const Tr for u8 {
fn req(&self) {}
fn prov(&self) {}
}
//~^^^ ERROR const trait implementations may not use default functions
impl const Tr for u16 {
fn prov(&self) {}
fn default() {}
} //~^^^ ERROR not all trait items implemented
impl const Tr for u32 {
fn req(&self) {}
fn default() {}
} //~^^^ ERROR const trait implementations may not use non-const default functions
fn main() {}

View file

@ -1,10 +1,33 @@
error: const trait implementations may not use default functions
--> $DIR/impl-with-default-fn.rs:15:1
error: const trait implementations may not use non-const default functions
--> $DIR/impl-with-default-fn.rs:18:1
|
LL | / impl const Tr for S {
LL | | fn req(&self) {}
LL | | }
| |_^
|
= note: `prov` not implemented
error: aborting due to previous error
error: const trait implementations may not use non-const default functions
--> $DIR/impl-with-default-fn.rs:33:1
|
LL | / impl const Tr for u32 {
LL | | fn req(&self) {}
LL | | fn default() {}
LL | | }
| |_^
|
= note: `prov` not implemented
error[E0046]: not all trait items implemented, missing: `req`
--> $DIR/impl-with-default-fn.rs:27:1
|
LL | fn req(&self);
| -------------- `req` from trait
...
LL | impl const Tr for u16 {
| ^^^^^^^^^^^^^^^^^^^^^ missing `req` in implementation
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0046`.