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`
This commit is contained in:
commit
05b209d3a2
18 changed files with 162 additions and 145 deletions
|
|
@ -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() {}
|
||||
|
|
@ -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
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
//! Test that #[inline] attribute cannot be applied to enum variants
|
||||
|
||||
enum Foo {
|
||||
#[inline]
|
||||
//~^ ERROR attribute should be applied
|
||||
|
|
@ -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]
|
||||
| ^^^^^^^^^
|
||||
6
tests/ui/attributes/inline-main.rs
Normal file
6
tests/ui/attributes/inline-main.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
//! Test that #[inline(always)] can be applied to main function
|
||||
|
||||
//@ run-pass
|
||||
|
||||
#[inline(always)]
|
||||
fn main() {}
|
||||
32
tests/ui/generics/unconstrained-type-params-inherent-impl.rs
Normal file
32
tests/ui/generics/unconstrained-type-params-inherent-impl.rs
Normal file
|
|
@ -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() {}
|
||||
|
|
@ -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
|
||||
|
||||
|
|
@ -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() { }
|
||||
|
|
@ -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() { }
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
fn main() {
|
||||
let _f = 10i32.abs; //~ ERROR attempted to take value of method
|
||||
}
|
||||
|
|
@ -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`.
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
//@ run-pass
|
||||
|
||||
#[inline(always)]
|
||||
fn main() {}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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`.
|
||||
33
tests/ui/methods/method-value-without-call.rs
Normal file
33
tests/ui/methods/method-value-without-call.rs
Normal file
|
|
@ -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
|
||||
}
|
||||
36
tests/ui/methods/method-value-without-call.stderr
Normal file
36
tests/ui/methods/method-value-without-call.stderr
Normal file
|
|
@ -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`.
|
||||
|
|
@ -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() {}
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue