Use ty::OpaqueTy everywhere
This commit is contained in:
parent
918ede6474
commit
7f3af72606
55 changed files with 156 additions and 118 deletions
|
@ -675,7 +675,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
|||
// relatable.
|
||||
Ok(t)
|
||||
}
|
||||
ty::Opaque(def_id, substs) => {
|
||||
ty::Opaque(ty::OpaqueTy { def_id, substs }) => {
|
||||
let s = self.relate(substs, substs)?;
|
||||
Ok(if s == substs { t } else { self.infcx.tcx.mk_opaque(def_id, s) })
|
||||
}
|
||||
|
|
|
@ -100,11 +100,15 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
|
|||
self.fields.instantiate(a, RelationDir::EqTo, b_id, self.a_is_expected)?;
|
||||
}
|
||||
|
||||
(&ty::Opaque(a_def_id, _), &ty::Opaque(b_def_id, _)) if a_def_id == b_def_id => {
|
||||
(
|
||||
&ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: _ }),
|
||||
) if a_def_id == b_def_id => {
|
||||
self.fields.infcx.super_combine_tys(self, a, b)?;
|
||||
}
|
||||
(&ty::Opaque(did, ..), _) | (_, &ty::Opaque(did, ..))
|
||||
if self.fields.define_opaque_types && did.is_local() =>
|
||||
(&ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Opaque(ty::OpaqueTy { def_id, substs: _ }))
|
||||
if self.fields.define_opaque_types && def_id.is_local() =>
|
||||
{
|
||||
self.fields.obligations.extend(
|
||||
infcx
|
||||
|
|
|
@ -338,8 +338,9 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
|
|||
|
||||
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(def_id, substs) => (def_id, substs),
|
||||
ty::Opaque(ty::OpaqueTy { def_id, substs }) => (def_id, substs),
|
||||
ty::Projection(data)
|
||||
if self.tcx.def_kind(data.item_def_id) == DefKind::ImplTraitPlaceholder =>
|
||||
{
|
||||
|
@ -1729,8 +1730,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
TypeError::Sorts(values) => {
|
||||
let extra = expected == found;
|
||||
let sort_string = |ty: Ty<'tcx>, path: Option<PathBuf>| {
|
||||
// FIXME(alias): Merge these
|
||||
let mut s = match (extra, ty.kind()) {
|
||||
(true, ty::Opaque(def_id, _)) => {
|
||||
(true, ty::Opaque(ty::OpaqueTy { def_id, .. })) => {
|
||||
let sm = self.tcx.sess.source_map();
|
||||
let pos = sm.lookup_char_pos(self.tcx.def_span(*def_id).lo());
|
||||
format!(
|
||||
|
@ -2383,7 +2385,10 @@ 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(_, _substs) if return_impl_trait => {
|
||||
ty::Closure(_, _substs)
|
||||
| ty::Opaque(ty::OpaqueTy { def_id: _, substs: _substs })
|
||||
if return_impl_trait =>
|
||||
{
|
||||
new_binding_suggestion(&mut err, type_param_span);
|
||||
}
|
||||
_ => {
|
||||
|
@ -2765,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(def_id, _) => Some((Self::Opaque, def_id)),
|
||||
ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) => Some((Self::Opaque, def_id)),
|
||||
ty::Generator(def_id, ..) => {
|
||||
Some((Self::Generator(tcx.generator_kind(def_id).unwrap()), def_id))
|
||||
}
|
||||
|
|
|
@ -486,12 +486,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
_ if self.same_type_modulo_infer(last_expr_ty, expected_ty) => {
|
||||
StatementAsExpression::CorrectType
|
||||
}
|
||||
(ty::Opaque(last_def_id, _), ty::Opaque(exp_def_id, _))
|
||||
if last_def_id == exp_def_id =>
|
||||
{
|
||||
StatementAsExpression::CorrectType
|
||||
}
|
||||
(ty::Opaque(last_def_id, last_bounds), ty::Opaque(exp_def_id, exp_bounds)) => {
|
||||
(
|
||||
ty::Opaque(ty::OpaqueTy { def_id: last_def_id, substs: _ }),
|
||||
ty::Opaque(ty::OpaqueTy { 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 }),
|
||||
) => {
|
||||
debug!(
|
||||
"both opaque, likely future {:?} {:?} {:?} {:?}",
|
||||
last_def_id, last_bounds, exp_def_id, exp_bounds
|
||||
|
@ -507,7 +509,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
(
|
||||
hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds: last_bounds, .. }),
|
||||
hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds: exp_bounds, .. }),
|
||||
) if std::iter::zip(*last_bounds, *exp_bounds).all(|(left, right)| {
|
||||
) if iter::zip(*last_bounds, *exp_bounds).all(|(left, right)| {
|
||||
match (left, right) {
|
||||
(
|
||||
hir::GenericBound::Trait(tl, ml),
|
||||
|
|
|
@ -105,11 +105,13 @@ where
|
|||
Ok(v)
|
||||
}
|
||||
|
||||
(&ty::Opaque(a_def_id, _), &ty::Opaque(b_def_id, _)) if a_def_id == b_def_id => {
|
||||
infcx.super_combine_tys(this, a, b)
|
||||
}
|
||||
(&ty::Opaque(did, ..), _) | (_, &ty::Opaque(did, ..))
|
||||
if this.define_opaque_types() && did.is_local() =>
|
||||
(
|
||||
&ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::OpaqueTy { 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: _ }))
|
||||
if this.define_opaque_types() && def_id.is_local() =>
|
||||
{
|
||||
this.add_obligations(
|
||||
infcx
|
||||
|
|
|
@ -608,16 +608,20 @@ where
|
|||
|
||||
(&ty::Infer(ty::TyVar(vid)), _) => self.relate_ty_var((vid, b)),
|
||||
|
||||
(&ty::Opaque(a_def_id, _), &ty::Opaque(b_def_id, _)) 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(),
|
||||
"failure to relate an opaque to itself should result in an error later on",
|
||||
);
|
||||
if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) }
|
||||
})
|
||||
}
|
||||
(&ty::Opaque(did, ..), _) | (_, &ty::Opaque(did, ..)) if did.is_local() => {
|
||||
(
|
||||
&ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::OpaqueTy { 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(),
|
||||
"failure to relate an opaque to itself should result in an error later on",
|
||||
);
|
||||
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: _ }))
|
||||
if def_id.is_local() =>
|
||||
{
|
||||
self.relate_opaques(a, b)
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,9 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
lt_op: |lt| lt,
|
||||
ct_op: |ct| ct,
|
||||
ty_op: |ty| match *ty.kind() {
|
||||
ty::Opaque(def_id, _substs) if replace_opaque_type(def_id) => {
|
||||
ty::Opaque(ty::OpaqueTy { def_id, substs: _substs })
|
||||
if replace_opaque_type(def_id) =>
|
||||
{
|
||||
let def_span = self.tcx.def_span(def_id);
|
||||
let span = if span.contains(def_span) { def_span } else { span };
|
||||
let code = traits::ObligationCauseCode::OpaqueReturnType(None);
|
||||
|
@ -104,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(def_id, substs) if def_id.is_local() => {
|
||||
ty::Opaque(ty::OpaqueTy { def_id, substs }) if def_id.is_local() => {
|
||||
let def_id = def_id.expect_local();
|
||||
let origin = match self.defining_use_anchor {
|
||||
DefiningAnchor::Bind(_) => {
|
||||
|
@ -147,18 +149,19 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
DefiningAnchor::Bubble => self.opaque_ty_origin_unchecked(def_id, cause.span),
|
||||
DefiningAnchor::Error => return None,
|
||||
};
|
||||
if let ty::Opaque(did2, _) = *b.kind() {
|
||||
if let ty::Opaque(ty::OpaqueTy { 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.
|
||||
// It does occur however in `fn fut() -> impl Future<Output = i32> { async { 42 } }`,
|
||||
// where it is of no concern, so we only check for TAITs.
|
||||
if let Some(OpaqueTyOrigin::TyAlias) =
|
||||
did2.as_local().and_then(|did2| self.opaque_type_origin(did2, cause.span))
|
||||
if let Some(OpaqueTyOrigin::TyAlias) = b_def_id
|
||||
.as_local()
|
||||
.and_then(|b_def_id| self.opaque_type_origin(b_def_id, cause.span))
|
||||
{
|
||||
self.tcx.sess.emit_err(OpaqueHiddenTypeDiag {
|
||||
span: cause.span,
|
||||
hidden_type: self.tcx.def_span(did2),
|
||||
hidden_type: self.tcx.def_span(b_def_id),
|
||||
opaque_type: self.tcx.def_span(def_id),
|
||||
});
|
||||
}
|
||||
|
@ -475,7 +478,7 @@ where
|
|||
substs.as_generator().resume_ty().visit_with(self);
|
||||
}
|
||||
|
||||
ty::Opaque(def_id, ref substs) => {
|
||||
ty::Opaque(ty::OpaqueTy { def_id, ref substs }) => {
|
||||
// Skip lifetime paramters that are not captures.
|
||||
let variances = self.tcx.variances_of(*def_id);
|
||||
|
||||
|
@ -578,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(def_id2, substs2)
|
||||
ty::Opaque(ty::OpaqueTy { def_id: def_id2, substs: substs2 })
|
||||
if def_id.to_def_id() == def_id2 && substs == substs2 =>
|
||||
{
|
||||
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(def_id, substs) => {
|
||||
ty::Opaque(ty::OpaqueTy { def_id, substs }) => {
|
||||
out.push(Component::Opaque(def_id, substs));
|
||||
},
|
||||
|
||||
|
|
|
@ -338,7 +338,7 @@ where
|
|||
substs,
|
||||
true,
|
||||
|ty| match *ty.kind() {
|
||||
ty::Opaque(def_id, substs) => (def_id, substs),
|
||||
ty::Opaque(ty::OpaqueTy { def_id, substs }) => (def_id, substs),
|
||||
_ => bug!("expected only projection types from env, not {:?}", ty),
|
||||
},
|
||||
);
|
||||
|
|
|
@ -130,12 +130,16 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
|
|||
Ok(self.tcx().ty_error_with_guaranteed(e))
|
||||
}
|
||||
|
||||
(&ty::Opaque(a_def_id, _), &ty::Opaque(b_def_id, _)) if a_def_id == b_def_id => {
|
||||
(
|
||||
&ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: _ }),
|
||||
&ty::Opaque(ty::OpaqueTy { 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(did, ..), _) | (_, &ty::Opaque(did, ..))
|
||||
if self.fields.define_opaque_types && did.is_local() =>
|
||||
(&ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), _)
|
||||
| (_, &ty::Opaque(ty::OpaqueTy { def_id, substs: _ }))
|
||||
if self.fields.define_opaque_types && def_id.is_local() =>
|
||||
{
|
||||
self.fields.obligations.extend(
|
||||
infcx
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue