From e6bc0ac6f365cca5aaec5cf7fe8d6adb15e973a7 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 3 Jan 2022 16:42:13 +0300 Subject: [PATCH] Add test for misused `#[rustc_must_implement_one_of]` --- .../ui/rustc_must_implement_one_of_misuse.rs | 38 +++++++++ .../rustc_must_implement_one_of_misuse.stderr | 82 +++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 src/test/ui/rustc_must_implement_one_of_misuse.rs create mode 100644 src/test/ui/rustc_must_implement_one_of_misuse.stderr diff --git a/src/test/ui/rustc_must_implement_one_of_misuse.rs b/src/test/ui/rustc_must_implement_one_of_misuse.rs new file mode 100644 index 000000000000..161e94273f8c --- /dev/null +++ b/src/test/ui/rustc_must_implement_one_of_misuse.rs @@ -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() {} diff --git a/src/test/ui/rustc_must_implement_one_of_misuse.stderr b/src/test/ui/rustc_must_implement_one_of_misuse.stderr new file mode 100644 index 000000000000..b5428cf33102 --- /dev/null +++ b/src/test/ui/rustc_must_implement_one_of_misuse.stderr @@ -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 +