diff --git a/src/test/ui/associated-type-bounds/issue-79949.rs b/src/test/ui/associated-type-bounds/issue-79949.rs new file mode 100644 index 0000000000000..9f924f1fd81d8 --- /dev/null +++ b/src/test/ui/associated-type-bounds/issue-79949.rs @@ -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(&self) -> i32 + where + for<'a> IM: T::T<'a>>>; +} + +trait T { + type T; +} +trait U {} + +fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-70303.rs b/src/test/ui/generic-associated-types/issue-70303.rs new file mode 100644 index 0000000000000..a1cb2295b639e --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-70303.rs @@ -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(document: &'d Doc) -> Lexer<'d, Cursor> + where + Doc: Document = Cursor>, + { + Lexer { + cursor: document.cursor(), + _phantom: std::marker::PhantomData, + } + } +} + +pub fn main() { + let doc = DocumentImpl {}; + let lexer: Lexer<'_, DocCursorImpl<'_>> = Lexer::from(&doc); +} diff --git a/src/test/ui/generic-associated-types/issue-70304.rs b/src/test/ui/generic-associated-types/issue-70304.rs new file mode 100644 index 0000000000000..225f61d132ee6 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-70304.rs @@ -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(document: &'d Doc) -> Lexer<'d, Cursor> + where + Doc: Document = Cursor>, + { + Lexer { + cursor: document.cursor(), + _phantom: std::marker::PhantomData, + } + } +} + +fn create_doc() -> impl Document = DocCursorImpl<'_>> { + //~^ ERROR: missing lifetime specifier + DocumentImpl {} +} + +pub fn main() { + let doc = create_doc(); + let lexer: Lexer<'_, DocCursorImpl<'_>> = Lexer::from(&doc); +} diff --git a/src/test/ui/generic-associated-types/issue-70304.stderr b/src/test/ui/generic-associated-types/issue-70304.stderr new file mode 100644 index 0000000000000..dfa86018976dc --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-70304.stderr @@ -0,0 +1,15 @@ +error[E0106]: missing lifetime specifier + --> $DIR/issue-70304.rs:55:41 + | +LL | fn create_doc() -> impl Document = 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 = DocCursorImpl<'_>> { + | ^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0106`. diff --git a/src/test/ui/generic-associated-types/issue-71176.rs b/src/test/ui/generic-associated-types/issue-71176.rs new file mode 100644 index 0000000000000..470476bf476a0 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-71176.rs @@ -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 { + inner: Box>, +} + +fn main() { + Holder { + inner: Box::new(()), + }; +} diff --git a/src/test/ui/generic-associated-types/issue-71176.stderr b/src/test/ui/generic-associated-types/issue-71176.stderr new file mode 100644 index 0000000000000..dd19dd4ad8e83 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-71176.stderr @@ -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`. diff --git a/src/test/ui/generic-associated-types/issue-78671.rs b/src/test/ui/generic-associated-types/issue-78671.rs new file mode 100644 index 0000000000000..1b02aac8bcb24 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-78671.rs @@ -0,0 +1,14 @@ +#![allow(incomplete_features)] +#![feature(generic_associated_types)] + +trait CollectionFamily { + type Member; + //~^ ERROR: missing generics for associated type +} +fn floatify() { + Box::new(Family) as &dyn CollectionFamily +} + +struct Family; + +fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-78671.stderr b/src/test/ui/generic-associated-types/issue-78671.stderr new file mode 100644 index 0000000000000..7a9aced5beab8 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-78671.stderr @@ -0,0 +1,19 @@ +error[E0107]: missing generics for associated type `CollectionFamily::Member` + --> $DIR/issue-78671.rs:5:10 + | +LL | type Member; + | ^^^^^^ expected 1 type argument + | +note: associated type defined here, with 1 type parameter: `T` + --> $DIR/issue-78671.rs:5:10 + | +LL | type Member; + | ^^^^^^ - +help: use angle brackets to add missing type argument + | +LL | type Member; + | ^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0107`. diff --git a/src/test/ui/generic-associated-types/issue-79636-1.rs b/src/test/ui/generic-associated-types/issue-79636-1.rs new file mode 100644 index 0000000000000..17f9387e29204 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-79636-1.rs @@ -0,0 +1,24 @@ +#![allow(incomplete_features)] +#![feature(generic_associated_types)] + +trait Monad { + type Unwrapped; + type Wrapped; + //~^ ERROR: missing generics for associated type `Monad::Wrapped` + + fn bind(self, f: F) -> Self::Wrapped { + todo!() + } +} + +fn join(outer: MOuter) -> MOuter::Wrapped +where + MOuter: Monad, + MInner: Monad>, +{ + outer.bind(|inner| inner) +} + +fn main() { + assert_eq!(join(Some(Some(true))), Some(true)); +} diff --git a/src/test/ui/generic-associated-types/issue-79636-1.stderr b/src/test/ui/generic-associated-types/issue-79636-1.stderr new file mode 100644 index 0000000000000..58eeb43f70d66 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-79636-1.stderr @@ -0,0 +1,19 @@ +error[E0107]: missing generics for associated type `Monad::Wrapped` + --> $DIR/issue-79636-1.rs:6:10 + | +LL | type Wrapped; + | ^^^^^^^ expected 1 type argument + | +note: associated type defined here, with 1 type parameter: `B` + --> $DIR/issue-79636-1.rs:6:10 + | +LL | type Wrapped; + | ^^^^^^^ - +help: use angle brackets to add missing type argument + | +LL | type Wrapped; + | ^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0107`. diff --git a/src/test/ui/generic-associated-types/issue-79636-2.rs b/src/test/ui/generic-associated-types/issue-79636-2.rs new file mode 100644 index 0000000000000..5a6542193752b --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-79636-2.rs @@ -0,0 +1,18 @@ +#![allow(incomplete_features)] +#![feature(generic_associated_types)] + +trait SomeTrait { + type Wrapped: SomeTrait; + //~^ ERROR: missing generics for associated type `SomeTrait::Wrapped` + + fn f() -> (); +} + +fn program() -> () +where + W: SomeTrait, +{ + return W::f(); +} + +fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-79636-2.stderr b/src/test/ui/generic-associated-types/issue-79636-2.stderr new file mode 100644 index 0000000000000..d5e3c56ebb9ef --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-79636-2.stderr @@ -0,0 +1,19 @@ +error[E0107]: missing generics for associated type `SomeTrait::Wrapped` + --> $DIR/issue-79636-2.rs:5:10 + | +LL | type Wrapped: 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: SomeTrait; + | ^^^^^^^ - +help: use angle brackets to add missing type argument + | +LL | type Wrapped: SomeTrait; + | ^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0107`.