Add #[default_method_body_is_const]
This commit is contained in:
parent
a84d1b21ae
commit
2db927d8d8
5 changed files with 82 additions and 22 deletions
|
|
@ -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() {}
|
||||
|
|
|
|||
|
|
@ -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`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue