about summary refs log tree commit diff
diff options
context:
space:
mode:
authormejrs <59372212+mejrs@users.noreply.github.com>2025-04-22 00:19:49 +0200
committermejrs <59372212+mejrs@users.noreply.github.com>2025-04-22 00:19:49 +0200
commitd2d844c65dd120a9f3cab15d7519499fcc4130a0 (patch)
tree8fbca8f44174413735182be0fa80b106e1079fb5
parent49e5e4e3a5610c240a717cb99003a5d5d3356679 (diff)
downloadrust-d2d844c65dd120a9f3cab15d7519499fcc4130a0.tar.gz
rust-d2d844c65dd120a9f3cab15d7519499fcc4130a0.zip
Improve rustc_on_unimplemented ui test
-rw-r--r--tests/ui/on-unimplemented/bad-annotation.rs69
-rw-r--r--tests/ui/on-unimplemented/bad-annotation.stderr70
2 files changed, 86 insertions, 53 deletions
diff --git a/tests/ui/on-unimplemented/bad-annotation.rs b/tests/ui/on-unimplemented/bad-annotation.rs
index f2b97865759..32b825ee3cc 100644
--- a/tests/ui/on-unimplemented/bad-annotation.rs
+++ b/tests/ui/on-unimplemented/bad-annotation.rs
@@ -1,64 +1,73 @@
-// ignore-tidy-linelength
-
+#![crate_type = "lib"]
 #![feature(rustc_attrs)]
-
 #![allow(unused)]
 
 #[rustc_on_unimplemented = "test error `{Self}` with `{Bar}` `{Baz}` `{Quux}`"]
-trait Foo<Bar, Baz, Quux>
-{}
+trait Foo<Bar, Baz, Quux> {}
 
-#[rustc_on_unimplemented="a collection of type `{Self}` cannot be built from an iterator over elements of type `{A}`"]
+#[rustc_on_unimplemented = "a collection of type `{Self}` cannot \
+ be built from an iterator over elements of type `{A}`"]
 trait MyFromIterator<A> {
     /// Builds a container with elements from an external iterator.
-    fn my_from_iter<T: Iterator<Item=A>>(iterator: T) -> Self;
+    fn my_from_iter<T: Iterator<Item = A>>(iterator: T) -> Self;
 }
 
 #[rustc_on_unimplemented]
 //~^ ERROR malformed `rustc_on_unimplemented` attribute
-trait BadAnnotation1
-{}
+trait NoContent {}
 
 #[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{C}>`"]
 //~^ ERROR cannot find parameter C on this trait
-trait BadAnnotation2<A,B>
-{}
+trait ParameterNotPresent<A, B> {}
 
 #[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{}>`"]
 //~^ ERROR positional format arguments are not allowed here
-trait BadAnnotation3<A,B>
-{}
+trait NoPositionalArgs<A, B> {}
 
-#[rustc_on_unimplemented(lorem="")]
+#[rustc_on_unimplemented(lorem = "")]
 //~^ ERROR this attribute must have a valid
-trait BadAnnotation4 {}
+trait EmptyMessage {}
 
 #[rustc_on_unimplemented(lorem(ipsum(dolor)))]
 //~^ ERROR this attribute must have a valid
-trait BadAnnotation5 {}
+trait Invalid {}
 
-#[rustc_on_unimplemented(message="x", message="y")]
+#[rustc_on_unimplemented(message = "x", message = "y")]
 //~^ ERROR this attribute must have a valid
-trait BadAnnotation6 {}
+trait DuplicateMessage {}
 
-#[rustc_on_unimplemented(message="x", on(desugared, message="y"))]
+#[rustc_on_unimplemented(message = "x", on(desugared, message = "y"))]
 //~^ ERROR this attribute must have a valid
-trait BadAnnotation7 {}
+trait OnInWrongPosition {}
 
-#[rustc_on_unimplemented(on(), message="y")]
+#[rustc_on_unimplemented(on(), message = "y")]
 //~^ ERROR empty `on`-clause
-trait BadAnnotation8 {}
+trait NoEmptyOn {}
 
-#[rustc_on_unimplemented(on="x", message="y")]
+#[rustc_on_unimplemented(on = "x", message = "y")]
 //~^ ERROR this attribute must have a valid
-trait BadAnnotation9 {}
+trait ExpectedPredicateInOn {}
 
-#[rustc_on_unimplemented(on(x="y"), message="y")]
-trait BadAnnotation10 {}
+#[rustc_on_unimplemented(on(x = "y"), message = "y")]
+trait OnWithoutDirectives {}
 
-#[rustc_on_unimplemented(on(desugared, on(desugared, message="x")), message="y")]
+#[rustc_on_unimplemented(on(desugared, on(desugared, message = "x")), message = "y")]
 //~^ ERROR this attribute must have a valid
-trait BadAnnotation11 {}
+trait NoNestedOn {}
 
-pub fn main() {
-}
+// caught by `OnUnimplementedDirective::parse`, *not* `eval_condition`
+#[rustc_on_unimplemented(on("y", message = "y"))]
+//~^ ERROR invalid `on`-clause
+trait UnsupportedLiteral {}
+
+#[rustc_on_unimplemented(on(not(a, b), message = "y"))]
+//~^ ERROR expected 1 cfg-pattern
+trait ExpectedOnePattern {}
+
+#[rustc_on_unimplemented(on(thing::What, message = "y"))]
+//~^ ERROR `cfg` predicate key must be an identifier
+trait KeyMustBeIdentifier {}
+
+#[rustc_on_unimplemented(on(thing::What = "value", message = "y"))]
+//~^ ERROR `cfg` predicate key must be an identifier
+trait KeyMustBeIdentifier2 {}
diff --git a/tests/ui/on-unimplemented/bad-annotation.stderr b/tests/ui/on-unimplemented/bad-annotation.stderr
index afd737dc85e..817d3c42cf6 100644
--- a/tests/ui/on-unimplemented/bad-annotation.stderr
+++ b/tests/ui/on-unimplemented/bad-annotation.stderr
@@ -1,5 +1,5 @@
 error: malformed `rustc_on_unimplemented` attribute input
-  --> $DIR/bad-annotation.rs:17:1
+  --> $DIR/bad-annotation.rs:15:1
    |
 LL | #[rustc_on_unimplemented]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -12,27 +12,27 @@ LL | #[rustc_on_unimplemented(/*opt*/ message = "...", /*opt*/ label = "...", /*
    |                         ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
 error[E0230]: cannot find parameter C on this trait
-  --> $DIR/bad-annotation.rs:22:90
+  --> $DIR/bad-annotation.rs:19:90
    |
 LL | #[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{C}>`"]
    |                                                                                          ^
 
 error[E0231]: positional format arguments are not allowed here
-  --> $DIR/bad-annotation.rs:27:90
+  --> $DIR/bad-annotation.rs:23:90
    |
 LL | #[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{}>`"]
    |                                                                                          ^
 
 error[E0232]: this attribute must have a valid value
-  --> $DIR/bad-annotation.rs:32:26
+  --> $DIR/bad-annotation.rs:27:26
    |
-LL | #[rustc_on_unimplemented(lorem="")]
-   |                          ^^^^^^^^ expected value here
+LL | #[rustc_on_unimplemented(lorem = "")]
+   |                          ^^^^^^^^^^ expected value here
    |
    = note: eg `#[rustc_on_unimplemented(message="foo")]`
 
 error[E0232]: this attribute must have a valid value
-  --> $DIR/bad-annotation.rs:36:26
+  --> $DIR/bad-annotation.rs:31:26
    |
 LL | #[rustc_on_unimplemented(lorem(ipsum(dolor)))]
    |                          ^^^^^^^^^^^^^^^^^^^ expected value here
@@ -40,44 +40,68 @@ LL | #[rustc_on_unimplemented(lorem(ipsum(dolor)))]
    = note: eg `#[rustc_on_unimplemented(message="foo")]`
 
 error[E0232]: this attribute must have a valid value
-  --> $DIR/bad-annotation.rs:40:39
+  --> $DIR/bad-annotation.rs:35:41
    |
-LL | #[rustc_on_unimplemented(message="x", message="y")]
-   |                                       ^^^^^^^^^^^ expected value here
+LL | #[rustc_on_unimplemented(message = "x", message = "y")]
+   |                                         ^^^^^^^^^^^^^ expected value here
    |
    = note: eg `#[rustc_on_unimplemented(message="foo")]`
 
 error[E0232]: this attribute must have a valid value
-  --> $DIR/bad-annotation.rs:44:39
+  --> $DIR/bad-annotation.rs:39:41
    |
-LL | #[rustc_on_unimplemented(message="x", on(desugared, message="y"))]
-   |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected value here
+LL | #[rustc_on_unimplemented(message = "x", on(desugared, message = "y"))]
+   |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected value here
    |
    = note: eg `#[rustc_on_unimplemented(message="foo")]`
 
 error[E0232]: empty `on`-clause in `#[rustc_on_unimplemented]`
-  --> $DIR/bad-annotation.rs:48:26
+  --> $DIR/bad-annotation.rs:43:26
    |
-LL | #[rustc_on_unimplemented(on(), message="y")]
+LL | #[rustc_on_unimplemented(on(), message = "y")]
    |                          ^^^^ empty on-clause here
 
 error[E0232]: this attribute must have a valid value
-  --> $DIR/bad-annotation.rs:52:26
+  --> $DIR/bad-annotation.rs:47:26
    |
-LL | #[rustc_on_unimplemented(on="x", message="y")]
-   |                          ^^^^^^ expected value here
+LL | #[rustc_on_unimplemented(on = "x", message = "y")]
+   |                          ^^^^^^^^ expected value here
    |
    = note: eg `#[rustc_on_unimplemented(message="foo")]`
 
 error[E0232]: this attribute must have a valid value
-  --> $DIR/bad-annotation.rs:59:40
+  --> $DIR/bad-annotation.rs:54:40
    |
-LL | #[rustc_on_unimplemented(on(desugared, on(desugared, message="x")), message="y")]
-   |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected value here
+LL | #[rustc_on_unimplemented(on(desugared, on(desugared, message = "x")), message = "y")]
+   |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected value here
    |
    = note: eg `#[rustc_on_unimplemented(message="foo")]`
 
-error: aborting due to 10 previous errors
+error[E0232]: invalid `on`-clause in `#[rustc_on_unimplemented]`
+  --> $DIR/bad-annotation.rs:59:26
+   |
+LL | #[rustc_on_unimplemented(on("y", message = "y"))]
+   |                          ^^^^^^^^^^^^^^^^^^^^^^ invalid on-clause here
+
+error[E0536]: expected 1 cfg-pattern
+  --> $DIR/bad-annotation.rs:63:29
+   |
+LL | #[rustc_on_unimplemented(on(not(a, b), message = "y"))]
+   |                             ^^^^^^^^^
+
+error: `cfg` predicate key must be an identifier
+  --> $DIR/bad-annotation.rs:67:29
+   |
+LL | #[rustc_on_unimplemented(on(thing::What, message = "y"))]
+   |                             ^^^^^^^^^^^
+
+error: `cfg` predicate key must be an identifier
+  --> $DIR/bad-annotation.rs:71:29
+   |
+LL | #[rustc_on_unimplemented(on(thing::What = "value", message = "y"))]
+   |                             ^^^^^^^^^^^
+
+error: aborting due to 14 previous errors
 
-Some errors have detailed explanations: E0230, E0231, E0232.
+Some errors have detailed explanations: E0230, E0231, E0232, E0536.
 For more information about an error, try `rustc --explain E0230`.