Skip to content

Commit

Permalink
Reveal the underlying types of impl Trait opaque types
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Oct 16, 2024
1 parent 4d5abb0 commit c134d50
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion engine/lib/import_thir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ end) : EXPR = struct
let impl = c_impl_expr span impl_expr in
let item = Concrete_ident.of_def_id (AssociatedItem Type) def_id in
TAssociatedType { impl; item }
| Alias { kind = Opaque; def_id; _ } ->
| Alias { kind = Opaque _; def_id; _ } ->
TOpaque (Concrete_ident.of_def_id Type def_id)
| Alias { kind = Inherent; _ } ->
assertion_failure [ span ] "Ty::Alias with AliasTyKind::Inherent"
Expand Down
23 changes: 16 additions & 7 deletions frontend/exporter/src/types/copied.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,10 @@ pub enum AliasKind {
/// An associated type in an inherent impl.
Inherent,
/// An `impl Trait` opaque type.
Opaque,
Opaque {
/// The real type hidden inside this opaque type.
hidden_ty: Ty,
},
/// A type alias that references opaque types. Likely to always be normalized away.
Weak,
}
Expand All @@ -1778,11 +1781,11 @@ impl Alias {
s: &S,
alias_kind: &rustc_type_ir::AliasTyKind,
alias_ty: &rustc_middle::ty::AliasTy<'tcx>,
) -> Self {
) -> TyKind {
let tcx = s.base().tcx;
use rustc_type_ir::AliasTyKind as RustAliasKind;
let kind = match alias_kind {
RustAliasKind::Projection => {
let tcx = s.base().tcx;
let trait_ref = alias_ty.trait_ref(tcx);
// In a case like:
// ```
Expand All @@ -1803,14 +1806,20 @@ impl Alias {
}
}
RustAliasKind::Inherent => AliasKind::Inherent,
RustAliasKind::Opaque => AliasKind::Opaque,
RustAliasKind::Opaque => {
// Reveal the underlying `impl Trait` type.
let ty = tcx.type_of(alias_ty.def_id).instantiate(tcx, alias_ty.args);
AliasKind::Opaque {
hidden_ty: ty.sinto(s),
}
}
RustAliasKind::Weak => AliasKind::Weak,
};
Alias {
TyKind::Alias(Alias {
kind,
args: alias_ty.args.sinto(s),
def_id: alias_ty.def_id.sinto(s),
}
})
}
}

Expand Down Expand Up @@ -1903,7 +1912,7 @@ pub enum TyKind {
Tuple(Vec<Ty>),
#[custom_arm(
rustc_middle::ty::TyKind::Alias(alias_kind, alias_ty) => {
TyKind::Alias(Alias::from(state, alias_kind, alias_ty))
Alias::from(state, alias_kind, alias_ty)
},
)]
Alias(Alias),
Expand Down

0 comments on commit c134d50

Please sign in to comment.