Skip to content

tests/ui: A New Order [12/N] #142417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/ui/associated-types/unconstrained-lifetime-assoc-type.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Test that #[inline] attribute cannot be applied to enum variants

enum Foo {
#[inline]
//~^ ERROR attribute should be applied
Expand Down
Original file line number Diff line number Diff line change
@@ -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]
| ^^^^^^^^^
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/attributes/inline-main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! Test that #[inline(always)] can be applied to main function

//@ run-pass

#[inline(always)]
fn main() {}
32 changes: 32 additions & 0 deletions tests/ui/generics/unconstrained-type-params-inherent-impl.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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

Expand Down
18 changes: 0 additions & 18 deletions tests/ui/impl-unused-rps-in-assoc-type.rs

This file was deleted.

25 changes: 0 additions & 25 deletions tests/ui/impl-unused-tps-inherent.rs

This file was deleted.

3 changes: 0 additions & 3 deletions tests/ui/implicit-method-bind.rs

This file was deleted.

14 changes: 0 additions & 14 deletions tests/ui/implicit-method-bind.stderr

This file was deleted.

4 changes: 0 additions & 4 deletions tests/ui/inlined-main.rs

This file was deleted.

30 changes: 0 additions & 30 deletions tests/ui/methods/method-missing-call.rs

This file was deleted.

25 changes: 0 additions & 25 deletions tests/ui/methods/method-missing-call.stderr

This file was deleted.

33 changes: 33 additions & 0 deletions tests/ui/methods/method-value-without-call.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 36 additions & 0 deletions tests/ui/methods/method-value-without-call.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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) {}
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -53,17 +61,15 @@ 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
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() {}
Loading
Loading