Skip to content

Commit e6bc0ac

Browse files
committed
Add test for misused #[rustc_must_implement_one_of]
1 parent 5ab40c8 commit e6bc0ac

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#![feature(rustc_attrs)]
2+
3+
#[rustc_must_implement_one_of(a, b)]
4+
//~^ Method not found in this trait
5+
//~| Method not found in this trait
6+
trait Tr0 {}
7+
8+
#[rustc_must_implement_one_of(a, b)]
9+
//~^ Method not found in this trait
10+
trait Tr1 {
11+
fn a() {}
12+
}
13+
14+
#[rustc_must_implement_one_of(a)]
15+
//~^ the `#[rustc_must_implement_one_of]` attribute must be used with at least 2 args
16+
trait Tr2 {
17+
fn a() {}
18+
}
19+
20+
#[rustc_must_implement_one_of]
21+
//~^ malformed `rustc_must_implement_one_of` attribute input
22+
trait Tr3 {}
23+
24+
#[rustc_must_implement_one_of(A, B)]
25+
trait Tr4 {
26+
const A: u8 = 1; //~ Not a method
27+
28+
type B; //~ Not a method
29+
}
30+
31+
#[rustc_must_implement_one_of(a, b)]
32+
trait Tr5 {
33+
fn a(); //~ This method doesn't have a default implementation
34+
35+
fn b(); //~ This method doesn't have a default implementation
36+
}
37+
38+
fn main() {}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
error: malformed `rustc_must_implement_one_of` attribute input
2+
--> $DIR/rustc_must_implement_one_of_misuse.rs:20:1
3+
|
4+
LL | #[rustc_must_implement_one_of]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_must_implement_one_of(method1, method2, ...)]`
6+
7+
error: Method not found in this trait
8+
--> $DIR/rustc_must_implement_one_of_misuse.rs:3:31
9+
|
10+
LL | #[rustc_must_implement_one_of(a, b)]
11+
| ^
12+
13+
error: Method not found in this trait
14+
--> $DIR/rustc_must_implement_one_of_misuse.rs:3:34
15+
|
16+
LL | #[rustc_must_implement_one_of(a, b)]
17+
| ^
18+
19+
error: Method not found in this trait
20+
--> $DIR/rustc_must_implement_one_of_misuse.rs:8:34
21+
|
22+
LL | #[rustc_must_implement_one_of(a, b)]
23+
| ^
24+
25+
error: the `#[rustc_must_implement_one_of]` attribute must be used with at least 2 args
26+
--> $DIR/rustc_must_implement_one_of_misuse.rs:14:1
27+
|
28+
LL | #[rustc_must_implement_one_of(a)]
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
31+
error: Not a method
32+
--> $DIR/rustc_must_implement_one_of_misuse.rs:26:5
33+
|
34+
LL | const A: u8 = 1;
35+
| ^^^^^^^^^^^^^^^^
36+
|
37+
note: required by this annotation
38+
--> $DIR/rustc_must_implement_one_of_misuse.rs:24:1
39+
|
40+
LL | #[rustc_must_implement_one_of(A, B)]
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42+
= note: All `#[rustc_must_implement_one_of]` arguments must be method identifiers
43+
44+
error: Not a method
45+
--> $DIR/rustc_must_implement_one_of_misuse.rs:28:5
46+
|
47+
LL | type B;
48+
| ^^^^^^^
49+
|
50+
note: required by this annotation
51+
--> $DIR/rustc_must_implement_one_of_misuse.rs:24:1
52+
|
53+
LL | #[rustc_must_implement_one_of(A, B)]
54+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55+
= note: All `#[rustc_must_implement_one_of]` arguments must be method identifiers
56+
57+
error: This method doesn't have a default implementation
58+
--> $DIR/rustc_must_implement_one_of_misuse.rs:33:5
59+
|
60+
LL | fn a();
61+
| ^^^^^^^
62+
|
63+
note: required by this annotation
64+
--> $DIR/rustc_must_implement_one_of_misuse.rs:31:1
65+
|
66+
LL | #[rustc_must_implement_one_of(a, b)]
67+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
68+
69+
error: This method doesn't have a default implementation
70+
--> $DIR/rustc_must_implement_one_of_misuse.rs:35:5
71+
|
72+
LL | fn b();
73+
| ^^^^^^^
74+
|
75+
note: required by this annotation
76+
--> $DIR/rustc_must_implement_one_of_misuse.rs:31:1
77+
|
78+
LL | #[rustc_must_implement_one_of(a, b)]
79+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
80+
81+
error: aborting due to 9 previous errors
82+

0 commit comments

Comments
 (0)