Combine projection and opaque into alias
This commit is contained in:
parent
c13bd83528
commit
61adaf8187
104 changed files with 387 additions and 381 deletions
|
@ -453,10 +453,10 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
|
|||
| ty::Dynamic(..)
|
||||
| ty::Never
|
||||
| ty::Tuple(..)
|
||||
| ty::Projection(..)
|
||||
| ty::Alias(ty::Projection, ..)
|
||||
| ty::Foreign(..)
|
||||
| ty::Param(..)
|
||||
| ty::Opaque(..) => {
|
||||
| ty::Alias(ty::Opaque, ..) => {
|
||||
if t.flags().intersects(self.needs_canonical_flags) {
|
||||
t.super_fold_with(self)
|
||||
} else {
|
||||
|
|
|
@ -675,7 +675,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
|||
// relatable.
|
||||
Ok(t)
|
||||
}
|
||||
ty::Opaque(ty::AliasTy { def_id, substs }) => {
|
||||
ty::Alias(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::AliasTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }),
|
||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Alias(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::AliasTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ }))
|
||||
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }))
|
||||
if self.fields.define_opaque_types && def_id.is_local() =>
|
||||
{
|
||||
self.fields.obligations.extend(
|
||||
|
|
|
@ -340,8 +340,8 @@ 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::AliasTy { def_id, substs }) => (def_id, substs),
|
||||
ty::Projection(data)
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => (def_id, substs),
|
||||
ty::Alias(ty::Projection, data)
|
||||
if self.tcx.def_kind(data.def_id) == DefKind::ImplTraitPlaceholder =>
|
||||
{
|
||||
(data.def_id, data.substs)
|
||||
|
@ -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::AliasTy { def_id, .. })) => {
|
||||
(true, ty::Alias(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!(
|
||||
|
@ -1742,7 +1742,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
pos.col.to_usize() + 1,
|
||||
)
|
||||
}
|
||||
(true, ty::Projection(proj))
|
||||
(true, ty::Alias(ty::Projection, proj))
|
||||
if self.tcx.def_kind(proj.def_id)
|
||||
== DefKind::ImplTraitPlaceholder =>
|
||||
{
|
||||
|
@ -2385,10 +2385,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
// fn get_later<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
|
||||
// suggest:
|
||||
// fn get_later<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
|
||||
ty::Closure(_, _substs)
|
||||
| ty::Opaque(ty::AliasTy { def_id: _, substs: _substs })
|
||||
if return_impl_trait =>
|
||||
{
|
||||
ty::Closure(..) | ty::Alias(ty::Opaque, ..) if return_impl_trait => {
|
||||
new_binding_suggestion(&mut err, type_param_span);
|
||||
}
|
||||
_ => {
|
||||
|
@ -2770,7 +2767,9 @@ 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::AliasTy { def_id, substs: _ }) => Some((Self::Opaque, def_id)),
|
||||
ty::Alias(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))
|
||||
}
|
||||
|
|
|
@ -852,7 +852,10 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
|
|||
match inner.unpack() {
|
||||
GenericArgKind::Lifetime(_) => {}
|
||||
GenericArgKind::Type(ty) => {
|
||||
if matches!(ty.kind(), ty::Opaque(..) | ty::Closure(..) | ty::Generator(..)) {
|
||||
if matches!(
|
||||
ty.kind(),
|
||||
ty::Alias(ty::Opaque, ..) | ty::Closure(..) | ty::Generator(..)
|
||||
) {
|
||||
// Opaque types can't be named by the user right now.
|
||||
//
|
||||
// Both the generic arguments of closures and generators can
|
||||
|
|
|
@ -487,12 +487,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
StatementAsExpression::CorrectType
|
||||
}
|
||||
(
|
||||
ty::Opaque(ty::AliasTy { def_id: last_def_id, substs: _ }),
|
||||
ty::Opaque(ty::AliasTy { def_id: exp_def_id, substs: _ }),
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: last_def_id, substs: _ }),
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, substs: _ }),
|
||||
) if last_def_id == exp_def_id => StatementAsExpression::CorrectType,
|
||||
(
|
||||
ty::Opaque(ty::AliasTy { def_id: last_def_id, substs: last_bounds }),
|
||||
ty::Opaque(ty::AliasTy { def_id: exp_def_id, substs: exp_bounds }),
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: last_def_id, substs: last_bounds }),
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, substs: exp_bounds }),
|
||||
) => {
|
||||
debug!(
|
||||
"both opaque, likely future {:?} {:?} {:?} {:?}",
|
||||
|
|
|
@ -205,12 +205,11 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
|
|||
| ty::Dynamic(..)
|
||||
| ty::Never
|
||||
| ty::Tuple(..)
|
||||
| ty::Projection(..)
|
||||
| ty::Alias(..)
|
||||
| ty::Foreign(..)
|
||||
| ty::Param(..)
|
||||
| ty::Closure(..)
|
||||
| ty::GeneratorWitness(..)
|
||||
| ty::Opaque(..) => t.super_fold_with(self),
|
||||
| ty::GeneratorWitness(..) => t.super_fold_with(self),
|
||||
|
||||
ty::Placeholder(..) | ty::Bound(..) => bug!("unexpected type {:?}", t),
|
||||
}
|
||||
|
|
|
@ -106,11 +106,11 @@ where
|
|||
}
|
||||
|
||||
(
|
||||
&ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }),
|
||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Alias(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::AliasTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ }))
|
||||
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }))
|
||||
if this.define_opaque_types() && def_id.is_local() =>
|
||||
{
|
||||
this.add_obligations(
|
||||
|
|
|
@ -281,7 +281,7 @@ where
|
|||
use rustc_span::DUMMY_SP;
|
||||
|
||||
match *value_ty.kind() {
|
||||
ty::Projection(other_projection_ty) => {
|
||||
ty::Alias(ty::Projection, other_projection_ty) => {
|
||||
let var = self.infcx.next_ty_var(TypeVariableOrigin {
|
||||
kind: TypeVariableOriginKind::MiscVariable,
|
||||
span: DUMMY_SP,
|
||||
|
@ -335,7 +335,9 @@ where
|
|||
return Ok(value_ty);
|
||||
}
|
||||
|
||||
ty::Projection(projection_ty) if D::normalization() == NormalizationStrategy::Lazy => {
|
||||
ty::Alias(ty::Projection, projection_ty)
|
||||
if D::normalization() == NormalizationStrategy::Lazy =>
|
||||
{
|
||||
return Ok(self.relate_projection_ty(projection_ty, self.infcx.tcx.mk_ty_var(vid)));
|
||||
}
|
||||
|
||||
|
@ -406,8 +408,8 @@ where
|
|||
}
|
||||
};
|
||||
let (a, b) = match (a.kind(), b.kind()) {
|
||||
(&ty::Opaque(..), _) => (a, generalize(b, false)?),
|
||||
(_, &ty::Opaque(..)) => (generalize(a, true)?, b),
|
||||
(&ty::Alias(ty::Opaque, ..), _) => (a, generalize(b, false)?),
|
||||
(_, &ty::Alias(ty::Opaque, ..)) => (generalize(a, true)?, b),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let cause = ObligationCause::dummy_with_span(self.delegate.span());
|
||||
|
@ -609,8 +611,8 @@ where
|
|||
(&ty::Infer(ty::TyVar(vid)), _) => self.relate_ty_var((vid, b)),
|
||||
|
||||
(
|
||||
&ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }),
|
||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Alias(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,20 +620,20 @@ where
|
|||
);
|
||||
if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) }
|
||||
}),
|
||||
(&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ }))
|
||||
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }))
|
||||
if def_id.is_local() =>
|
||||
{
|
||||
self.relate_opaques(a, b)
|
||||
}
|
||||
|
||||
(&ty::Projection(projection_ty), _)
|
||||
(&ty::Alias(ty::Projection, projection_ty), _)
|
||||
if D::normalization() == NormalizationStrategy::Lazy =>
|
||||
{
|
||||
Ok(self.relate_projection_ty(projection_ty, b))
|
||||
}
|
||||
|
||||
(_, &ty::Projection(projection_ty))
|
||||
(_, &ty::Alias(ty::Projection, projection_ty))
|
||||
if D::normalization() == NormalizationStrategy::Lazy =>
|
||||
{
|
||||
Ok(self.relate_projection_ty(projection_ty, a))
|
||||
|
|
|
@ -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::AliasTy { def_id, substs: _substs })
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, 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::AliasTy { def_id, substs }) if def_id.is_local() => {
|
||||
ty::Alias(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,9 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
DefiningAnchor::Bubble => self.opaque_ty_origin_unchecked(def_id, cause.span),
|
||||
DefiningAnchor::Error => return None,
|
||||
};
|
||||
if let ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }) = *b.kind() {
|
||||
if let ty::Alias(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 +480,7 @@ where
|
|||
substs.as_generator().resume_ty().visit_with(self);
|
||||
}
|
||||
|
||||
ty::Opaque(ty::AliasTy { def_id, ref substs }) => {
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, ref substs }) => {
|
||||
// Skip lifetime paramters that are not captures.
|
||||
let variances = self.tcx.variances_of(*def_id);
|
||||
|
||||
|
@ -489,7 +491,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
ty::Projection(proj)
|
||||
ty::Alias(ty::Projection, proj)
|
||||
if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder =>
|
||||
{
|
||||
// Skip lifetime paramters that are not captures.
|
||||
|
@ -566,7 +568,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
// We can't normalize associated types from `rustc_infer`,
|
||||
// but we can eagerly register inference variables for them.
|
||||
// FIXME(RPITIT): Don't replace RPITITs with inference vars.
|
||||
ty::Projection(projection_ty)
|
||||
ty::Alias(ty::Projection, projection_ty)
|
||||
if !projection_ty.has_escaping_bound_vars()
|
||||
&& tcx.def_kind(projection_ty.def_id)
|
||||
!= DefKind::ImplTraitPlaceholder =>
|
||||
|
@ -581,13 +583,13 @@ 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::AliasTy { def_id: def_id2, substs: substs2 })
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def_id2, substs: substs2 })
|
||||
if def_id.to_def_id() == def_id2 && substs == substs2 =>
|
||||
{
|
||||
hidden_ty
|
||||
}
|
||||
// FIXME(RPITIT): This can go away when we move to associated types
|
||||
ty::Projection(proj)
|
||||
ty::Alias(ty::Projection, proj)
|
||||
if def_id.to_def_id() == proj.def_id && substs == proj.substs =>
|
||||
{
|
||||
hidden_ty
|
||||
|
|
|
@ -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::AliasTy { def_id, substs }) => {
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
|
||||
out.push(Component::Opaque(def_id, substs));
|
||||
},
|
||||
|
||||
|
@ -142,7 +142,7 @@ fn compute_components<'tcx>(
|
|||
// trait-ref. Therefore, if we see any higher-ranked regions,
|
||||
// we simply fallback to the most restrictive rule, which
|
||||
// requires that `Pi: 'a` for all `i`.
|
||||
ty::Projection(ref data) => {
|
||||
ty::Alias(ty::Projection, ref data) => {
|
||||
if !data.has_escaping_bound_vars() {
|
||||
// best case: no escaping regions, so push the
|
||||
// projection and skip the subtree (thus generating no
|
||||
|
|
|
@ -338,7 +338,7 @@ where
|
|||
substs,
|
||||
true,
|
||||
|ty| match *ty.kind() {
|
||||
ty::Opaque(ty::AliasTy { def_id, substs }) => (def_id, substs),
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => (def_id, substs),
|
||||
_ => bug!("expected only projection types from env, not {:?}", ty),
|
||||
},
|
||||
);
|
||||
|
@ -359,7 +359,9 @@ where
|
|||
projection_ty.substs,
|
||||
false,
|
||||
|ty| match ty.kind() {
|
||||
ty::Projection(projection_ty) => (projection_ty.def_id, projection_ty.substs),
|
||||
ty::Alias(ty::Projection, projection_ty) => {
|
||||
(projection_ty.def_id, projection_ty.substs)
|
||||
}
|
||||
_ => bug!("expected only projection types from env, not {:?}", ty),
|
||||
},
|
||||
);
|
||||
|
|
|
@ -131,14 +131,14 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
|
|||
}
|
||||
|
||||
(
|
||||
&ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }),
|
||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Alias(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::AliasTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ }))
|
||||
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }))
|
||||
if self.fields.define_opaque_types && def_id.is_local() =>
|
||||
{
|
||||
self.fields.obligations.extend(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue