Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2bf63a5

Browse files
committed
Add regression tests
1 parent 1163aa7 commit 2bf63a5

22 files changed

+494
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// check-pass
2+
3+
trait Trait<'a> {
4+
type Out;
5+
fn call(&'a self) -> Self::Out;
6+
}
7+
8+
struct X(());
9+
10+
impl<'a> Trait<'a> for X {
11+
type Out = ();
12+
fn call(&'a self) -> Self::Out {
13+
()
14+
}
15+
}
16+
17+
fn f() -> impl for<'a> Trait<'a, Out = impl Sized + 'a> {
18+
X(())
19+
}
20+
21+
fn main() {
22+
let _ = f();
23+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use std::marker::PhantomData;
2+
3+
fn _alias_check() {
4+
WrongImpl::foo(0i32);
5+
//~^ ERROR the trait bound `RawImpl<_>: Raw<_>` is not satisfied
6+
WrongImpl::<()>::foo(0i32);
7+
//~^ ERROR the trait bound `RawImpl<()>: Raw<()>` is not satisfied
8+
//~| ERROR trait bounds were not satisfied
9+
CorrectImpl::foo(0i32);
10+
}
11+
12+
pub trait Raw<T: ?Sized> {
13+
type Value;
14+
}
15+
16+
pub type WrongImpl<T> = SafeImpl<T, RawImpl<T>>;
17+
18+
pub type CorrectImpl<T> = SafeImpl<[T], RawImpl<T>>;
19+
20+
pub struct RawImpl<T>(PhantomData<T>);
21+
22+
impl<T> Raw<[T]> for RawImpl<T> {
23+
type Value = T;
24+
}
25+
26+
pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
27+
28+
impl<T: ?Sized, A: Raw<T>> SafeImpl<T, A> {
29+
pub fn foo(value: A::Value) {}
30+
}
31+
32+
fn main() {}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
error[E0277]: the trait bound `RawImpl<_>: Raw<_>` is not satisfied
2+
--> $DIR/issue-62742.rs:4:5
3+
|
4+
LL | WrongImpl::foo(0i32);
5+
| ^^^^^^^^^ the trait `Raw<_>` is not implemented for `RawImpl<_>`
6+
|
7+
= help: the following implementations were found:
8+
<RawImpl<T> as Raw<[T]>>
9+
note: required by a bound in `SafeImpl`
10+
--> $DIR/issue-62742.rs:26:35
11+
|
12+
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
13+
| ^^^^^^ required by this bound in `SafeImpl`
14+
15+
error[E0599]: the function or associated item `foo` exists for struct `SafeImpl<(), RawImpl<()>>`, but its trait bounds were not satisfied
16+
--> $DIR/issue-62742.rs:6:22
17+
|
18+
LL | WrongImpl::<()>::foo(0i32);
19+
| ^^^ function or associated item cannot be called on `SafeImpl<(), RawImpl<()>>` due to unsatisfied trait bounds
20+
...
21+
LL | pub struct RawImpl<T>(PhantomData<T>);
22+
| -------------------------------------- doesn't satisfy `RawImpl<()>: Raw<()>`
23+
...
24+
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
25+
| --------------------------------------------------------------- function or associated item `foo` not found for this
26+
|
27+
= note: the following trait bounds were not satisfied:
28+
`RawImpl<()>: Raw<()>`
29+
note: the following trait must be implemented
30+
--> $DIR/issue-62742.rs:12:1
31+
|
32+
LL | / pub trait Raw<T: ?Sized> {
33+
LL | | type Value;
34+
LL | | }
35+
| |_^
36+
37+
error[E0277]: the trait bound `RawImpl<()>: Raw<()>` is not satisfied
38+
--> $DIR/issue-62742.rs:6:5
39+
|
40+
LL | WrongImpl::<()>::foo(0i32);
41+
| ^^^^^^^^^^^^^^^ the trait `Raw<()>` is not implemented for `RawImpl<()>`
42+
|
43+
= help: the following implementations were found:
44+
<RawImpl<T> as Raw<[T]>>
45+
note: required by a bound in `SafeImpl`
46+
--> $DIR/issue-62742.rs:26:35
47+
|
48+
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
49+
| ^^^^^^ required by this bound in `SafeImpl`
50+
51+
error: aborting due to 3 previous errors
52+
53+
Some errors have detailed explanations: E0277, E0599.
54+
For more information about an error, try `rustc --explain E0277`.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: implementation of `FnOnce` is not general enough
2+
--> $DIR/issue-67830.rs:23:5
3+
|
4+
LL | Wrap(|a| Some(a).into_iter())
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
6+
|
7+
= note: closure with signature `fn(&'2 A) -> std::option::IntoIter<&A>` must implement `FnOnce<(&'1 A,)>`, for any lifetime `'1`...
8+
= note: ...but it actually implements `FnOnce<(&'2 A,)>`, for some specific lifetime `'2`
9+
10+
error: implementation of `FnOnce` is not general enough
11+
--> $DIR/issue-67830.rs:23:5
12+
|
13+
LL | Wrap(|a| Some(a).into_iter())
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
15+
|
16+
= note: closure with signature `fn(&'2 A) -> std::option::IntoIter<&A>` must implement `FnOnce<(&'1 A,)>`, for any lifetime `'1`...
17+
= note: ...but it actually implements `FnOnce<(&'2 A,)>`, for some specific lifetime `'2`
18+
19+
error: aborting due to 2 previous errors
20+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
trait MyFn<Arg> {
2+
type Output;
3+
fn call(&self, arg: Arg) -> Self::Output;
4+
}
5+
6+
struct Wrap<F>(F);
7+
8+
impl<A, B, F> MyFn<A> for Wrap<F>
9+
where
10+
F: Fn(A) -> B
11+
{
12+
type Output = B;
13+
14+
fn call(&self, arg: A) -> Self::Output {
15+
(self.0)(arg)
16+
}
17+
}
18+
19+
20+
struct A;
21+
fn test() -> impl for<'a> MyFn<&'a A, Output=impl Iterator + 'a> {
22+
//~^ ERROR implementation of `FnOnce` is not general enough
23+
Wrap(|a| Some(a).into_iter())
24+
}
25+
26+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: implementation of `FnOnce` is not general enough
2+
--> $DIR/issue-67830.rs:21:66
3+
|
4+
LL | fn test() -> impl for<'a> MyFn<&'a A, Output=impl Iterator + 'a> {
5+
| __________________________________________________________________^
6+
LL | |
7+
LL | | Wrap(|a| Some(a).into_iter())
8+
LL | | }
9+
| |_^ implementation of `FnOnce` is not general enough
10+
|
11+
= note: closure with signature `fn(&'2 A) -> std::option::IntoIter<&A>` must implement `FnOnce<(&'1 A,)>`, for any lifetime `'1`...
12+
= note: ...but it actually implements `FnOnce<(&'2 A,)>`, for some specific lifetime `'2`
13+
14+
error: aborting due to previous error
15+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
type Closure = impl Fn() -> u64;
4+
struct Anonymous(Closure);
5+
6+
fn main() {
7+
let y = || -> Closure { || 3 };
8+
Anonymous(|| { //~ ERROR mismatched types
9+
3 //~^ ERROR mismatched types
10+
})
11+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-74282.rs:8:15
3+
|
4+
LL | type Closure = impl Fn() -> u64;
5+
| ---------------- the expected opaque type
6+
...
7+
LL | Anonymous(|| {
8+
| _______________^
9+
LL | | 3
10+
LL | | })
11+
| |_____^ expected closure, found a different closure
12+
|
13+
= note: expected opaque type `Closure`
14+
found closure `[closure@$DIR/issue-74282.rs:8:15: 10:6]`
15+
= note: no two closures, even if identical, have the same type
16+
= help: consider boxing your closure and/or using it as a trait object
17+
18+
error[E0308]: mismatched types
19+
--> $DIR/issue-74282.rs:8:5
20+
|
21+
LL | fn main() {
22+
| - expected `()` because of default return type
23+
LL | let y = || -> Closure { || 3 };
24+
LL | / Anonymous(|| {
25+
LL | | 3
26+
LL | | })
27+
| | ^- help: consider using a semicolon here: `;`
28+
| |______|
29+
| expected `()`, found struct `Anonymous`
30+
31+
error: aborting due to 2 previous errors
32+
33+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
// check-pass
4+
5+
trait Foo<T> {}
6+
impl<T, U> Foo<T> for U {}
7+
8+
type Scope = impl Foo<()>;
9+
10+
#[allow(unused)]
11+
fn infer_scope() -> Scope {
12+
()
13+
}
14+
15+
#[allow(unused)]
16+
fn ice() -> impl Foo<Scope>
17+
{
18+
loop {}
19+
}
20+
21+
fn main() {}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
trait Trait {
4+
type Associated;
5+
fn func() -> Self::Associated;
6+
}
7+
8+
trait Bound {}
9+
pub struct Struct;
10+
11+
impl Trait for Struct {
12+
type Associated = impl Bound;
13+
14+
fn func() -> Self::Associated {
15+
Some(42).map(|_| j) //~ ERROR cannot find value `j` in this scope
16+
}
17+
}
18+
19+
fn main() {}

0 commit comments

Comments
 (0)