Skip to content

Commit 7932f21

Browse files
committed
moved renamed docs stderr formatted | impl-unused-tps.rs
1 parent cdaf91f commit 7932f21

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//! Comprehensive test for type parameter constraints in trait implementations
2+
//!
3+
//! This tests various scenarios of type parameter usage in trait implementations:
4+
//! - Properly constrained parameters through trait bounds
5+
//! - Unconstrained parameters that should cause compilation errors
6+
//! - Complex constraint scenarios with `where` clauses and associated types
7+
//! - Conflicting implementations detection
8+
19
trait Foo<A> {
210
fn get(&self, A: &A) {}
311
}
@@ -7,34 +15,34 @@ trait Bar {
715
}
816

917
impl<T> Foo<T> for [isize; 0] {
10-
// OK, T is used in `Foo<T>`.
18+
// OK: T is used in the trait bound `Foo<T>`
1119
}
1220

1321
impl<T, U> Foo<T> for [isize; 1] {
1422
//~^ ERROR the type parameter `U` is not constrained
23+
// T is constrained by `Foo<T>`, but U is completely unused
1524
}
1625

1726
impl<T, U> Foo<T> for [isize; 2]
1827
where
1928
T: Bar<Out = U>,
2029
{
21-
// OK, `U` is now constrained by the output type parameter.
30+
// OK: T is constrained by `Foo<T>`, U is constrained by the where clause
2231
}
2332

2433
impl<T: Bar<Out = U>, U> Foo<T> for [isize; 3] {
25-
// OK, same as above but written differently.
34+
// OK: Same as above but using bound syntax instead of where clause
2635
}
2736

2837
impl<T, U> Foo<T> for U {
2938
//~^ ERROR conflicting implementations of trait `Foo<_>` for type `[isize; 0]`
39+
// This conflicts with the first impl when U = [isize; 0]
3040
}
3141

3242
impl<T, U> Bar for T {
3343
//~^ ERROR the type parameter `U` is not constrained
34-
3544
type Out = U;
36-
37-
// Using `U` in an associated type within the impl is not good enough!
45+
// Using U only in associated type definition is insufficient for constraint
3846
}
3947

4048
impl<T, U> Bar for T
@@ -43,7 +51,7 @@ where
4351
{
4452
//~^^^^ ERROR the type parameter `U` is not constrained by the impl trait, self type, or predicates
4553
//~| ERROR conflicting implementations of trait `Bar`
46-
// This crafty self-referential attempt is still no good.
54+
// Self-referential constraint doesn't properly constrain U
4755
}
4856

4957
impl<T, U, V> Foo<T> for T
@@ -53,17 +61,15 @@ where
5361
//~^^^^ ERROR the type parameter `U` is not constrained
5462
//~| ERROR the type parameter `V` is not constrained
5563
//~| ERROR conflicting implementations of trait `Foo<[isize; 0]>` for type `[isize; 0]`
56-
57-
// Here, `V` is bound by an output type parameter, but the inputs
58-
// are not themselves constrained.
64+
// V is bound through output type, but U and V are not properly constrained as inputs
5965
}
6066

6167
impl<T, U, V> Foo<(T, U)> for T
6268
where
6369
(T, U): Bar<Out = V>,
6470
{
6571
//~^^^^ ERROR conflicting implementations of trait `Foo<([isize; 0], _)>` for type `[isize; 0]`
66-
// As above, but both T and U ARE constrained.
72+
// Both T and U are constrained through `Foo<(T, U)>`, but creates conflicting impl
6773
}
6874

6975
fn main() {}

tests/ui/impl-unused-tps.stderr renamed to tests/ui/traits/constrained-type-params-trait-impl.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0119]: conflicting implementations of trait `Foo<_>` for type `[isize; 0]`
2-
--> $DIR/impl-unused-tps.rs:28:1
2+
--> $DIR/constrained-type-params-trait-impl.rs:37:1
33
|
44
LL | impl<T> Foo<T> for [isize; 0] {
55
| ----------------------------- first implementation here
@@ -8,7 +8,7 @@ LL | impl<T, U> Foo<T> for U {
88
| ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `[isize; 0]`
99

1010
error[E0119]: conflicting implementations of trait `Foo<[isize; 0]>` for type `[isize; 0]`
11-
--> $DIR/impl-unused-tps.rs:49:1
11+
--> $DIR/constrained-type-params-trait-impl.rs:57:1
1212
|
1313
LL | impl<T> Foo<T> for [isize; 0] {
1414
| ----------------------------- first implementation here
@@ -19,7 +19,7 @@ LL | | (T, U): Bar<Out = V>,
1919
| |_________________________^ conflicting implementation for `[isize; 0]`
2020

2121
error[E0119]: conflicting implementations of trait `Foo<([isize; 0], _)>` for type `[isize; 0]`
22-
--> $DIR/impl-unused-tps.rs:61:1
22+
--> $DIR/constrained-type-params-trait-impl.rs:67:1
2323
|
2424
LL | impl<T> Foo<T> for [isize; 0] {
2525
| ----------------------------- first implementation here
@@ -30,37 +30,37 @@ LL | | (T, U): Bar<Out = V>,
3030
| |_________________________^ conflicting implementation for `[isize; 0]`
3131

3232
error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
33-
--> $DIR/impl-unused-tps.rs:13:9
33+
--> $DIR/constrained-type-params-trait-impl.rs:21:9
3434
|
3535
LL | impl<T, U> Foo<T> for [isize; 1] {
3636
| ^ unconstrained type parameter
3737

3838
error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
39-
--> $DIR/impl-unused-tps.rs:32:9
39+
--> $DIR/constrained-type-params-trait-impl.rs:42:9
4040
|
4141
LL | impl<T, U> Bar for T {
4242
| ^ unconstrained type parameter
4343

4444
error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
45-
--> $DIR/impl-unused-tps.rs:40:9
45+
--> $DIR/constrained-type-params-trait-impl.rs:48:9
4646
|
4747
LL | impl<T, U> Bar for T
4848
| ^ unconstrained type parameter
4949

5050
error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
51-
--> $DIR/impl-unused-tps.rs:49:9
51+
--> $DIR/constrained-type-params-trait-impl.rs:57:9
5252
|
5353
LL | impl<T, U, V> Foo<T> for T
5454
| ^ unconstrained type parameter
5555

5656
error[E0207]: the type parameter `V` is not constrained by the impl trait, self type, or predicates
57-
--> $DIR/impl-unused-tps.rs:49:12
57+
--> $DIR/constrained-type-params-trait-impl.rs:57:12
5858
|
5959
LL | impl<T, U, V> Foo<T> for T
6060
| ^ unconstrained type parameter
6161

6262
error[E0119]: conflicting implementations of trait `Bar`
63-
--> $DIR/impl-unused-tps.rs:40:1
63+
--> $DIR/constrained-type-params-trait-impl.rs:48:1
6464
|
6565
LL | impl<T, U> Bar for T {
6666
| -------------------- first implementation here

0 commit comments

Comments
 (0)