Skip to content

Commit aac948b

Browse files
committed
cleaned up some tests
1 parent fd50e10 commit aac948b

18 files changed

+162
-145
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Regression test for issue #22077
2+
//! lifetime parameters must be constrained in associated type definitions
3+
4+
trait Fun {
5+
type Output;
6+
fn call<'x>(&'x self) -> Self::Output;
7+
}
8+
9+
struct Holder {
10+
x: String,
11+
}
12+
13+
impl<'a> Fun for Holder {
14+
//~^ ERROR E0207
15+
type Output = &'a str;
16+
fn call<'b>(&'b self) -> &'b str {
17+
&self.x[..]
18+
}
19+
}
20+
21+
fn main() {}

tests/ui/impl-unused-rps-in-assoc-type.stderr renamed to tests/ui/associated-types/unconstrained-lifetime-assoc-type.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
2-
--> $DIR/impl-unused-rps-in-assoc-type.rs:11:6
2+
--> $DIR/unconstrained-lifetime-assoc-type.rs:13:6
33
|
44
LL | impl<'a> Fun for Holder {
55
| ^^ unconstrained lifetime parameter

tests/ui/inline-disallow-on-variant.rs renamed to tests/ui/attributes/inline-attribute-enum-variant-error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Test that #[inline] attribute cannot be applied to enum variants
2+
13
enum Foo {
24
#[inline]
35
//~^ ERROR attribute should be applied

tests/ui/inline-disallow-on-variant.stderr renamed to tests/ui/attributes/inline-attribute-enum-variant-error.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0518]: attribute should be applied to function or closure
2-
--> $DIR/inline-disallow-on-variant.rs:2:5
2+
--> $DIR/inline-attribute-enum-variant-error.rs:4:5
33
|
44
LL | #[inline]
55
| ^^^^^^^^^

tests/ui/attributes/inline-main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! Test that #[inline(always)] can be applied to main function
2+
3+
//@ run-pass
4+
5+
#[inline(always)]
6+
fn main() {}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//! Test for unconstrained type parameters in inherent implementations
2+
3+
struct MyType;
4+
5+
struct MyType1<T>(T);
6+
7+
trait Bar {
8+
type Out;
9+
}
10+
11+
impl<T> MyType {
12+
//~^ ERROR the type parameter `T` is not constrained
13+
// T is completely unused - this should fail
14+
}
15+
16+
impl<T> MyType1<T> {
17+
// OK: T is used in the self type `MyType1<T>`
18+
}
19+
20+
impl<T, U> MyType1<T> {
21+
//~^ ERROR the type parameter `U` is not constrained
22+
// T is used in self type, but U is unconstrained - this should fail
23+
}
24+
25+
impl<T, U> MyType1<T>
26+
where
27+
T: Bar<Out = U>,
28+
{
29+
// OK: T is used in self type, U is constrained through the where clause
30+
}
31+
32+
fn main() {}

tests/ui/impl-unused-tps-inherent.stderr renamed to tests/ui/generics/unconstrained-type-params-inherent-impl.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
2-
--> $DIR/impl-unused-tps-inherent.rs:9:6
2+
--> $DIR/unconstrained-type-params-inherent-impl.rs:11:6
33
|
44
LL | impl<T> MyType {
55
| ^ unconstrained type parameter
66

77
error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
8-
--> $DIR/impl-unused-tps-inherent.rs:17:8
8+
--> $DIR/unconstrained-type-params-inherent-impl.rs:20:9
99
|
10-
LL | impl<T,U> MyType1<T> {
11-
| ^ unconstrained type parameter
10+
LL | impl<T, U> MyType1<T> {
11+
| ^ unconstrained type parameter
1212

1313
error: aborting due to 2 previous errors
1414

tests/ui/impl-unused-rps-in-assoc-type.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/ui/impl-unused-tps-inherent.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/ui/implicit-method-bind.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/ui/implicit-method-bind.stderr

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/ui/inlined-main.rs

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/ui/methods/method-missing-call.rs

Lines changed: 0 additions & 30 deletions
This file was deleted.

tests/ui/methods/method-missing-call.stderr

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! Test taking a method value without parentheses
2+
3+
struct Point {
4+
x: isize,
5+
y: isize,
6+
}
7+
8+
impl Point {
9+
fn new() -> Point {
10+
Point { x: 0, y: 0 }
11+
}
12+
13+
fn get_x(&self) -> isize {
14+
self.x
15+
}
16+
}
17+
18+
fn main() {
19+
// Test with primitive type method
20+
let _f = 10i32.abs; //~ ERROR attempted to take value of method
21+
22+
// Test with custom type method
23+
let point: Point = Point::new();
24+
let px: isize = point.get_x; //~ ERROR attempted to take value of method `get_x` on type `Point`
25+
26+
// Test with method chains - ensure the span is useful
27+
let ys = &[1, 2, 3, 4, 5, 6, 7];
28+
let a = ys
29+
.iter()
30+
.map(|x| x)
31+
.filter(|&&x| x == 1)
32+
.filter_map; //~ ERROR attempted to take value of method `filter_map` on type
33+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error[E0615]: attempted to take value of method `abs` on type `i32`
2+
--> $DIR/method-value-without-call.rs:20:20
3+
|
4+
LL | let _f = 10i32.abs;
5+
| ^^^ method, not a field
6+
|
7+
help: use parentheses to call the method
8+
|
9+
LL | let _f = 10i32.abs();
10+
| ++
11+
12+
error[E0615]: attempted to take value of method `get_x` on type `Point`
13+
--> $DIR/method-value-without-call.rs:24:27
14+
|
15+
LL | let px: isize = point.get_x;
16+
| ^^^^^ method, not a field
17+
|
18+
help: use parentheses to call the method
19+
|
20+
LL | let px: isize = point.get_x();
21+
| ++
22+
23+
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}>`
24+
--> $DIR/method-value-without-call.rs:32:10
25+
|
26+
LL | .filter_map;
27+
| ^^^^^^^^^^ method, not a field
28+
|
29+
help: use parentheses to call the method
30+
|
31+
LL | .filter_map(_);
32+
| +++
33+
34+
error: aborting due to 3 previous errors
35+
36+
For more information about this error, try `rustc --explain E0615`.
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() {}

0 commit comments

Comments
 (0)