Skip to content
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

Add GAT related tests #84379

Merged
merged 6 commits into from
Apr 22, 2021
Merged
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
26 changes: 26 additions & 0 deletions src/test/ui/associated-type-bounds/issue-79949.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// check-pass

#![allow(incomplete_features)]
#![feature(associated_type_bounds)]
#![feature(generic_associated_types)]

trait MP {
type T<'a>;
}
struct S(String);
impl MP for S {
type T<'a> = &'a str;
}

trait SR: MP {
fn sr<IM>(&self) -> i32
where
for<'a> IM: T<T: U<<Self as MP>::T<'a>>>;
}

trait T {
type T;
}
trait U<X> {}

fn main() {}
60 changes: 60 additions & 0 deletions src/test/ui/generic-associated-types/issue-70303.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// check-pass

#![allow(incomplete_features)]
#![feature(generic_associated_types)]

trait Document {
type Cursor<'a>: DocCursor<'a>;

fn cursor(&self) -> Self::Cursor<'_>;
}

struct DocumentImpl {}

impl Document for DocumentImpl {
type Cursor<'a> = DocCursorImpl<'a>;

fn cursor(&self) -> Self::Cursor<'_> {
DocCursorImpl {
document: &self,
}
}
}


trait DocCursor<'a> {}

struct DocCursorImpl<'a> {
document: &'a DocumentImpl,
}

impl<'a> DocCursor<'a> for DocCursorImpl<'a> {}

struct Lexer<'d, Cursor>
where
Cursor: DocCursor<'d>,
{
cursor: Cursor,
_phantom: std::marker::PhantomData<&'d ()>,
}


impl<'d, Cursor> Lexer<'d, Cursor>
where
Cursor: DocCursor<'d>,
{
pub fn from<Doc>(document: &'d Doc) -> Lexer<'d, Cursor>
where
Doc: Document<Cursor<'d> = Cursor>,
{
Lexer {
cursor: document.cursor(),
_phantom: std::marker::PhantomData,
}
}
}

pub fn main() {
let doc = DocumentImpl {};
let lexer: Lexer<'_, DocCursorImpl<'_>> = Lexer::from(&doc);
}
63 changes: 63 additions & 0 deletions src/test/ui/generic-associated-types/issue-70304.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#![allow(incomplete_features)]
#![feature(generic_associated_types)]

trait Document {
type Cursor<'a>: DocCursor<'a>;

fn cursor(&self) -> Self::Cursor<'_>;
}

struct DocumentImpl {}

impl Document for DocumentImpl {
type Cursor<'a> = DocCursorImpl<'a>;

fn cursor(&self) -> Self::Cursor<'_> {
DocCursorImpl {
document: &self,
}
}
}


trait DocCursor<'a> {}

struct DocCursorImpl<'a> {
document: &'a DocumentImpl,
}

impl<'a> DocCursor<'a> for DocCursorImpl<'a> {}

struct Lexer<'d, Cursor>
where
Cursor: DocCursor<'d>,
{
cursor: Cursor,
_phantom: std::marker::PhantomData<&'d ()>,
}


impl<'d, Cursor> Lexer<'d, Cursor>
where
Cursor: DocCursor<'d>,
{
pub fn from<Doc>(document: &'d Doc) -> Lexer<'d, Cursor>
where
Doc: Document<Cursor<'d> = Cursor>,
{
Lexer {
cursor: document.cursor(),
_phantom: std::marker::PhantomData,
}
}
}

fn create_doc() -> impl Document<Cursor<'_> = DocCursorImpl<'_>> {
//~^ ERROR: missing lifetime specifier
DocumentImpl {}
}

pub fn main() {
let doc = create_doc();
let lexer: Lexer<'_, DocCursorImpl<'_>> = Lexer::from(&doc);
}
15 changes: 15 additions & 0 deletions src/test/ui/generic-associated-types/issue-70304.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0106]: missing lifetime specifier
--> $DIR/issue-70304.rs:55:41
|
LL | fn create_doc() -> impl Document<Cursor<'_> = DocCursorImpl<'_>> {
| ^^ expected named lifetime parameter
|
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
help: consider using the `'static` lifetime
|
LL | fn create_doc() -> impl Document<Cursor<'static> = DocCursorImpl<'_>> {
| ^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0106`.
21 changes: 21 additions & 0 deletions src/test/ui/generic-associated-types/issue-71176.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#![allow(incomplete_features)]
#![feature(generic_associated_types)]

trait Provider {
type A<'a>;
//~^ ERROR: missing generics for associated type
}

impl Provider for () {
type A<'a> = ();
}

struct Holder<B> {
inner: Box<dyn Provider<A = B>>,
}

fn main() {
Holder {
inner: Box::new(()),
};
}
19 changes: 19 additions & 0 deletions src/test/ui/generic-associated-types/issue-71176.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0107]: missing generics for associated type `Provider::A`
--> $DIR/issue-71176.rs:5:10
|
LL | type A<'a>;
| ^ expected 1 lifetime argument
|
note: associated type defined here, with 1 lifetime parameter: `'a`
--> $DIR/issue-71176.rs:5:10
|
LL | type A<'a>;
| ^ --
help: use angle brackets to add missing lifetime argument
|
LL | type A<'a><'a>;
| ^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0107`.
14 changes: 14 additions & 0 deletions src/test/ui/generic-associated-types/issue-78671.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![allow(incomplete_features)]
#![feature(generic_associated_types)]

trait CollectionFamily {
type Member<T>;
//~^ ERROR: missing generics for associated type
}
fn floatify() {
Box::new(Family) as &dyn CollectionFamily<Member=usize>
}

struct Family;

fn main() {}
19 changes: 19 additions & 0 deletions src/test/ui/generic-associated-types/issue-78671.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0107]: missing generics for associated type `CollectionFamily::Member`
--> $DIR/issue-78671.rs:5:10
|
LL | type Member<T>;
| ^^^^^^ expected 1 type argument
|
note: associated type defined here, with 1 type parameter: `T`
--> $DIR/issue-78671.rs:5:10
|
LL | type Member<T>;
| ^^^^^^ -
help: use angle brackets to add missing type argument
|
LL | type Member<T><T>;
| ^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0107`.
24 changes: 24 additions & 0 deletions src/test/ui/generic-associated-types/issue-79636-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![allow(incomplete_features)]
#![feature(generic_associated_types)]

trait Monad {
type Unwrapped;
type Wrapped<B>;
//~^ ERROR: missing generics for associated type `Monad::Wrapped`

fn bind<B, F>(self, f: F) -> Self::Wrapped<B> {
todo!()
}
}

fn join<MOuter, MInner, A>(outer: MOuter) -> MOuter::Wrapped<A>
where
MOuter: Monad<Unwrapped = MInner>,
MInner: Monad<Unwrapped = A, Wrapped = MOuter::Wrapped<A>>,
{
outer.bind(|inner| inner)
}

fn main() {
assert_eq!(join(Some(Some(true))), Some(true));
}
19 changes: 19 additions & 0 deletions src/test/ui/generic-associated-types/issue-79636-1.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0107]: missing generics for associated type `Monad::Wrapped`
--> $DIR/issue-79636-1.rs:6:10
|
LL | type Wrapped<B>;
| ^^^^^^^ expected 1 type argument
|
note: associated type defined here, with 1 type parameter: `B`
--> $DIR/issue-79636-1.rs:6:10
|
LL | type Wrapped<B>;
| ^^^^^^^ -
help: use angle brackets to add missing type argument
|
LL | type Wrapped<B><B>;
| ^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0107`.
18 changes: 18 additions & 0 deletions src/test/ui/generic-associated-types/issue-79636-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![allow(incomplete_features)]
#![feature(generic_associated_types)]

trait SomeTrait {
type Wrapped<A>: SomeTrait;
//~^ ERROR: missing generics for associated type `SomeTrait::Wrapped`

fn f() -> ();
}

fn program<W>() -> ()
where
W: SomeTrait<Wrapped = W>,
{
return W::f();
}

fn main() {}
19 changes: 19 additions & 0 deletions src/test/ui/generic-associated-types/issue-79636-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0107]: missing generics for associated type `SomeTrait::Wrapped`
--> $DIR/issue-79636-2.rs:5:10
|
LL | type Wrapped<A>: SomeTrait;
| ^^^^^^^ expected 1 type argument
|
note: associated type defined here, with 1 type parameter: `A`
--> $DIR/issue-79636-2.rs:5:10
|
LL | type Wrapped<A>: SomeTrait;
| ^^^^^^^ -
help: use angle brackets to add missing type argument
|
LL | type Wrapped<A><A>: SomeTrait;
| ^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0107`.