Revert "Auto merge of #102417 - oli-obk:opaque_lifetimes2, r=jackh726"

This reverts commit cb9467515b5a9b15aaa905683c6b4dd9e851056c, reversing
changes made to 57781b24c54f9548722927ba88c343ff28da94ce.
This commit is contained in:
Oli Scherer 2023-08-08 08:35:38 +00:00
parent 61efe9d298
commit e0a60f0740
22 changed files with 71 additions and 80 deletions

View File

@ -129,7 +129,15 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
// By default, RPIT are invariant wrt type and const generics, but they are bivariant wrt // By default, RPIT are invariant wrt type and const generics, but they are bivariant wrt
// lifetime generics. // lifetime generics.
let mut variances: Vec<_> = std::iter::repeat(ty::Invariant).take(generics.count()).collect(); let variances = std::iter::repeat(ty::Invariant).take(generics.count());
let mut variances: Vec<_> = match tcx.opaque_type_origin(item_def_id) {
rustc_hir::OpaqueTyOrigin::FnReturn(_) | rustc_hir::OpaqueTyOrigin::AsyncFn(_) => {
variances.collect()
}
// But TAIT are invariant for all generics
rustc_hir::OpaqueTyOrigin::TyAlias { .. } => return tcx.arena.alloc_from_iter(variances),
};
// Mark all lifetimes from parent generics as unused (Bivariant). // Mark all lifetimes from parent generics as unused (Bivariant).
// This will be overridden later if required. // This will be overridden later if required.

View File

@ -13,7 +13,8 @@ impl MyTy<'_> {
} }
} }
type Opaque<'a> = impl Sized; type Opaque2 = impl Sized;
type Opaque<'a> = Opaque2;
fn define<'a>() -> Opaque<'a> {} fn define<'a>() -> Opaque<'a> {}
fn test<'a>() { fn test<'a>() {

View File

@ -11,7 +11,8 @@ fn test_closure() {
closure(&opaque()); closure(&opaque());
} }
type Opaque<'a> = impl Sized; type Opaque2 = impl Sized;
type Opaque<'a> = Opaque2;
fn define<'a>() -> Opaque<'a> {} fn define<'a>() -> Opaque<'a> {}
fn test_tait(_: &Opaque<'_>) { fn test_tait(_: &Opaque<'_>) {

View File

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

View File

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

View File

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

View File

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

View File

@ -2,11 +2,7 @@
fn main() {} fn main() {}
pub trait Captures<'a> {} type Two<'a, 'b> = impl std::fmt::Debug;
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> { fn one<'a>(t: &'a ()) -> Two<'a, 'a> {
//~^ ERROR non-defining opaque type use //~^ ERROR non-defining opaque type use

View File

@ -1,25 +1,25 @@
error: non-defining opaque type use in defining scope error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_lifetime_param.rs:11:26 --> $DIR/generic_duplicate_lifetime_param.rs:7:26
| |
LL | fn one<'a>(t: &'a ()) -> Two<'a, 'a> { LL | fn one<'a>(t: &'a ()) -> Two<'a, 'a> {
| ^^^^^^^^^^^ generic argument `'a` used twice | ^^^^^^^^^^^ generic argument `'a` used twice
| |
note: for this opaque type note: for this opaque type
--> $DIR/generic_duplicate_lifetime_param.rs:9:20 --> $DIR/generic_duplicate_lifetime_param.rs:5:20
| |
LL | type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; LL | type Two<'a, 'b> = impl std::fmt::Debug;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
error: non-defining opaque type use in defining scope error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_lifetime_param.rs:13:5 --> $DIR/generic_duplicate_lifetime_param.rs:9:5
| |
LL | t LL | t
| ^ | ^
| |
note: lifetime used multiple times note: lifetime used multiple times
--> $DIR/generic_duplicate_lifetime_param.rs:9:10 --> $DIR/generic_duplicate_lifetime_param.rs:5:10
| |
LL | type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; LL | type Two<'a, 'b> = impl std::fmt::Debug;
| ^^ ^^ | ^^ ^^
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View File

@ -14,11 +14,7 @@ fn main() {}
// test that unused generic parameters are ok // test that unused generic parameters are ok
type TwoTys<T, U> = impl Debug; type TwoTys<T, U> = impl Debug;
pub trait Captures<'a> {} type TwoLifetimes<'a, 'b> = impl Debug;
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; 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 error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:25:30 --> $DIR/generic_duplicate_param_use.rs:21:30
| |
LL | fn one_ty<T: Debug>(t: T) -> TwoTys<T, T> { LL | fn one_ty<T: Debug>(t: T) -> TwoTys<T, T> {
| ^^^^^^^^^^^^ generic argument `T` used twice | ^^^^^^^^^^^^ generic argument `T` used twice
@ -11,7 +11,7 @@ LL | type TwoTys<T, U> = impl Debug;
| ^^^^^^^^^^ | ^^^^^^^^^^
error: non-defining opaque type use in defining scope error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:27:5 --> $DIR/generic_duplicate_param_use.rs:23:5
| |
LL | t LL | t
| ^ | ^
@ -23,49 +23,49 @@ LL | type TwoTys<T, U> = impl Debug;
| ^ ^ | ^ ^
error: non-defining opaque type use in defining scope error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:31:36 --> $DIR/generic_duplicate_param_use.rs:27:36
| |
LL | fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> { LL | fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> {
| ^^^^^^^^^^^^^^^^^^^^ generic argument `'a` used twice | ^^^^^^^^^^^^^^^^^^^^ generic argument `'a` used twice
| |
note: for this opaque type note: for this opaque type
--> $DIR/generic_duplicate_param_use.rs:21:29 --> $DIR/generic_duplicate_param_use.rs:17:29
| |
LL | type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>; LL | type TwoLifetimes<'a, 'b> = impl Debug;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^
error: non-defining opaque type use in defining scope error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:33:5 --> $DIR/generic_duplicate_param_use.rs:29:5
| |
LL | t LL | t
| ^ | ^
| |
note: lifetime used multiple times note: lifetime used multiple times
--> $DIR/generic_duplicate_param_use.rs:21:19 --> $DIR/generic_duplicate_param_use.rs:17:19
| |
LL | type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>; LL | type TwoLifetimes<'a, 'b> = impl Debug;
| ^^ ^^ | ^^ ^^
error: non-defining opaque type use in defining scope error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:37:50 --> $DIR/generic_duplicate_param_use.rs:33:50
| |
LL | fn one_const<const N: usize>(t: *mut [u8; N]) -> TwoConsts<N, N> { LL | fn one_const<const N: usize>(t: *mut [u8; N]) -> TwoConsts<N, N> {
| ^^^^^^^^^^^^^^^ generic argument `N` used twice | ^^^^^^^^^^^^^^^ generic argument `N` used twice
| |
note: for this opaque type note: for this opaque type
--> $DIR/generic_duplicate_param_use.rs:23:50 --> $DIR/generic_duplicate_param_use.rs:19:50
| |
LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug; LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug;
| ^^^^^^^^^^ | ^^^^^^^^^^
error: non-defining opaque type use in defining scope error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:39:5 --> $DIR/generic_duplicate_param_use.rs:35:5
| |
LL | t LL | t
| ^ | ^
| |
note: constant used multiple times note: constant used multiple times
--> $DIR/generic_duplicate_param_use.rs:23:16 --> $DIR/generic_duplicate_param_use.rs:19:16
| |
LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug; LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug;
| ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^

View File

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

View File

@ -1,7 +1,7 @@
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]
mod test_lifetime_param { mod test_lifetime_param {
type Ty<'a> = impl Sized + 'a; type Ty<'a> = impl Sized;
fn defining(a: &str) -> Ty<'_> { a } fn defining(a: &str) -> Ty<'_> { a }
fn assert_static<'a: 'static>() {} fn assert_static<'a: 'static>() {}
fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() } fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() }
@ -9,7 +9,7 @@ mod test_lifetime_param {
} }
mod test_higher_kinded_lifetime_param { mod test_higher_kinded_lifetime_param {
type Ty<'a> = impl Sized + 'a; type Ty<'a> = impl Sized;
fn defining(a: &str) -> Ty<'_> { a } fn defining(a: &str) -> Ty<'_> { a }
fn assert_static<'a: 'static>() {} fn assert_static<'a: 'static>() {}
fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() } fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() }

View File

@ -1,16 +1,20 @@
// check-pass // check-pass
#![feature(impl_trait_in_assoc_type)] #![feature(impl_trait_in_assoc_type, type_alias_impl_trait)]
trait Callable { mod foo {
type Output; pub trait Callable {
fn call() -> Self::Output; type Output;
} fn call() -> Self::Output;
}
impl<'a> Callable for &'a () { pub type OutputHelper = impl Sized;
type Output = impl Sized; impl<'a> Callable for &'a () {
fn call() -> Self::Output {} type Output = OutputHelper;
fn call() -> Self::Output {}
}
} }
use foo::*;
fn test<'a>() -> impl Sized { fn test<'a>() -> impl Sized {
<&'a () as Callable>::call() <&'a () as Callable>::call()

View File

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

View File

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

View File

@ -1,7 +1,8 @@
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]
type Opaque<'a, T> = impl Sized; type Opaque2<T> = impl Sized;
type Opaque<'a, T> = Opaque2<T>;
fn defining<'a, T>(x: &'a i32) -> Opaque<T> { x } fn defining<'a, T>(x: &'a i32) -> Opaque<T> { x }
//~^ ERROR: hidden type for `Opaque<'a, T>` captures lifetime that does not appear in bounds //~^ ERROR: hidden type for `Opaque2<T>` captures lifetime that does not appear in bounds
fn main() {} fn main() {}

View File

@ -1,8 +1,9 @@
error[E0700]: hidden type for `Opaque<'a, T>` captures lifetime that does not appear in bounds error[E0700]: hidden type for `Opaque2<T>` captures lifetime that does not appear in bounds
--> $DIR/missing_lifetime_bound.rs:4:47 --> $DIR/missing_lifetime_bound.rs:5:47
| |
LL | type Opaque<'a, T> = impl Sized; LL | type Opaque2<T> = impl Sized;
| ---------- opaque type defined here | ---------- opaque type defined here
LL | type Opaque<'a, T> = Opaque2<T>;
LL | fn defining<'a, T>(x: &'a i32) -> Opaque<T> { x } LL | fn defining<'a, T>(x: &'a i32) -> Opaque<T> { x }
| -- ^ | -- ^
| | | |

View File

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

View File

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

View File

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

View File

@ -22,9 +22,9 @@ fn bar() {
} }
// desugared // desugared
type FooX<'a> = impl Sized; type FooX = impl Sized;
impl<'a> Foo<'a> { impl<'a> Foo<'a> {
fn foo(&self) -> FooX<'a> {} fn foo(&self) -> FooX {}
} }
// use site // use site