Skip to content

Commit 88b29f5

Browse files
committed
Test for misusing attribute
1 parent a79e08c commit 88b29f5

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ rustc_queries! {
11371137
}
11381138

11391139
query impl_constness(def_id: DefId) -> hir::Constness {
1140-
desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1140+
desc { |tcx| "looking up whether `{}` is a const impl", tcx.def_path_str(def_id) }
11411141
}
11421142

11431143
query check_item_well_formed(key: LocalDefId) -> () {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(const_trait_impl)]
2+
#![allow(incomplete_features)]
3+
4+
#[default_method_body_is_const] //~ ERROR attribute should be applied
5+
trait A {
6+
#[default_method_body_is_const] //~ ERROR attribute should be applied
7+
fn no_body(self);
8+
9+
#[default_method_body_is_const]
10+
fn correct_use(&self) {}
11+
}
12+
13+
#[default_method_body_is_const] //~ ERROR attribute should be applied
14+
fn main() {}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error: attribute should be applied to a trait method with body
2+
--> $DIR/attr-misuse.rs:4:1
3+
|
4+
LL | #[default_method_body_is_const]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
LL | / trait A {
7+
LL | | #[default_method_body_is_const]
8+
LL | | fn no_body(self);
9+
LL | |
10+
LL | | #[default_method_body_is_const]
11+
LL | | fn correct_use(&self) {}
12+
LL | | }
13+
| |_- not a trait method or missing a body
14+
15+
error: attribute should be applied to a trait method with body
16+
--> $DIR/attr-misuse.rs:13:1
17+
|
18+
LL | #[default_method_body_is_const]
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
LL | fn main() {}
21+
| ------------ not a trait method or missing a body
22+
23+
error: attribute should be applied to a trait method with body
24+
--> $DIR/attr-misuse.rs:6:5
25+
|
26+
LL | #[default_method_body_is_const]
27+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28+
LL | fn no_body(self);
29+
| ----------------- not a trait method or missing a body
30+
31+
error: aborting due to 3 previous errors
32+

0 commit comments

Comments
 (0)