Rollup merge of #72788 - matthewjasper:projection-bound-validation, r=nikomatsakis
Projection bound validation During selection we use bounds declared on associated types (e.g. `type X: Copy`) to satisfy trait/projection bounds. This would be fine so long as those bounds are checked on any impls/trait objects. For simple cases they are because the bound `Self::X: Copy` gets normalized when we check the impl. However, for default values with specialization and higher-ranked bounds from GATs or otherwise, we can't normalize when checking the impl, and so we use the bound from the trait to prove that the bound applies to the impl, which is clearly unsound. This PR makes 2 fixes for this: 1. Requiring that the bounds on the trait apply to a projection type with the corresponding substs, so a bound `for<'a> <Self as X<'a>>::U: Copy` on the trait cannot be used to prove `<T as X<'_>>::U: Copy`. 2. Actually checking that the bounds that we still allow apply to generic/default associated types. Opening for a crater run. Closes #68641 Closes #68642 Closes #68643 Closes #68644 Closes #68645 Closes #68656 r? @ghost
This commit is contained in:
commit
1a171d0d5b
86 changed files with 1590 additions and 496 deletions
18
src/test/ui/associated-types/hr-associated-type-bound-1.rs
Normal file
18
src/test/ui/associated-types/hr-associated-type-bound-1.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
trait X<'a>
|
||||
where
|
||||
for<'b> <Self as X<'b>>::U: Clone,
|
||||
{
|
||||
type U: ?Sized;
|
||||
fn f(&self, x: &Self::U) {
|
||||
<Self::U>::clone(x);
|
||||
}
|
||||
}
|
||||
|
||||
impl X<'_> for i32 {
|
||||
type U = str;
|
||||
//~^ ERROR the trait bound `for<'b> <i32 as X<'b>>::U: std::clone::Clone`
|
||||
}
|
||||
|
||||
fn main() {
|
||||
1i32.f("abc");
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
error[E0277]: the trait bound `for<'b> <i32 as X<'b>>::U: std::clone::Clone` is not satisfied
|
||||
--> $DIR/hr-associated-type-bound-1.rs:12:14
|
||||
|
|
||||
LL | trait X<'a>
|
||||
| - required by a bound in this
|
||||
LL | where
|
||||
LL | for<'b> <Self as X<'b>>::U: Clone,
|
||||
| ----- required by this bound in `X`
|
||||
...
|
||||
LL | type U = str;
|
||||
| ^^^ the trait `for<'b> std::clone::Clone` is not implemented for `<i32 as X<'b>>::U`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<&T as std::clone::Clone>
|
||||
<&mut T as std::clone::Clone>
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
21
src/test/ui/associated-types/hr-associated-type-bound-2.rs
Normal file
21
src/test/ui/associated-types/hr-associated-type-bound-2.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
trait X<'a>
|
||||
where
|
||||
for<'b> <Self as X<'b>>::U: Clone,
|
||||
{
|
||||
type U: ?Sized;
|
||||
fn f(&self, x: &Self::U) {
|
||||
<Self::U>::clone(x);
|
||||
}
|
||||
}
|
||||
|
||||
impl X<'_> for u32
|
||||
where
|
||||
for<'b> <Self as X<'b>>::U: Clone,
|
||||
{
|
||||
type U = str;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
1u32.f("abc");
|
||||
//~^ ERROR no method named `f` found for type `u32` in the current scope
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
error[E0599]: no method named `f` found for type `u32` in the current scope
|
||||
--> $DIR/hr-associated-type-bound-2.rs:19:10
|
||||
|
|
||||
LL | 1u32.f("abc");
|
||||
| ^ method not found in `u32`
|
||||
|
|
||||
= note: the method `f` exists but the following trait bounds were not satisfied:
|
||||
`<u32 as X<'b>>::U: std::clone::Clone`
|
||||
which is required by `u32: X`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0599`.
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
trait X<'a>
|
||||
where
|
||||
for<'b> <Self as X<'b>>::U: Clone,
|
||||
{
|
||||
type U: ?Sized;
|
||||
}
|
||||
fn f<'a, T: X<'a> + ?Sized>(x: &<T as X<'a>>::U) {
|
||||
//~^ ERROR the trait bound `for<'b> <T as X<'b>>::U: std::clone::Clone` is not satisfied
|
||||
<<T as X<'_>>::U>::clone(x);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
f::<dyn X<'_, U = str>>("abc");
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
error[E0277]: the trait bound `for<'b> <T as X<'b>>::U: std::clone::Clone` is not satisfied
|
||||
--> $DIR/hr-associated-type-bound-object.rs:7:13
|
||||
|
|
||||
LL | trait X<'a>
|
||||
| - required by a bound in this
|
||||
LL | where
|
||||
LL | for<'b> <Self as X<'b>>::U: Clone,
|
||||
| ----- required by this bound in `X`
|
||||
...
|
||||
LL | fn f<'a, T: X<'a> + ?Sized>(x: &<T as X<'a>>::U) {
|
||||
| ^^^^^ the trait `for<'b> std::clone::Clone` is not implemented for `<T as X<'b>>::U`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<&T as std::clone::Clone>
|
||||
<&mut T as std::clone::Clone>
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
trait Y<'a, T: ?Sized>
|
||||
where
|
||||
T: Y<'a, Self>,
|
||||
for<'b> <Self as Y<'b, T>>::V: Clone,
|
||||
for<'b> <T as Y<'b, Self>>::V: Clone,
|
||||
{
|
||||
type V: ?Sized;
|
||||
fn g(&self, x: &Self::V) {
|
||||
<Self::V>::clone(x);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Y<'a, u8> for u8 {
|
||||
type V = str;
|
||||
//~^ ERROR the trait bound `for<'b> <u8 as Y<'b, u8>>::V: std::clone::Clone` is not satisfied
|
||||
}
|
||||
|
||||
fn main() {
|
||||
1u8.g("abc");
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
error[E0277]: the trait bound `for<'b> <u8 as Y<'b, u8>>::V: std::clone::Clone` is not satisfied
|
||||
--> $DIR/hr-associated-type-bound-param-1.rs:14:14
|
||||
|
|
||||
LL | trait Y<'a, T: ?Sized>
|
||||
| - required by a bound in this
|
||||
...
|
||||
LL | for<'b> <Self as Y<'b, T>>::V: Clone,
|
||||
| ----- required by this bound in `Y`
|
||||
...
|
||||
LL | type V = str;
|
||||
| ^^^ the trait `for<'b> std::clone::Clone` is not implemented for `<u8 as Y<'b, u8>>::V`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<&T as std::clone::Clone>
|
||||
<&mut T as std::clone::Clone>
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
trait Z<'a, T: ?Sized>
|
||||
where
|
||||
T: Z<'a, u16>,
|
||||
//~^ the trait bound `for<'b> <u16 as Z<'b, u16>>::W: std::clone::Clone` is not satisfied
|
||||
//~| the trait bound `for<'b> <u16 as Z<'b, u16>>::W: std::clone::Clone` is not satisfied
|
||||
for<'b> <T as Z<'b, u16>>::W: Clone,
|
||||
{
|
||||
type W: ?Sized;
|
||||
fn h(&self, x: &T::W) {
|
||||
<T::W>::clone(x);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Z<'a, u16> for u16 {
|
||||
type W = str;
|
||||
//~^ ERROR the trait bound `for<'b> <u16 as Z<'b, u16>>::W: std::clone::Clone
|
||||
}
|
||||
|
||||
fn main() {
|
||||
1u16.h("abc");
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
error[E0277]: the trait bound `for<'b> <u16 as Z<'b, u16>>::W: std::clone::Clone` is not satisfied
|
||||
--> $DIR/hr-associated-type-bound-param-2.rs:3:8
|
||||
|
|
||||
LL | trait Z<'a, T: ?Sized>
|
||||
| - required by a bound in this
|
||||
LL | where
|
||||
LL | T: Z<'a, u16>,
|
||||
| ^^^^^^^^^^ the trait `for<'b> std::clone::Clone` is not implemented for `<u16 as Z<'b, u16>>::W`
|
||||
...
|
||||
LL | for<'b> <T as Z<'b, u16>>::W: Clone,
|
||||
| ----- required by this bound in `Z`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<&T as std::clone::Clone>
|
||||
<&mut T as std::clone::Clone>
|
||||
|
||||
error[E0277]: the trait bound `for<'b> <u16 as Z<'b, u16>>::W: std::clone::Clone` is not satisfied
|
||||
--> $DIR/hr-associated-type-bound-param-2.rs:15:14
|
||||
|
|
||||
LL | trait Z<'a, T: ?Sized>
|
||||
| - required by a bound in this
|
||||
...
|
||||
LL | for<'b> <T as Z<'b, u16>>::W: Clone,
|
||||
| ----- required by this bound in `Z`
|
||||
...
|
||||
LL | type W = str;
|
||||
| ^^^ the trait `for<'b> std::clone::Clone` is not implemented for `<u16 as Z<'b, u16>>::W`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<&T as std::clone::Clone>
|
||||
<&mut T as std::clone::Clone>
|
||||
|
||||
error[E0277]: the trait bound `for<'b> <u16 as Z<'b, u16>>::W: std::clone::Clone` is not satisfied
|
||||
--> $DIR/hr-associated-type-bound-param-2.rs:3:8
|
||||
|
|
||||
LL | trait Z<'a, T: ?Sized>
|
||||
| - required by a bound in this
|
||||
LL | where
|
||||
LL | T: Z<'a, u16>,
|
||||
| ^^^^^^^^^^ the trait `for<'b> std::clone::Clone` is not implemented for `<u16 as Z<'b, u16>>::W`
|
||||
...
|
||||
LL | for<'b> <T as Z<'b, u16>>::W: Clone,
|
||||
| ----- required by this bound in `Z`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<&T as std::clone::Clone>
|
||||
<&mut T as std::clone::Clone>
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// ignore-tidy-linelength
|
||||
|
||||
trait X<'a, T>
|
||||
where
|
||||
for<'b> T: X<'b, T>,
|
||||
for<'b> <T as X<'b, T>>::U: Clone,
|
||||
{
|
||||
type U: ?Sized;
|
||||
fn f(x: &<T as X<'_, T>>::U) {
|
||||
<<T as X<'_, T>>::U>::clone(x);
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, T> X<'_, (T,)> for (S,) {
|
||||
type U = str;
|
||||
//~^ ERROR the trait bound `for<'b> <(T,) as X<'b, (T,)>>::U: std::clone::Clone` is not satisfied
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
<(i32,) as X<(i32,)>>::f("abc");
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
error[E0277]: the trait bound `for<'b> <(T,) as X<'b, (T,)>>::U: std::clone::Clone` is not satisfied
|
||||
--> $DIR/hr-associated-type-bound-param-3.rs:15:14
|
||||
|
|
||||
LL | trait X<'a, T>
|
||||
| - required by a bound in this
|
||||
...
|
||||
LL | for<'b> <T as X<'b, T>>::U: Clone,
|
||||
| ----- required by this bound in `X`
|
||||
...
|
||||
LL | type U = str;
|
||||
| ^^^ the trait `for<'b> std::clone::Clone` is not implemented for `<(T,) as X<'b, (T,)>>::U`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<&T as std::clone::Clone>
|
||||
<&mut T as std::clone::Clone>
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
trait X<'a, T>
|
||||
where
|
||||
for<'b> (T,): X<'b, T>,
|
||||
for<'b> <(T,) as X<'b, T>>::U: Clone,
|
||||
{
|
||||
type U: ?Sized;
|
||||
fn f(x: &<(T,) as X<'_, T>>::U) {
|
||||
<<(T,) as X<'_, T>>::U>::clone(x);
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, T> X<'_, T> for (S,) {
|
||||
type U = str;
|
||||
//~^ ERROR the trait bound `for<'b> <(T,) as X<'b, T>>::U: std::clone::Clone` is not satisfied
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
<(i32,) as X<i32>>::f("abc");
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
error[E0277]: the trait bound `for<'b> <(T,) as X<'b, T>>::U: std::clone::Clone` is not satisfied
|
||||
--> $DIR/hr-associated-type-bound-param-4.rs:13:14
|
||||
|
|
||||
LL | trait X<'a, T>
|
||||
| - required by a bound in this
|
||||
...
|
||||
LL | for<'b> <(T,) as X<'b, T>>::U: Clone,
|
||||
| ----- required by this bound in `X`
|
||||
...
|
||||
LL | type U = str;
|
||||
| ^^^ the trait `for<'b> std::clone::Clone` is not implemented for `<(T,) as X<'b, T>>::U`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<&T as std::clone::Clone>
|
||||
<&mut T as std::clone::Clone>
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
// ignore-tidy-linelength
|
||||
|
||||
trait Cycle: Sized {
|
||||
type Next: Cycle<Next = Self>;
|
||||
}
|
||||
|
||||
impl<T> Cycle for Box<T> {
|
||||
type Next = Vec<T>;
|
||||
}
|
||||
|
||||
impl<T> Cycle for Vec<T> {
|
||||
type Next = Box<T>;
|
||||
}
|
||||
|
||||
trait X<'a, T: Cycle + for<'b> X<'b, T>>
|
||||
where
|
||||
for<'b> <T as X<'b, T>>::U: Clone,
|
||||
for<'b> T::Next: X<'b, T::Next>,
|
||||
for<'b> <T::Next as X<'b, T::Next>>::U: Clone,
|
||||
{
|
||||
type U: ?Sized;
|
||||
fn f(x: &<T as X<'_, T>>::U) {
|
||||
<<T as X<'_, T>>::U>::clone(x);
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, T> X<'_, Vec<T>> for S {
|
||||
type U = str;
|
||||
//~^ ERROR the trait bound `for<'b> <std::boxed::Box<T> as X<'b, std::boxed::Box<T>>>::U: std::clone::Clone` is not satisfied
|
||||
//~| ERROR the trait bound `for<'b> <std::vec::Vec<T> as X<'b, std::vec::Vec<T>>>::U: std::clone::Clone` is not satisfied
|
||||
}
|
||||
|
||||
impl<S, T> X<'_, Box<T>> for S {
|
||||
type U = str;
|
||||
//~^ ERROR the trait bound `for<'b> <std::boxed::Box<T> as X<'b, std::boxed::Box<T>>>::U: std::clone::Clone` is not satisfied
|
||||
//~| ERROR the trait bound `for<'b> <std::vec::Vec<T> as X<'b, std::vec::Vec<T>>>::U: std::clone::Clone` is not satisfied
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
<i32 as X<Box<i32>>>::f("abc");
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
error[E0277]: the trait bound `for<'b> <std::boxed::Box<T> as X<'b, std::boxed::Box<T>>>::U: std::clone::Clone` is not satisfied
|
||||
--> $DIR/hr-associated-type-bound-param-5.rs:28:14
|
||||
|
|
||||
LL | trait X<'a, T: Cycle + for<'b> X<'b, T>>
|
||||
| - required by a bound in this
|
||||
...
|
||||
LL | for<'b> <T::Next as X<'b, T::Next>>::U: Clone,
|
||||
| ----- required by this bound in `X`
|
||||
...
|
||||
LL | type U = str;
|
||||
| ^^^ the trait `for<'b> std::clone::Clone` is not implemented for `<std::boxed::Box<T> as X<'b, std::boxed::Box<T>>>::U`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<&T as std::clone::Clone>
|
||||
<&mut T as std::clone::Clone>
|
||||
|
||||
error[E0277]: the trait bound `for<'b> <std::vec::Vec<T> as X<'b, std::vec::Vec<T>>>::U: std::clone::Clone` is not satisfied
|
||||
--> $DIR/hr-associated-type-bound-param-5.rs:28:14
|
||||
|
|
||||
LL | trait X<'a, T: Cycle + for<'b> X<'b, T>>
|
||||
| - required by a bound in this
|
||||
LL | where
|
||||
LL | for<'b> <T as X<'b, T>>::U: Clone,
|
||||
| ----- required by this bound in `X`
|
||||
...
|
||||
LL | type U = str;
|
||||
| ^^^ the trait `for<'b> std::clone::Clone` is not implemented for `<std::vec::Vec<T> as X<'b, std::vec::Vec<T>>>::U`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<&T as std::clone::Clone>
|
||||
<&mut T as std::clone::Clone>
|
||||
|
||||
error[E0277]: the trait bound `for<'b> <std::vec::Vec<T> as X<'b, std::vec::Vec<T>>>::U: std::clone::Clone` is not satisfied
|
||||
--> $DIR/hr-associated-type-bound-param-5.rs:34:14
|
||||
|
|
||||
LL | trait X<'a, T: Cycle + for<'b> X<'b, T>>
|
||||
| - required by a bound in this
|
||||
...
|
||||
LL | for<'b> <T::Next as X<'b, T::Next>>::U: Clone,
|
||||
| ----- required by this bound in `X`
|
||||
...
|
||||
LL | type U = str;
|
||||
| ^^^ the trait `for<'b> std::clone::Clone` is not implemented for `<std::vec::Vec<T> as X<'b, std::vec::Vec<T>>>::U`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<&T as std::clone::Clone>
|
||||
<&mut T as std::clone::Clone>
|
||||
|
||||
error[E0277]: the trait bound `for<'b> <std::boxed::Box<T> as X<'b, std::boxed::Box<T>>>::U: std::clone::Clone` is not satisfied
|
||||
--> $DIR/hr-associated-type-bound-param-5.rs:34:14
|
||||
|
|
||||
LL | trait X<'a, T: Cycle + for<'b> X<'b, T>>
|
||||
| - required by a bound in this
|
||||
LL | where
|
||||
LL | for<'b> <T as X<'b, T>>::U: Clone,
|
||||
| ----- required by this bound in `X`
|
||||
...
|
||||
LL | type U = str;
|
||||
| ^^^ the trait `for<'b> std::clone::Clone` is not implemented for `<std::boxed::Box<T> as X<'b, std::boxed::Box<T>>>::U`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<&T as std::clone::Clone>
|
||||
<&mut T as std::clone::Clone>
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
trait X<'a, T>
|
||||
where
|
||||
for<'b> T: X<'b, T>,
|
||||
for<'b> <T as X<'b, T>>::U: Clone,
|
||||
{
|
||||
type U: ?Sized;
|
||||
fn f(x: &<T as X<'_, T>>::U) {
|
||||
<<T as X<'_, T>>::U>::clone(x);
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, T> X<'_, T> for (S,) {
|
||||
//~^ ERROR the trait bound `for<'b> T: X<'b, T>` is not satisfied
|
||||
type U = str;
|
||||
//~^ ERROR the trait bound `for<'b> <T as X<'b, T>>::U: std::clone::Clone` is not satisfied
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
<(i32,) as X<i32>>::f("abc");
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
error[E0277]: the trait bound `for<'b> <T as X<'b, T>>::U: std::clone::Clone` is not satisfied
|
||||
--> $DIR/hr-associated-type-bound-param-6.rs:14:14
|
||||
|
|
||||
LL | trait X<'a, T>
|
||||
| - required by a bound in this
|
||||
...
|
||||
LL | for<'b> <T as X<'b, T>>::U: Clone,
|
||||
| ----- required by this bound in `X`
|
||||
...
|
||||
LL | type U = str;
|
||||
| ^^^ the trait `for<'b> std::clone::Clone` is not implemented for `<T as X<'b, T>>::U`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<&T as std::clone::Clone>
|
||||
<&mut T as std::clone::Clone>
|
||||
|
||||
error[E0277]: the trait bound `for<'b> T: X<'b, T>` is not satisfied
|
||||
--> $DIR/hr-associated-type-bound-param-6.rs:12:12
|
||||
|
|
||||
LL | trait X<'a, T>
|
||||
| - required by a bound in this
|
||||
LL | where
|
||||
LL | for<'b> T: X<'b, T>,
|
||||
| -------- required by this bound in `X`
|
||||
...
|
||||
LL | impl<S, T> X<'_, T> for (S,) {
|
||||
| ^^^^^^^^ the trait `for<'b> X<'b, T>` is not implemented for `T`
|
||||
|
|
||||
help: consider restricting type parameter `T`
|
||||
|
|
||||
LL | impl<S, T: for<'b> X<'b, T>> X<'_, T> for (S,) {
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
trait UnsafeCopy<'a, T: Copy>
|
||||
where
|
||||
for<'b> <Self as UnsafeCopy<'b, T>>::Item: std::ops::Deref<Target = T>,
|
||||
{
|
||||
type Item;
|
||||
|
||||
fn bug(item: &Self::Item) -> () {
|
||||
let x: T = **item;
|
||||
&x as *const _;
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + std::ops::Deref> UnsafeCopy<'_, T> for T {
|
||||
//~^ ERROR the trait bound `<T as UnsafeCopy<'b, T>>::Item: std::ops::Deref` is not satisfied
|
||||
type Item = T;
|
||||
//~^ ERROR the trait bound `for<'b> <T as UnsafeCopy<'b, T>>::Item: std::ops::Deref
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
<&'static str>::bug(&"");
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
error[E0277]: the trait bound `for<'b> <T as UnsafeCopy<'b, T>>::Item: std::ops::Deref` is not satisfied
|
||||
--> $DIR/hr-associated-type-projection-1.rs:15:17
|
||||
|
|
||||
LL | trait UnsafeCopy<'a, T: Copy>
|
||||
| ---------- required by a bound in this
|
||||
LL | where
|
||||
LL | for<'b> <Self as UnsafeCopy<'b, T>>::Item: std::ops::Deref<Target = T>,
|
||||
| --------------------------- required by this bound in `UnsafeCopy`
|
||||
...
|
||||
LL | type Item = T;
|
||||
| ^ the trait `for<'b> std::ops::Deref` is not implemented for `<T as UnsafeCopy<'b, T>>::Item`
|
||||
|
|
||||
= help: the following implementations were found:
|
||||
<&T as std::ops::Deref>
|
||||
<&mut T as std::ops::Deref>
|
||||
|
||||
error[E0277]: the trait bound `<T as UnsafeCopy<'b, T>>::Item: std::ops::Deref` is not satisfied
|
||||
--> $DIR/hr-associated-type-projection-1.rs:13:33
|
||||
|
|
||||
LL | impl<T: Copy + std::ops::Deref> UnsafeCopy<'_, T> for T {
|
||||
| ^^^^^^^^^^^^^^^^^ the trait `std::ops::Deref` is not implemented for `<T as UnsafeCopy<'b, T>>::Item`
|
||||
|
|
||||
help: consider further restricting the associated type
|
||||
|
|
||||
LL | impl<T: Copy + std::ops::Deref> UnsafeCopy<'_, T> for T where <T as UnsafeCopy<'b, T>>::Item: std::ops::Deref {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -3,11 +3,9 @@ use std::ops::Deref;
|
|||
trait PointerFamily<U> {
|
||||
type Pointer<T>: Deref<Target = T>;
|
||||
//~^ ERROR generic associated types are unstable
|
||||
//~| ERROR type-generic associated types are not yet implemented
|
||||
type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
|
||||
//~^ ERROR generic associated types are unstable
|
||||
//~| ERROR where clauses on associated types are unstable
|
||||
//~| ERROR type-generic associated types are not yet implemented
|
||||
}
|
||||
|
||||
struct Foo;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ LL | type Pointer<T>: Deref<Target = T>;
|
|||
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: generic associated types are unstable
|
||||
--> $DIR/feature-gate-generic_associated_types.rs:7:5
|
||||
--> $DIR/feature-gate-generic_associated_types.rs:6:5
|
||||
|
|
||||
LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -17,7 +17,7 @@ LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
|
|||
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: where clauses on associated types are unstable
|
||||
--> $DIR/feature-gate-generic_associated_types.rs:7:5
|
||||
--> $DIR/feature-gate-generic_associated_types.rs:6:5
|
||||
|
|
||||
LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -26,7 +26,7 @@ LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
|
|||
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: generic associated types are unstable
|
||||
--> $DIR/feature-gate-generic_associated_types.rs:16:5
|
||||
--> $DIR/feature-gate-generic_associated_types.rs:14:5
|
||||
|
|
||||
LL | type Pointer<Usize> = Box<Usize>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -35,7 +35,7 @@ LL | type Pointer<Usize> = Box<Usize>;
|
|||
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: generic associated types are unstable
|
||||
--> $DIR/feature-gate-generic_associated_types.rs:18:5
|
||||
--> $DIR/feature-gate-generic_associated_types.rs:16:5
|
||||
|
|
||||
LL | type Pointer2<U32> = Box<U32>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -44,7 +44,7 @@ LL | type Pointer2<U32> = Box<U32>;
|
|||
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: where clauses on associated types are unstable
|
||||
--> $DIR/feature-gate-generic_associated_types.rs:23:5
|
||||
--> $DIR/feature-gate-generic_associated_types.rs:21:5
|
||||
|
|
||||
LL | type Assoc where Self: Sized;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -53,7 +53,7 @@ LL | type Assoc where Self: Sized;
|
|||
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: where clauses on associated types are unstable
|
||||
--> $DIR/feature-gate-generic_associated_types.rs:28:5
|
||||
--> $DIR/feature-gate-generic_associated_types.rs:26:5
|
||||
|
|
||||
LL | type Assoc where Self: Sized = Foo;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -61,22 +61,6 @@ LL | type Assoc where Self: Sized = Foo;
|
|||
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
|
||||
|
||||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/feature-gate-generic_associated_types.rs:4:5
|
||||
|
|
||||
LL | type Pointer<T>: Deref<Target = T>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/feature-gate-generic_associated_types.rs:7:5
|
||||
|
|
||||
LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
#![allow(incomplete_features)]
|
||||
#![feature(generic_associated_types)]
|
||||
#![feature(associated_type_defaults)]
|
||||
|
||||
// A Collection trait and collection families. Based on
|
||||
// http://smallcultfollowing.com/babysteps/blog/2016/11/03/
|
||||
// associated-type-constructors-part-2-family-traits/
|
||||
|
||||
// check that we don't normalize with trait defaults.
|
||||
|
||||
trait Collection<T> {
|
||||
type Iter<'iter>: Iterator<Item=&'iter T> where T: 'iter;
|
||||
type Family: CollectionFamily;
|
||||
// Test associated type defaults with parameters
|
||||
type Sibling<U>: Collection<U> =
|
||||
<<Self as Collection<T>>::Family as CollectionFamily>::Member<U>;
|
||||
|
||||
fn empty() -> Self;
|
||||
|
||||
fn add(&mut self, value: T);
|
||||
|
||||
fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>;
|
||||
}
|
||||
|
||||
trait CollectionFamily {
|
||||
type Member<T>: Collection<T, Family = Self>;
|
||||
}
|
||||
|
||||
struct VecFamily;
|
||||
|
||||
impl CollectionFamily for VecFamily {
|
||||
type Member<T> = Vec<T>;
|
||||
}
|
||||
|
||||
impl<T> Collection<T> for Vec<T> {
|
||||
type Iter<'iter> where T: 'iter = std::slice::Iter<'iter, T>;
|
||||
type Family = VecFamily;
|
||||
|
||||
fn empty() -> Self {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
fn add(&mut self, value: T) {
|
||||
self.push(value)
|
||||
}
|
||||
|
||||
fn iterate<'iter>(&'iter self) -> Self::Iter<'iter> {
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
fn floatify_sibling<C>(ints: &C) -> <C as Collection<i32>>::Sibling<f32>
|
||||
where
|
||||
C: Collection<i32>,
|
||||
{
|
||||
let mut res = <C::Family as CollectionFamily>::Member::<f32>::empty();
|
||||
for &v in ints.iterate() {
|
||||
res.add(v as f32);
|
||||
}
|
||||
res
|
||||
//~^ ERROR mismatched types
|
||||
}
|
||||
|
||||
fn use_floatify() {
|
||||
let a = vec![1i32, 2, 3];
|
||||
let c = floatify_sibling(&a);
|
||||
assert_eq!(Some(&1.0), c.iterate().next());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
use_floatify();
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/collections-project-default.rs:60:5
|
||||
|
|
||||
LL | fn floatify_sibling<C>(ints: &C) -> <C as Collection<i32>>::Sibling<f32>
|
||||
| ------------------------------------ expected `<C as Collection<i32>>::Sibling<f32>` because of return type
|
||||
...
|
||||
LL | res
|
||||
| ^^^ expected Collection::Sibling, found CollectionFamily::Member
|
||||
|
|
||||
= note: expected associated type `<C as Collection<i32>>::Sibling<f32>`
|
||||
found associated type `<<C as Collection<i32>>::Family as CollectionFamily>::Member<f32>`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
|
|
@ -6,13 +6,14 @@
|
|||
// http://smallcultfollowing.com/babysteps/blog/2016/11/03/
|
||||
// associated-type-constructors-part-2-family-traits/
|
||||
|
||||
// run-pass
|
||||
|
||||
trait Collection<T> {
|
||||
type Iter<'iter>: Iterator<Item=&'iter T>;
|
||||
type Iter<'iter>: Iterator<Item=&'iter T> where T: 'iter;
|
||||
type Family: CollectionFamily;
|
||||
// Test associated type defaults with parameters
|
||||
type Sibling<U>: Collection<U> =
|
||||
<<Self as Collection<T>>::Family as CollectionFamily>::Member<U>;
|
||||
//~^^ ERROR type-generic associated types are not yet implemented
|
||||
|
||||
fn empty() -> Self;
|
||||
|
||||
|
|
@ -23,7 +24,6 @@ trait Collection<T> {
|
|||
|
||||
trait CollectionFamily {
|
||||
type Member<T>: Collection<T, Family = Self>;
|
||||
//~^ ERROR type-generic associated types are not yet implemented
|
||||
}
|
||||
|
||||
struct VecFamily;
|
||||
|
|
@ -33,7 +33,7 @@ impl CollectionFamily for VecFamily {
|
|||
}
|
||||
|
||||
impl<T> Collection<T> for Vec<T> {
|
||||
type Iter<'iter> = std::slice::Iter<'iter, T>;
|
||||
type Iter<'iter> where T: 'iter = std::slice::Iter<'iter, T>;
|
||||
type Family = VecFamily;
|
||||
|
||||
fn empty() -> Self {
|
||||
|
|
@ -53,18 +53,7 @@ fn floatify<C>(ints: &C) -> <<C as Collection<i32>>::Family as CollectionFamily>
|
|||
where
|
||||
C: Collection<i32>,
|
||||
{
|
||||
let mut res = C::Family::Member::<f32>::empty();
|
||||
for &v in ints.iterate() {
|
||||
res.add(v as f32);
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
fn floatify_sibling<C>(ints: &C) -> <C as Collection<i32>>::Sibling<f32>
|
||||
where
|
||||
C: Collection<i32>,
|
||||
{
|
||||
let mut res = C::Family::Member::<f32>::empty();
|
||||
let mut res = <C::Family as CollectionFamily>::Member::<f32>::empty();
|
||||
for &v in ints.iterate() {
|
||||
res.add(v as f32);
|
||||
}
|
||||
|
|
@ -72,11 +61,11 @@ where
|
|||
}
|
||||
|
||||
fn use_floatify() {
|
||||
let a = vec![1i32, 2, 3];
|
||||
let b = floatify(a);
|
||||
println!("{}", b.iterate().next());
|
||||
let c = floatify_sibling(a);
|
||||
println!("{}", c.iterate().next());
|
||||
let a = vec![1, 2, 3];
|
||||
let b = floatify(&a);
|
||||
assert_eq!(Some(&1.0), b.iterate().next());
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
fn main() {
|
||||
use_floatify();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/collections.rs:13:5
|
||||
|
|
||||
LL | / type Sibling<U>: Collection<U> =
|
||||
LL | | <<Self as Collection<T>>::Family as CollectionFamily>::Member<U>;
|
||||
| |_________________________________________________________________________^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/collections.rs:25:5
|
||||
|
|
||||
LL | type Member<T>: Collection<T, Family = Self>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#![allow(incomplete_features)]
|
||||
#![feature(generic_associated_types)]
|
||||
|
||||
// FIXME(#30472) normalize enough to handle this.
|
||||
// check-pass
|
||||
|
||||
use std::ops::Deref;
|
||||
|
||||
|
|
@ -17,7 +17,6 @@ trait Baz {
|
|||
}
|
||||
|
||||
impl<T> Baz for T where T: Foo {
|
||||
//~^ ERROR type mismatch resolving
|
||||
type Quux<'a> where T: 'a = T;
|
||||
|
||||
type Baa<'a> where T: 'a = &'a <T as Foo>::Bar<'a, 'static>;
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
error[E0271]: type mismatch resolving `for<'a> <<T as Baz>::Baa<'a> as std::ops::Deref>::Target == <<T as Baz>::Quux<'a> as Foo>::Bar<'a, 'static>`
|
||||
--> $DIR/construct_with_other_type.rs:19:9
|
||||
|
|
||||
LL | impl<T> Baz for T where T: Foo {
|
||||
| - ^^^ expected type parameter `T`, found associated type
|
||||
| |
|
||||
| this type parameter
|
||||
|
|
||||
= note: expected associated type `<T as Foo>::Bar<'_, 'static>`
|
||||
found associated type `<<T as Baz>::Quux<'_> as Foo>::Bar<'_, 'static>`
|
||||
help: consider further restricting this bound
|
||||
|
|
||||
LL | impl<T> Baz for T where T: Foo + Baz<Quux = T> {
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0271`.
|
||||
|
|
@ -6,7 +6,6 @@ struct Foo;
|
|||
trait MyTrait {
|
||||
type Item<T>;
|
||||
//~^ ERROR generic associated types are unstable [E0658]
|
||||
//~| ERROR type-generic associated types are not yet implemented
|
||||
}
|
||||
|
||||
impl MyTrait for Foo {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ LL | type Item<T>;
|
|||
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: generic associated types are unstable
|
||||
--> $DIR/gat-dont-ice-on-absent-feature-2.rs:13:5
|
||||
--> $DIR/gat-dont-ice-on-absent-feature-2.rs:12:5
|
||||
|
|
||||
LL | type Item<T> = T;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -16,14 +16,6 @@ LL | type Item<T> = T;
|
|||
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
|
||||
|
||||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/gat-dont-ice-on-absent-feature-2.rs:7:5
|
||||
|
|
||||
LL | type Item<T>;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
|
|
@ -9,11 +9,8 @@ use std::fmt::{Display, Debug};
|
|||
trait Foo {
|
||||
type Assoc where Self: Sized;
|
||||
type Assoc2<T> where T: Display;
|
||||
//~^ ERROR type-generic associated types are not yet implemented
|
||||
type Assoc3<T>;
|
||||
//~^ ERROR type-generic associated types are not yet implemented
|
||||
type WithDefault<'a, T: Debug + 'a> = dyn Iterator<Item=T>;
|
||||
//~^ ERROR type-generic associated types are not yet implemented
|
||||
type WithDefault<'a, T: Debug + 'a>: ?Sized = dyn Iterator<Item=T>;
|
||||
type NoGenerics;
|
||||
}
|
||||
|
||||
|
|
@ -23,6 +20,7 @@ impl Foo for Bar {
|
|||
type Assoc = usize;
|
||||
type Assoc2<T> = Vec<T>;
|
||||
type Assoc3<T> where T: Iterator = Vec<T>;
|
||||
//~^ impl has stricter requirements than trait
|
||||
type WithDefault<'a, T: Debug + 'a> = &'a dyn Iterator<Item=T>;
|
||||
type NoGenerics = ::std::cell::Cell<i32>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,12 @@
|
|||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/generic-associated-types-where.rs:11:5
|
||||
|
|
||||
LL | type Assoc2<T> where T: Display;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/generic-associated-types-where.rs:13:5
|
||||
error[E0276]: impl has stricter requirements than trait
|
||||
--> $DIR/generic-associated-types-where.rs:22:5
|
||||
|
|
||||
LL | type Assoc3<T>;
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
| --------------- definition of `Assoc3` from trait
|
||||
...
|
||||
LL | type Assoc3<T> where T: Iterator = Vec<T>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: std::iter::Iterator`
|
||||
|
||||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/generic-associated-types-where.rs:15:5
|
||||
|
|
||||
LL | type WithDefault<'a, T: Debug + 'a> = dyn Iterator<Item=T>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0276`.
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@
|
|||
|
||||
trait Foo {
|
||||
type Assoc3<T>;
|
||||
//~^ type-generic associated types are not yet implemented
|
||||
}
|
||||
|
||||
struct Bar;
|
||||
|
||||
impl Foo for Bar {
|
||||
type Assoc3<T> where T: Iterator = Vec<T>;
|
||||
//~^ ERROR impl has stricter requirements than trait
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/issue-47206-where-clause.rs:7:5
|
||||
error[E0276]: impl has stricter requirements than trait
|
||||
--> $DIR/issue-47206-where-clause.rs:13:5
|
||||
|
|
||||
LL | type Assoc3<T>;
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
| --------------- definition of `Assoc3` from trait
|
||||
...
|
||||
LL | type Assoc3<T> where T: Iterator = Vec<T>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `T: std::iter::Iterator`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0276`.
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
#![allow(incomplete_features)]
|
||||
#![feature(generic_associated_types)]
|
||||
|
||||
// FIXME(generic-associated-types) Investigate why this doesn't compile.
|
||||
// check-pass
|
||||
|
||||
trait Iterator {
|
||||
type Item<'a>: 'a;
|
||||
//~^ ERROR the requirement `for<'a> <Self as Iterator>::Item<'a>: 'a` is not satisfied
|
||||
}
|
||||
|
||||
impl Iterator for () {
|
||||
type Item<'a> = &'a ();
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
error[E0280]: the requirement `for<'a> <Self as Iterator>::Item<'a>: 'a` is not satisfied
|
||||
--> $DIR/issue-62326-parameter-out-of-range.rs:7:20
|
||||
|
|
||||
LL | trait Iterator {
|
||||
| -------- required by a bound in this
|
||||
LL | type Item<'a>: 'a;
|
||||
| ^^ required by this bound in `Iterator`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -7,7 +7,6 @@ trait Trait1 {
|
|||
trait Trait2 {
|
||||
type Type1<B>: Trait1<A=B>;
|
||||
//~^ ERROR: generic associated types are unstable
|
||||
//~| ERROR: type-generic associated types are not yet implemented
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -7,14 +7,6 @@ LL | type Type1<B>: Trait1<A=B>;
|
|||
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
= help: add `#![feature(generic_associated_types)]` to the crate attributes to enable
|
||||
|
||||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/issue-67424.rs:8:5
|
||||
|
|
||||
LL | type Type1<B>: Trait1<A=B>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
// Regression test for #68641
|
||||
|
||||
#![feature(generic_associated_types)]
|
||||
//~^ WARNING the feature `generic_associated_types` is incomplete and may not
|
||||
|
||||
trait UnsafeCopy {
|
||||
type Item<'a>: Copy;
|
||||
|
||||
fn copy<'a>(item: &Self::Item<'a>) -> Self::Item<'a> {
|
||||
*item
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> UnsafeCopy for T {
|
||||
type Item<'a> = T;
|
||||
//~^ ERROR the trait bound `T: std::marker::Copy` is not satisfied
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut s = String::from("Hello world!");
|
||||
|
||||
let copy = String::copy(&s);
|
||||
|
||||
// Do we indeed point to the samme memory?
|
||||
assert!(s.as_ptr() == copy.as_ptr());
|
||||
|
||||
// Any use of `copy` is certeinly UB after this
|
||||
drop(s);
|
||||
|
||||
// UB UB UB UB UB!!
|
||||
println!("{}", copy);
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/issue-68641-check-gat-bounds.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
|
||||
|
||||
error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
|
||||
--> $DIR/issue-68641-check-gat-bounds.rs:15:5
|
||||
|
|
||||
LL | type Item<'a>: Copy;
|
||||
| -------------------- required by `UnsafeCopy::Item`
|
||||
...
|
||||
LL | type Item<'a> = T;
|
||||
| ^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
|
||||
|
|
||||
help: consider restricting type parameter `T`
|
||||
|
|
||||
LL | impl<T: std::marker::Copy> UnsafeCopy for T {
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// Regression test for #68642
|
||||
|
||||
#![feature(generic_associated_types)]
|
||||
//~^ WARNING the feature `generic_associated_types` is incomplete and may not
|
||||
|
||||
trait Fun {
|
||||
type F<'a>: Fn() -> u32;
|
||||
|
||||
fn callme<'a>(f: Self::F<'a>) -> u32 {
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Fun for T {
|
||||
type F<'a> = Self;
|
||||
//~^ ERROR expected a `std::ops::Fn<()>` closure, found `T`
|
||||
}
|
||||
|
||||
fn main() {
|
||||
<fn() -> usize>::callme(|| 1);
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/issue-68642-broken-llvm-ir.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
|
||||
|
||||
error[E0277]: expected a `std::ops::Fn<()>` closure, found `T`
|
||||
--> $DIR/issue-68642-broken-llvm-ir.rs:15:5
|
||||
|
|
||||
LL | type F<'a>: Fn() -> u32;
|
||||
| ------------------------ required by `Fun::F`
|
||||
...
|
||||
LL | type F<'a> = Self;
|
||||
| ^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `T`
|
||||
|
|
||||
= help: the trait `std::ops::Fn<()>` is not implemented for `T`
|
||||
= note: wrap the `T` in a closure with no arguments: `|| { /* code */ }
|
||||
help: consider restricting type parameter `T`
|
||||
|
|
||||
LL | impl<T: std::ops::Fn<()>> Fun for T {
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// Regression test for #68643
|
||||
|
||||
#![feature(generic_associated_types)]
|
||||
//~^ WARNING the feature `generic_associated_types` is incomplete and may not
|
||||
|
||||
trait Fun {
|
||||
type F<'a>: Fn() -> u32;
|
||||
|
||||
fn callme<'a>(f: Self::F<'a>) -> u32 {
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Fun for T {
|
||||
type F<'a> = Self;
|
||||
//~^ ERROR expected a `std::ops::Fn<()>` closure, found `T`
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
<fn()>::callme(|| {});
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/issue-68643-broken-mir.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
|
||||
|
||||
error[E0277]: expected a `std::ops::Fn<()>` closure, found `T`
|
||||
--> $DIR/issue-68643-broken-mir.rs:15:5
|
||||
|
|
||||
LL | type F<'a>: Fn() -> u32;
|
||||
| ------------------------ required by `Fun::F`
|
||||
...
|
||||
LL | type F<'a> = Self;
|
||||
| ^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `T`
|
||||
|
|
||||
= help: the trait `std::ops::Fn<()>` is not implemented for `T`
|
||||
= note: wrap the `T` in a closure with no arguments: `|| { /* code */ }
|
||||
help: consider restricting type parameter `T`
|
||||
|
|
||||
LL | impl<T: std::ops::Fn<()>> Fun for T {
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// Regression test for #68644
|
||||
|
||||
#![feature(generic_associated_types)]
|
||||
//~^ WARNING the feature `generic_associated_types` is incomplete and may not
|
||||
|
||||
trait Fun {
|
||||
type F<'a>: Fn() -> u32;
|
||||
|
||||
fn callme<'a>(f: Self::F<'a>) -> u32 {
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Fun for T {
|
||||
type F<'a> = Self;
|
||||
//~^ ERROR expected a `std::ops::Fn<()>` closure, found `T`
|
||||
}
|
||||
|
||||
fn main() {
|
||||
<u8>::callme(0);
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/issue-68644-codegen-selection.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
|
||||
|
||||
error[E0277]: expected a `std::ops::Fn<()>` closure, found `T`
|
||||
--> $DIR/issue-68644-codegen-selection.rs:15:5
|
||||
|
|
||||
LL | type F<'a>: Fn() -> u32;
|
||||
| ------------------------ required by `Fun::F`
|
||||
...
|
||||
LL | type F<'a> = Self;
|
||||
| ^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `T`
|
||||
|
|
||||
= help: the trait `std::ops::Fn<()>` is not implemented for `T`
|
||||
= note: wrap the `T` in a closure with no arguments: `|| { /* code */ }
|
||||
help: consider restricting type parameter `T`
|
||||
|
|
||||
LL | impl<T: std::ops::Fn<()>> Fun for T {
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// Regression test for #68645
|
||||
|
||||
#![feature(generic_associated_types)]
|
||||
//~^ WARNING the feature `generic_associated_types` is incomplete and may not
|
||||
|
||||
trait Fun {
|
||||
type F<'a>: Fn() -> u32;
|
||||
|
||||
fn callme<'a>(f: Self::F<'a>) -> u32 {
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Fun for T {
|
||||
type F<'a> = Self;
|
||||
//~^ ERROR expected a `std::ops::Fn<()>` closure, found `T`
|
||||
}
|
||||
|
||||
fn main() {
|
||||
<&dyn Iterator<Item = u8>>::callme(&std::iter::once(1));
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/issue-68645-codegen-fulfillment.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
|
||||
|
||||
error[E0277]: expected a `std::ops::Fn<()>` closure, found `T`
|
||||
--> $DIR/issue-68645-codegen-fulfillment.rs:15:5
|
||||
|
|
||||
LL | type F<'a>: Fn() -> u32;
|
||||
| ------------------------ required by `Fun::F`
|
||||
...
|
||||
LL | type F<'a> = Self;
|
||||
| ^^^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `T`
|
||||
|
|
||||
= help: the trait `std::ops::Fn<()>` is not implemented for `T`
|
||||
= note: wrap the `T` in a closure with no arguments: `|| { /* code */ }
|
||||
help: consider restricting type parameter `T`
|
||||
|
|
||||
LL | impl<T: std::ops::Fn<()>> Fun for T {
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
// Regression test for #68656
|
||||
|
||||
#![feature(generic_associated_types)]
|
||||
//~^ WARNING the feature `generic_associated_types` is incomplete and may not
|
||||
|
||||
trait UnsafeCopy<T: Copy> {
|
||||
type Item<'a>: std::ops::Deref<Target = T>;
|
||||
|
||||
fn bug<'a>(item: &Self::Item<'a>) -> () {
|
||||
let x: T = **item;
|
||||
&x as *const _;
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + std::ops::Deref> UnsafeCopy<T> for T {
|
||||
type Item<'a> = T;
|
||||
//~^ ERROR type mismatch resolving `<T as std::ops::Deref>::Target == T`
|
||||
}
|
||||
|
||||
fn main() {
|
||||
<&'static str>::bug(&"");
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/issue-68656-unsized-values.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
|
||||
|
||||
error[E0271]: type mismatch resolving `<T as std::ops::Deref>::Target == T`
|
||||
--> $DIR/issue-68656-unsized-values.rs:16:5
|
||||
|
|
||||
LL | type Item<'a>: std::ops::Deref<Target = T>;
|
||||
| ------------------------------------------- required by `UnsafeCopy::Item`
|
||||
...
|
||||
LL | impl<T: Copy + std::ops::Deref> UnsafeCopy<T> for T {
|
||||
| - this type parameter
|
||||
LL | type Item<'a> = T;
|
||||
| ^^^^^^^^^^^^^^^^^^ expected type parameter `T`, found associated type
|
||||
|
|
||||
= note: expected type parameter `T`
|
||||
found associated type `<T as std::ops::Deref>::Target`
|
||||
help: consider further restricting this bound
|
||||
|
|
||||
LL | impl<T: Copy + std::ops::Deref + std::ops::Deref<Target = T>> UnsafeCopy<T> for T {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0271`.
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#![allow(incomplete_features)]
|
||||
#![feature(generic_associated_types)]
|
||||
|
||||
// FIXME(#30472) normalize enough to handle this.
|
||||
// run-pass
|
||||
|
||||
trait Iterable {
|
||||
type Item<'a> where Self: 'a;
|
||||
|
|
@ -13,39 +13,35 @@ trait Iterable {
|
|||
// Impl for struct type
|
||||
impl<T> Iterable for Vec<T> {
|
||||
type Item<'a> where T: 'a = <std::slice::Iter<'a, T> as Iterator>::Item;
|
||||
//~^ ERROR type mismatch resolving
|
||||
type Iter<'a> where T: 'a = std::slice::Iter<'a, T>;
|
||||
|
||||
fn iter<'a>(&'a self) -> Self::Iter<'a> {
|
||||
//~^ ERROR type mismatch resolving
|
||||
self.iter()
|
||||
self[..].iter()
|
||||
}
|
||||
}
|
||||
|
||||
// Impl for a primitive type
|
||||
impl<T> Iterable for [T] {
|
||||
type Item<'a> where T: 'a = <std::slice::Iter<'a, T> as Iterator>::Item;
|
||||
//~^ ERROR type mismatch resolving
|
||||
type Iter<'a> where T: 'a = std::slice::Iter<'a, T>;
|
||||
|
||||
fn iter<'a>(&'a self) -> Self::Iter<'a> {
|
||||
//~^ ERROR type mismatch resolving
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
fn make_iter<'a, I: Iterable>(it: &'a I) -> I::Iter<'a> {
|
||||
fn make_iter<'a, I: Iterable + ?Sized>(it: &'a I) -> I::Iter<'a> {
|
||||
it.iter()
|
||||
}
|
||||
|
||||
fn get_first<'a, I: Iterable>(it: &'a I) -> Option<I::Item<'a>> {
|
||||
fn get_first<'a, I: Iterable + ?Sized>(it: &'a I) -> Option<I::Item<'a>> {
|
||||
it.iter().next()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let v = vec![1, 2, 3];
|
||||
assert_eq!(v, make_iter(&v).copied().collect());
|
||||
assert_eq!(v, make_iter(&*v).copied().collect());
|
||||
assert_eq!(1, get_first(&v));
|
||||
assert_eq!(1, get_first(&*v));
|
||||
assert_eq!(v, make_iter(&v).copied().collect::<Vec<_>>());
|
||||
assert_eq!(v, make_iter(&*v).copied().collect::<Vec<_>>());
|
||||
assert_eq!(Some(&1), get_first(&v));
|
||||
assert_eq!(Some(&1), get_first(&*v));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
error[E0271]: type mismatch resolving `for<'a> <<std::vec::Vec<T> as Iterable>::Iter<'a> as std::iter::Iterator>::Item == <std::vec::Vec<T> as Iterable>::Item<'a>`
|
||||
--> $DIR/iterable.rs:15:33
|
||||
|
|
||||
LL | type Item<'a> where T: 'a = <std::slice::Iter<'a, T> as Iterator>::Item;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found associated type
|
||||
|
|
||||
= note: expected reference `&T`
|
||||
found associated type `<std::vec::Vec<T> as Iterable>::Item<'_>`
|
||||
= help: consider constraining the associated type `<std::vec::Vec<T> as Iterable>::Item<'_>` to `&_`
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
|
||||
|
||||
error[E0271]: type mismatch resolving `for<'a> <<[T] as Iterable>::Iter<'a> as std::iter::Iterator>::Item == <[T] as Iterable>::Item<'a>`
|
||||
--> $DIR/iterable.rs:27:33
|
||||
|
|
||||
LL | type Item<'a> where T: 'a = <std::slice::Iter<'a, T> as Iterator>::Item;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found associated type
|
||||
|
|
||||
= note: expected reference `&T`
|
||||
found associated type `<[T] as Iterable>::Item<'_>`
|
||||
= help: consider constraining the associated type `<[T] as Iterable>::Item<'_>` to `&_`
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
|
||||
|
||||
error[E0271]: type mismatch resolving `for<'a> <<std::vec::Vec<T> as Iterable>::Iter<'a> as std::iter::Iterator>::Item == <std::vec::Vec<T> as Iterable>::Item<'a>`
|
||||
--> $DIR/iterable.rs:19:30
|
||||
|
|
||||
LL | trait Iterable {
|
||||
| -------- required by a bound in this
|
||||
LL | type Item<'a> where Self: 'a;
|
||||
LL | type Iter<'a>: Iterator<Item = Self::Item<'a>> where Self: 'a;
|
||||
| --------------------- required by this bound in `Iterable`
|
||||
...
|
||||
LL | fn iter<'a>(&'a self) -> Self::Iter<'a> {
|
||||
| ^^^^^^^^^^^^^^ expected associated type, found reference
|
||||
|
|
||||
= note: expected associated type `<std::vec::Vec<T> as Iterable>::Item<'_>`
|
||||
found reference `&T`
|
||||
= help: consider constraining the associated type `<std::vec::Vec<T> as Iterable>::Item<'_>` to `&_` or calling a method that returns `<std::vec::Vec<T> as Iterable>::Item<'_>`
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
|
||||
|
||||
error[E0271]: type mismatch resolving `for<'a> <<[T] as Iterable>::Iter<'a> as std::iter::Iterator>::Item == <[T] as Iterable>::Item<'a>`
|
||||
--> $DIR/iterable.rs:31:30
|
||||
|
|
||||
LL | trait Iterable {
|
||||
| -------- required by a bound in this
|
||||
LL | type Item<'a> where Self: 'a;
|
||||
LL | type Iter<'a>: Iterator<Item = Self::Item<'a>> where Self: 'a;
|
||||
| --------------------- required by this bound in `Iterable`
|
||||
...
|
||||
LL | fn iter<'a>(&'a self) -> Self::Iter<'a> {
|
||||
| ^^^^^^^^^^^^^^ expected associated type, found reference
|
||||
|
|
||||
= note: expected associated type `<[T] as Iterable>::Item<'_>`
|
||||
found reference `&T`
|
||||
= help: consider constraining the associated type `<[T] as Iterable>::Item<'_>` to `&_` or calling a method that returns `<[T] as Iterable>::Item<'_>`
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0271`.
|
||||
|
|
@ -34,12 +34,11 @@ impl<B: std::ops::Add<Output = B>> Add for D<B> {
|
|||
|
||||
struct E<B>(B);
|
||||
|
||||
impl<B: Add> Add for E<B> where B: Add<Output = B>, B: std::ops::Add<Output = B> {
|
||||
//~^ ERROR equality constraints are not yet supported in `where` clauses
|
||||
impl<B: Add> Add for E<B> where B: Add<Output = B> {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self {
|
||||
Self(self.0 + rhs.0) //~ ERROR mismatched types
|
||||
Self(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,12 +34,11 @@ impl<B> Add for D<B> {
|
|||
|
||||
struct E<B>(B);
|
||||
|
||||
impl<B: Add> Add for E<B> where <B as Add>::Output = B {
|
||||
//~^ ERROR equality constraints are not yet supported in `where` clauses
|
||||
impl<B: Add> Add for E<B> where B: Add<Output = B> {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self {
|
||||
Self(self.0 + rhs.0) //~ ERROR mismatched types
|
||||
Self(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,3 @@
|
|||
error: equality constraints are not yet supported in `where` clauses
|
||||
--> $DIR/missing-bounds.rs:37:33
|
||||
|
|
||||
LL | impl<B: Add> Add for E<B> where <B as Add>::Output = B {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ not supported
|
||||
|
|
||||
= note: see issue #20041 <https://github.com/rust-lang/rust/issues/20041> for more information
|
||||
help: if `Output` is an associated type you're trying to set, use the associated type binding syntax
|
||||
|
|
||||
LL | impl<B: Add> Add for E<B> where B: Add<Output = B> {
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/missing-bounds.rs:11:11
|
||||
|
|
||||
|
|
@ -55,23 +43,7 @@ help: consider restricting type parameter `B`
|
|||
LL | impl<B: std::ops::Add<Output = B>> Add for D<B> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/missing-bounds.rs:42:14
|
||||
|
|
||||
LL | impl<B: Add> Add for E<B> where <B as Add>::Output = B {
|
||||
| - this type parameter
|
||||
...
|
||||
LL | Self(self.0 + rhs.0)
|
||||
| ^^^^^^^^^^^^^^ expected type parameter `B`, found associated type
|
||||
|
|
||||
= note: expected type parameter `B`
|
||||
found associated type `<B as std::ops::Add>::Output`
|
||||
help: consider further restricting type parameter `B`
|
||||
|
|
||||
LL | impl<B: Add> Add for E<B> where <B as Add>::Output = B, B: std::ops::Add<Output = B> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0308, E0369.
|
||||
For more information about an error, try `rustc --explain E0308`.
|
||||
|
|
|
|||
|
|
@ -7,18 +7,14 @@ trait Foo {
|
|||
type B<'a, 'b>;
|
||||
type C;
|
||||
type D<T>;
|
||||
//~^ ERROR type-generic associated types are not yet implemented
|
||||
type E<'a, T>;
|
||||
//~^ ERROR type-generic associated types are not yet implemented
|
||||
// Test parameters in default values
|
||||
type FOk<T> = Self::E<'static, T>;
|
||||
//~^ ERROR type-generic associated types are not yet implemented
|
||||
type FErr1 = Self::E<'static, 'static>;
|
||||
//~^ ERROR wrong number of lifetime arguments: expected 1, found 2
|
||||
//~| ERROR wrong number of type arguments: expected 1, found 0
|
||||
type FErr2<T> = Self::E<'static, T, u32>;
|
||||
//~^ ERROR type-generic associated types are not yet implemented
|
||||
//~| ERROR wrong number of type arguments: expected 1, found 2
|
||||
//~^ ERROR wrong number of type arguments: expected 1, found 2
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,53 +1,21 @@
|
|||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/parameter_number_and_kind.rs:9:5
|
||||
|
|
||||
LL | type D<T>;
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/parameter_number_and_kind.rs:11:5
|
||||
|
|
||||
LL | type E<'a, T>;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/parameter_number_and_kind.rs:14:5
|
||||
|
|
||||
LL | type FOk<T> = Self::E<'static, T>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/parameter_number_and_kind.rs:19:5
|
||||
|
|
||||
LL | type FErr2<T> = Self::E<'static, T, u32>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error[E0107]: wrong number of lifetime arguments: expected 1, found 2
|
||||
--> $DIR/parameter_number_and_kind.rs:16:35
|
||||
--> $DIR/parameter_number_and_kind.rs:13:35
|
||||
|
|
||||
LL | type FErr1 = Self::E<'static, 'static>;
|
||||
| ^^^^^^^ unexpected lifetime argument
|
||||
|
||||
error[E0107]: wrong number of type arguments: expected 1, found 0
|
||||
--> $DIR/parameter_number_and_kind.rs:16:18
|
||||
--> $DIR/parameter_number_and_kind.rs:13:18
|
||||
|
|
||||
LL | type FErr1 = Self::E<'static, 'static>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 type argument
|
||||
|
||||
error[E0107]: wrong number of type arguments: expected 1, found 2
|
||||
--> $DIR/parameter_number_and_kind.rs:19:41
|
||||
--> $DIR/parameter_number_and_kind.rs:16:41
|
||||
|
|
||||
LL | type FErr2<T> = Self::E<'static, T, u32>;
|
||||
| ^^^ unexpected type argument
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0107`.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#![allow(incomplete_features)]
|
||||
#![feature(generic_associated_types)]
|
||||
|
||||
// FIXME(#44265): allow type-generic associated types.
|
||||
// check-pass
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
|
@ -9,7 +9,6 @@ use std::ops::Deref;
|
|||
|
||||
trait PointerFamily {
|
||||
type Pointer<T>: Deref<Target = T>;
|
||||
//~^ ERROR type-generic associated types are not yet implemented
|
||||
fn new<T>(value: T) -> Self::Pointer<T>;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/pointer_family.rs:11:5
|
||||
|
|
||||
LL | type Pointer<T>: Deref<Target = T>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -18,12 +18,10 @@ impl<'a> NoShadow<'a> for &'a u32 {
|
|||
trait ShadowT<T> {
|
||||
type Bar<T>;
|
||||
//~^ ERROR the name `T` is already used
|
||||
//~| ERROR type-generic associated types are not yet implemented
|
||||
}
|
||||
|
||||
trait NoShadowT<T> {
|
||||
type Bar<U>; // OK
|
||||
//~^ ERROR type-generic associated types are not yet implemented
|
||||
}
|
||||
|
||||
impl<T> NoShadowT<T> for Option<T> {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ LL | type Bar<T>;
|
|||
| ^ already used
|
||||
|
||||
error[E0403]: the name `T` is already used for a generic parameter in this item's generic parameters
|
||||
--> $DIR/shadowing.rs:30:14
|
||||
--> $DIR/shadowing.rs:28:14
|
||||
|
|
||||
LL | impl<T> NoShadowT<T> for Option<T> {
|
||||
| - first use of `T`
|
||||
|
|
@ -30,23 +30,7 @@ LL | impl<'a> NoShadow<'a> for &'a u32 {
|
|||
LL | type Bar<'a> = i32;
|
||||
| ^^ lifetime 'a already in scope
|
||||
|
||||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/shadowing.rs:19:5
|
||||
|
|
||||
LL | type Bar<T>;
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error: type-generic associated types are not yet implemented
|
||||
--> $DIR/shadowing.rs:25:5
|
||||
|
|
||||
LL | type Bar<U>; // OK
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0403, E0496.
|
||||
For more information about an error, try `rustc --explain E0403`.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
#![allow(incomplete_features)]
|
||||
#![feature(generic_associated_types)]
|
||||
|
||||
trait ATy {
|
||||
type Item<'a>: 'a;
|
||||
}
|
||||
|
||||
impl<'b> ATy for &'b () {
|
||||
type Item<'a> = &'b ();
|
||||
//~^ ERROR does not fulfill the required lifetime
|
||||
}
|
||||
|
||||
trait StaticTy {
|
||||
type Item<'a>: 'static;
|
||||
}
|
||||
|
||||
impl StaticTy for () {
|
||||
type Item<'a> = &'a ();
|
||||
//~^ ERROR does not fulfill the required lifetime
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
error[E0477]: the type `&'b ()` does not fulfill the required lifetime
|
||||
--> $DIR/unsatisfied-outlives-bound.rs:9:5
|
||||
|
|
||||
LL | type Item<'a> = &'b ();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: type must outlive the lifetime `'a` as defined on the associated item at 9:15
|
||||
--> $DIR/unsatisfied-outlives-bound.rs:9:15
|
||||
|
|
||||
LL | type Item<'a> = &'b ();
|
||||
| ^^
|
||||
|
||||
error[E0477]: the type `&'a ()` does not fulfill the required lifetime
|
||||
--> $DIR/unsatisfied-outlives-bound.rs:18:5
|
||||
|
|
||||
LL | type Item<'a> = &'a ();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: type must satisfy the static lifetime
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0477`.
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
// run-pass
|
||||
#![feature(specialization)]
|
||||
//~^ WARN the feature `specialization` is incomplete
|
||||
|
||||
|
|
@ -8,6 +7,7 @@ trait Iterate<'a> {
|
|||
}
|
||||
impl<'a, T> Iterate<'a> for T where T: Check {
|
||||
default type Ty = ();
|
||||
//~^ ERROR the trait bound `(): Valid` is not satisfied
|
||||
default fn iterate(self) {}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/issue-38091.rs:2:12
|
||||
--> $DIR/issue-38091.rs:1:12
|
||||
|
|
||||
LL | #![feature(specialization)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
@ -7,5 +7,15 @@ LL | #![feature(specialization)]
|
|||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
error[E0277]: the trait bound `(): Valid` is not satisfied
|
||||
--> $DIR/issue-38091.rs:9:5
|
||||
|
|
||||
LL | type Ty: Valid;
|
||||
| --------------- required by `Iterate::Ty`
|
||||
...
|
||||
LL | default type Ty = ();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Valid` is not implemented for `()`
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
// Check that we check that default associated types satisfy the required
|
||||
// bounds on them.
|
||||
|
||||
#![feature(specialization)]
|
||||
//~^ WARNING `specialization` is incomplete
|
||||
|
||||
trait X {
|
||||
type U: Clone;
|
||||
fn unsafe_clone(&self, x: Option<&Self::U>) {
|
||||
x.cloned();
|
||||
}
|
||||
}
|
||||
|
||||
// We cannot normalize `<T as X>::U` to `str` here, because the default could
|
||||
// be overridden. The error here must therefore be found by a method other than
|
||||
// normalization.
|
||||
impl<T> X for T {
|
||||
default type U = str;
|
||||
//~^ ERROR the trait bound `str: std::clone::Clone` is not satisfied
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
1.unsafe_clone(None);
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/deafult-associated-type-bound-1.rs:4:12
|
||||
|
|
||||
LL | #![feature(specialization)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
|
||||
|
||||
error[E0277]: the trait bound `str: std::clone::Clone` is not satisfied
|
||||
--> $DIR/deafult-associated-type-bound-1.rs:18:5
|
||||
|
|
||||
LL | type U: Clone;
|
||||
| -------------- required by `X::U`
|
||||
...
|
||||
LL | default type U = str;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ the trait `std::clone::Clone` is not implemented for `str`
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
// Check that generic predicates are also checked for default associated types.
|
||||
#![feature(specialization)]
|
||||
//~^ WARNING `specialization` is incomplete
|
||||
|
||||
trait X<T> {
|
||||
type U: PartialEq<T>;
|
||||
fn unsafe_compare(x: Option<Self::U>, y: Option<T>) {
|
||||
match (x, y) {
|
||||
(Some(a), Some(b)) => a == b,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: 'static, T> X<B> for T {
|
||||
default type U = &'static B;
|
||||
//~^ ERROR can't compare `&'static B` with `B`
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
<i32 as X<i32>>::unsafe_compare(None, None);
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/deafult-associated-type-bound-2.rs:2:12
|
||||
|
|
||||
LL | #![feature(specialization)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
|
||||
|
||||
error[E0277]: can't compare `&'static B` with `B`
|
||||
--> $DIR/deafult-associated-type-bound-2.rs:16:5
|
||||
|
|
||||
LL | type U: PartialEq<T>;
|
||||
| --------------------- required by `X::U`
|
||||
...
|
||||
LL | default type U = &'static B;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `&'static B == B`
|
||||
|
|
||||
= help: the trait `std::cmp::PartialEq<B>` is not implemented for `&'static B`
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// Check that default generics associated types are validated.
|
||||
|
||||
#![feature(specialization)]
|
||||
#![feature(generic_associated_types)]
|
||||
//~^^ WARNING `specialization` is incomplete
|
||||
//~^^ WARNING the feature `generic_associated_types` is incomplete
|
||||
|
||||
trait X {
|
||||
type U<'a>: PartialEq<&'a Self>;
|
||||
fn unsafe_compare<'b>(x: Option<Self::U<'b>>, y: Option<&'b Self>) {
|
||||
match (x, y) {
|
||||
(Some(a), Some(b)) => a == b,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: 'static> X for T {
|
||||
default type U<'a> = &'a T;
|
||||
//~^ ERROR can't compare `T` with `T`
|
||||
}
|
||||
|
||||
struct NotComparable;
|
||||
|
||||
pub fn main() {
|
||||
<NotComparable as X>::unsafe_compare(None, None);
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/deafult-generic-associated-type-bound.rs:3:12
|
||||
|
|
||||
LL | #![feature(specialization)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
|
||||
|
||||
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/deafult-generic-associated-type-bound.rs:4:12
|
||||
|
|
||||
LL | #![feature(generic_associated_types)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
|
||||
|
||||
error[E0277]: can't compare `T` with `T`
|
||||
--> $DIR/deafult-generic-associated-type-bound.rs:19:5
|
||||
|
|
||||
LL | type U<'a>: PartialEq<&'a Self>;
|
||||
| -------------------------------- required by `X::U`
|
||||
...
|
||||
LL | default type U<'a> = &'a T;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `T == T`
|
||||
|
|
||||
= help: the trait `std::cmp::PartialEq` is not implemented for `T`
|
||||
= note: required because of the requirements on the impl of `std::cmp::PartialEq` for `&'a T`
|
||||
help: consider further restricting this bound
|
||||
|
|
||||
LL | impl<T: 'static + std::cmp::PartialEq> X for T {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error; 2 warnings emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -7,7 +7,6 @@ fn f() where
|
|||
//~^ ERROR use of undeclared lifetime name `'a`
|
||||
for<'a> dyn for<'b> Trait2<'a, 'b>: Trait2<'a, 'b>,
|
||||
//~^ ERROR use of undeclared lifetime name `'b`
|
||||
//~| ERROR nested quantification of lifetimes
|
||||
{}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -7,12 +7,6 @@ LL | for<'a> dyn Trait1<'a>: Trait1<'a>, // OK
|
|||
LL | (dyn for<'a> Trait1<'a>): Trait1<'a>,
|
||||
| ^^ undeclared lifetime
|
||||
|
||||
error[E0316]: nested quantification of lifetimes
|
||||
--> $DIR/where-lifetime-resolution.rs:8:17
|
||||
|
|
||||
LL | for<'a> dyn for<'b> Trait2<'a, 'b>: Trait2<'a, 'b>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0261]: use of undeclared lifetime name `'b`
|
||||
--> $DIR/where-lifetime-resolution.rs:8:52
|
||||
|
|
||||
|
|
@ -22,6 +16,6 @@ LL | fn f() where
|
|||
LL | for<'a> dyn for<'b> Trait2<'a, 'b>: Trait2<'a, 'b>,
|
||||
| ^^ undeclared lifetime
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0261`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue