Test for misusing attribute

This commit is contained in:
Deadbeef 2021-07-10 15:58:16 +08:00
parent a79e08ca2a
commit 88b29f5fb2
No known key found for this signature in database
GPG Key ID: 6525773485376D92
3 changed files with 47 additions and 1 deletions

View File

@ -1137,7 +1137,7 @@ rustc_queries! {
}
query impl_constness(def_id: DefId) -> hir::Constness {
desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
desc { |tcx| "looking up whether `{}` is a const impl", tcx.def_path_str(def_id) }
}
query check_item_well_formed(key: LocalDefId) -> () {

View File

@ -0,0 +1,14 @@
#![feature(const_trait_impl)]
#![allow(incomplete_features)]
#[default_method_body_is_const] //~ ERROR attribute should be applied
trait A {
#[default_method_body_is_const] //~ ERROR attribute should be applied
fn no_body(self);
#[default_method_body_is_const]
fn correct_use(&self) {}
}
#[default_method_body_is_const] //~ ERROR attribute should be applied
fn main() {}

View File

@ -0,0 +1,32 @@
error: attribute should be applied to a trait method with body
--> $DIR/attr-misuse.rs:4:1
|
LL | #[default_method_body_is_const]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | / trait A {
LL | | #[default_method_body_is_const]
LL | | fn no_body(self);
LL | |
LL | | #[default_method_body_is_const]
LL | | fn correct_use(&self) {}
LL | | }
| |_- not a trait method or missing a body
error: attribute should be applied to a trait method with body
--> $DIR/attr-misuse.rs:13:1
|
LL | #[default_method_body_is_const]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | fn main() {}
| ------------ not a trait method or missing a body
error: attribute should be applied to a trait method with body
--> $DIR/attr-misuse.rs:6:5
|
LL | #[default_method_body_is_const]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | fn no_body(self);
| ----------------- not a trait method or missing a body
error: aborting due to 3 previous errors