Skip to content

Commit 29d628c

Browse files
Fix compilation errors for TyAlias
1 parent 3381673 commit 29d628c

File tree

8 files changed

+22
-16
lines changed

8 files changed

+22
-16
lines changed

compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_hir as hir;
1212
use rustc_hir::def::DefKind;
1313
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
1414
use rustc_middle::ty::fast_reject::{simplify_type, SimplifiedType, TreatParams};
15-
use rustc_middle::ty::{self, CrateInherentImpls, Ty, TyCtxt};
15+
use rustc_middle::ty::{self, CrateInherentImpls, Subst, Ty, TyCtxt};
1616
use rustc_span::symbol::sym;
1717
use rustc_span::Span;
1818

compiler/rustc_hir_typeck/src/cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +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"),
126+
ty::TyAlias(..) => bug!("unexpected TyAlias in pointer_kind"),
127127
ty::Param(ref p) => Some(PointerKind::OfParam(p)),
128128
// Insufficient type information.
129129
ty::Placeholder(..) | ty::Bound(..) | ty::Infer(_) => None,

compiler/rustc_middle/src/ty/layout.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ where
670670
// as the `Abi` or `FieldsShape` is checked by users.
671671
if i == 0 {
672672
let nil = tcx.mk_unit();
673-
let unit_ptr_ty = if this.ty.is_unsafe_ptr() {
673+
let unit_ptr_ty = if ty.is_unsafe_ptr() {
674674
tcx.mk_mut_ptr(nil)
675675
} else {
676676
tcx.mk_mut_ref(tcx.lifetimes.re_static, nil)
@@ -680,7 +680,7 @@ where
680680
// the `Result` should always work because the type is
681681
// always either `*mut ()` or `&'static mut ()`.
682682
return TyMaybeWithLayout::TyAndLayout(TyAndLayout {
683-
ty: this.ty,
683+
ty,
684684
..tcx.layout_of(ty::ParamEnv::reveal_all().and(unit_ptr_ty)).unwrap()
685685
});
686686
}
@@ -779,7 +779,7 @@ where
779779
| ty::Param(_)
780780
| ty::Infer(_)
781781
| ty::TyAlias(_, _)
782-
| ty::Error(_) => bug!("TyAndLayout::field: unexpected type `{}`", this.ty),
782+
| ty::Error(_) => bug!("TyAndLayout::field: unexpected type `{}`", ty),
783783
}
784784
}
785785

compiler/rustc_privacy/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_middle::span_bug;
2828
use rustc_middle::ty::abstract_const::{walk_abstract_const, AbstractConst, Node as ACNode};
2929
use rustc_middle::ty::query::Providers;
3030
use rustc_middle::ty::subst::InternalSubsts;
31-
use rustc_middle::ty::{self, Const, DefIdTree, GenericParamDefKind};
31+
use rustc_middle::ty::{self, Const, DefIdTree, GenericParamDefKind, Subst};
3232
use rustc_middle::ty::{TraitRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor};
3333
use rustc_session::lint;
3434
use rustc_span::hygiene::Transparency;
@@ -275,7 +275,6 @@ where
275275
| ty::FnPtr(..)
276276
| ty::Param(..)
277277
| ty::Error(_)
278-
| ty::TyAlias(..)
279278
| ty::GeneratorWitness(..) => {}
280279
ty::Bound(..) | ty::Placeholder(..) | ty::Infer(..) => {
281280
bug!("unexpected type: {:?}", ty)

compiler/rustc_trait_selection/src/traits/project.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,12 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
465465
}
466466
}
467467

468-
fn fold_reveal(&mut self, ty: Ty<'tcx>, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
468+
fn fold_alias_or_revealed_opaque(
469+
&mut self,
470+
ty: Ty<'tcx>,
471+
def_id: DefId,
472+
substs: SubstsRef<'tcx>,
473+
) -> Ty<'tcx> {
469474
let recursion_limit = self.tcx().recursion_limit();
470475
if !recursion_limit.value_within_limit(self.depth) {
471476
let obligation =
@@ -534,11 +539,11 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
534539
// Only normalize `impl Trait` outside of type inference, usually in codegen.
535540
match self.param_env.reveal() {
536541
Reveal::UserFacing => ty.super_fold_with(self),
537-
Reveal::All => self.fold_reveal(ty, def_id, substs),
542+
Reveal::All => self.fold_alias_or_revealed_opaque(ty, def_id, substs),
538543
}
539544
}
540545

541-
ty::TyAlias(def_id, substs) => self.fold_reveal(ty, def_id, substs),
546+
ty::TyAlias(def_id, substs) => self.fold_alias_or_revealed_opaque(ty, def_id, substs),
542547

543548
ty::Projection(data) if !data.has_escaping_bound_vars() => {
544549
// This branch is *mostly* just an optimization: when we don't
@@ -1418,7 +1423,7 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
14181423
let bounds = match *obligation.predicate.self_ty().kind() {
14191424
ty::Projection(ref data) => tcx.bound_item_bounds(data.item_def_id).subst(tcx, data.substs),
14201425
ty::Opaque(def_id, substs) => tcx.bound_item_bounds(def_id).subst(tcx, substs),
1421-
ty::TyAlias(def_id, substs) => tcx.bound_item_bounds(def_id).subst(tcx, substs),
1426+
// ty::TyAlias(def_id, substs) => tcx.bound_item_bounds(def_id).subst(tcx, substs),
14221427
ty::Infer(ty::TyVar(_)) => {
14231428
// If the self-type is an inference variable, then it MAY wind up
14241429
// being a projected type, so induce an ambiguity.

compiler/rustc_trait_selection/src/traits/query/normalize.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ struct QueryNormalizer<'cx, 'tcx> {
166166
}
167167

168168
impl<'cx, 'tcx> QueryNormalizer<'cx, 'tcx> {
169-
fn fold_reveal(
169+
fn fold_alias_or_revealed_opaque(
170170
&mut self,
171171
ty: Ty<'tcx>,
172172
def_id: DefId,
@@ -238,11 +238,11 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
238238
// Only normalize `impl Trait` outside of type inference, usually in codegen.
239239
match self.param_env.reveal() {
240240
Reveal::UserFacing => ty.try_super_fold_with(self),
241-
Reveal::All => self.fold_reveal(ty, def_id, substs),
241+
Reveal::All => self.fold_alias_or_revealed_opaque(ty, def_id, substs),
242242
}
243243
}
244244

245-
ty::TyAlias(def_id, substs) => self.fold_reveal(ty, def_id, substs),
245+
ty::TyAlias(def_id, substs) => self.fold_alias_or_revealed_opaque(ty, def_id, substs),
246246

247247
ty::Projection(data) if !data.has_escaping_bound_vars() => {
248248
// This branch is just an optimization: when we don't have escaping bound vars,

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
154154
let (def_id, substs) = match *placeholder_self_ty.kind() {
155155
ty::Projection(proj) => (proj.item_def_id, proj.substs),
156156
ty::Opaque(def_id, substs) => (def_id, substs),
157+
ty::TyAlias(def_id, substs) => (def_id, substs),
157158
_ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty),
158159
};
159160

compiler/rustc_trait_selection/src/traits/wf.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -907,8 +907,9 @@ impl<'tcx> WfPredicates<'tcx> {
907907
));
908908
}
909909

910-
ty::TyAlias(..) => {
911-
bug!("unexpected TyAlias in WfPredicates::compute");
910+
ty::TyAlias(did, substs) => {
911+
let obligations = self.nominal_obligations(did, substs);
912+
self.out.extend(obligations);
912913
}
913914
}
914915

0 commit comments

Comments
 (0)