Skip to content

Commit 36461e0

Browse files
authored
Rollup merge of rust-lang#93757 - jackh726:gat-bug-tests, r=nikomatsakis
Add some known GAT bugs as tests In the spirit of rust-lang/compiler-team#476 These tests are marked as "check-fail", but also commented with "this should pass". This many of the open GAT issues that are accepted bugs. r? ``@nikomatsakis``
2 parents 602898a + ba42215 commit 36461e0

20 files changed

+450
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// check-fail
2+
3+
// This should pass, but it requires `Sized` to be coinductive.
4+
5+
#![feature(generic_associated_types)]
6+
7+
trait Allocator {
8+
type Allocated<T>;
9+
}
10+
11+
enum LinkedList<A: Allocator> {
12+
Head,
13+
Next(A::Allocated<Self>)
14+
//~^ overflow
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0275]: overflow evaluating the requirement `LinkedList<A>: Sized`
2+
--> $DIR/issue-80626.rs:13:10
3+
|
4+
LL | Next(A::Allocated<Self>)
5+
| ^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: no field of an enum variant may have a dynamically sized type
8+
= help: change the field's type to have a statically known size
9+
help: borrowed types always have a statically known size
10+
|
11+
LL | Next(&A::Allocated<Self>)
12+
| +
13+
help: the `Box` type always has a statically known size and allocates its contents in the heap
14+
|
15+
LL | Next(Box<A::Allocated<Self>>)
16+
| ++++ +
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0275`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// check-fail
2+
3+
// This should pass, but seems to run into a TAIT issue.
4+
5+
#![feature(generic_associated_types)]
6+
#![feature(type_alias_impl_trait)]
7+
8+
pub trait Stream {
9+
type Item;
10+
}
11+
12+
impl Stream for () {
13+
type Item = i32;
14+
}
15+
16+
trait Yay<AdditionalValue> {
17+
type InnerStream<'s>: Stream<Item = i32> + 's;
18+
fn foo<'s>() -> Self::InnerStream<'s>;
19+
}
20+
21+
impl<'a> Yay<&'a ()> for () {
22+
type InnerStream<'s> = impl Stream<Item = i32> + 's;
23+
//~^ the type
24+
fn foo<'s>() -> Self::InnerStream<'s> { todo!() }
25+
}
26+
27+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0477]: the type `impl Stream<Item = i32>` does not fulfill the required lifetime
2+
--> $DIR/issue-86218.rs:22:28
3+
|
4+
LL | type InnerStream<'s> = impl Stream<Item = i32> + 's;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: type must outlive the lifetime `'s` as defined here as required by this binding
8+
--> $DIR/issue-86218.rs:22:22
9+
|
10+
LL | type InnerStream<'s> = impl Stream<Item = i32> + 's;
11+
| ^^
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0477`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// check-fail
2+
3+
// This should pass, but we need an extension of implied bounds (probably).
4+
5+
#![feature(generic_associated_types)]
6+
7+
pub trait AsRef2 {
8+
type Output<'a> where Self: 'a;
9+
10+
fn as_ref2<'a>(&'a self) -> Self::Output<'a>;
11+
}
12+
13+
impl<T> AsRef2 for Vec<T> {
14+
type Output<'a> where Self: 'a = &'a [T];
15+
16+
fn as_ref2<'a>(&'a self) -> Self::Output<'a> {
17+
&self[..]
18+
}
19+
}
20+
21+
#[derive(Debug)]
22+
struct Foo<T>(T);
23+
#[derive(Debug)]
24+
struct FooRef<'a, U>(&'a [U]);
25+
26+
impl<'b, T, U> AsRef2 for Foo<T> //~ the type parameter
27+
where
28+
// * `for<'b, 'c> T: AsRef2<Output<'b> = &'c [U]>>` does not work
29+
//
30+
// * `U` is unconstrained but should be allowed in this context because `Output` is
31+
// an associated type
32+
T: AsRef2<Output<'b> = &'b [U]>,
33+
U: 'b
34+
{
35+
type Output<'a> where Self: 'a = FooRef<'a, U>;
36+
37+
fn as_ref2<'a>(&'a self) -> Self::Output<'a> {
38+
FooRef(self.0.as_ref2())
39+
}
40+
}
41+
42+
fn main() {
43+
let foo = Foo(vec![1, 2, 3]);
44+
dbg!(foo.as_ref2());
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
2+
--> $DIR/issue-87735.rs:26:13
3+
|
4+
LL | impl<'b, T, U> AsRef2 for Foo<T>
5+
| ^ unconstrained type parameter
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0207`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// check-fail
2+
3+
// This should pass, but unnormalized input args aren't treated as implied.
4+
5+
#![feature(generic_associated_types)]
6+
7+
trait MyTrait {
8+
type Assoc<'a, 'b> where 'b: 'a;
9+
fn do_sth(arg: Self::Assoc<'_, '_>);
10+
}
11+
12+
struct Foo;
13+
14+
impl MyTrait for Foo {
15+
type Assoc<'a, 'b> where 'b: 'a = u32;
16+
17+
fn do_sth(_: u32) {} //~ lifetime bound
18+
// fn do_sth(_: Self::Assoc<'static, 'static>) {}
19+
// fn do_sth(_: Self::Assoc<'_, '_>) {}
20+
}
21+
22+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0478]: lifetime bound not satisfied
2+
--> $DIR/issue-87748.rs:17:5
3+
|
4+
LL | fn do_sth(_: u32) {}
5+
| ^^^^^^^^^^^^^^^^^
6+
|
7+
note: lifetime parameter instantiated with the anonymous lifetime #2 defined here
8+
--> $DIR/issue-87748.rs:17:5
9+
|
10+
LL | fn do_sth(_: u32) {}
11+
| ^^^^^^^^^^^^^^^^^
12+
note: but lifetime parameter must outlive the anonymous lifetime #1 defined here
13+
--> $DIR/issue-87748.rs:17:5
14+
|
15+
LL | fn do_sth(_: u32) {}
16+
| ^^^^^^^^^^^^^^^^^
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0478`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// check-fail
2+
3+
// This should pass.
4+
5+
#![feature(generic_associated_types)]
6+
7+
use std::fmt::Debug;
8+
9+
trait Foo {
10+
type Ass where Self::Ass: Debug;
11+
}
12+
13+
#[derive(Debug)]
14+
struct Bar;
15+
16+
impl Foo for Bar {
17+
type Ass = Bar;
18+
//~^ overflow
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0275]: overflow evaluating the requirement `<Bar as Foo>::Ass == _`
2+
--> $DIR/issue-87755.rs:17:16
3+
|
4+
LL | type Ass = Bar;
5+
| ^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0275`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// check-fail
2+
3+
// This should pass, but using a type alias vs a reference directly
4+
// changes late-bound -> early-bound.
5+
6+
#![feature(generic_associated_types)]
7+
8+
trait Scanner {
9+
type Input<'a>;
10+
type Token<'a>;
11+
12+
fn scan<'a>(&mut self, i : Self::Input<'a>) -> Self::Token<'a>;
13+
}
14+
15+
struct IdScanner();
16+
17+
impl Scanner for IdScanner {
18+
type Input<'a> = &'a str;
19+
type Token<'a> = &'a str;
20+
21+
fn scan<'a>(&mut self, s : &'a str) -> &'a str { //~ lifetime parameters
22+
s
23+
}
24+
}
25+
26+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0195]: lifetime parameters or bounds on method `scan` do not match the trait declaration
2+
--> $DIR/issue-87803.rs:21:12
3+
|
4+
LL | fn scan<'a>(&mut self, i : Self::Input<'a>) -> Self::Token<'a>;
5+
| ---- lifetimes in impl do not match this method in trait
6+
...
7+
LL | fn scan<'a>(&mut self, s : &'a str) -> &'a str {
8+
| ^^^^ lifetimes do not match method in trait
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0195`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// check-fail
2+
3+
// This should pass, but has a missed normalization due to HRTB.
4+
5+
#![feature(generic_associated_types)]
6+
7+
trait Iterable {
8+
type Iterator<'a> where Self: 'a;
9+
fn iter(&self) -> Self::Iterator<'_>;
10+
}
11+
12+
struct SomeImplementation();
13+
14+
impl Iterable for SomeImplementation {
15+
type Iterator<'a> = std::iter::Empty<usize>;
16+
fn iter(&self) -> Self::Iterator<'_> {
17+
std::iter::empty()
18+
}
19+
}
20+
21+
fn do_something<I: Iterable>(i: I, mut f: impl for<'a> Fn(&mut I::Iterator<'a>)) {
22+
f(&mut i.iter());
23+
}
24+
25+
fn main() {
26+
do_something(SomeImplementation(), |_| ());
27+
do_something(SomeImplementation(), test);
28+
//~^ type mismatch
29+
}
30+
31+
fn test<'a, I: Iterable>(_: &mut I::Iterator<'a>) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0631]: type mismatch in function arguments
2+
--> $DIR/issue-88382.rs:27:40
3+
|
4+
LL | do_something(SomeImplementation(), test);
5+
| ------------ ^^^^ expected signature of `for<'a> fn(&mut <SomeImplementation as Iterable>::Iterator<'a>) -> _`
6+
| |
7+
| required by a bound introduced by this call
8+
...
9+
LL | fn test<'a, I: Iterable>(_: &mut I::Iterator<'a>) {}
10+
| ------------------------------------------------- found signature of `for<'r> fn(&'r mut std::iter::Empty<usize>) -> _`
11+
|
12+
note: required by a bound in `do_something`
13+
--> $DIR/issue-88382.rs:21:56
14+
|
15+
LL | fn do_something<I: Iterable>(i: I, mut f: impl for<'a> Fn(&mut I::Iterator<'a>)) {
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `do_something`
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0631`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// check-fail
2+
3+
// This should pass, but has a missed normalization due to HRTB.
4+
5+
#![feature(generic_associated_types)]
6+
7+
pub trait Marker {}
8+
9+
pub trait Trait {
10+
type Assoc<'a>;
11+
}
12+
13+
fn test<T>(value: T)
14+
where
15+
T: Trait,
16+
for<'a> T::Assoc<'a>: Marker,
17+
{
18+
}
19+
20+
impl Marker for () {}
21+
22+
struct Foo;
23+
24+
impl Trait for Foo {
25+
type Assoc<'a> = ();
26+
}
27+
28+
fn main() {
29+
test(Foo);
30+
//~^ the trait bound
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0277]: the trait bound `for<'a> <_ as Trait>::Assoc<'a>: Marker` is not satisfied
2+
--> $DIR/issue-88460.rs:29:5
3+
|
4+
LL | test(Foo);
5+
| ^^^^ the trait `for<'a> Marker` is not implemented for `<_ as Trait>::Assoc<'a>`
6+
|
7+
note: required by a bound in `test`
8+
--> $DIR/issue-88460.rs:16:27
9+
|
10+
LL | fn test<T>(value: T)
11+
| ---- required by a bound in this
12+
...
13+
LL | for<'a> T::Assoc<'a>: Marker,
14+
| ^^^^^^ required by this bound in `test`
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// check-fail
2+
3+
// This should pass, but requires more logic.
4+
5+
#![feature(generic_associated_types)]
6+
7+
trait A {
8+
type I<'a>;
9+
}
10+
11+
pub struct TestA<F>
12+
{
13+
f: F,
14+
}
15+
16+
impl<F> A for TestA<F> {
17+
type I<'a> = &'a F;
18+
}
19+
20+
struct TestB<Q, F>
21+
{
22+
q: Q,
23+
f: F,
24+
}
25+
26+
impl<'q, Q, I, F> A for TestB<Q, F> //~ the type parameter
27+
where
28+
Q: A<I<'q> = &'q I>,
29+
F: Fn(I),
30+
{
31+
type I<'a> = ();
32+
}
33+
34+
fn main() {}

0 commit comments

Comments
 (0)