diff options
| author | Georg Semmler <github@weiznich.de> | 2023-06-02 13:55:46 +0200 |
|---|---|---|
| committer | Georg Semmler <github@weiznich.de> | 2023-09-12 20:03:18 +0200 |
| commit | 5b8a7a09178f73a581db2b21cf516fea7be9b49f (patch) | |
| tree | 369b9a76b0f426403c66d007390830fb15208f89 /tests | |
| parent | e5fedceabf4e0564231db592b6d1f35e1ca27908 (diff) | |
| download | rust-5b8a7a09178f73a581db2b21cf516fea7be9b49f.tar.gz rust-5b8a7a09178f73a581db2b21cf516fea7be9b49f.zip | |
`#[diagnostic::on_unimplemented]` without filters
This commit adds support for a `#[diagnostic::on_unimplemented]` attribute with the following options: * `message` to customize the primary error message * `note` to add a customized note message to an error message * `label` to customize the label part of the error message Co-authored-by: León Orell Valerian Liehr <me@fmease.dev> Co-authored-by: Michael Goulet <michael@errs.io>
Diffstat (limited to 'tests')
9 files changed, 207 insertions, 6 deletions
diff --git a/tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.rs b/tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.rs index a686ed9c84e..b08e291621f 100644 --- a/tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.rs +++ b/tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.rs @@ -1,12 +1,12 @@ #[diagnostic::non_existing_attribute] //~^ERROR `#[diagnostic]` attribute name space is experimental [E0658] -//~|WARNING unknown diagnostic attribute [unknown_diagnostic_attributes] +//~|WARNING unknown diagnostic attribute [unknown_or_malformed_diagnostic_attributes] pub trait Bar { } #[diagnostic::non_existing_attribute(with_option = "foo")] //~^ERROR `#[diagnostic]` attribute name space is experimental [E0658] -//~|WARNING unknown diagnostic attribute [unknown_diagnostic_attributes] +//~|WARNING unknown diagnostic attribute [unknown_or_malformed_diagnostic_attributes] struct Foo; fn main() { diff --git a/tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.stderr b/tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.stderr index 45c95cbb3c7..017d00e2c8e 100644 --- a/tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.stderr +++ b/tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.stderr @@ -4,7 +4,7 @@ error[E0658]: `#[diagnostic]` attribute name space is experimental LL | #[diagnostic::non_existing_attribute] | ^^^^^^^^^^ | - = note: see issue #94785 <https://github.com/rust-lang/rust/issues/94785> for more information + = note: see issue #111996 <https://github.com/rust-lang/rust/issues/111996> for more information = help: add `#![feature(diagnostic_namespace)]` to the crate attributes to enable error[E0658]: `#[diagnostic]` attribute name space is experimental @@ -13,7 +13,7 @@ error[E0658]: `#[diagnostic]` attribute name space is experimental LL | #[diagnostic::non_existing_attribute(with_option = "foo")] | ^^^^^^^^^^ | - = note: see issue #94785 <https://github.com/rust-lang/rust/issues/94785> for more information + = note: see issue #111996 <https://github.com/rust-lang/rust/issues/111996> for more information = help: add `#![feature(diagnostic_namespace)]` to the crate attributes to enable warning: unknown diagnostic attribute @@ -22,7 +22,7 @@ warning: unknown diagnostic attribute LL | #[diagnostic::non_existing_attribute] | ^^^^^^^^^^^^^^^^^^^^^^ | - = note: `#[warn(unknown_diagnostic_attributes)]` on by default + = note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default warning: unknown diagnostic attribute --> $DIR/feature-gate-diagnostic_namespace.rs:7:15 diff --git a/tests/ui/diagnostic_namespace/non_existing_attributes_accepted.stderr b/tests/ui/diagnostic_namespace/non_existing_attributes_accepted.stderr index 4f9b7ba2bcf..753077b365e 100644 --- a/tests/ui/diagnostic_namespace/non_existing_attributes_accepted.stderr +++ b/tests/ui/diagnostic_namespace/non_existing_attributes_accepted.stderr @@ -4,7 +4,7 @@ warning: unknown diagnostic attribute LL | #[diagnostic::non_existing_attribute] | ^^^^^^^^^^^^^^^^^^^^^^ | - = note: `#[warn(unknown_diagnostic_attributes)]` on by default + = note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default warning: unknown diagnostic attribute --> $DIR/non_existing_attributes_accepted.rs:8:15 diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.rs b/tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.rs new file mode 100644 index 00000000000..00fb59d14d7 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.rs @@ -0,0 +1,37 @@ +#![feature(diagnostic_namespace)] + +#[diagnostic::on_unimplemented(unsupported = "foo")] +//~^WARN malformed `on_unimplemented` attribute +//~|WARN malformed `on_unimplemented` attribute +trait Foo {} + +#[diagnostic::on_unimplemented(message = "Baz")] +//~^WARN `#[diagnostic::on_unimplemented]` can only be applied to trait definitions +struct Bar {} + +#[diagnostic::on_unimplemented(message = "Boom", unsupported = "Bar")] +//~^WARN malformed `on_unimplemented` attribute +//~|WARN malformed `on_unimplemented` attribute +trait Baz {} + +#[diagnostic::on_unimplemented(message = "Boom", on(_Self = "i32", message = "whatever"))] +//~^WARN malformed `on_unimplemented` attribute +//~|WARN malformed `on_unimplemented` attribute +trait Boom {} + +#[diagnostic::on_unimplemented = "boom"] +//~^WARN malformed `on_unimplemented` attribute +trait Doom {} + +fn take_foo(_: impl Foo) {} +fn take_baz(_: impl Baz) {} +fn take_boom(_: impl Boom) {} + +fn main() { + take_foo(1_i32); + //~^ERROR the trait bound `i32: Foo` is not satisfied + take_baz(1_i32); + //~^ERROR Boom + take_boom(1_i32); + //~^ERROR Boom +} diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.stderr b/tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.stderr new file mode 100644 index 00000000000..bb1b29ef248 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.stderr @@ -0,0 +1,110 @@ +warning: `#[diagnostic::on_unimplemented]` can only be applied to trait definitions + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:8:1 + | +LL | #[diagnostic::on_unimplemented(message = "Baz")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default + +warning: malformed `on_unimplemented` attribute + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:3:32 + | +LL | #[diagnostic::on_unimplemented(unsupported = "foo")] + | ^^^^^^^^^^^^^^^^^^^ + +warning: malformed `on_unimplemented` attribute + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:12:50 + | +LL | #[diagnostic::on_unimplemented(message = "Boom", unsupported = "Bar")] + | ^^^^^^^^^^^^^^^^^^^ + +warning: malformed `on_unimplemented` attribute + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:17:50 + | +LL | #[diagnostic::on_unimplemented(message = "Boom", on(_Self = "i32", message = "whatever"))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: malformed `on_unimplemented` attribute + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:22:1 + | +LL | #[diagnostic::on_unimplemented = "boom"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: malformed `on_unimplemented` attribute + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:3:32 + | +LL | #[diagnostic::on_unimplemented(unsupported = "foo")] + | ^^^^^^^^^^^^^^^^^^^ + +error[E0277]: the trait bound `i32: Foo` is not satisfied + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:31:14 + | +LL | take_foo(1_i32); + | -------- ^^^^^ the trait `Foo` is not implemented for `i32` + | | + | required by a bound introduced by this call + | +help: this trait has no implementations, consider adding one + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:6:1 + | +LL | trait Foo {} + | ^^^^^^^^^ +note: required by a bound in `take_foo` + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:26:21 + | +LL | fn take_foo(_: impl Foo) {} + | ^^^ required by this bound in `take_foo` + +warning: malformed `on_unimplemented` attribute + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:12:50 + | +LL | #[diagnostic::on_unimplemented(message = "Boom", unsupported = "Bar")] + | ^^^^^^^^^^^^^^^^^^^ + +error[E0277]: Boom + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:33:14 + | +LL | take_baz(1_i32); + | -------- ^^^^^ the trait `Baz` is not implemented for `i32` + | | + | required by a bound introduced by this call + | +help: this trait has no implementations, consider adding one + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:15:1 + | +LL | trait Baz {} + | ^^^^^^^^^ +note: required by a bound in `take_baz` + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:27:21 + | +LL | fn take_baz(_: impl Baz) {} + | ^^^ required by this bound in `take_baz` + +warning: malformed `on_unimplemented` attribute + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:17:50 + | +LL | #[diagnostic::on_unimplemented(message = "Boom", on(_Self = "i32", message = "whatever"))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0277]: Boom + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:35:15 + | +LL | take_boom(1_i32); + | --------- ^^^^^ the trait `Boom` is not implemented for `i32` + | | + | required by a bound introduced by this call + | +help: this trait has no implementations, consider adding one + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:20:1 + | +LL | trait Boom {} + | ^^^^^^^^^^ +note: required by a bound in `take_boom` + --> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:28:22 + | +LL | fn take_boom(_: impl Boom) {} + | ^^^^ required by this bound in `take_boom` + +error: aborting due to 3 previous errors; 8 warnings emitted + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/feature-gate-diagnostic_on_unimplemented.rs b/tests/ui/diagnostic_namespace/on_unimplemented/feature-gate-diagnostic_on_unimplemented.rs new file mode 100644 index 00000000000..609a840c118 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/feature-gate-diagnostic_on_unimplemented.rs @@ -0,0 +1,7 @@ +#[diagnostic::on_unimplemented(message = "Foo")] +//~^ERROR `#[diagnostic]` attribute name space is experimental [E0658] +pub trait Bar { +} + +fn main() { +} diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/feature-gate-diagnostic_on_unimplemented.stderr b/tests/ui/diagnostic_namespace/on_unimplemented/feature-gate-diagnostic_on_unimplemented.stderr new file mode 100644 index 00000000000..21f02e3a73b --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/feature-gate-diagnostic_on_unimplemented.stderr @@ -0,0 +1,12 @@ +error[E0658]: `#[diagnostic]` attribute name space is experimental + --> $DIR/feature-gate-diagnostic_on_unimplemented.rs:1:3 + | +LL | #[diagnostic::on_unimplemented(message = "Foo")] + | ^^^^^^^^^^ + | + = note: see issue #111996 <https://github.com/rust-lang/rust/issues/111996> for more information + = help: add `#![feature(diagnostic_namespace)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/on_unimplemented_simple.rs b/tests/ui/diagnostic_namespace/on_unimplemented/on_unimplemented_simple.rs new file mode 100644 index 00000000000..797edbc9ec5 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/on_unimplemented_simple.rs @@ -0,0 +1,11 @@ +#![feature(diagnostic_namespace)] + +#[diagnostic::on_unimplemented(message = "Foo", label = "Bar", note = "Baz")] +trait Foo {} + +fn takes_foo(_: impl Foo) {} + +fn main() { + takes_foo(()); + //~^ERROR Foo +} diff --git a/tests/ui/diagnostic_namespace/on_unimplemented/on_unimplemented_simple.stderr b/tests/ui/diagnostic_namespace/on_unimplemented/on_unimplemented_simple.stderr new file mode 100644 index 00000000000..549c7caa720 --- /dev/null +++ b/tests/ui/diagnostic_namespace/on_unimplemented/on_unimplemented_simple.stderr @@ -0,0 +1,24 @@ +error[E0277]: Foo + --> $DIR/on_unimplemented_simple.rs:9:15 + | +LL | takes_foo(()); + | --------- ^^ Bar + | | + | required by a bound introduced by this call + | + = help: the trait `Foo` is not implemented for `()` + = note: Baz +help: this trait has no implementations, consider adding one + --> $DIR/on_unimplemented_simple.rs:4:1 + | +LL | trait Foo {} + | ^^^^^^^^^ +note: required by a bound in `takes_foo` + --> $DIR/on_unimplemented_simple.rs:6:22 + | +LL | fn takes_foo(_: impl Foo) {} + | ^^^ required by this bound in `takes_foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. |
