Skip to content

Commit e0a60f0

Browse files
committed
Revert "Auto merge of rust-lang#102417 - oli-obk:opaque_lifetimes2, r=jackh726"
This reverts commit cb94675, reversing changes made to 57781b2.
1 parent 61efe9d commit e0a60f0

22 files changed

+71
-80
lines changed

compiler/rustc_hir_analysis/src/variance/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,15 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
129129

130130
// By default, RPIT are invariant wrt type and const generics, but they are bivariant wrt
131131
// lifetime generics.
132-
let mut variances: Vec<_> = std::iter::repeat(ty::Invariant).take(generics.count()).collect();
132+
let variances = std::iter::repeat(ty::Invariant).take(generics.count());
133+
134+
let mut variances: Vec<_> = match tcx.opaque_type_origin(item_def_id) {
135+
rustc_hir::OpaqueTyOrigin::FnReturn(_) | rustc_hir::OpaqueTyOrigin::AsyncFn(_) => {
136+
variances.collect()
137+
}
138+
// But TAIT are invariant for all generics
139+
rustc_hir::OpaqueTyOrigin::TyAlias { .. } => return tcx.arena.alloc_from_iter(variances),
140+
};
133141

134142
// Mark all lifetimes from parent generics as unused (Bivariant).
135143
// This will be overridden later if required.

tests/ui/impl-trait/issue-108591.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ impl MyTy<'_> {
1313
}
1414
}
1515

16-
type Opaque<'a> = impl Sized;
16+
type Opaque2 = impl Sized;
17+
type Opaque<'a> = Opaque2;
1718
fn define<'a>() -> Opaque<'a> {}
1819

1920
fn test<'a>() {

tests/ui/impl-trait/issue-108592.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ fn test_closure() {
1111
closure(&opaque());
1212
}
1313

14-
type Opaque<'a> = impl Sized;
14+
type Opaque2 = impl Sized;
15+
type Opaque<'a> = Opaque2;
1516
fn define<'a>() -> Opaque<'a> {}
1617

1718
fn test_tait(_: &Opaque<'_>) {

tests/ui/impl-trait/issue-86465.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#![feature(type_alias_impl_trait)]
22

3-
pub trait Captures<'a> {}
4-
5-
impl<'a, T: ?Sized> Captures<'a> for T {}
6-
7-
type X<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
3+
type X<'a, 'b> = impl std::fmt::Debug;
84

95
fn f<'t, 'u>(a: &'t u32, b: &'u u32) -> (X<'t, 'u>, X<'u, 't>) {
106
(a, a)

tests/ui/impl-trait/issue-86465.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: concrete type differs from previous defining opaque type use
2-
--> $DIR/issue-86465.rs:10:5
2+
--> $DIR/issue-86465.rs:6:5
33
|
44
LL | (a, a)
55
| ^^^^^^

tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
#![feature(type_alias_impl_trait)]
22
#![allow(dead_code)]
33

4-
pub trait Captures<'a> {}
5-
6-
impl<'a, T: ?Sized> Captures<'a> for T {}
7-
8-
type OneLifetime<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
4+
type OneLifetime<'a, 'b> = impl std::fmt::Debug;
95

106
fn foo<'a, 'b>(a: &'a u32, b: &'b u32) -> OneLifetime<'a, 'b> {
117
a

tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: concrete type differs from previous defining opaque type use
2-
--> $DIR/different_lifetimes_defining_uses.rs:15:5
2+
--> $DIR/different_lifetimes_defining_uses.rs:11:5
33
|
44
LL | b
55
| ^ expected `&'a u32`, got `&'b u32`
66
|
77
note: previous use here
8-
--> $DIR/different_lifetimes_defining_uses.rs:11:5
8+
--> $DIR/different_lifetimes_defining_uses.rs:7:5
99
|
1010
LL | a
1111
| ^

tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
fn main() {}
44

5-
pub trait Captures<'a> {}
6-
7-
impl<'a, T: ?Sized> Captures<'a> for T {}
8-
9-
type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
5+
type Two<'a, 'b> = impl std::fmt::Debug;
106

117
fn one<'a>(t: &'a ()) -> Two<'a, 'a> {
128
//~^ ERROR non-defining opaque type use

tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
error: non-defining opaque type use in defining scope
2-
--> $DIR/generic_duplicate_lifetime_param.rs:11:26
2+
--> $DIR/generic_duplicate_lifetime_param.rs:7:26
33
|
44
LL | fn one<'a>(t: &'a ()) -> Two<'a, 'a> {
55
| ^^^^^^^^^^^ generic argument `'a` used twice
66
|
77
note: for this opaque type
8-
--> $DIR/generic_duplicate_lifetime_param.rs:9:20
8+
--> $DIR/generic_duplicate_lifetime_param.rs:5:20
99
|
10-
LL | type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
LL | type Two<'a, 'b> = impl std::fmt::Debug;
11+
| ^^^^^^^^^^^^^^^^^^^^
1212

1313
error: non-defining opaque type use in defining scope
14-
--> $DIR/generic_duplicate_lifetime_param.rs:13:5
14+
--> $DIR/generic_duplicate_lifetime_param.rs:9:5
1515
|
1616
LL | t
1717
| ^
1818
|
1919
note: lifetime used multiple times
20-
--> $DIR/generic_duplicate_lifetime_param.rs:9:10
20+
--> $DIR/generic_duplicate_lifetime_param.rs:5:10
2121
|
22-
LL | type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
22+
LL | type Two<'a, 'b> = impl std::fmt::Debug;
2323
| ^^ ^^
2424

2525
error: aborting due to 2 previous errors

tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ fn main() {}
1414
// test that unused generic parameters are ok
1515
type TwoTys<T, U> = impl Debug;
1616

17-
pub trait Captures<'a> {}
18-
19-
impl<'a, T: ?Sized> Captures<'a> for T {}
20-
21-
type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>;
17+
type TwoLifetimes<'a, 'b> = impl Debug;
2218

2319
type TwoConsts<const X: usize, const Y: usize> = impl Debug;
2420

0 commit comments

Comments
 (0)