diff --git a/src/test/ui/generic-associated-types/gat-in-trait-path-undeclared-lifetime.rs b/src/test/ui/generic-associated-types/gat-in-trait-path-undeclared-lifetime.rs new file mode 100644 index 0000000000000..2c543455b6ebd --- /dev/null +++ b/src/test/ui/generic-associated-types/gat-in-trait-path-undeclared-lifetime.rs @@ -0,0 +1,12 @@ +#![feature(generic_associated_types)] + //~^ WARNING: the feature `generic_associated_types` is incomplete + +trait X { + type Y<'x>; +} + +fn main() { + fn _f(arg : Box X = &'a [u32]>>) {} + //~^ ERROR: use of undeclared lifetime name `'x` + //~| ERROR: binding for associated type `Y` references lifetime +} diff --git a/src/test/ui/generic-associated-types/gat-in-trait-path-undeclared-lifetime.stderr b/src/test/ui/generic-associated-types/gat-in-trait-path-undeclared-lifetime.stderr new file mode 100644 index 0000000000000..1c7c107d78354 --- /dev/null +++ b/src/test/ui/generic-associated-types/gat-in-trait-path-undeclared-lifetime.stderr @@ -0,0 +1,29 @@ +warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/gat-in-trait-path-undeclared-lifetime.rs:1:12 + | +LL | #![feature(generic_associated_types)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #44265 for more information + +error[E0261]: use of undeclared lifetime name `'x` + --> $DIR/gat-in-trait-path-undeclared-lifetime.rs:9:35 + | +LL | fn _f(arg : Box X = &'a [u32]>>) {} + | - ^^ undeclared lifetime + | | + | help: consider introducing lifetime `'x` here: `<'x>` + | + = help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes + +error[E0582]: binding for associated type `Y` references lifetime `'a`, which does not appear in the trait input types + --> $DIR/gat-in-trait-path-undeclared-lifetime.rs:9:33 + | +LL | fn _f(arg : Box X = &'a [u32]>>) {} + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors; 1 warning emitted + +Some errors have detailed explanations: E0261, E0582. +For more information about an error, try `rustc --explain E0261`. diff --git a/src/test/ui/generic-associated-types/gat-in-trait-path.rs b/src/test/ui/generic-associated-types/gat-in-trait-path.rs new file mode 100644 index 0000000000000..2dbd1840dec55 --- /dev/null +++ b/src/test/ui/generic-associated-types/gat-in-trait-path.rs @@ -0,0 +1,30 @@ +// check-pass + +#![feature(generic_associated_types)] + //~^ WARNING: the feature `generic_associated_types` is incomplete +#![feature(associated_type_defaults)] + +trait Foo { + type A<'a> where Self: 'a; +} + +struct Fooy; + +impl Foo for Fooy { + type A<'a> = &'a (); +} + +#[derive(Clone)] +struct Fooer(T); + +impl Foo for Fooer { + type A<'x> where T: 'x = &'x (); +} + +fn f(_arg : Box Foo = &'a ()>>) {} + + +fn main() { + let foo = Fooer(5); + f(Box::new(foo)); +} diff --git a/src/test/ui/generic-associated-types/gat-in-trait-path.stderr b/src/test/ui/generic-associated-types/gat-in-trait-path.stderr new file mode 100644 index 0000000000000..f3769827f04b2 --- /dev/null +++ b/src/test/ui/generic-associated-types/gat-in-trait-path.stderr @@ -0,0 +1,11 @@ +warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/gat-in-trait-path.rs:3:12 + | +LL | #![feature(generic_associated_types)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #44265 for more information + +warning: 1 warning emitted + diff --git a/src/test/ui/generic-associated-types/gat-trait-path-generic-type-arg.rs b/src/test/ui/generic-associated-types/gat-trait-path-generic-type-arg.rs new file mode 100644 index 0000000000000..cff5a21052f9b --- /dev/null +++ b/src/test/ui/generic-associated-types/gat-trait-path-generic-type-arg.rs @@ -0,0 +1,16 @@ +#![feature(generic_associated_types)] + //~^ WARNING: the feature `generic_associated_types` is incomplete + +trait Foo { + type F<'a>; + + fn identity<'a>(t: &'a Self::F<'a>) -> &'a Self::F<'a> { t } +} + +impl Foo for T { + type F = &[u8]; + //~^ ERROR: the name `T1` is already used for + //~| ERROR: missing lifetime specifier +} + +fn main() {} diff --git a/src/test/ui/generic-associated-types/gat-trait-path-generic-type-arg.stderr b/src/test/ui/generic-associated-types/gat-trait-path-generic-type-arg.stderr new file mode 100644 index 0000000000000..e83af1d0c739d --- /dev/null +++ b/src/test/ui/generic-associated-types/gat-trait-path-generic-type-arg.stderr @@ -0,0 +1,32 @@ +error[E0403]: the name `T1` is already used for a generic parameter in this item's generic parameters + --> $DIR/gat-trait-path-generic-type-arg.rs:11:12 + | +LL | impl Foo for T { + | -- first use of `T1` +LL | type F = &[u8]; + | ^^ already used + +warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/gat-trait-path-generic-type-arg.rs:1:12 + | +LL | #![feature(generic_associated_types)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #44265 for more information + +error[E0106]: missing lifetime specifier + --> $DIR/gat-trait-path-generic-type-arg.rs:11:18 + | +LL | type F = &[u8]; + | ^ expected named lifetime parameter + | +help: consider introducing a named lifetime parameter + | +LL | type F<'a, T1> = &'a [u8]; + | ^^^ ^^^ + +error: aborting due to 2 previous errors; 1 warning emitted + +Some errors have detailed explanations: E0106, E0403. +For more information about an error, try `rustc --explain E0106`. diff --git a/src/test/ui/generic-associated-types/gat-trait-path-missing-lifetime.rs b/src/test/ui/generic-associated-types/gat-trait-path-missing-lifetime.rs new file mode 100644 index 0000000000000..e69e355ba48e5 --- /dev/null +++ b/src/test/ui/generic-associated-types/gat-trait-path-missing-lifetime.rs @@ -0,0 +1,18 @@ +#![feature(generic_associated_types)] + //~^ WARNING: the feature `generic_associated_types` is incomplete + +trait X { + type Y<'a>; + //~^ ERROR missing generics for + //~| ERROR missing generics for + + fn foo<'a>(t : Self::Y<'a>) -> Self::Y<'a> { t } +} + +impl X for T { + fn foo<'a, T1: X>(t : T1) -> T1::Y<'a> { + t + } +} + +fn main() {} diff --git a/src/test/ui/generic-associated-types/gat-trait-path-missing-lifetime.stderr b/src/test/ui/generic-associated-types/gat-trait-path-missing-lifetime.stderr new file mode 100644 index 0000000000000..9c6e2ce3e17a3 --- /dev/null +++ b/src/test/ui/generic-associated-types/gat-trait-path-missing-lifetime.stderr @@ -0,0 +1,44 @@ +warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/gat-trait-path-missing-lifetime.rs:1:12 + | +LL | #![feature(generic_associated_types)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #44265 for more information + +error[E0107]: missing generics for associated type `X::Y` + --> $DIR/gat-trait-path-missing-lifetime.rs:5:8 + | +LL | type Y<'a>; + | ^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/gat-trait-path-missing-lifetime.rs:5:8 + | +LL | type Y<'a>; + | ^ -- +help: use angle brackets to add missing lifetime argument + | +LL | type Y<'a><'a>; + | ^^^^ + +error[E0107]: missing generics for associated type `X::Y` + --> $DIR/gat-trait-path-missing-lifetime.rs:5:8 + | +LL | type Y<'a>; + | ^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/gat-trait-path-missing-lifetime.rs:5:8 + | +LL | type Y<'a>; + | ^ -- +help: use angle brackets to add missing lifetime argument + | +LL | type Y<'a><'a>; + | ^^^^ + +error: aborting due to 2 previous errors; 1 warning emitted + +For more information about this error, try `rustc --explain E0107`. diff --git a/src/test/ui/generic-associated-types/gat-trait-path-parenthesised-args.rs b/src/test/ui/generic-associated-types/gat-trait-path-parenthesised-args.rs new file mode 100644 index 0000000000000..bb1f27a17ca4c --- /dev/null +++ b/src/test/ui/generic-associated-types/gat-trait-path-parenthesised-args.rs @@ -0,0 +1,15 @@ +#![feature(generic_associated_types)] + //~^ WARNING: the feature `generic_associated_types` is incomplete + +trait X { + type Y<'a>; + //~^ ERROR this associated type + //~| ERROR this associated type +} + +fn foo<'a>(arg: Box>) {} + //~^ ERROR: lifetime in trait object type must be followed by `+` + //~| ERROR: parenthesized generic arguments cannot be used + //~| WARNING: trait objects without an explicit `dyn` are deprecated + +fn main() {} diff --git a/src/test/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr b/src/test/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr new file mode 100644 index 0000000000000..20cb6d8828755 --- /dev/null +++ b/src/test/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr @@ -0,0 +1,68 @@ +error: lifetime in trait object type must be followed by `+` + --> $DIR/gat-trait-path-parenthesised-args.rs:10:29 + | +LL | fn foo<'a>(arg: Box>) {} + | ^^ + +error: parenthesized generic arguments cannot be used in associated type constraints + --> $DIR/gat-trait-path-parenthesised-args.rs:10:27 + | +LL | fn foo<'a>(arg: Box>) {} + | ^^^^^ + +warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/gat-trait-path-parenthesised-args.rs:1:12 + | +LL | #![feature(generic_associated_types)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #44265 for more information + +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/gat-trait-path-parenthesised-args.rs:10:29 + | +LL | fn foo<'a>(arg: Box>) {} + | ^^ help: use `dyn`: `dyn 'a` + | + = note: `#[warn(bare_trait_objects)]` on by default + +error[E0107]: this associated type takes 1 lifetime argument but 0 lifetime arguments were supplied + --> $DIR/gat-trait-path-parenthesised-args.rs:5:8 + | +LL | type Y<'a>; + | ^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/gat-trait-path-parenthesised-args.rs:5:8 + | +LL | type Y<'a>; + | ^ -- +help: add missing lifetime argument + | +LL | fn foo<'a>(arg: Box>) {} + | ^^ + +error[E0107]: this associated type takes 0 type arguments but 1 type argument was supplied + --> $DIR/gat-trait-path-parenthesised-args.rs:5:8 + | +LL | type Y<'a>; + | ________^- + | | | + | | expected 0 type arguments +LL | | +LL | | +LL | | } +LL | | +LL | | fn foo<'a>(arg: Box>) {} + | |_________________________________________- help: remove these generics + | +note: associated type defined here, with 0 type parameters + --> $DIR/gat-trait-path-parenthesised-args.rs:5:8 + | +LL | type Y<'a>; + | ^ + +error: aborting due to 4 previous errors; 2 warnings emitted + +For more information about this error, try `rustc --explain E0107`. diff --git a/src/test/ui/generic-associated-types/issue-67510-pass.rs b/src/test/ui/generic-associated-types/issue-67510-pass.rs new file mode 100644 index 0000000000000..ff38b3e93eb1a --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-67510-pass.rs @@ -0,0 +1,12 @@ +// check-pass + +#![feature(generic_associated_types)] + //~^ WARNING: the feature `generic_associated_types` is incomplete + +trait X { + type Y<'a>; +} + +fn _func1<'a>(_x: Box=&'a ()>>) {} + +fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-67510-pass.stderr b/src/test/ui/generic-associated-types/issue-67510-pass.stderr new file mode 100644 index 0000000000000..0fbf704df76a1 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-67510-pass.stderr @@ -0,0 +1,11 @@ +warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/issue-67510-pass.rs:3:12 + | +LL | #![feature(generic_associated_types)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #44265 for more information + +warning: 1 warning emitted + diff --git a/src/test/ui/generic-associated-types/issue-67510.rs b/src/test/ui/generic-associated-types/issue-67510.rs new file mode 100644 index 0000000000000..62b22089f917c --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-67510.rs @@ -0,0 +1,13 @@ +#![feature(generic_associated_types)] + //~^ WARNING: the feature `generic_associated_types` is incomplete + +trait X { + type Y<'a>; +} + +fn f(x: Box=&'a ()>>) {} + //~^ ERROR: use of undeclared lifetime name `'a` + //~| ERROR: use of undeclared lifetime name `'a` + + +fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-67510.stderr b/src/test/ui/generic-associated-types/issue-67510.stderr new file mode 100644 index 0000000000000..12755c56974f2 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-67510.stderr @@ -0,0 +1,32 @@ +warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/issue-67510.rs:1:12 + | +LL | #![feature(generic_associated_types)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #44265 for more information + +error[E0261]: use of undeclared lifetime name `'a` + --> $DIR/issue-67510.rs:8:21 + | +LL | fn f(x: Box=&'a ()>>) {} + | - ^^ undeclared lifetime + | | + | help: consider introducing lifetime `'a` here: `<'a>` + | + = help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes + +error[E0261]: use of undeclared lifetime name `'a` + --> $DIR/issue-67510.rs:8:26 + | +LL | fn f(x: Box=&'a ()>>) {} + | - ^^ undeclared lifetime + | | + | help: consider introducing lifetime `'a` here: `<'a>` + | + = help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes + +error: aborting due to 2 previous errors; 1 warning emitted + +For more information about this error, try `rustc --explain E0261`. diff --git a/src/test/ui/generic-associated-types/issue-68648-1.rs b/src/test/ui/generic-associated-types/issue-68648-1.rs new file mode 100644 index 0000000000000..f294b22f73c67 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-68648-1.rs @@ -0,0 +1,26 @@ +// check-pass + +#![feature(generic_associated_types)] + //~^ WARNING: the feature `generic_associated_types` is incomplete + + +trait Fun { + type F<'a>; + + fn identity<'a>(t: Self::F<'a>) -> Self::F<'a> { t } +} + +impl Fun for T { + type F<'a> = Self; +} + +fn bug<'a, T: for<'b> Fun = T>>(t: T) -> T::F<'a> { + T::identity(t) +} + + +fn main() { + let x = 10; + + bug(x); +} diff --git a/src/test/ui/generic-associated-types/issue-68648-1.stderr b/src/test/ui/generic-associated-types/issue-68648-1.stderr new file mode 100644 index 0000000000000..322a8f9e13f81 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-68648-1.stderr @@ -0,0 +1,11 @@ +warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/issue-68648-1.rs:3:12 + | +LL | #![feature(generic_associated_types)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #44265 for more information + +warning: 1 warning emitted + diff --git a/src/test/ui/generic-associated-types/issue-68648-2.rs b/src/test/ui/generic-associated-types/issue-68648-2.rs new file mode 100644 index 0000000000000..e55bfcd4ba295 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-68648-2.rs @@ -0,0 +1,24 @@ +#![feature(generic_associated_types)] + //~^ WARNING: the feature `generic_associated_types` is incomplete + +trait Fun { + type F<'a>; + + fn identity<'a>(t: Self::F<'a>) -> Self::F<'a> { t } +} + +impl Fun for T { + type F<'a> = Self; +} + +fn bug<'a, T: Fun = T>>(t: T) -> T::F<'a> { + T::identity(()) + //~^ ERROR: mismatched types +} + + +fn main() { + let x = 10; + + bug(x); +} diff --git a/src/test/ui/generic-associated-types/issue-68648-2.stderr b/src/test/ui/generic-associated-types/issue-68648-2.stderr new file mode 100644 index 0000000000000..b51e0bca9f7a9 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-68648-2.stderr @@ -0,0 +1,23 @@ +warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/issue-68648-2.rs:1:12 + | +LL | #![feature(generic_associated_types)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #44265 for more information + +error[E0308]: mismatched types + --> $DIR/issue-68648-2.rs:15:17 + | +LL | fn bug<'a, T: Fun = T>>(t: T) -> T::F<'a> { + | - this type parameter +LL | T::identity(()) + | ^^ expected type parameter `T`, found `()` + | + = note: expected type parameter `T` + found unit type `()` + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/generic-associated-types/issue-68649-pass.rs b/src/test/ui/generic-associated-types/issue-68649-pass.rs new file mode 100644 index 0000000000000..396315302f74c --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-68649-pass.rs @@ -0,0 +1,25 @@ +// check-pass + +#![feature(generic_associated_types)] + //~^ WARNING: the feature `generic_associated_types` is incomplete + +trait Fun { + type F<'a>; + + fn identity<'a>(t: Self::F<'a>) -> Self::F<'a> { t } +} + +impl Fun for T { + type F<'a> = Self; +} + +fn bug<'a, T: Fun = T>>(t: T) -> T::F<'a> { + T::identity(t) +} + + +fn main() { + let x = 10; + + bug(x); +} diff --git a/src/test/ui/generic-associated-types/issue-68649-pass.stderr b/src/test/ui/generic-associated-types/issue-68649-pass.stderr new file mode 100644 index 0000000000000..e4a2f8d2a6401 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-68649-pass.stderr @@ -0,0 +1,11 @@ +warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/issue-68649-pass.rs:3:12 + | +LL | #![feature(generic_associated_types)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #44265 for more information + +warning: 1 warning emitted + diff --git a/src/test/ui/generic-associated-types/issue-74684-1.rs b/src/test/ui/generic-associated-types/issue-74684-1.rs new file mode 100644 index 0000000000000..a483da863ff00 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-74684-1.rs @@ -0,0 +1,26 @@ +#![feature(generic_associated_types)] + //~^ WARNING: the feature `generic_associated_types` is incomplete + +trait Fun { + type F<'a>: ?Sized; + + fn identity<'a>(t: &'a Self::F<'a>) -> &'a Self::F<'a> { t } +} + +impl Fun for T { + type F<'a> = [u8]; +} + +fn bug<'a, T: ?Sized + Fun = [u8]>>(_ : Box) -> &'static T::F<'a> { + let a = [0; 1]; + let _x = T::identity(&a); + //~^ ERROR: `a` does not live long enough + todo!() +} + + +fn main() { + let x = 10; + + bug(Box::new(x)); +} diff --git a/src/test/ui/generic-associated-types/issue-74684-1.stderr b/src/test/ui/generic-associated-types/issue-74684-1.stderr new file mode 100644 index 0000000000000..651da696827c3 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-74684-1.stderr @@ -0,0 +1,27 @@ +warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/issue-74684-1.rs:1:12 + | +LL | #![feature(generic_associated_types)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #44265 for more information + +error[E0597]: `a` does not live long enough + --> $DIR/issue-74684-1.rs:16:26 + | +LL | fn bug<'a, T: ?Sized + Fun = [u8]>>(_ : Box) -> &'static T::F<'a> { + | -- lifetime `'a` defined here +LL | let a = [0; 1]; +LL | let _x = T::identity(&a); + | ------------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `a` is borrowed for `'a` +... +LL | } + | - `a` dropped here while still borrowed + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/generic-associated-types/issue-74684-2.rs b/src/test/ui/generic-associated-types/issue-74684-2.rs new file mode 100644 index 0000000000000..0caf19cb03038 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-74684-2.rs @@ -0,0 +1,26 @@ +#![feature(generic_associated_types)] + //~^ WARNING: the feature `generic_associated_types` is incomplete + +trait Fun { + type F<'a>: ?Sized; + + fn identity<'a>(t: &'a Self::F<'a>) -> &'a Self::F<'a> { t } +} + +impl Fun for T { + type F<'a> = i32; +} + +fn bug<'a, T: ?Sized + Fun = [u8]>>(t: Box) -> &'static T::F<'a> { + let a = [0; 1]; + let x = T::identity(&a); + todo!() +} + + +fn main() { + let x = 10; + + bug(Box::new(x)); + //~^ ERROR: type mismatch resolving `<{integer} as Fun>::F<'_> == [u8]` +} diff --git a/src/test/ui/generic-associated-types/issue-74684-2.stderr b/src/test/ui/generic-associated-types/issue-74684-2.stderr new file mode 100644 index 0000000000000..8c3484f9a7300 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-74684-2.stderr @@ -0,0 +1,21 @@ +warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/issue-74684-2.rs:1:12 + | +LL | #![feature(generic_associated_types)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #44265 for more information + +error[E0271]: type mismatch resolving `<{integer} as Fun>::F<'_> == [u8]` + --> $DIR/issue-74684-2.rs:24:5 + | +LL | fn bug<'a, T: ?Sized + Fun = [u8]>>(t: Box) -> &'static T::F<'a> { + | ------------ required by this bound in `bug` +... +LL | bug(Box::new(x)); + | ^^^ expected slice `[u8]`, found `i32` + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0271`. diff --git a/src/test/ui/generic-associated-types/issue-76535.rs b/src/test/ui/generic-associated-types/issue-76535.rs new file mode 100644 index 0000000000000..2b4757d8d15ed --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-76535.rs @@ -0,0 +1,41 @@ +#![feature(generic_associated_types)] + //~^ WARNING the feature + +pub trait SubTrait {} + +pub trait SuperTrait { + type SubType<'a>: SubTrait; + //~^ ERROR missing generics for associated + + fn get_sub<'a>(&'a mut self) -> Self::SubType<'a>; +} + +pub struct SubStruct<'a> { + sup: &'a mut SuperStruct, +} + +impl<'a> SubTrait for SubStruct<'a> {} + +pub struct SuperStruct { + value: u8, +} + +impl SuperStruct { + pub fn new(value: u8) -> SuperStruct { + SuperStruct { value } + } +} + +impl SuperTrait for SuperStruct { + type SubType<'a> = SubStruct<'a>; + + fn get_sub<'a>(&'a mut self) -> Self::SubType<'a> { + SubStruct { sup: self } + } +} + +fn main() { + let sub: Box> = Box::new(SuperStruct::new(0)); + //~^ ERROR the trait + //~| ERROR the trait +} diff --git a/src/test/ui/generic-associated-types/issue-76535.stderr b/src/test/ui/generic-associated-types/issue-76535.stderr new file mode 100644 index 0000000000000..ce4875af9c012 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-76535.stderr @@ -0,0 +1,63 @@ +warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/issue-76535.rs:1:12 + | +LL | #![feature(generic_associated_types)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #44265 for more information + +error[E0107]: missing generics for associated type `SuperTrait::SubType` + --> $DIR/issue-76535.rs:7:10 + | +LL | type SubType<'a>: SubTrait; + | ^^^^^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-76535.rs:7:10 + | +LL | type SubType<'a>: SubTrait; + | ^^^^^^^ -- +help: use angle brackets to add missing lifetime argument + | +LL | type SubType<'a><'a>: SubTrait; + | ^^^^ + +error[E0038]: the trait `SuperTrait` cannot be made into an object + --> $DIR/issue-76535.rs:38:14 + | +LL | let sub: Box> = Box::new(SuperStruct::new(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SuperTrait` cannot be made into an object + | + = help: consider moving `get_sub` to another trait +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/issue-76535.rs:10:37 + | +LL | pub trait SuperTrait { + | ---------- this trait cannot be made into an object... +... +LL | fn get_sub<'a>(&'a mut self) -> Self::SubType<'a>; + | ^^^^^^^^^^^^^^^^^ ...because method `get_sub` references the `Self` type in its return type + +error[E0038]: the trait `SuperTrait` cannot be made into an object + --> $DIR/issue-76535.rs:38:57 + | +LL | let sub: Box> = Box::new(SuperStruct::new(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SuperTrait` cannot be made into an object + | + = help: consider moving `get_sub` to another trait +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/issue-76535.rs:10:37 + | +LL | pub trait SuperTrait { + | ---------- this trait cannot be made into an object... +... +LL | fn get_sub<'a>(&'a mut self) -> Self::SubType<'a>; + | ^^^^^^^^^^^^^^^^^ ...because method `get_sub` references the `Self` type in its return type + = note: required because of the requirements on the impl of `CoerceUnsized>>>` for `Box` + = note: required by cast to type `Box>>` + +error: aborting due to 3 previous errors; 1 warning emitted + +Some errors have detailed explanations: E0038, E0107. +For more information about an error, try `rustc --explain E0038`. diff --git a/src/test/ui/generic-associated-types/issue-79422.rs b/src/test/ui/generic-associated-types/issue-79422.rs new file mode 100644 index 0000000000000..26b38430dd9a5 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-79422.rs @@ -0,0 +1,47 @@ +#![allow(incomplete_features)] +#![feature(generic_associated_types)] + +trait RefCont<'a, T> { + fn t(&'a self) -> &'a T; +} + +impl<'a, T> RefCont<'a, T> for &'a T { + fn t(&'a self) -> &'a T { + self + } +} + +impl<'a, T> RefCont<'a, T> for Box { + fn t(&'a self) -> &'a T { + self.as_ref() + } +} + +trait MapLike { + type VRefCont<'a>: RefCont<'a, V>; + //~^ ERROR missing generics + fn get<'a>(&'a self, key: &K) -> Option>; +} + +impl MapLike for std::collections::BTreeMap { + type VRefCont<'a> = &'a V; + fn get<'a>(&'a self, key: &K) -> Option<&'a V> { + std::collections::BTreeMap::get(self, key) + } +} + +struct Source; + +impl MapLike for Source { + type VRefCont<'a> = Box; + fn get<'a>(&self, _: &K) -> Option> { + Some(Box::new(V::default())) + } +} + +fn main() { + let m = Box::new(std::collections::BTreeMap::::new()) + as Box>>; + //~^ ERROR the trait + //~^^^ ERROR the trait +} diff --git a/src/test/ui/generic-associated-types/issue-79422.stderr b/src/test/ui/generic-associated-types/issue-79422.stderr new file mode 100644 index 0000000000000..d2e12962715f0 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-79422.stderr @@ -0,0 +1,54 @@ +error[E0107]: missing generics for associated type `MapLike::VRefCont` + --> $DIR/issue-79422.rs:21:10 + | +LL | type VRefCont<'a>: RefCont<'a, V>; + | ^^^^^^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-79422.rs:21:10 + | +LL | type VRefCont<'a>: RefCont<'a, V>; + | ^^^^^^^^ -- +help: use angle brackets to add missing lifetime argument + | +LL | type VRefCont<'a><'a>: RefCont<'a, V>; + | ^^^^ + +error[E0038]: the trait `MapLike` cannot be made into an object + --> $DIR/issue-79422.rs:44:12 + | +LL | as Box>>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `MapLike` cannot be made into an object + | + = help: consider moving `get` to another trait +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/issue-79422.rs:23:38 + | +LL | trait MapLike { + | ------- this trait cannot be made into an object... +... +LL | fn get<'a>(&'a self, key: &K) -> Option>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...because method `get` references the `Self` type in its return type + +error[E0038]: the trait `MapLike` cannot be made into an object + --> $DIR/issue-79422.rs:43:13 + | +LL | let m = Box::new(std::collections::BTreeMap::::new()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `MapLike` cannot be made into an object + | + = help: consider moving `get` to another trait +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/issue-79422.rs:23:38 + | +LL | trait MapLike { + | ------- this trait cannot be made into an object... +... +LL | fn get<'a>(&'a self, key: &K) -> Option>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...because method `get` references the `Self` type in its return type + = note: required because of the requirements on the impl of `CoerceUnsized + 'static)>>>` for `Box>` + = note: required by cast to type `Box + 'static)>>` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0038, E0107. +For more information about an error, try `rustc --explain E0038`. diff --git a/src/test/ui/generic-associated-types/issue-80433-reduced.rs b/src/test/ui/generic-associated-types/issue-80433-reduced.rs new file mode 100644 index 0000000000000..7c1673edc51a4 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-80433-reduced.rs @@ -0,0 +1,24 @@ +// check-pass + +#![allow(incomplete_features)] +#![feature(generic_associated_types)] + +struct E {} + +trait TestMut { + type Output<'a>; + fn test_mut(&mut self) -> Self::Output<'static>; +} + +impl TestMut for E { + type Output<'a> = usize; + fn test_mut(&mut self) -> Self::Output<'static> { + todo!() + } +} + +fn test_simpler<'a>(_: impl TestMut = usize>) {} + +fn main() { + test_simpler(E {}); +} diff --git a/src/test/ui/generic-associated-types/issue-80433.rs b/src/test/ui/generic-associated-types/issue-80433.rs new file mode 100644 index 0000000000000..ea65f05de23d7 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-80433.rs @@ -0,0 +1,35 @@ +#![feature(generic_associated_types)] +#![allow(incomplete_features)] + +#[derive(Default)] +struct E { + data: T, +} + +trait TestMut { + type Output<'a>; + //~^ ERROR missing generics + fn test_mut<'a>(&'a mut self) -> Self::Output<'a>; +} + +impl TestMut for E +where + T: 'static, +{ + type Output<'a> = &'a mut T; + fn test_mut<'a>(&'a mut self) -> Self::Output<'a> { + &mut self.data + } +} + +fn test_simpler<'a>(dst: &'a mut impl TestMut) +{ + for n in 0i16..100 { + *dst.test_mut() = n.into(); + } +} + +fn main() { + let mut t1: E = Default::default(); + test_simpler(&mut t1); +} diff --git a/src/test/ui/generic-associated-types/issue-80433.stderr b/src/test/ui/generic-associated-types/issue-80433.stderr new file mode 100644 index 0000000000000..5398920fafdb0 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-80433.stderr @@ -0,0 +1,19 @@ +error[E0107]: missing generics for associated type `TestMut::Output` + --> $DIR/issue-80433.rs:10:10 + | +LL | type Output<'a>; + | ^^^^^^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/issue-80433.rs:10:10 + | +LL | type Output<'a>; + | ^^^^^^ -- +help: use angle brackets to add missing lifetime argument + | +LL | type Output<'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/parse/trait-path-type-error-once-implemented.rs b/src/test/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.rs index e203a5e0d2de6..2d38770bcdff8 100644 --- a/src/test/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.rs +++ b/src/test/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.rs @@ -1,10 +1,14 @@ #![feature(generic_associated_types)] + //~^ the feature `generic_associated_types` is incomplete trait X { type Y<'a>; + //~^ ERROR this associated type + //~| ERROR this associated type } const _: () = { fn f2<'a>(arg : Box = &'a ()>>) {} - //~^ ERROR: generic associated types in trait paths are currently not implemented }; + +fn main() {} diff --git a/src/test/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr b/src/test/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr index e59a72a99eeb9..60b8fb9bcaa23 100644 --- a/src/test/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr +++ b/src/test/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.stderr @@ -1,8 +1,49 @@ -error: generic associated types in trait paths are currently not implemented - --> $DIR/trait-path-type-error-once-implemented.rs:8:30 +warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/trait-path-type-error-once-implemented.rs:1:12 | -LL | fn f2<'a>(arg : Box = &'a ()>>) {} - | ^^^ +LL | #![feature(generic_associated_types)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #44265 for more information + +error[E0107]: this associated type takes 1 lifetime argument but 0 lifetime arguments were supplied + --> $DIR/trait-path-type-error-once-implemented.rs:5:10 + | +LL | type Y<'a>; + | ^ expected 1 lifetime argument + | +note: associated type defined here, with 1 lifetime parameter: `'a` + --> $DIR/trait-path-type-error-once-implemented.rs:5:10 + | +LL | type Y<'a>; + | ^ -- +help: add missing lifetime argument + | +LL | fn f2<'a>(arg : Box = &'a ()>>) {} + | ^^ + +error[E0107]: this associated type takes 0 const arguments but 1 const argument was supplied + --> $DIR/trait-path-type-error-once-implemented.rs:5:10 + | +LL | type Y<'a>; + | __________^- + | | | + | | expected 0 const arguments +LL | | +LL | | +LL | | } +LL | | +LL | | const _: () = { +LL | | fn f2<'a>(arg : Box = &'a ()>>) {} + | |________________________________- help: remove these generics + | +note: associated type defined here, with 0 const parameters + --> $DIR/trait-path-type-error-once-implemented.rs:5:10 + | +LL | type Y<'a>; + | ^ -error: aborting due to previous error +error: aborting due to 2 previous errors; 1 warning emitted +For more information about this error, try `rustc --explain E0107`. diff --git a/src/test/ui/generic-associated-types/parse/trait-path-unimplemented.rs b/src/test/ui/generic-associated-types/parse/trait-path-unimplemented.rs deleted file mode 100644 index 02d53d5faeec5..0000000000000 --- a/src/test/ui/generic-associated-types/parse/trait-path-unimplemented.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![feature(generic_associated_types)] - -trait X { - type Y<'a>; -} - -const _: () = { - fn f1<'a>(arg : Box = &'a ()>>) {} - //~^ ERROR: generic associated types in trait paths are currently not implemented -}; - -const _: () = { - fn f1<'a>(arg : Box>) {} - //~^ ERROR: lifetime in trait object type must be followed by `+` -}; - -fn main() {} diff --git a/src/test/ui/generic-associated-types/parse/trait-path-unimplemented.stderr b/src/test/ui/generic-associated-types/parse/trait-path-unimplemented.stderr deleted file mode 100644 index 1fba9cebd2491..0000000000000 --- a/src/test/ui/generic-associated-types/parse/trait-path-unimplemented.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: lifetime in trait object type must be followed by `+` - --> $DIR/trait-path-unimplemented.rs:13:31 - | -LL | fn f1<'a>(arg : Box>) {} - | ^^ - -error: generic associated types in trait paths are currently not implemented - --> $DIR/trait-path-unimplemented.rs:8:30 - | -LL | fn f1<'a>(arg : Box = &'a ()>>) {} - | ^^^^ - -error: aborting due to 2 previous errors -