From b6647b569262215f4f69a93b8e8121438c9db98b Mon Sep 17 00:00:00 2001 From: marmeladema Date: Tue, 20 Apr 2021 22:40:09 +0100 Subject: [PATCH 1/6] Add test for issue #79949 --- .../ui/associated-type-bounds/issue-79949.rs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/test/ui/associated-type-bounds/issue-79949.rs 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() {} From 19e51aaef7cf2f7a9e0e72168caf73a94a1cbfb1 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Tue, 20 Apr 2021 23:33:13 +0100 Subject: [PATCH 2/6] Add test for issue #79636 --- .../generic-associated-types/issue-79636-1.rs | 24 +++++++++++++++++++ .../issue-79636-1.stderr | 19 +++++++++++++++ .../generic-associated-types/issue-79636-2.rs | 18 ++++++++++++++ .../issue-79636-2.stderr | 19 +++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 src/test/ui/generic-associated-types/issue-79636-1.rs create mode 100644 src/test/ui/generic-associated-types/issue-79636-1.stderr create mode 100644 src/test/ui/generic-associated-types/issue-79636-2.rs create mode 100644 src/test/ui/generic-associated-types/issue-79636-2.stderr 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`. From 25cb1af7b232c93396b122ed6eb0887a388183f7 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Tue, 20 Apr 2021 23:41:40 +0100 Subject: [PATCH 3/6] Add test for issue #78671 --- .../generic-associated-types/issue-78671.rs | 14 ++++++++++++++ .../issue-78671.stderr | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/test/ui/generic-associated-types/issue-78671.rs create mode 100644 src/test/ui/generic-associated-types/issue-78671.stderr 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`. From 1ef760d88e8cbbc73ca53598f8de5536d1fbfac9 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Tue, 20 Apr 2021 23:49:04 +0100 Subject: [PATCH 4/6] Add test for issue #70303 --- .../generic-associated-types/issue-70303.rs | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/test/ui/generic-associated-types/issue-70303.rs 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); +} From cbd0d89a26a7688970af5c8cc9e455deafd3697d Mon Sep 17 00:00:00 2001 From: marmeladema Date: Tue, 20 Apr 2021 23:59:05 +0100 Subject: [PATCH 5/6] Add test for issue #70304 --- .../generic-associated-types/issue-70304.rs | 63 +++++++++++++++++++ .../issue-70304.stderr | 15 +++++ 2 files changed, 78 insertions(+) create mode 100644 src/test/ui/generic-associated-types/issue-70304.rs create mode 100644 src/test/ui/generic-associated-types/issue-70304.stderr 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`. From d328dbc60f51a70f0c6eeec644af303719e563a4 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Wed, 21 Apr 2021 00:07:42 +0100 Subject: [PATCH 6/6] Add test for issue #71176 --- .../generic-associated-types/issue-71176.rs | 21 +++++++++++++++++++ .../issue-71176.stderr | 19 +++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/test/ui/generic-associated-types/issue-71176.rs create mode 100644 src/test/ui/generic-associated-types/issue-71176.stderr 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`.