Skip to content

Commit 8b20c6a

Browse files
Add TyKind::TyAlias support in rustc_typeck
1 parent b756929 commit 8b20c6a

File tree

5 files changed

+13
-0
lines changed

5 files changed

+13
-0
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
856856
// Const parameters are well formed if their type is structural match.
857857
hir::GenericParamKind::Const { ty: hir_ty, default: _ } => {
858858
let ty = tcx.type_of(tcx.hir().local_def_id(param.hir_id));
859+
let ty = tcx.peel_off_ty_alias(ty);
859860

860861
if tcx.features().adt_const_params {
861862
if let Some(non_structural_match_ty) =

compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ impl<'tcx> InherentCollect<'tcx> {
187187
};
188188

189189
let self_ty = self.tcx.type_of(item.def_id);
190+
let self_ty = self.tcx.peel_off_ty_alias(self_ty);
191+
190192
match *self_ty.kind() {
191193
ty::Adt(def, _) => {
192194
self.check_def_id(item, self_ty, def.did());
@@ -197,6 +199,9 @@ impl<'tcx> InherentCollect<'tcx> {
197199
ty::Dynamic(data, ..) if data.principal_def_id().is_some() => {
198200
self.check_def_id(item, self_ty, data.principal_def_id().unwrap());
199201
}
202+
ty::TyAlias(..) => {
203+
span_bug!(ty.span, "unexpected TyAlias in InherentCollect::check_item");
204+
}
200205
ty::Dynamic(..) => {
201206
struct_span_err!(
202207
self.tcx.sess,

compiler/rustc_hir_analysis/src/coherence/orphan.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ fn do_orphan_check_impl<'tcx>(
4949
let sp = tcx.def_span(def_id);
5050
let tr = impl_.of_trait.as_ref().unwrap();
5151

52+
let trait_ref = tcx.peel_off_ty_alias(trait_ref);
53+
5254
// Ensure no opaque types are present in this impl header. See issues #76202 and #86411 for examples,
5355
// and #84660 where it would otherwise allow unsoundness.
5456
if trait_ref.has_opaque_types() {

compiler/rustc_hir_analysis/src/variance/constraints.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
257257
self.add_constraints_from_invariant_substs(current, substs, variance);
258258
}
259259

260+
ty::TyAlias(_, substs) => {
261+
self.add_constraints_from_invariant_substs(current, substs, variance);
262+
}
263+
260264
ty::Dynamic(data, r, _) => {
261265
// The type `Foo<T+'a>` is contravariant w/r/t `'a`:
262266
let contra = self.contravariant(variance);

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
123123
// We should really try to normalize here.
124124
ty::Projection(ref pi) => Some(PointerKind::OfProjection(pi)),
125125
ty::Opaque(def_id, substs) => Some(PointerKind::OfOpaque(def_id, substs)),
126+
ty::TyAlias(..) => span_bug!(span, "unexpected TyAlias in pointer_kind"),
126127
ty::Param(ref p) => Some(PointerKind::OfParam(p)),
127128
// Insufficient type information.
128129
ty::Placeholder(..) | ty::Bound(..) | ty::Infer(_) => None,

0 commit comments

Comments
 (0)