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:
commit
e7f20335a6
26
src/test/ui/associated-type-bounds/issue-79949.rs
Normal file
26
src/test/ui/associated-type-bounds/issue-79949.rs
Normal 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() {}
|
60
src/test/ui/generic-associated-types/issue-70303.rs
Normal file
60
src/test/ui/generic-associated-types/issue-70303.rs
Normal 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);
|
||||
}
|
63
src/test/ui/generic-associated-types/issue-70304.rs
Normal file
63
src/test/ui/generic-associated-types/issue-70304.rs
Normal 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);
|
||||
}
|
15
src/test/ui/generic-associated-types/issue-70304.stderr
Normal file
15
src/test/ui/generic-associated-types/issue-70304.stderr
Normal 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`.
|
21
src/test/ui/generic-associated-types/issue-71176.rs
Normal file
21
src/test/ui/generic-associated-types/issue-71176.rs
Normal 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(()),
|
||||
};
|
||||
}
|
19
src/test/ui/generic-associated-types/issue-71176.stderr
Normal file
19
src/test/ui/generic-associated-types/issue-71176.stderr
Normal 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`.
|
14
src/test/ui/generic-associated-types/issue-78671.rs
Normal file
14
src/test/ui/generic-associated-types/issue-78671.rs
Normal 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() {}
|
19
src/test/ui/generic-associated-types/issue-78671.stderr
Normal file
19
src/test/ui/generic-associated-types/issue-78671.stderr
Normal 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`.
|
24
src/test/ui/generic-associated-types/issue-79636-1.rs
Normal file
24
src/test/ui/generic-associated-types/issue-79636-1.rs
Normal 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));
|
||||
}
|
19
src/test/ui/generic-associated-types/issue-79636-1.stderr
Normal file
19
src/test/ui/generic-associated-types/issue-79636-1.stderr
Normal 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`.
|
18
src/test/ui/generic-associated-types/issue-79636-2.rs
Normal file
18
src/test/ui/generic-associated-types/issue-79636-2.rs
Normal 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() {}
|
19
src/test/ui/generic-associated-types/issue-79636-2.stderr
Normal file
19
src/test/ui/generic-associated-types/issue-79636-2.stderr
Normal 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`.
|
Loading…
x
Reference in New Issue
Block a user