Skip to content

Commit

Permalink
Don't repeatedly duplicate TAIT lifetimes for each subsequently neste…
Browse files Browse the repository at this point in the history
…d TAIT
  • Loading branch information
compiler-errors committed Apr 18, 2024
1 parent 00ed4ed commit fc312ab
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 7 deletions.
15 changes: 9 additions & 6 deletions compiler/rustc_hir_analysis/src/collect/generics_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,19 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
}
Some(fn_def_id.to_def_id())
}
ItemKind::OpaqueTy(hir::OpaqueTy {
origin: hir::OpaqueTyOrigin::TyAlias { .. },
ItemKind::OpaqueTy(&hir::OpaqueTy {
origin: hir::OpaqueTyOrigin::TyAlias { parent, in_assoc_ty },
..
}) => {
let parent_id = tcx.hir().get_parent_item(hir_id);
assert_ne!(parent_id, hir::CRATE_OWNER_ID);
debug!("generics_of: parent of opaque ty {:?} is {:?}", def_id, parent_id);
if in_assoc_ty {
assert!(matches!(tcx.def_kind(parent), DefKind::AssocTy));
} else {
assert!(matches!(tcx.def_kind(parent), DefKind::TyAlias));
}
debug!("generics_of: parent of opaque ty {:?} is {:?}", def_id, parent);
// Opaque types are always nested within another item, and
// inherit the generics of the item.
Some(parent_id.to_def_id())
Some(parent.to_def_id())
}
_ => None,
},
Expand Down
24 changes: 24 additions & 0 deletions tests/ui/type-alias-impl-trait/variance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,28 @@ impl<'i> Foo<'i> for () {
//~^ ERROR: unconstrained opaque type
}

trait Nesting<'a> {
type Output;
}
impl<'a> Nesting<'a> for &'a () {
type Output = &'a ();
}
type NestedDeeply<'a> =
impl Nesting< //~ [*, o]
'a,
Output = impl Nesting< //~ [*, o]
'a,
Output = impl Nesting< //~ [*, o]
'a,
Output = impl Nesting< //~ [*, o]
'a,
Output = impl Nesting<'a> //~ [*, o]
>
>,
>,
>;
fn test<'a>() -> NestedDeeply<'a> {
&()
}

fn main() {}
57 changes: 56 additions & 1 deletion tests/ui/type-alias-impl-trait/variance.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,61 @@ error: [*, *, o, o]
LL | type ExplicitCaptureFromGat<'a> = impl Sized + Captures<'a>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 24 previous errors
error: [*, o]
--> $DIR/variance.rs:62:25
|
LL | type NestedDeeply<'a> = impl Nesting<
| _________________________^
LL | | 'a,
LL | | Output = impl Nesting<
LL | | 'a,
... |
LL | | >,
LL | | >;
| |_^

error: [*, o]
--> $DIR/variance.rs:64:14
|
LL | Output = impl Nesting<
| ______________^
LL | | 'a,
LL | | Output = impl Nesting<
LL | | 'a,
... |
LL | | >,
LL | | >,
| |_____^

error: [*, o]
--> $DIR/variance.rs:66:18
|
LL | Output = impl Nesting<
| __________________^
LL | | 'a,
LL | | Output = impl Nesting<
LL | | 'a,
LL | | Output = impl Nesting<'a>
LL | | >
LL | | >,
| |_________^

error: [*, o]
--> $DIR/variance.rs:68:22
|
LL | Output = impl Nesting<
| ______________________^
LL | | 'a,
LL | | Output = impl Nesting<'a>
LL | | >
| |_____________^

error: [*, o]
--> $DIR/variance.rs:70:26
|
LL | Output = impl Nesting<'a>
| ^^^^^^^^^^^^^^^^

error: aborting due to 29 previous errors

For more information about this error, try `rustc --explain E0657`.

0 comments on commit fc312ab

Please sign in to comment.