Skip to content

Commit dc35d58

Browse files
committed
Show that the behaviour is the same for RPIT and TAIT
1 parent e82b0cd commit dc35d58

9 files changed

+230
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
trait Duh {}
4+
5+
impl Duh for i32 {}
6+
7+
trait Trait {
8+
type Assoc: Duh;
9+
}
10+
11+
// the fact that `R` is the `::Output` projection on `F` causes
12+
// an intermediate inference var to be generated which is then later
13+
// compared against the actually found `Assoc` type.
14+
impl<R: Duh, F: FnMut() -> R> Trait for F {
15+
type Assoc = R;
16+
}
17+
18+
type Sendable = impl Send;
19+
20+
// The `Sendable` here is then later compared against the inference var
21+
// created, causing the inference var to be set to `Sendable` instead of
22+
// the hidden type. We already have obligations registered on the inference
23+
// var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque
24+
// type does not implement `Duh`, even if its hidden type does. So we error out.
25+
fn foo() -> impl Trait<Assoc = Sendable> {
26+
//~^ ERROR `Sendable: Duh` is not satisfied
27+
//~| ERROR `Sendable: Duh` is not satisfied
28+
|| 42
29+
}
30+
31+
fn main() {
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0277]: the trait bound `Sendable: Duh` is not satisfied
2+
--> $DIR/nested-return-type2-tait.rs:25:13
3+
|
4+
LL | fn foo() -> impl Trait<Assoc = Sendable> {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Duh` is not implemented for `Sendable`
6+
|
7+
note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait.rs:28:5: 28:10]`
8+
--> $DIR/nested-return-type2-tait.rs:14:31
9+
|
10+
LL | impl<R: Duh, F: FnMut() -> R> Trait for F {
11+
| ^^^^^ ^
12+
13+
error[E0277]: the trait bound `Sendable: Duh` is not satisfied
14+
--> $DIR/nested-return-type2-tait.rs:25:42
15+
|
16+
LL | fn foo() -> impl Trait<Assoc = Sendable> {
17+
| __________________________________________^
18+
LL | |
19+
LL | |
20+
LL | | || 42
21+
LL | | }
22+
| |_^ the trait `Duh` is not implemented for `Sendable`
23+
|
24+
note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait.rs:28:5: 28:10]`
25+
--> $DIR/nested-return-type2-tait.rs:14:31
26+
|
27+
LL | impl<R: Duh, F: FnMut() -> R> Trait for F {
28+
| ^^^^^ ^
29+
30+
error: aborting due to 2 previous errors
31+
32+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
trait Duh {}
4+
5+
impl Duh for i32 {}
6+
7+
trait Trait {
8+
type Assoc: Duh;
9+
}
10+
11+
// the fact that `R` is the `::Output` projection on `F` causes
12+
// an intermediate inference var to be generated which is then later
13+
// compared against the actually found `Assoc` type.
14+
impl<R: Duh, F: FnMut() -> R> Trait for F {
15+
type Assoc = R;
16+
}
17+
18+
type Sendable = impl Send;
19+
type Traitable = impl Trait<Assoc = Sendable>;
20+
21+
// The `impl Send` here is then later compared against the inference var
22+
// created, causing the inference var to be set to `impl Send` instead of
23+
// the hidden type. We already have obligations registered on the inference
24+
// var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque
25+
// type does not implement `Duh`, even if its hidden type does. So we error out.
26+
fn foo() -> Traitable {
27+
|| 42
28+
//~^ ERROR `Sendable: Duh` is not satisfied
29+
}
30+
31+
fn main() {
32+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `Sendable: Duh` is not satisfied
2+
--> $DIR/nested-return-type2-tait2.rs:27:5
3+
|
4+
LL | || 42
5+
| ^^^^^ the trait `Duh` is not implemented for `Sendable`
6+
|
7+
note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait2.rs:27:5: 27:10]`
8+
--> $DIR/nested-return-type2-tait2.rs:14:31
9+
|
10+
LL | impl<R: Duh, F: FnMut() -> R> Trait for F {
11+
| ^^^^^ ^
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
trait Duh {}
4+
5+
impl Duh for i32 {}
6+
7+
trait Trait {
8+
type Assoc: Duh;
9+
}
10+
11+
// the fact that `R` is the `::Output` projection on `F` causes
12+
// an intermediate inference var to be generated which is then later
13+
// compared against the actually found `Assoc` type.
14+
impl<R: Duh, F: FnMut() -> R> Trait for F {
15+
type Assoc = R;
16+
}
17+
18+
type Traitable = impl Trait<Assoc = impl Send>;
19+
20+
// The `impl Send` here is then later compared against the inference var
21+
// created, causing the inference var to be set to `impl Send` instead of
22+
// the hidden type. We already have obligations registered on the inference
23+
// var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque
24+
// type does not implement `Duh`, even if its hidden type does. So we error out.
25+
fn foo() -> Traitable {
26+
|| 42
27+
//~^ ERROR `impl Send: Duh` is not satisfied
28+
}
29+
30+
fn main() {
31+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `impl Send: Duh` is not satisfied
2+
--> $DIR/nested-return-type2-tait3.rs:26:5
3+
|
4+
LL | || 42
5+
| ^^^^^ the trait `Duh` is not implemented for `impl Send`
6+
|
7+
note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait3.rs:26:5: 26:10]`
8+
--> $DIR/nested-return-type2-tait3.rs:14:31
9+
|
10+
LL | impl<R: Duh, F: FnMut() -> R> Trait for F {
11+
| ^^^^^ ^
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// check-pass
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
trait Duh {}
6+
7+
impl Duh for i32 {}
8+
9+
trait Trait {
10+
type Assoc: Duh;
11+
}
12+
13+
impl<F: Duh> Trait for F {
14+
type Assoc = F;
15+
}
16+
17+
type Sendable = impl Send;
18+
19+
fn foo() -> impl Trait<Assoc = Sendable> {
20+
42
21+
}
22+
23+
fn main() {
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// check-pass
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
trait Duh {}
6+
7+
impl Duh for i32 {}
8+
9+
trait Trait {
10+
type Assoc: Duh;
11+
}
12+
13+
impl<F: Duh> Trait for F {
14+
type Assoc = F;
15+
}
16+
17+
type Sendable = impl Send;
18+
type Traitable = impl Trait<Assoc = Sendable>;
19+
20+
fn foo() -> Traitable {
21+
42
22+
}
23+
24+
fn main() {
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// check-pass
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
trait Duh {}
6+
7+
impl Duh for i32 {}
8+
9+
trait Trait {
10+
type Assoc: Duh;
11+
}
12+
13+
impl<F: Duh> Trait for F {
14+
type Assoc = F;
15+
}
16+
17+
type Traitable = impl Trait<Assoc = impl Send>;
18+
19+
fn foo() -> Traitable {
20+
42
21+
}
22+
23+
fn main() {
24+
}

0 commit comments

Comments
 (0)