Require lifetime bounds for opaque types in order to allow hidden types to capture said lifetimes

This commit is contained in:
Oli Scherer 2022-09-28 16:01:05 +00:00
parent 1755c85302
commit 1dc2119c03
20 changed files with 150 additions and 36 deletions

View file

@ -1,6 +1,10 @@
#![feature(type_alias_impl_trait)]
type X<'a, 'b> = impl std::fmt::Debug;
pub trait Captures<'a> {}
impl<'a, T: ?Sized> Captures<'a> for T {}
type X<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
fn f<'t, 'u>(a: &'t u32, b: &'u u32) -> (X<'t, 'u>, X<'u, 't>) {
(a, a)

View file

@ -1,5 +1,5 @@
error: concrete type differs from previous defining opaque type use
--> $DIR/issue-86465.rs:6:5
--> $DIR/issue-86465.rs:10:5
|
LL | (a, a)
| ^^^^^^

View file

@ -1,7 +1,11 @@
#![feature(type_alias_impl_trait)]
#![allow(dead_code)]
type OneLifetime<'a, 'b> = impl std::fmt::Debug;
pub trait Captures<'a> {}
impl<'a, T: ?Sized> Captures<'a> for T {}
type OneLifetime<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
fn foo<'a, 'b>(a: &'a u32, b: &'b u32) -> OneLifetime<'a, 'b> {
a

View file

@ -1,11 +1,11 @@
error: concrete type differs from previous defining opaque type use
--> $DIR/different_lifetimes_defining_uses.rs:11:5
--> $DIR/different_lifetimes_defining_uses.rs:15:5
|
LL | b
| ^ expected `&'a u32`, got `&'b u32`
|
note: previous use here
--> $DIR/different_lifetimes_defining_uses.rs:7:5
--> $DIR/different_lifetimes_defining_uses.rs:11:5
|
LL | a
| ^

View file

@ -2,8 +2,11 @@
fn main() {}
type Two<'a, 'b> = impl std::fmt::Debug;
pub trait Captures<'a> {}
impl<'a, T: ?Sized> Captures<'a> for T {}
type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
fn one<'a>(t: &'a ()) -> Two<'a, 'a> {
t

View file

@ -1,13 +1,13 @@
error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_lifetime_param.rs:9:5
--> $DIR/generic_duplicate_lifetime_param.rs:12:5
|
LL | t
| ^
|
note: lifetime used multiple times
--> $DIR/generic_duplicate_lifetime_param.rs:5:10
--> $DIR/generic_duplicate_lifetime_param.rs:9:10
|
LL | type Two<'a, 'b> = impl std::fmt::Debug;
LL | type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
| ^^ ^^
error: aborting due to previous error

View file

@ -7,7 +7,12 @@ fn main() {}
// test that unused generic parameters are ok
type TwoTys<T, U> = impl Debug;
type TwoLifetimes<'a, 'b> = impl Debug;
pub trait Captures<'a> {}
impl<'a, T: ?Sized> Captures<'a> for T {}
type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>;
type TwoConsts<const X: usize, const Y: usize> = impl Debug;

View file

@ -1,5 +1,5 @@
error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:16:5
--> $DIR/generic_duplicate_param_use.rs:21:5
|
LL | t
| ^
@ -10,26 +10,26 @@ note: type used multiple times
LL | type TwoTys<T, U> = impl Debug;
| ^ ^
error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:21:5
|
LL | t
| ^
|
note: lifetime used multiple times
--> $DIR/generic_duplicate_param_use.rs:10:19
|
LL | type TwoLifetimes<'a, 'b> = impl Debug;
| ^^ ^^
error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:26:5
|
LL | t
| ^
|
note: lifetime used multiple times
--> $DIR/generic_duplicate_param_use.rs:15:19
|
LL | type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>;
| ^^ ^^
error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:31:5
|
LL | t
| ^
|
note: constant used multiple times
--> $DIR/generic_duplicate_param_use.rs:12:16
--> $DIR/generic_duplicate_param_use.rs:17:16
|
LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug;
| ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^

View file

@ -1,10 +1,11 @@
// build-pass (FIXME(62277): could be check-pass?)
// check-pass
#![feature(type_alias_impl_trait)]
fn main() {}
type Region<'a> = impl std::fmt::Debug;
type Region<'a> = impl std::fmt::Debug + 'a;
fn region<'b>(a: &'b ()) -> Region<'b> {
a

View file

@ -1,7 +1,7 @@
#![feature(type_alias_impl_trait)]
mod test_lifetime_param {
type Ty<'a> = impl Sized;
type Ty<'a> = impl Sized + 'a;
fn defining(a: &str) -> Ty<'_> { a }
fn assert_static<'a: 'static>() {}
//~^ WARN: unnecessary lifetime parameter `'a`
@ -10,7 +10,7 @@ mod test_lifetime_param {
}
mod test_higher_kinded_lifetime_param {
type Ty<'a> = impl Sized;
type Ty<'a> = impl Sized + 'a;
fn defining(a: &str) -> Ty<'_> { a }
fn assert_static<'a: 'static>() {}
//~^ WARN: unnecessary lifetime parameter `'a`

View file

@ -4,7 +4,7 @@
use std::future::Future;
type G<'a, T> = impl Future<Output = ()>;
type G<'a, T> = impl Future<Output = ()> + 'a;
trait Trait {
type F: Future<Output = ()>;

View file

@ -6,7 +6,7 @@ LL | async move { self.f().await }
|
help: consider restricting type parameter `T`
|
LL | type G<'a, T: Trait> = impl Future<Output = ()>;
LL | type G<'a, T: Trait> = impl Future<Output = ()> + 'a;
| +++++++
error: aborting due to previous error

View file

@ -0,0 +1,7 @@
#![feature(type_alias_impl_trait)]
type Opaque<'a, T> = impl Sized;
fn defining<'a, T>(x: &'a i32) -> Opaque<T> { x }
//~^ ERROR: non-defining opaque type use in defining scope
fn main() {}

View file

@ -0,0 +1,8 @@
error: non-defining opaque type use in defining scope
--> $DIR/missing_lifetime_bound.rs:4:47
|
LL | fn defining<'a, T>(x: &'a i32) -> Opaque<T> { x }
| ^ lifetime `'a` is part of concrete type but not used in parameter list of the `impl Trait` type alias
error: aborting due to previous error

View file

@ -1,6 +1,10 @@
#![feature(type_alias_impl_trait)]
type Foo<'a, 'b> = impl std::fmt::Debug;
pub trait Captures<'a> {}
impl<'a, T: ?Sized> Captures<'a> for T {}
type Foo<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) {
(i, i) //~ ERROR concrete type differs from previous

View file

@ -1,5 +1,5 @@
error: concrete type differs from previous defining opaque type use
--> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5
--> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:10:5
|
LL | (i, i)
| ^^^^^^

View file

@ -7,7 +7,11 @@ fn f<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<A, B>)
(a.clone(), a)
}
type Foo<'a, 'b> = impl std::fmt::Debug;
pub trait Captures<'a> {}
impl<'a, T: ?Sized> Captures<'a> for T {}
type Foo<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) {
(i, j)