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 0000000000000..2c4af7da92154 --- /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 similarity index 84% rename from tests/ui/impl-unused-rps-in-assoc-type.stderr rename to tests/ui/associated-types/unconstrained-lifetime-assoc-type.stderr index ef61fa4be4830..15d0820c895dd 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 similarity index 58% rename from tests/ui/inline-disallow-on-variant.rs rename to tests/ui/attributes/inline-attribute-enum-variant-error.rs index d92a4e8cc8df1..305b285d2a4f6 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 similarity index 84% rename from tests/ui/inline-disallow-on-variant.stderr rename to tests/ui/attributes/inline-attribute-enum-variant-error.stderr index 255f6bc6a1957..a4564d8f72254 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 0000000000000..7181ee19b6711 --- /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 0000000000000..c971de0d1f2a3 --- /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); + +trait Bar { + type Out; +} + +impl MyType { + //~^ ERROR the type parameter `T` is not constrained + // T is completely unused - this should fail +} + +impl MyType1 { + // OK: T is used in the self type `MyType1` +} + +impl MyType1 { + //~^ ERROR the type parameter `U` is not constrained + // T is used in self type, but U is unconstrained - this should fail +} + +impl MyType1 +where + T: Bar, +{ + // 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 similarity index 66% rename from tests/ui/impl-unused-tps-inherent.stderr rename to tests/ui/generics/unconstrained-type-params-inherent-impl.stderr index 43f63cf968cf5..19b02ad396cd3 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 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 MyType1 { - | ^ unconstrained type parameter +LL | impl MyType1 { + | ^ 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 ea41997a69858..0000000000000 --- 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 83a228e551aa6..0000000000000 --- a/tests/ui/impl-unused-tps-inherent.rs +++ /dev/null @@ -1,25 +0,0 @@ -struct MyType; - -struct MyType1(T); - -trait Bar { - type Out; -} - -impl MyType { - //~^ ERROR the type parameter `T` is not constrained -} - -impl MyType1 { - // OK, T is used in `Foo`. -} - -impl MyType1 { - //~^ ERROR the type parameter `U` is not constrained -} - -impl MyType1 where T: Bar { - // OK, T is used in `Foo`. -} - -fn main() { } diff --git a/tests/ui/implicit-method-bind.rs b/tests/ui/implicit-method-bind.rs deleted file mode 100644 index 5e27516a89a41..0000000000000 --- 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 e9357113f364e..0000000000000 --- 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 731ac0dddca61..0000000000000 --- 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 7ce1e9a4f1bda..0000000000000 --- 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 bc508461b690c..0000000000000 --- 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, {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 0000000000000..43bee4864b422 --- /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 0000000000000..0c3870e286875 --- /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, {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 similarity index 53% rename from tests/ui/impl-unused-tps.rs rename to tests/ui/traits/constrained-type-params-trait-impl.rs index a5836db3c8e66..301bbdb2ccb3e 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 { fn get(&self, A: &A) {} } @@ -7,34 +15,34 @@ trait Bar { } impl Foo for [isize; 0] { - // OK, T is used in `Foo`. + // OK: T is used in the trait bound `Foo` } impl Foo for [isize; 1] { //~^ ERROR the type parameter `U` is not constrained + // T is constrained by `Foo`, but U is completely unused } impl Foo for [isize; 2] where T: Bar, { - // OK, `U` is now constrained by the output type parameter. + // OK: T is constrained by `Foo`, U is constrained by the where clause } impl, U> Foo for [isize; 3] { - // OK, same as above but written differently. + // OK: Same as above but using bound syntax instead of where clause } impl Foo for U { //~^ ERROR conflicting implementations of trait `Foo<_>` for type `[isize; 0]` + // This conflicts with the first impl when U = [isize; 0] } impl 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 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 Foo 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 Foo<(T, U)> for T @@ -63,7 +69,7 @@ where (T, U): Bar, { //~^^^^ 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 similarity index 82% rename from tests/ui/impl-unused-tps.stderr rename to tests/ui/traits/constrained-type-params-trait-impl.stderr index eff5ffff9b6ac..2175129a8df79 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 Foo for [isize; 0] { | ----------------------------- first implementation here @@ -8,7 +8,7 @@ LL | impl Foo 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 Foo for [isize; 0] { | ----------------------------- first implementation here @@ -19,7 +19,7 @@ LL | | (T, U): Bar, | |_________________________^ 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 Foo for [isize; 0] { | ----------------------------- first implementation here @@ -30,37 +30,37 @@ LL | | (T, U): Bar, | |_________________________^ 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 Foo 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 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 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 Foo 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 Foo 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 Bar for T { | -------------------- first implementation here