Auto merge of #116887 - lcnr:alias-ty-constructor, r=compiler-errors
`TyCtxt::mk_alias_ty` -> `AliasTy::new`
This commit is contained in:
commit
e1aa9edde0
@ -448,7 +448,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||
|
||||
debug!(?args_trait_ref_and_assoc_item);
|
||||
|
||||
tcx.mk_alias_ty(assoc_item.def_id, args_trait_ref_and_assoc_item)
|
||||
ty::AliasTy::new(tcx, assoc_item.def_id, args_trait_ref_and_assoc_item)
|
||||
})
|
||||
};
|
||||
|
||||
|
@ -437,7 +437,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
);
|
||||
|
||||
let quiet_projection_ty =
|
||||
tcx.mk_alias_ty(projection_ty.def_id, args_with_infer_self);
|
||||
ty::AliasTy::new(tcx, projection_ty.def_id, args_with_infer_self);
|
||||
|
||||
let term = pred.skip_binder().term;
|
||||
|
||||
|
@ -916,7 +916,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
// Type aliases defined in crates that have the
|
||||
// feature `lazy_type_alias` enabled get encoded as a type alias that normalization will
|
||||
// then actually instantiate the where bounds of.
|
||||
let alias_ty = tcx.mk_alias_ty(did, args);
|
||||
let alias_ty = ty::AliasTy::new(tcx, did, args);
|
||||
Ty::new_alias(tcx, ty::Weak, alias_ty)
|
||||
} else {
|
||||
tcx.at(span).type_of(did).instantiate(tcx, args)
|
||||
@ -1718,7 +1718,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
.chain(args.into_iter().skip(parent_args.len())),
|
||||
);
|
||||
|
||||
let ty = Ty::new_alias(tcx, ty::Inherent, tcx.mk_alias_ty(assoc_item, args));
|
||||
let ty = Ty::new_alias(tcx, ty::Inherent, ty::AliasTy::new(tcx, assoc_item, args));
|
||||
|
||||
return Ok(Some((ty, assoc_item)));
|
||||
}
|
||||
|
@ -2286,7 +2286,7 @@ pub(super) fn check_type_bounds<'tcx>(
|
||||
_ => predicates.push(
|
||||
ty::Binder::bind_with_vars(
|
||||
ty::ProjectionPredicate {
|
||||
projection_ty: tcx.mk_alias_ty(trait_ty.def_id, rebased_args),
|
||||
projection_ty: ty::AliasTy::new(tcx, trait_ty.def_id, rebased_args),
|
||||
term: normalize_impl_ty.into(),
|
||||
},
|
||||
bound_vars,
|
||||
|
@ -674,7 +674,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
);
|
||||
|
||||
let quiet_projection_ty =
|
||||
tcx.mk_alias_ty(projection_ty.def_id, args_with_infer_self);
|
||||
ty::AliasTy::new(tcx, projection_ty.def_id, args_with_infer_self);
|
||||
|
||||
let term = pred.skip_binder().term;
|
||||
|
||||
|
@ -1687,7 +1687,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
&& let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(_def_id))
|
||||
{
|
||||
// If this is an inherent projection.
|
||||
|
||||
generics.params.len() + 1
|
||||
} else {
|
||||
generics.count()
|
||||
@ -1897,15 +1896,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
self.mk_args_from_iter(iter::once(self_ty.into()).chain(rest))
|
||||
}
|
||||
|
||||
pub fn mk_alias_ty(
|
||||
self,
|
||||
def_id: DefId,
|
||||
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
|
||||
) -> ty::AliasTy<'tcx> {
|
||||
let args = self.check_and_mk_args(def_id, args);
|
||||
ty::AliasTy { def_id, args, _use_mk_alias_ty_instead: () }
|
||||
}
|
||||
|
||||
pub fn mk_bound_variable_kinds_from_iter<I, T>(self, iter: I) -> T::Output
|
||||
where
|
||||
I: Iterator<Item = T>,
|
||||
|
@ -1023,7 +1023,7 @@ impl<'tcx> Term<'tcx> {
|
||||
_ => None,
|
||||
},
|
||||
TermKind::Const(ct) => match ct.kind() {
|
||||
ConstKind::Unevaluated(uv) => Some(tcx.mk_alias_ty(uv.def, uv.args)),
|
||||
ConstKind::Unevaluated(uv) => Some(AliasTy::new(tcx, uv.def, uv.args)),
|
||||
_ => None,
|
||||
},
|
||||
}
|
||||
|
@ -288,7 +288,7 @@ impl<'tcx> Relate<'tcx> for ty::AliasTy<'tcx> {
|
||||
}
|
||||
def => bug!("unknown alias DefKind: {def:?}"),
|
||||
};
|
||||
Ok(relation.tcx().mk_alias_ty(a.def_id, args))
|
||||
Ok(ty::AliasTy::new(relation.tcx(), a.def_id, args))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1213,11 +1213,20 @@ pub struct AliasTy<'tcx> {
|
||||
pub def_id: DefId,
|
||||
|
||||
/// This field exists to prevent the creation of `AliasTy` without using
|
||||
/// [TyCtxt::mk_alias_ty].
|
||||
pub(super) _use_mk_alias_ty_instead: (),
|
||||
/// [AliasTy::new].
|
||||
_use_alias_ty_new_instead: (),
|
||||
}
|
||||
|
||||
impl<'tcx> AliasTy<'tcx> {
|
||||
pub fn new(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
def_id: DefId,
|
||||
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
|
||||
) -> ty::AliasTy<'tcx> {
|
||||
let args = tcx.check_and_mk_args(def_id, args);
|
||||
ty::AliasTy { def_id, args, _use_alias_ty_new_instead: () }
|
||||
}
|
||||
|
||||
pub fn kind(self, tcx: TyCtxt<'tcx>) -> ty::AliasKind {
|
||||
match tcx.def_kind(self.def_id) {
|
||||
DefKind::AssocTy
|
||||
@ -1245,7 +1254,7 @@ impl<'tcx> AliasTy<'tcx> {
|
||||
}
|
||||
|
||||
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
|
||||
tcx.mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.args.iter().skip(1)))
|
||||
AliasTy::new(tcx, self.def_id, [self_ty.into()].into_iter().chain(self.args.iter().skip(1)))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1667,8 +1676,11 @@ impl<'tcx> ExistentialProjection<'tcx> {
|
||||
debug_assert!(!self_ty.has_escaping_bound_vars());
|
||||
|
||||
ty::ProjectionPredicate {
|
||||
projection_ty: tcx
|
||||
.mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.args)),
|
||||
projection_ty: AliasTy::new(
|
||||
tcx,
|
||||
self.def_id,
|
||||
[self_ty.into()].into_iter().chain(self.args),
|
||||
),
|
||||
term: self.term,
|
||||
}
|
||||
}
|
||||
@ -1971,7 +1983,7 @@ impl<'tcx> Ty<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn new_opaque(tcx: TyCtxt<'tcx>, def_id: DefId, args: GenericArgsRef<'tcx>) -> Ty<'tcx> {
|
||||
Ty::new_alias(tcx, ty::Opaque, tcx.mk_alias_ty(def_id, args))
|
||||
Ty::new_alias(tcx, ty::Opaque, AliasTy::new(tcx, def_id, args))
|
||||
}
|
||||
|
||||
/// Constructs a `TyKind::Error` type with current `ErrorGuaranteed`
|
||||
@ -2135,7 +2147,7 @@ impl<'tcx> Ty<'tcx> {
|
||||
item_def_id: DefId,
|
||||
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
|
||||
) -> Ty<'tcx> {
|
||||
Ty::new_alias(tcx, ty::Projection, tcx.mk_alias_ty(item_def_id, args))
|
||||
Ty::new_alias(tcx, ty::Projection, AliasTy::new(tcx, item_def_id, args))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -129,7 +129,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
|
||||
self.at.cause.clone(),
|
||||
self.at.param_env,
|
||||
ty::ProjectionPredicate {
|
||||
projection_ty: tcx.mk_alias_ty(uv.def, uv.args),
|
||||
projection_ty: AliasTy::new(tcx, uv.def, uv.args),
|
||||
term: new_infer_ct.into(),
|
||||
},
|
||||
);
|
||||
|
@ -352,8 +352,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
|
||||
|
||||
let pred = tupled_inputs_and_output
|
||||
.map_bound(|(inputs, output)| ty::ProjectionPredicate {
|
||||
projection_ty: tcx
|
||||
.mk_alias_ty(goal.predicate.def_id(), [goal.predicate.self_ty(), inputs]),
|
||||
projection_ty: ty::AliasTy::new(
|
||||
tcx,
|
||||
goal.predicate.def_id(),
|
||||
[goal.predicate.self_ty(), inputs],
|
||||
),
|
||||
term: output.into(),
|
||||
})
|
||||
.to_predicate(tcx);
|
||||
@ -472,7 +475,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
|
||||
ecx,
|
||||
goal,
|
||||
ty::ProjectionPredicate {
|
||||
projection_ty: ecx.tcx().mk_alias_ty(goal.predicate.def_id(), [self_ty]),
|
||||
projection_ty: ty::AliasTy::new(ecx.tcx(), goal.predicate.def_id(), [self_ty]),
|
||||
term,
|
||||
}
|
||||
.to_predicate(tcx),
|
||||
@ -512,9 +515,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
|
||||
ecx,
|
||||
goal,
|
||||
ty::ProjectionPredicate {
|
||||
projection_ty: ecx
|
||||
.tcx()
|
||||
.mk_alias_ty(goal.predicate.def_id(), [self_ty, generator.resume_ty()]),
|
||||
projection_ty: ty::AliasTy::new(
|
||||
ecx.tcx(),
|
||||
goal.predicate.def_id(),
|
||||
[self_ty, generator.resume_ty()],
|
||||
),
|
||||
term,
|
||||
}
|
||||
.to_predicate(tcx),
|
||||
|
@ -3937,7 +3937,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
// This corresponds to `<ExprTy as Iterator>::Item = _`.
|
||||
let projection = ty::Binder::dummy(ty::PredicateKind::Clause(
|
||||
ty::ClauseKind::Projection(ty::ProjectionPredicate {
|
||||
projection_ty: self.tcx.mk_alias_ty(proj.def_id, args),
|
||||
projection_ty: ty::AliasTy::new(self.tcx, proj.def_id, args),
|
||||
term: ty_var.into(),
|
||||
}),
|
||||
));
|
||||
|
@ -2072,7 +2072,7 @@ fn confirm_generator_candidate<'cx, 'tcx>(
|
||||
};
|
||||
|
||||
ty::ProjectionPredicate {
|
||||
projection_ty: tcx.mk_alias_ty(obligation.predicate.def_id, trait_ref.args),
|
||||
projection_ty: ty::AliasTy::new(tcx, obligation.predicate.def_id, trait_ref.args),
|
||||
term: ty.into(),
|
||||
}
|
||||
});
|
||||
@ -2116,7 +2116,7 @@ fn confirm_future_candidate<'cx, 'tcx>(
|
||||
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Output);
|
||||
|
||||
ty::ProjectionPredicate {
|
||||
projection_ty: tcx.mk_alias_ty(obligation.predicate.def_id, trait_ref.args),
|
||||
projection_ty: ty::AliasTy::new(tcx, obligation.predicate.def_id, trait_ref.args),
|
||||
term: return_ty.into(),
|
||||
}
|
||||
});
|
||||
@ -2172,7 +2172,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
|
||||
};
|
||||
|
||||
let predicate =
|
||||
ty::ProjectionPredicate { projection_ty: tcx.mk_alias_ty(item_def_id, args), term };
|
||||
ty::ProjectionPredicate { projection_ty: ty::AliasTy::new(tcx, item_def_id, args), term };
|
||||
|
||||
confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
|
||||
.with_addl_obligations(obligations)
|
||||
@ -2245,7 +2245,7 @@ fn confirm_callable_candidate<'cx, 'tcx>(
|
||||
flag,
|
||||
)
|
||||
.map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate {
|
||||
projection_ty: tcx.mk_alias_ty(fn_once_output_def_id, trait_ref.args),
|
||||
projection_ty: ty::AliasTy::new(tcx, fn_once_output_def_id, trait_ref.args),
|
||||
term: ret_type.into(),
|
||||
});
|
||||
|
||||
|
@ -704,7 +704,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
let ty = traits::normalize_projection_type(
|
||||
self,
|
||||
param_env,
|
||||
tcx.mk_alias_ty(tcx.lang_items().deref_target()?, trait_ref.args),
|
||||
ty::AliasTy::new(tcx, tcx.lang_items().deref_target()?, trait_ref.args),
|
||||
cause.clone(),
|
||||
0,
|
||||
// We're *intentionally* throwing these away,
|
||||
|
@ -1133,7 +1133,7 @@ pub fn make_projection<'tcx>(
|
||||
#[cfg(debug_assertions)]
|
||||
assert_generic_args_match(tcx, assoc_item.def_id, args);
|
||||
|
||||
Some(tcx.mk_alias_ty(assoc_item.def_id, args))
|
||||
Some(ty::AliasTy::new(tcx, assoc_item.def_id, args))
|
||||
}
|
||||
helper(
|
||||
tcx,
|
||||
|
Loading…
x
Reference in New Issue
Block a user