Check associated opaque types don't use unconstrained lifetimes
This commit is contained in:
parent
033bd8c7af
commit
7f41cf4cef
5 changed files with 57 additions and 14 deletions
|
|
@ -6,7 +6,7 @@
|
|||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||
|
||||
trait UnwrapItemsExt<const C: usize> {
|
||||
trait UnwrapItemsExt<'a, const C: usize> {
|
||||
type Iter;
|
||||
fn unwrap_items(self) -> Self::Iter;
|
||||
}
|
||||
|
|
@ -18,18 +18,16 @@ trait MyTrait<'a, const C: usize> {
|
|||
const MY_CONST: usize;
|
||||
}
|
||||
|
||||
impl<'a, const C: usize> MyTrait<'a, {C}> for MyStruct<{C}> {
|
||||
impl<'a, const C: usize> MyTrait<'a, { C }> for MyStruct<{ C }> {
|
||||
type MyItem = u8;
|
||||
const MY_CONST: usize = C;
|
||||
}
|
||||
|
||||
impl<'a, I, const C: usize> UnwrapItemsExt<{C}> for I
|
||||
where
|
||||
{
|
||||
type Iter = impl MyTrait<'a, {C}>;
|
||||
impl<'a, I, const C: usize> UnwrapItemsExt<'a, { C }> for I {
|
||||
type Iter = impl MyTrait<'a, { C }>;
|
||||
|
||||
fn unwrap_items(self) -> Self::Iter {
|
||||
MyStruct::<{C}> {}
|
||||
MyStruct::<{ C }> {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
// Tests that we don't allow unconstrained lifetime parameters in impls when
|
||||
// the lifetime is used in an associated opaque type.
|
||||
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
trait UnwrapItemsExt {
|
||||
type Iter;
|
||||
fn unwrap_items(self) -> Self::Iter;
|
||||
}
|
||||
|
||||
struct MyStruct {}
|
||||
|
||||
trait MyTrait<'a> {}
|
||||
|
||||
impl<'a> MyTrait<'a> for MyStruct {}
|
||||
|
||||
impl<'a, I> UnwrapItemsExt for I {
|
||||
//~^ ERROR the lifetime parameter `'a` is not constrained
|
||||
type Iter = impl MyTrait<'a>;
|
||||
|
||||
fn unwrap_items(self) -> Self::Iter {
|
||||
MyStruct {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
|
||||
--> $DIR/assoc-type-lifetime-unconstrained.rs:17:6
|
||||
|
|
||||
LL | impl<'a, I> UnwrapItemsExt for I {
|
||||
| ^^ unconstrained lifetime parameter
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0207`.
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
trait UnwrapItemsExt {
|
||||
trait UnwrapItemsExt<'a> {
|
||||
type Iter;
|
||||
fn unwrap_items(self) -> Self::Iter;
|
||||
}
|
||||
|
|
@ -15,9 +15,7 @@ trait MyTrait<'a> {}
|
|||
|
||||
impl<'a> MyTrait<'a> for MyStruct {}
|
||||
|
||||
impl<'a, I> UnwrapItemsExt for I
|
||||
where
|
||||
{
|
||||
impl<'a, I> UnwrapItemsExt<'a> for I {
|
||||
type Iter = impl MyTrait<'a>;
|
||||
|
||||
fn unwrap_items(self) -> Self::Iter {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue