add tests
This commit is contained in:
parent
9e920151a3
commit
12d411febb
@ -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<dyn for<'a> X<Y<'x> = &'a [u32]>>) {}
|
||||
//~^ ERROR: use of undeclared lifetime name `'x`
|
||||
//~| ERROR: binding for associated type `Y` references lifetime
|
||||
}
|
@ -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 <https://github.com/rust-lang/rust/issues/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<dyn for<'a> X<Y<'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<dyn for<'a> X<Y<'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`.
|
30
src/test/ui/generic-associated-types/gat-in-trait-path.rs
Normal file
30
src/test/ui/generic-associated-types/gat-in-trait-path.rs
Normal file
@ -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>(T);
|
||||
|
||||
impl<T> Foo for Fooer<T> {
|
||||
type A<'x> where T: 'x = &'x ();
|
||||
}
|
||||
|
||||
fn f(_arg : Box<dyn for<'a> Foo<A<'a> = &'a ()>>) {}
|
||||
|
||||
|
||||
fn main() {
|
||||
let foo = Fooer(5);
|
||||
f(Box::new(foo));
|
||||
}
|
@ -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 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
@ -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 <T, T1> Foo for T {
|
||||
type F<T1> = &[u8];
|
||||
//~^ ERROR: the name `T1` is already used for
|
||||
//~| ERROR: missing lifetime specifier
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -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 <T, T1> Foo for T {
|
||||
| -- first use of `T1`
|
||||
LL | type F<T1> = &[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 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error[E0106]: missing lifetime specifier
|
||||
--> $DIR/gat-trait-path-generic-type-arg.rs:11:18
|
||||
|
|
||||
LL | type F<T1> = &[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`.
|
@ -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<T> X for T {
|
||||
fn foo<'a, T1: X<Y = T1>>(t : T1) -> T1::Y<'a> {
|
||||
t
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -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 <https://github.com/rust-lang/rust/issues/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`.
|
@ -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<dyn X<Y('a) = &'a ()>>) {}
|
||||
//~^ 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() {}
|
@ -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<dyn X<Y('a) = &'a ()>>) {}
|
||||
| ^^
|
||||
|
||||
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<dyn X<Y('a) = &'a ()>>) {}
|
||||
| ^^^^^
|
||||
|
||||
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 <https://github.com/rust-lang/rust/issues/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<dyn X<Y('a) = &'a ()>>) {}
|
||||
| ^^ 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<dyn X<Y('a'a) = &'a ()>>) {}
|
||||
| ^^
|
||||
|
||||
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<dyn X<Y('a) = &'a ()>>) {}
|
||||
| |_________________________________________- 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`.
|
12
src/test/ui/generic-associated-types/issue-67510-pass.rs
Normal file
12
src/test/ui/generic-associated-types/issue-67510-pass.rs
Normal file
@ -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<dyn X<Y<'a>=&'a ()>>) {}
|
||||
|
||||
fn main() {}
|
11
src/test/ui/generic-associated-types/issue-67510-pass.stderr
Normal file
11
src/test/ui/generic-associated-types/issue-67510-pass.stderr
Normal file
@ -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 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
13
src/test/ui/generic-associated-types/issue-67510.rs
Normal file
13
src/test/ui/generic-associated-types/issue-67510.rs
Normal file
@ -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<dyn X<Y<'a>=&'a ()>>) {}
|
||||
//~^ ERROR: use of undeclared lifetime name `'a`
|
||||
//~| ERROR: use of undeclared lifetime name `'a`
|
||||
|
||||
|
||||
fn main() {}
|
32
src/test/ui/generic-associated-types/issue-67510.stderr
Normal file
32
src/test/ui/generic-associated-types/issue-67510.stderr
Normal file
@ -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 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error[E0261]: use of undeclared lifetime name `'a`
|
||||
--> $DIR/issue-67510.rs:8:21
|
||||
|
|
||||
LL | fn f(x: Box<dyn X<Y<'a>=&'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<dyn X<Y<'a>=&'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`.
|
26
src/test/ui/generic-associated-types/issue-68648-1.rs
Normal file
26
src/test/ui/generic-associated-types/issue-68648-1.rs
Normal file
@ -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 <T> Fun for T {
|
||||
type F<'a> = Self;
|
||||
}
|
||||
|
||||
fn bug<'a, T: for<'b> Fun<F<'b> = T>>(t: T) -> T::F<'a> {
|
||||
T::identity(t)
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let x = 10;
|
||||
|
||||
bug(x);
|
||||
}
|
11
src/test/ui/generic-associated-types/issue-68648-1.stderr
Normal file
11
src/test/ui/generic-associated-types/issue-68648-1.stderr
Normal file
@ -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 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
24
src/test/ui/generic-associated-types/issue-68648-2.rs
Normal file
24
src/test/ui/generic-associated-types/issue-68648-2.rs
Normal file
@ -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 <T> Fun for T {
|
||||
type F<'a> = Self;
|
||||
}
|
||||
|
||||
fn bug<'a, T: Fun<F<'a> = T>>(t: T) -> T::F<'a> {
|
||||
T::identity(())
|
||||
//~^ ERROR: mismatched types
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let x = 10;
|
||||
|
||||
bug(x);
|
||||
}
|
23
src/test/ui/generic-associated-types/issue-68648-2.stderr
Normal file
23
src/test/ui/generic-associated-types/issue-68648-2.stderr
Normal file
@ -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 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-68648-2.rs:15:17
|
||||
|
|
||||
LL | fn bug<'a, T: Fun<F<'a> = 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`.
|
25
src/test/ui/generic-associated-types/issue-68649-pass.rs
Normal file
25
src/test/ui/generic-associated-types/issue-68649-pass.rs
Normal file
@ -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 <T> Fun for T {
|
||||
type F<'a> = Self;
|
||||
}
|
||||
|
||||
fn bug<'a, T: Fun<F<'a> = T>>(t: T) -> T::F<'a> {
|
||||
T::identity(t)
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let x = 10;
|
||||
|
||||
bug(x);
|
||||
}
|
11
src/test/ui/generic-associated-types/issue-68649-pass.stderr
Normal file
11
src/test/ui/generic-associated-types/issue-68649-pass.stderr
Normal file
@ -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 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
26
src/test/ui/generic-associated-types/issue-74684-1.rs
Normal file
26
src/test/ui/generic-associated-types/issue-74684-1.rs
Normal file
@ -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 <T> Fun for T {
|
||||
type F<'a> = [u8];
|
||||
}
|
||||
|
||||
fn bug<'a, T: ?Sized + Fun<F<'a> = [u8]>>(_ : Box<T>) -> &'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));
|
||||
}
|
27
src/test/ui/generic-associated-types/issue-74684-1.stderr
Normal file
27
src/test/ui/generic-associated-types/issue-74684-1.stderr
Normal file
@ -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 <https://github.com/rust-lang/rust/issues/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<F<'a> = [u8]>>(_ : Box<T>) -> &'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`.
|
26
src/test/ui/generic-associated-types/issue-74684-2.rs
Normal file
26
src/test/ui/generic-associated-types/issue-74684-2.rs
Normal file
@ -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 <T> Fun for T {
|
||||
type F<'a> = i32;
|
||||
}
|
||||
|
||||
fn bug<'a, T: ?Sized + Fun<F<'a> = [u8]>>(t: Box<T>) -> &'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]`
|
||||
}
|
21
src/test/ui/generic-associated-types/issue-74684-2.stderr
Normal file
21
src/test/ui/generic-associated-types/issue-74684-2.stderr
Normal file
@ -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 <https://github.com/rust-lang/rust/issues/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<F<'a> = [u8]>>(t: Box<T>) -> &'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`.
|
41
src/test/ui/generic-associated-types/issue-76535.rs
Normal file
41
src/test/ui/generic-associated-types/issue-76535.rs
Normal file
@ -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<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0));
|
||||
//~^ ERROR the trait
|
||||
//~| ERROR the trait
|
||||
}
|
63
src/test/ui/generic-associated-types/issue-76535.stderr
Normal file
63
src/test/ui/generic-associated-types/issue-76535.stderr
Normal file
@ -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 <https://github.com/rust-lang/rust/issues/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<dyn SuperTrait<SubType = SubStruct>> = 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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
||||
--> $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<dyn SuperTrait<SubType = SubStruct>> = 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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
||||
--> $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<Box<dyn SuperTrait<SubType = SubStruct<'_>>>>` for `Box<SuperStruct>`
|
||||
= note: required by cast to type `Box<dyn SuperTrait<SubType = SubStruct<'_>>>`
|
||||
|
||||
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`.
|
47
src/test/ui/generic-associated-types/issue-79422.rs
Normal file
47
src/test/ui/generic-associated-types/issue-79422.rs
Normal file
@ -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<T> {
|
||||
fn t(&'a self) -> &'a T {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
trait MapLike<K, V> {
|
||||
type VRefCont<'a>: RefCont<'a, V>;
|
||||
//~^ ERROR missing generics
|
||||
fn get<'a>(&'a self, key: &K) -> Option<Self::VRefCont<'a>>;
|
||||
}
|
||||
|
||||
impl<K: Ord, V: 'static> MapLike<K, V> for std::collections::BTreeMap<K, V> {
|
||||
type VRefCont<'a> = &'a V;
|
||||
fn get<'a>(&'a self, key: &K) -> Option<&'a V> {
|
||||
std::collections::BTreeMap::get(self, key)
|
||||
}
|
||||
}
|
||||
|
||||
struct Source;
|
||||
|
||||
impl<K, V: Default> MapLike<K, V> for Source {
|
||||
type VRefCont<'a> = Box<V>;
|
||||
fn get<'a>(&self, _: &K) -> Option<Box<V>> {
|
||||
Some(Box::new(V::default()))
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let m = Box::new(std::collections::BTreeMap::<u8, u8>::new())
|
||||
as Box<dyn MapLike<u8, u8, VRefCont = dyn RefCont<'_, u8>>>;
|
||||
//~^ ERROR the trait
|
||||
//~^^^ ERROR the trait
|
||||
}
|
54
src/test/ui/generic-associated-types/issue-79422.stderr
Normal file
54
src/test/ui/generic-associated-types/issue-79422.stderr
Normal file
@ -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<dyn MapLike<u8, u8, VRefCont = dyn RefCont<'_, u8>>>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
||||
--> $DIR/issue-79422.rs:23:38
|
||||
|
|
||||
LL | trait MapLike<K, V> {
|
||||
| ------- this trait cannot be made into an object...
|
||||
...
|
||||
LL | fn get<'a>(&'a self, key: &K) -> Option<Self::VRefCont<'a>>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...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::<u8, u8>::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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
||||
--> $DIR/issue-79422.rs:23:38
|
||||
|
|
||||
LL | trait MapLike<K, V> {
|
||||
| ------- this trait cannot be made into an object...
|
||||
...
|
||||
LL | fn get<'a>(&'a self, key: &K) -> Option<Self::VRefCont<'a>>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...because method `get` references the `Self` type in its return type
|
||||
= note: required because of the requirements on the impl of `CoerceUnsized<Box<dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + 'static)>>>` for `Box<BTreeMap<u8, u8>>`
|
||||
= note: required by cast to type `Box<dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + '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`.
|
24
src/test/ui/generic-associated-types/issue-80433-reduced.rs
Normal file
24
src/test/ui/generic-associated-types/issue-80433-reduced.rs
Normal file
@ -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<Output<'a> = usize>) {}
|
||||
|
||||
fn main() {
|
||||
test_simpler(E {});
|
||||
}
|
35
src/test/ui/generic-associated-types/issue-80433.rs
Normal file
35
src/test/ui/generic-associated-types/issue-80433.rs
Normal file
@ -0,0 +1,35 @@
|
||||
#![feature(generic_associated_types)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
#[derive(Default)]
|
||||
struct E<T> {
|
||||
data: T,
|
||||
}
|
||||
|
||||
trait TestMut {
|
||||
type Output<'a>;
|
||||
//~^ ERROR missing generics
|
||||
fn test_mut<'a>(&'a mut self) -> Self::Output<'a>;
|
||||
}
|
||||
|
||||
impl<T> TestMut for E<T>
|
||||
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<Output = &'a mut f32>)
|
||||
{
|
||||
for n in 0i16..100 {
|
||||
*dst.test_mut() = n.into();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut t1: E<f32> = Default::default();
|
||||
test_simpler(&mut t1);
|
||||
}
|
19
src/test/ui/generic-associated-types/issue-80433.stderr
Normal file
19
src/test/ui/generic-associated-types/issue-80433.stderr
Normal file
@ -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`.
|
@ -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<dyn X<Y<1> = &'a ()>>) {}
|
||||
//~^ ERROR: generic associated types in trait paths are currently not implemented
|
||||
};
|
||||
|
||||
fn main() {}
|
||||
|
@ -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<dyn X<Y<1> = &'a ()>>) {}
|
||||
| ^^^
|
||||
LL | #![feature(generic_associated_types)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error: aborting due to previous error
|
||||
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<dyn X<Y<'a1> = &'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<dyn X<Y<1> = &'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 2 previous errors; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0107`.
|
||||
|
@ -1,17 +0,0 @@
|
||||
#![feature(generic_associated_types)]
|
||||
|
||||
trait X {
|
||||
type Y<'a>;
|
||||
}
|
||||
|
||||
const _: () = {
|
||||
fn f1<'a>(arg : Box<dyn X<Y<'a> = &'a ()>>) {}
|
||||
//~^ ERROR: generic associated types in trait paths are currently not implemented
|
||||
};
|
||||
|
||||
const _: () = {
|
||||
fn f1<'a>(arg : Box<dyn X<Y('a) = &'a ()>>) {}
|
||||
//~^ ERROR: lifetime in trait object type must be followed by `+`
|
||||
};
|
||||
|
||||
fn main() {}
|
@ -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<dyn X<Y('a) = &'a ()>>) {}
|
||||
| ^^
|
||||
|
||||
error: generic associated types in trait paths are currently not implemented
|
||||
--> $DIR/trait-path-unimplemented.rs:8:30
|
||||
|
|
||||
LL | fn f1<'a>(arg : Box<dyn X<Y<'a> = &'a ()>>) {}
|
||||
| ^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
Loading…
x
Reference in New Issue
Block a user