squash OpaqueTy and ProjectionTy into AliasTy
This commit is contained in:
parent
5c6afb850c
commit
c13bd83528
66 changed files with 182 additions and 197 deletions
|
@ -411,7 +411,7 @@ impl<'tcx> ToTrace<'tcx> for ty::PolyTraitRef<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToTrace<'tcx> for ty::ProjectionTy<'tcx> {
|
||||
impl<'tcx> ToTrace<'tcx> for ty::AliasTy<'tcx> {
|
||||
fn to_trace(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
cause: &ObligationCause<'tcx>,
|
||||
|
|
|
@ -675,7 +675,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
|||
// relatable.
|
||||
Ok(t)
|
||||
}
|
||||
ty::Opaque(ty::OpaqueTy { def_id, substs }) => {
|
||||
ty::Opaque(ty::AliasTy { def_id, substs }) => {
|
||||
let s = self.relate(substs, substs)?;
|
||||
Ok(if s == substs { t } else { self.infcx.tcx.mk_opaque(def_id, s) })
|
||||
}
|
||||
|
|
|
@ -101,13 +101,13 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
|
|||
}
|
||||
|
||||
(
|
||||
&ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }),
|
||||
) if a_def_id == b_def_id => {
|
||||
self.fields.infcx.super_combine_tys(self, a, b)?;
|
||||
}
|
||||
(&ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Opaque(ty::OpaqueTy { def_id, substs: _ }))
|
||||
(&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ }))
|
||||
if self.fields.define_opaque_types && def_id.is_local() =>
|
||||
{
|
||||
self.fields.obligations.extend(
|
||||
|
|
|
@ -340,7 +340,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
|
||||
// FIXME(alias): Merge these
|
||||
let (def_id, substs) = match *ty.kind() {
|
||||
ty::Opaque(ty::OpaqueTy { def_id, substs }) => (def_id, substs),
|
||||
ty::Opaque(ty::AliasTy { def_id, substs }) => (def_id, substs),
|
||||
ty::Projection(data)
|
||||
if self.tcx.def_kind(data.def_id) == DefKind::ImplTraitPlaceholder =>
|
||||
{
|
||||
|
@ -1732,7 +1732,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
let sort_string = |ty: Ty<'tcx>, path: Option<PathBuf>| {
|
||||
// FIXME(alias): Merge these
|
||||
let mut s = match (extra, ty.kind()) {
|
||||
(true, ty::Opaque(ty::OpaqueTy { def_id, .. })) => {
|
||||
(true, ty::Opaque(ty::AliasTy { def_id, .. })) => {
|
||||
let sm = self.tcx.sess.source_map();
|
||||
let pos = sm.lookup_char_pos(self.tcx.def_span(*def_id).lo());
|
||||
format!(
|
||||
|
@ -2386,7 +2386,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
// suggest:
|
||||
// fn get_later<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
|
||||
ty::Closure(_, _substs)
|
||||
| ty::Opaque(ty::OpaqueTy { def_id: _, substs: _substs })
|
||||
| ty::Opaque(ty::AliasTy { def_id: _, substs: _substs })
|
||||
if return_impl_trait =>
|
||||
{
|
||||
new_binding_suggestion(&mut err, type_param_span);
|
||||
|
@ -2770,7 +2770,7 @@ impl TyCategory {
|
|||
pub fn from_ty(tcx: TyCtxt<'_>, ty: Ty<'_>) -> Option<(Self, DefId)> {
|
||||
match *ty.kind() {
|
||||
ty::Closure(def_id, _) => Some((Self::Closure, def_id)),
|
||||
ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) => Some((Self::Opaque, def_id)),
|
||||
ty::Opaque(ty::AliasTy { def_id, substs: _ }) => Some((Self::Opaque, def_id)),
|
||||
ty::Generator(def_id, ..) => {
|
||||
Some((Self::Generator(tcx.generator_kind(def_id).unwrap()), def_id))
|
||||
}
|
||||
|
|
|
@ -487,12 +487,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
StatementAsExpression::CorrectType
|
||||
}
|
||||
(
|
||||
ty::Opaque(ty::OpaqueTy { def_id: last_def_id, substs: _ }),
|
||||
ty::Opaque(ty::OpaqueTy { def_id: exp_def_id, substs: _ }),
|
||||
ty::Opaque(ty::AliasTy { def_id: last_def_id, substs: _ }),
|
||||
ty::Opaque(ty::AliasTy { def_id: exp_def_id, substs: _ }),
|
||||
) if last_def_id == exp_def_id => StatementAsExpression::CorrectType,
|
||||
(
|
||||
ty::Opaque(ty::OpaqueTy { def_id: last_def_id, substs: last_bounds }),
|
||||
ty::Opaque(ty::OpaqueTy { def_id: exp_def_id, substs: exp_bounds }),
|
||||
ty::Opaque(ty::AliasTy { def_id: last_def_id, substs: last_bounds }),
|
||||
ty::Opaque(ty::AliasTy { def_id: exp_def_id, substs: exp_bounds }),
|
||||
) => {
|
||||
debug!(
|
||||
"both opaque, likely future {:?} {:?} {:?} {:?}",
|
||||
|
|
|
@ -106,11 +106,11 @@ where
|
|||
}
|
||||
|
||||
(
|
||||
&ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }),
|
||||
) if a_def_id == b_def_id => infcx.super_combine_tys(this, a, b),
|
||||
(&ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Opaque(ty::OpaqueTy { def_id, substs: _ }))
|
||||
(&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ }))
|
||||
if this.define_opaque_types() && def_id.is_local() =>
|
||||
{
|
||||
this.add_obligations(
|
||||
|
|
|
@ -275,7 +275,7 @@ where
|
|||
/// `ProjectionEq(projection = ?U)`, `ProjectionEq(other_projection = ?U)`.
|
||||
fn relate_projection_ty(
|
||||
&mut self,
|
||||
projection_ty: ty::ProjectionTy<'tcx>,
|
||||
projection_ty: ty::AliasTy<'tcx>,
|
||||
value_ty: Ty<'tcx>,
|
||||
) -> Ty<'tcx> {
|
||||
use rustc_span::DUMMY_SP;
|
||||
|
@ -609,8 +609,8 @@ where
|
|||
(&ty::Infer(ty::TyVar(vid)), _) => self.relate_ty_var((vid, b)),
|
||||
|
||||
(
|
||||
&ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }),
|
||||
) if a_def_id == b_def_id => infcx.super_combine_tys(self, a, b).or_else(|err| {
|
||||
self.tcx().sess.delay_span_bug(
|
||||
self.delegate.span(),
|
||||
|
@ -618,8 +618,8 @@ where
|
|||
);
|
||||
if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) }
|
||||
}),
|
||||
(&ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Opaque(ty::OpaqueTy { def_id, substs: _ }))
|
||||
(&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ }))
|
||||
if def_id.is_local() =>
|
||||
{
|
||||
self.relate_opaques(a, b)
|
||||
|
|
|
@ -66,7 +66,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
lt_op: |lt| lt,
|
||||
ct_op: |ct| ct,
|
||||
ty_op: |ty| match *ty.kind() {
|
||||
ty::Opaque(ty::OpaqueTy { def_id, substs: _substs })
|
||||
ty::Opaque(ty::AliasTy { def_id, substs: _substs })
|
||||
if replace_opaque_type(def_id) =>
|
||||
{
|
||||
let def_span = self.tcx.def_span(def_id);
|
||||
|
@ -106,7 +106,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
}
|
||||
let (a, b) = if a_is_expected { (a, b) } else { (b, a) };
|
||||
let process = |a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected| match *a.kind() {
|
||||
ty::Opaque(ty::OpaqueTy { def_id, substs }) if def_id.is_local() => {
|
||||
ty::Opaque(ty::AliasTy { def_id, substs }) if def_id.is_local() => {
|
||||
let def_id = def_id.expect_local();
|
||||
let origin = match self.defining_use_anchor {
|
||||
DefiningAnchor::Bind(_) => {
|
||||
|
@ -149,7 +149,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
DefiningAnchor::Bubble => self.opaque_ty_origin_unchecked(def_id, cause.span),
|
||||
DefiningAnchor::Error => return None,
|
||||
};
|
||||
if let ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: _ }) = *b.kind() {
|
||||
if let ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }) = *b.kind() {
|
||||
// We could accept this, but there are various ways to handle this situation, and we don't
|
||||
// want to make a decision on it right now. Likely this case is so super rare anyway, that
|
||||
// no one encounters it in practice.
|
||||
|
@ -478,7 +478,7 @@ where
|
|||
substs.as_generator().resume_ty().visit_with(self);
|
||||
}
|
||||
|
||||
ty::Opaque(ty::OpaqueTy { def_id, ref substs }) => {
|
||||
ty::Opaque(ty::AliasTy { def_id, ref substs }) => {
|
||||
// Skip lifetime paramters that are not captures.
|
||||
let variances = self.tcx.variances_of(*def_id);
|
||||
|
||||
|
@ -581,7 +581,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
}
|
||||
// Replace all other mentions of the same opaque type with the hidden type,
|
||||
// as the bounds must hold on the hidden type after all.
|
||||
ty::Opaque(ty::OpaqueTy { def_id: def_id2, substs: substs2 })
|
||||
ty::Opaque(ty::AliasTy { def_id: def_id2, substs: substs2 })
|
||||
if def_id.to_def_id() == def_id2 && substs == substs2 =>
|
||||
{
|
||||
hidden_ty
|
||||
|
|
|
@ -23,7 +23,7 @@ pub enum Component<'tcx> {
|
|||
// is not in a position to judge which is the best technique, so
|
||||
// we just product the projection as a component and leave it to
|
||||
// the consumer to decide (but see `EscapingProjection` below).
|
||||
Projection(ty::ProjectionTy<'tcx>),
|
||||
Projection(ty::AliasTy<'tcx>),
|
||||
|
||||
// In the case where a projection has escaping regions -- meaning
|
||||
// regions bound within the type itself -- we always use
|
||||
|
@ -130,7 +130,7 @@ fn compute_components<'tcx>(
|
|||
// outlives any other lifetime, which is unsound.
|
||||
// See https://github.com/rust-lang/rust/issues/84305 for
|
||||
// more details.
|
||||
ty::Opaque(ty::OpaqueTy { def_id, substs }) => {
|
||||
ty::Opaque(ty::AliasTy { def_id, substs }) => {
|
||||
out.push(Component::Opaque(def_id, substs));
|
||||
},
|
||||
|
||||
|
|
|
@ -338,7 +338,7 @@ where
|
|||
substs,
|
||||
true,
|
||||
|ty| match *ty.kind() {
|
||||
ty::Opaque(ty::OpaqueTy { def_id, substs }) => (def_id, substs),
|
||||
ty::Opaque(ty::AliasTy { def_id, substs }) => (def_id, substs),
|
||||
_ => bug!("expected only projection types from env, not {:?}", ty),
|
||||
},
|
||||
);
|
||||
|
@ -349,7 +349,7 @@ where
|
|||
&mut self,
|
||||
origin: infer::SubregionOrigin<'tcx>,
|
||||
region: ty::Region<'tcx>,
|
||||
projection_ty: ty::ProjectionTy<'tcx>,
|
||||
projection_ty: ty::AliasTy<'tcx>,
|
||||
) {
|
||||
self.generic_must_outlive(
|
||||
origin,
|
||||
|
|
|
@ -16,7 +16,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
pub fn infer_projection(
|
||||
&self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
projection_ty: ty::ProjectionTy<'tcx>,
|
||||
projection_ty: ty::AliasTy<'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
recursion_depth: usize,
|
||||
obligations: &mut Vec<PredicateObligation<'tcx>>,
|
||||
|
|
|
@ -169,7 +169,7 @@ pub struct Verify<'tcx> {
|
|||
#[derive(Copy, Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)]
|
||||
pub enum GenericKind<'tcx> {
|
||||
Param(ty::ParamTy),
|
||||
Projection(ty::ProjectionTy<'tcx>),
|
||||
Projection(ty::AliasTy<'tcx>),
|
||||
Opaque(DefId, SubstsRef<'tcx>),
|
||||
}
|
||||
|
||||
|
|
|
@ -131,14 +131,14 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
|
|||
}
|
||||
|
||||
(
|
||||
&ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }),
|
||||
) if a_def_id == b_def_id => {
|
||||
self.fields.infcx.super_combine_tys(self, a, b)?;
|
||||
Ok(a)
|
||||
}
|
||||
(&ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Opaque(ty::OpaqueTy { def_id, substs: _ }))
|
||||
(&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ }))
|
||||
if self.fields.define_opaque_types && def_id.is_local() =>
|
||||
{
|
||||
self.fields.obligations.extend(
|
||||
|
|
|
@ -77,11 +77,11 @@ pub struct ProjectionCacheStorage<'tcx> {
|
|||
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
||||
pub struct ProjectionCacheKey<'tcx> {
|
||||
ty: ty::ProjectionTy<'tcx>,
|
||||
ty: ty::AliasTy<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx> ProjectionCacheKey<'tcx> {
|
||||
pub fn new(ty: ty::ProjectionTy<'tcx>) -> Self {
|
||||
pub fn new(ty: ty::AliasTy<'tcx>) -> Self {
|
||||
Self { ty }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue