about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-06-29 12:29:55 +0200
committerGitHub <noreply@github.com>2025-06-29 12:29:55 +0200
commit05b209d3a2f398c834cd9ecbe5eb095a49c26f02 (patch)
tree35511853255aa5c37e6eb5f253bc7fd11b8d814f /tests
parent15b227f71532fffcab7663ffc1b2711e955a02de (diff)
parentaac948b702737e8ead5e800bd9f5dd03b5b6b534 (diff)
downloadrust-05b209d3a2f398c834cd9ecbe5eb095a49c26f02.tar.gz
rust-05b209d3a2f398c834cd9ecbe5eb095a49c26f02.zip
Rollup merge of #142417 - Kivooeo:tf12, r=jieyouxu
`tests/ui`: A New Order [12/N]

Some `tests/ui/` housekeeping, to trim down number of tests directly under `tests/ui/`. Part of rust-lang/rust#133895.

r? `@jieyouxu`
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/associated-types/unconstrained-lifetime-assoc-type.rs21
-rw-r--r--tests/ui/associated-types/unconstrained-lifetime-assoc-type.stderr (renamed from tests/ui/impl-unused-rps-in-assoc-type.stderr)2
-rw-r--r--tests/ui/attributes/inline-attribute-enum-variant-error.rs (renamed from tests/ui/inline-disallow-on-variant.rs)2
-rw-r--r--tests/ui/attributes/inline-attribute-enum-variant-error.stderr (renamed from tests/ui/inline-disallow-on-variant.stderr)2
-rw-r--r--tests/ui/attributes/inline-main.rs6
-rw-r--r--tests/ui/generics/unconstrained-type-params-inherent-impl.rs32
-rw-r--r--tests/ui/generics/unconstrained-type-params-inherent-impl.stderr (renamed from tests/ui/impl-unused-tps-inherent.stderr)8
-rw-r--r--tests/ui/impl-unused-rps-in-assoc-type.rs18
-rw-r--r--tests/ui/impl-unused-tps-inherent.rs25
-rw-r--r--tests/ui/implicit-method-bind.rs3
-rw-r--r--tests/ui/implicit-method-bind.stderr14
-rw-r--r--tests/ui/inlined-main.rs4
-rw-r--r--tests/ui/methods/method-missing-call.rs30
-rw-r--r--tests/ui/methods/method-missing-call.stderr25
-rw-r--r--tests/ui/methods/method-value-without-call.rs33
-rw-r--r--tests/ui/methods/method-value-without-call.stderr36
-rw-r--r--tests/ui/traits/constrained-type-params-trait-impl.rs (renamed from tests/ui/impl-unused-tps.rs)28
-rw-r--r--tests/ui/traits/constrained-type-params-trait-impl.stderr (renamed from tests/ui/impl-unused-tps.stderr)18
18 files changed, 162 insertions, 145 deletions
diff --git a/tests/ui/associated-types/unconstrained-lifetime-assoc-type.rs b/tests/ui/associated-types/unconstrained-lifetime-assoc-type.rs
new file mode 100644
index 00000000000..2c4af7da921
--- /dev/null
+++ b/tests/ui/associated-types/unconstrained-lifetime-assoc-type.rs
@@ -0,0 +1,21 @@
+//! Regression test for issue #22077
+//! lifetime parameters must be constrained in associated type definitions
+
+trait Fun {
+    type Output;
+    fn call<'x>(&'x self) -> Self::Output;
+}
+
+struct Holder {
+    x: String,
+}
+
+impl<'a> Fun for Holder {
+    //~^ ERROR E0207
+    type Output = &'a str;
+    fn call<'b>(&'b self) -> &'b str {
+        &self.x[..]
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/impl-unused-rps-in-assoc-type.stderr b/tests/ui/associated-types/unconstrained-lifetime-assoc-type.stderr
index ef61fa4be48..15d0820c895 100644
--- a/tests/ui/impl-unused-rps-in-assoc-type.stderr
+++ b/tests/ui/associated-types/unconstrained-lifetime-assoc-type.stderr
@@ -1,5 +1,5 @@
 error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
-  --> $DIR/impl-unused-rps-in-assoc-type.rs:11:6
+  --> $DIR/unconstrained-lifetime-assoc-type.rs:13:6
    |
 LL | impl<'a> Fun for Holder {
    |      ^^ unconstrained lifetime parameter
diff --git a/tests/ui/inline-disallow-on-variant.rs b/tests/ui/attributes/inline-attribute-enum-variant-error.rs
index d92a4e8cc8d..305b285d2a4 100644
--- a/tests/ui/inline-disallow-on-variant.rs
+++ b/tests/ui/attributes/inline-attribute-enum-variant-error.rs
@@ -1,3 +1,5 @@
+//! Test that #[inline] attribute cannot be applied to enum variants
+
 enum Foo {
     #[inline]
     //~^ ERROR attribute should be applied
diff --git a/tests/ui/inline-disallow-on-variant.stderr b/tests/ui/attributes/inline-attribute-enum-variant-error.stderr
index 255f6bc6a19..a4564d8f722 100644
--- a/tests/ui/inline-disallow-on-variant.stderr
+++ b/tests/ui/attributes/inline-attribute-enum-variant-error.stderr
@@ -1,5 +1,5 @@
 error[E0518]: attribute should be applied to function or closure
-  --> $DIR/inline-disallow-on-variant.rs:2:5
+  --> $DIR/inline-attribute-enum-variant-error.rs:4:5
    |
 LL |     #[inline]
    |     ^^^^^^^^^
diff --git a/tests/ui/attributes/inline-main.rs b/tests/ui/attributes/inline-main.rs
new file mode 100644
index 00000000000..7181ee19b67
--- /dev/null
+++ b/tests/ui/attributes/inline-main.rs
@@ -0,0 +1,6 @@
+//! Test that #[inline(always)] can be applied to main function
+
+//@ run-pass
+
+#[inline(always)]
+fn main() {}
diff --git a/tests/ui/generics/unconstrained-type-params-inherent-impl.rs b/tests/ui/generics/unconstrained-type-params-inherent-impl.rs
new file mode 100644
index 00000000000..c971de0d1f2
--- /dev/null
+++ b/tests/ui/generics/unconstrained-type-params-inherent-impl.rs
@@ -0,0 +1,32 @@
+//! Test for unconstrained type parameters in inherent implementations
+
+struct MyType;
+
+struct MyType1<T>(T);
+
+trait Bar {
+    type Out;
+}
+
+impl<T> MyType {
+    //~^ ERROR the type parameter `T` is not constrained
+    // T is completely unused - this should fail
+}
+
+impl<T> MyType1<T> {
+    // OK: T is used in the self type `MyType1<T>`
+}
+
+impl<T, U> MyType1<T> {
+    //~^ ERROR the type parameter `U` is not constrained
+    // T is used in self type, but U is unconstrained - this should fail
+}
+
+impl<T, U> MyType1<T>
+where
+    T: Bar<Out = U>,
+{
+    // OK: T is used in self type, U is constrained through the where clause
+}
+
+fn main() {}
diff --git a/tests/ui/impl-unused-tps-inherent.stderr b/tests/ui/generics/unconstrained-type-params-inherent-impl.stderr
index 43f63cf968c..19b02ad396c 100644
--- a/tests/ui/impl-unused-tps-inherent.stderr
+++ b/tests/ui/generics/unconstrained-type-params-inherent-impl.stderr
@@ -1,14 +1,14 @@
 error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
-  --> $DIR/impl-unused-tps-inherent.rs:9:6
+  --> $DIR/unconstrained-type-params-inherent-impl.rs:11:6
    |
 LL | impl<T> MyType {
    |      ^ unconstrained type parameter
 
 error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
-  --> $DIR/impl-unused-tps-inherent.rs:17:8
+  --> $DIR/unconstrained-type-params-inherent-impl.rs:20:9
    |
-LL | impl<T,U> MyType1<T> {
-   |        ^ unconstrained type parameter
+LL | impl<T, U> MyType1<T> {
+   |         ^ unconstrained type parameter
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/impl-unused-rps-in-assoc-type.rs b/tests/ui/impl-unused-rps-in-assoc-type.rs
deleted file mode 100644
index ea41997a698..00000000000
--- a/tests/ui/impl-unused-rps-in-assoc-type.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-// Test that lifetime parameters must be constrained if they appear in
-// an associated type def'n. Issue #22077.
-
-trait Fun {
-    type Output;
-    fn call<'x>(&'x self) -> Self::Output;
-}
-
-struct Holder { x: String }
-
-impl<'a> Fun for Holder { //~ ERROR E0207
-    type Output = &'a str;
-    fn call<'b>(&'b self) -> &'b str {
-        &self.x[..]
-    }
-}
-
-fn main() { }
diff --git a/tests/ui/impl-unused-tps-inherent.rs b/tests/ui/impl-unused-tps-inherent.rs
deleted file mode 100644
index 83a228e551a..00000000000
--- a/tests/ui/impl-unused-tps-inherent.rs
+++ /dev/null
@@ -1,25 +0,0 @@
-struct MyType;
-
-struct MyType1<T>(T);
-
-trait Bar {
-    type Out;
-}
-
-impl<T> MyType {
-    //~^ ERROR  the type parameter `T` is not constrained
-}
-
-impl<T> MyType1<T> {
-    // OK, T is used in `Foo<T>`.
-}
-
-impl<T,U> MyType1<T> {
-    //~^ ERROR  the type parameter `U` is not constrained
-}
-
-impl<T,U> MyType1<T> where T: Bar<Out=U> {
-    // OK, T is used in `Foo<T>`.
-}
-
-fn main() { }
diff --git a/tests/ui/implicit-method-bind.rs b/tests/ui/implicit-method-bind.rs
deleted file mode 100644
index 5e27516a89a..00000000000
--- a/tests/ui/implicit-method-bind.rs
+++ /dev/null
@@ -1,3 +0,0 @@
-fn main() {
-    let _f = 10i32.abs; //~ ERROR attempted to take value of method
-}
diff --git a/tests/ui/implicit-method-bind.stderr b/tests/ui/implicit-method-bind.stderr
deleted file mode 100644
index e9357113f36..00000000000
--- a/tests/ui/implicit-method-bind.stderr
+++ /dev/null
@@ -1,14 +0,0 @@
-error[E0615]: attempted to take value of method `abs` on type `i32`
-  --> $DIR/implicit-method-bind.rs:2:20
-   |
-LL |     let _f = 10i32.abs;
-   |                    ^^^ method, not a field
-   |
-help: use parentheses to call the method
-   |
-LL |     let _f = 10i32.abs();
-   |                       ++
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0615`.
diff --git a/tests/ui/inlined-main.rs b/tests/ui/inlined-main.rs
deleted file mode 100644
index 731ac0dddca..00000000000
--- a/tests/ui/inlined-main.rs
+++ /dev/null
@@ -1,4 +0,0 @@
-//@ run-pass
-
-#[inline(always)]
-fn main() {}
diff --git a/tests/ui/methods/method-missing-call.rs b/tests/ui/methods/method-missing-call.rs
deleted file mode 100644
index 7ce1e9a4f1b..00000000000
--- a/tests/ui/methods/method-missing-call.rs
+++ /dev/null
@@ -1,30 +0,0 @@
-// Tests to make sure that parens are needed for method calls without arguments.
-// outputs text to make sure either an anonymous function is provided or
-// open-close '()' parens are given
-
-
-struct Point {
-    x: isize,
-    y: isize
-}
-impl Point {
-    fn new() -> Point {
-        Point{x:0, y:0}
-    }
-    fn get_x(&self) -> isize {
-        self.x
-    }
-}
-
-fn main() {
-    let point: Point = Point::new();
-    let px: isize =  point
-                        .get_x;//~ ERROR attempted to take value of method `get_x` on type `Point`
-
-    // Ensure the span is useful
-    let ys = &[1,2,3,4,5,6,7];
-    let a = ys.iter()
-              .map(|x| x)
-              .filter(|&&x| x == 1)
-              .filter_map; //~ ERROR attempted to take value of method `filter_map` on type
-}
diff --git a/tests/ui/methods/method-missing-call.stderr b/tests/ui/methods/method-missing-call.stderr
deleted file mode 100644
index bc508461b69..00000000000
--- a/tests/ui/methods/method-missing-call.stderr
+++ /dev/null
@@ -1,25 +0,0 @@
-error[E0615]: attempted to take value of method `get_x` on type `Point`
-  --> $DIR/method-missing-call.rs:22:26
-   |
-LL |                         .get_x;
-   |                          ^^^^^ method, not a field
-   |
-help: use parentheses to call the method
-   |
-LL |                         .get_x();
-   |                               ++
-
-error[E0615]: attempted to take value of method `filter_map` on type `Filter<Map<std::slice::Iter<'_, {integer}>, {closure@$DIR/method-missing-call.rs:27:20: 27:23}>, {closure@$DIR/method-missing-call.rs:28:23: 28:28}>`
-  --> $DIR/method-missing-call.rs:29:16
-   |
-LL |               .filter_map;
-   |                ^^^^^^^^^^ method, not a field
-   |
-help: use parentheses to call the method
-   |
-LL |               .filter_map(_);
-   |                          +++
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0615`.
diff --git a/tests/ui/methods/method-value-without-call.rs b/tests/ui/methods/method-value-without-call.rs
new file mode 100644
index 00000000000..43bee4864b4
--- /dev/null
+++ b/tests/ui/methods/method-value-without-call.rs
@@ -0,0 +1,33 @@
+//! Test taking a method value without parentheses
+
+struct Point {
+    x: isize,
+    y: isize,
+}
+
+impl Point {
+    fn new() -> Point {
+        Point { x: 0, y: 0 }
+    }
+
+    fn get_x(&self) -> isize {
+        self.x
+    }
+}
+
+fn main() {
+    // Test with primitive type method
+    let _f = 10i32.abs; //~ ERROR attempted to take value of method
+
+    // Test with custom type method
+    let point: Point = Point::new();
+    let px: isize = point.get_x; //~ ERROR attempted to take value of method `get_x` on type `Point`
+
+    // Test with method chains - ensure the span is useful
+    let ys = &[1, 2, 3, 4, 5, 6, 7];
+    let a = ys
+        .iter()
+        .map(|x| x)
+        .filter(|&&x| x == 1)
+        .filter_map; //~ ERROR attempted to take value of method `filter_map` on type
+}
diff --git a/tests/ui/methods/method-value-without-call.stderr b/tests/ui/methods/method-value-without-call.stderr
new file mode 100644
index 00000000000..0c3870e2868
--- /dev/null
+++ b/tests/ui/methods/method-value-without-call.stderr
@@ -0,0 +1,36 @@
+error[E0615]: attempted to take value of method `abs` on type `i32`
+  --> $DIR/method-value-without-call.rs:20:20
+   |
+LL |     let _f = 10i32.abs;
+   |                    ^^^ method, not a field
+   |
+help: use parentheses to call the method
+   |
+LL |     let _f = 10i32.abs();
+   |                       ++
+
+error[E0615]: attempted to take value of method `get_x` on type `Point`
+  --> $DIR/method-value-without-call.rs:24:27
+   |
+LL |     let px: isize = point.get_x;
+   |                           ^^^^^ method, not a field
+   |
+help: use parentheses to call the method
+   |
+LL |     let px: isize = point.get_x();
+   |                                ++
+
+error[E0615]: attempted to take value of method `filter_map` on type `Filter<Map<std::slice::Iter<'_, {integer}>, {closure@$DIR/method-value-without-call.rs:30:14: 30:17}>, {closure@$DIR/method-value-without-call.rs:31:17: 31:22}>`
+  --> $DIR/method-value-without-call.rs:32:10
+   |
+LL |         .filter_map;
+   |          ^^^^^^^^^^ method, not a field
+   |
+help: use parentheses to call the method
+   |
+LL |         .filter_map(_);
+   |                    +++
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0615`.
diff --git a/tests/ui/impl-unused-tps.rs b/tests/ui/traits/constrained-type-params-trait-impl.rs
index a5836db3c8e..301bbdb2ccb 100644
--- a/tests/ui/impl-unused-tps.rs
+++ b/tests/ui/traits/constrained-type-params-trait-impl.rs
@@ -1,3 +1,11 @@
+//! Comprehensive test for type parameter constraints in trait implementations
+//!
+//! This tests various scenarios of type parameter usage in trait implementations:
+//! - Properly constrained parameters through trait bounds
+//! - Unconstrained parameters that should cause compilation errors
+//! - Complex constraint scenarios with `where` clauses and associated types
+//! - Conflicting implementations detection
+
 trait Foo<A> {
     fn get(&self, A: &A) {}
 }
@@ -7,34 +15,34 @@ trait Bar {
 }
 
 impl<T> Foo<T> for [isize; 0] {
-    // OK, T is used in `Foo<T>`.
+    // OK: T is used in the trait bound `Foo<T>`
 }
 
 impl<T, U> Foo<T> for [isize; 1] {
     //~^ ERROR the type parameter `U` is not constrained
+    // T is constrained by `Foo<T>`, but U is completely unused
 }
 
 impl<T, U> Foo<T> for [isize; 2]
 where
     T: Bar<Out = U>,
 {
-    // OK, `U` is now constrained by the output type parameter.
+    // OK: T is constrained by `Foo<T>`, U is constrained by the where clause
 }
 
 impl<T: Bar<Out = U>, U> Foo<T> for [isize; 3] {
-    // OK, same as above but written differently.
+    // OK: Same as above but using bound syntax instead of where clause
 }
 
 impl<T, U> Foo<T> for U {
     //~^ ERROR conflicting implementations of trait `Foo<_>` for type `[isize; 0]`
+    // This conflicts with the first impl when U = [isize; 0]
 }
 
 impl<T, U> Bar for T {
     //~^ ERROR the type parameter `U` is not constrained
-
     type Out = U;
-
-    // Using `U` in an associated type within the impl is not good enough!
+    // Using U only in associated type definition is insufficient for constraint
 }
 
 impl<T, U> Bar for T
@@ -43,7 +51,7 @@ where
 {
     //~^^^^ ERROR the type parameter `U` is not constrained by the impl trait, self type, or predicates
     //~| ERROR conflicting implementations of trait `Bar`
-    // This crafty self-referential attempt is still no good.
+    // Self-referential constraint doesn't properly constrain U
 }
 
 impl<T, U, V> Foo<T> for T
@@ -53,9 +61,7 @@ where
     //~^^^^ ERROR the type parameter `U` is not constrained
     //~| ERROR the type parameter `V` is not constrained
     //~| ERROR conflicting implementations of trait `Foo<[isize; 0]>` for type `[isize; 0]`
-
-    // Here, `V` is bound by an output type parameter, but the inputs
-    // are not themselves constrained.
+    // V is bound through output type, but U and V are not properly constrained as inputs
 }
 
 impl<T, U, V> Foo<(T, U)> for T
@@ -63,7 +69,7 @@ where
     (T, U): Bar<Out = V>,
 {
     //~^^^^ ERROR conflicting implementations of trait `Foo<([isize; 0], _)>` for type `[isize; 0]`
-    // As above, but both T and U ARE constrained.
+    // Both T and U are constrained through `Foo<(T, U)>`, but creates conflicting impl
 }
 
 fn main() {}
diff --git a/tests/ui/impl-unused-tps.stderr b/tests/ui/traits/constrained-type-params-trait-impl.stderr
index eff5ffff9b6..2175129a8df 100644
--- a/tests/ui/impl-unused-tps.stderr
+++ b/tests/ui/traits/constrained-type-params-trait-impl.stderr
@@ -1,5 +1,5 @@
 error[E0119]: conflicting implementations of trait `Foo<_>` for type `[isize; 0]`
-  --> $DIR/impl-unused-tps.rs:28:1
+  --> $DIR/constrained-type-params-trait-impl.rs:37:1
    |
 LL | impl<T> Foo<T> for [isize; 0] {
    | ----------------------------- first implementation here
@@ -8,7 +8,7 @@ LL | impl<T, U> Foo<T> for U {
    | ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `[isize; 0]`
 
 error[E0119]: conflicting implementations of trait `Foo<[isize; 0]>` for type `[isize; 0]`
-  --> $DIR/impl-unused-tps.rs:49:1
+  --> $DIR/constrained-type-params-trait-impl.rs:57:1
    |
 LL |   impl<T> Foo<T> for [isize; 0] {
    |   ----------------------------- first implementation here
@@ -19,7 +19,7 @@ LL | |     (T, U): Bar<Out = V>,
    | |_________________________^ conflicting implementation for `[isize; 0]`
 
 error[E0119]: conflicting implementations of trait `Foo<([isize; 0], _)>` for type `[isize; 0]`
-  --> $DIR/impl-unused-tps.rs:61:1
+  --> $DIR/constrained-type-params-trait-impl.rs:67:1
    |
 LL |   impl<T> Foo<T> for [isize; 0] {
    |   ----------------------------- first implementation here
@@ -30,37 +30,37 @@ LL | |     (T, U): Bar<Out = V>,
    | |_________________________^ conflicting implementation for `[isize; 0]`
 
 error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
-  --> $DIR/impl-unused-tps.rs:13:9
+  --> $DIR/constrained-type-params-trait-impl.rs:21:9
    |
 LL | impl<T, U> Foo<T> for [isize; 1] {
    |         ^ unconstrained type parameter
 
 error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
-  --> $DIR/impl-unused-tps.rs:32:9
+  --> $DIR/constrained-type-params-trait-impl.rs:42:9
    |
 LL | impl<T, U> Bar for T {
    |         ^ unconstrained type parameter
 
 error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
-  --> $DIR/impl-unused-tps.rs:40:9
+  --> $DIR/constrained-type-params-trait-impl.rs:48:9
    |
 LL | impl<T, U> Bar for T
    |         ^ unconstrained type parameter
 
 error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
-  --> $DIR/impl-unused-tps.rs:49:9
+  --> $DIR/constrained-type-params-trait-impl.rs:57:9
    |
 LL | impl<T, U, V> Foo<T> for T
    |         ^ unconstrained type parameter
 
 error[E0207]: the type parameter `V` is not constrained by the impl trait, self type, or predicates
-  --> $DIR/impl-unused-tps.rs:49:12
+  --> $DIR/constrained-type-params-trait-impl.rs:57:12
    |
 LL | impl<T, U, V> Foo<T> for T
    |            ^ unconstrained type parameter
 
 error[E0119]: conflicting implementations of trait `Bar`
-  --> $DIR/impl-unused-tps.rs:40:1
+  --> $DIR/constrained-type-params-trait-impl.rs:48:1
    |
 LL |   impl<T, U> Bar for T {
    |   -------------------- first implementation here