Add test for misused #[rustc_must_implement_one_of]

This commit is contained in:
Maybe Waffle 2022-01-03 16:42:13 +03:00
parent 5ab40c8f99
commit e6bc0ac6f3
2 changed files with 120 additions and 0 deletions

View file

@ -0,0 +1,38 @@
#![feature(rustc_attrs)]
#[rustc_must_implement_one_of(a, b)]
//~^ Method not found in this trait
//~| Method not found in this trait
trait Tr0 {}
#[rustc_must_implement_one_of(a, b)]
//~^ Method not found in this trait
trait Tr1 {
fn a() {}
}
#[rustc_must_implement_one_of(a)]
//~^ the `#[rustc_must_implement_one_of]` attribute must be used with at least 2 args
trait Tr2 {
fn a() {}
}
#[rustc_must_implement_one_of]
//~^ malformed `rustc_must_implement_one_of` attribute input
trait Tr3 {}
#[rustc_must_implement_one_of(A, B)]
trait Tr4 {
const A: u8 = 1; //~ Not a method
type B; //~ Not a method
}
#[rustc_must_implement_one_of(a, b)]
trait Tr5 {
fn a(); //~ This method doesn't have a default implementation
fn b(); //~ This method doesn't have a default implementation
}
fn main() {}

View file

@ -0,0 +1,82 @@
error: malformed `rustc_must_implement_one_of` attribute input
--> $DIR/rustc_must_implement_one_of_misuse.rs:20:1
|
LL | #[rustc_must_implement_one_of]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_must_implement_one_of(method1, method2, ...)]`
error: Method not found in this trait
--> $DIR/rustc_must_implement_one_of_misuse.rs:3:31
|
LL | #[rustc_must_implement_one_of(a, b)]
| ^
error: Method not found in this trait
--> $DIR/rustc_must_implement_one_of_misuse.rs:3:34
|
LL | #[rustc_must_implement_one_of(a, b)]
| ^
error: Method not found in this trait
--> $DIR/rustc_must_implement_one_of_misuse.rs:8:34
|
LL | #[rustc_must_implement_one_of(a, b)]
| ^
error: the `#[rustc_must_implement_one_of]` attribute must be used with at least 2 args
--> $DIR/rustc_must_implement_one_of_misuse.rs:14:1
|
LL | #[rustc_must_implement_one_of(a)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Not a method
--> $DIR/rustc_must_implement_one_of_misuse.rs:26:5
|
LL | const A: u8 = 1;
| ^^^^^^^^^^^^^^^^
|
note: required by this annotation
--> $DIR/rustc_must_implement_one_of_misuse.rs:24:1
|
LL | #[rustc_must_implement_one_of(A, B)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: All `#[rustc_must_implement_one_of]` arguments must be method identifiers
error: Not a method
--> $DIR/rustc_must_implement_one_of_misuse.rs:28:5
|
LL | type B;
| ^^^^^^^
|
note: required by this annotation
--> $DIR/rustc_must_implement_one_of_misuse.rs:24:1
|
LL | #[rustc_must_implement_one_of(A, B)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: All `#[rustc_must_implement_one_of]` arguments must be method identifiers
error: This method doesn't have a default implementation
--> $DIR/rustc_must_implement_one_of_misuse.rs:33:5
|
LL | fn a();
| ^^^^^^^
|
note: required by this annotation
--> $DIR/rustc_must_implement_one_of_misuse.rs:31:1
|
LL | #[rustc_must_implement_one_of(a, b)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: This method doesn't have a default implementation
--> $DIR/rustc_must_implement_one_of_misuse.rs:35:5
|
LL | fn b();
| ^^^^^^^
|
note: required by this annotation
--> $DIR/rustc_must_implement_one_of_misuse.rs:31:1
|
LL | #[rustc_must_implement_one_of(a, b)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 9 previous errors