Rollup merge of #84379 - marmeladema:test-for-issue-79949, r=jackh726

Add GAT related tests

Closes #79949
Closes #79636
Closes #78671
Closes #70303
Closes #70304
Closes #71176
This commit is contained in:
Mara Bos 2021-04-21 23:06:19 +02:00 committed by GitHub
commit e7f20335a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 317 additions and 0 deletions

View File

@ -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() {}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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`.

View File

@ -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(()),
};
}

View File

@ -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`.

View File

@ -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() {}

View File

@ -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`.

View File

@ -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));
}

View File

@ -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`.

View File

@ -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() {}

View File

@ -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`.