diff options
| author | lcnr <rust@lcnr.de> | 2023-06-27 23:09:53 +0200 |
|---|---|---|
| committer | lcnr <rust@lcnr.de> | 2023-07-03 09:12:14 +0200 |
| commit | bd0d533d230d7c14ab638c4ea2c580d0761e1426 (patch) | |
| tree | 5f5daa51912d3e78d5fcd8519a0f50875fb1cde5 | |
| parent | 8ebb3d49e41ce0764b71fb9b3e7ec219f5a2fbda (diff) | |
| download | rust-bd0d533d230d7c14ab638c4ea2c580d0761e1426.tar.gz rust-bd0d533d230d7c14ab638c4ea2c580d0761e1426.zip | |
fix structurally relate for weak aliases
| -rw-r--r-- | compiler/rustc_middle/src/ty/relate.rs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 74a3bddf2fa..85d09cfbc72 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -544,17 +544,8 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>( Ok(tcx.mk_fn_ptr(fty)) } - // these two are already handled downstream in case of lazy normalization - (&ty::Alias(ty::Projection, a_data), &ty::Alias(ty::Projection, b_data)) => { - let projection_ty = relation.relate(a_data, b_data)?; - Ok(tcx.mk_projection(projection_ty.def_id, projection_ty.substs)) - } - - (&ty::Alias(ty::Inherent, a_data), &ty::Alias(ty::Inherent, b_data)) => { - let alias_ty = relation.relate(a_data, b_data)?; - Ok(tcx.mk_alias(ty::Inherent, tcx.mk_alias_ty(alias_ty.def_id, alias_ty.substs))) - } - + // The substs of opaque types may not all be invariant, so we have + // to treat them separately from other aliases. ( &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: a_substs, .. }), &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: b_substs, .. }), @@ -571,6 +562,19 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>( Ok(tcx.mk_opaque(a_def_id, substs)) } + // Alias tend to mostly already be handled downstream due to normalization. + (&ty::Alias(a_kind, a_data), &ty::Alias(b_kind, b_data)) => { + // FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): This if can be removed + // and the assert uncommented once the new desugaring is stable. + if a_kind == b_kind { + let alias_ty = relation.relate(a_data, b_data)?; + // assert_eq!(a_kind, b_kind); + Ok(tcx.mk_alias(a_kind, alias_ty)) + } else { + Err(TypeError::Sorts(expected_found(relation, a, b))) + } + } + _ => Err(TypeError::Sorts(expected_found(relation, a, b))), } } |
