diff options
| author | Michael Goulet <michael@errs.io> | 2022-11-26 21:09:39 +0000 | 
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2022-12-13 17:29:26 +0000 | 
| commit | 7f3af726065d9eaabf93d87f22d97f60cca7a5f1 (patch) | |
| tree | d3501a3fc742f5e786697c99c7e230a497551e1a /compiler/rustc_infer/src | |
| parent | 918ede64740b3610dfd8b43ff0d995261a236ac5 (diff) | |
| download | rust-7f3af726065d9eaabf93d87f22d97f60cca7a5f1.tar.gz rust-7f3af726065d9eaabf93d87f22d97f60cca7a5f1.zip | |
Use ty::OpaqueTy everywhere
Diffstat (limited to 'compiler/rustc_infer/src')
| -rw-r--r-- | compiler/rustc_infer/src/infer/combine.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/equate.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/error_reporting/mod.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/error_reporting/suggest.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/lattice.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/nll_relate/mod.rs | 24 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/opaque_types.rs | 19 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/outlives/components.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/outlives/obligations.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/sub.rs | 10 | 
10 files changed, 67 insertions, 43 deletions
| diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index cf895ed0d3e..4f6a0630d3d 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -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) }) } diff --git a/compiler/rustc_infer/src/infer/equate.rs b/compiler/rustc_infer/src/infer/equate.rs index 17f932e78a1..c0056c27a58 100644 --- a/compiler/rustc_infer/src/infer/equate.rs +++ b/compiler/rustc_infer/src/infer/equate.rs @@ -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 diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 987559d7e47..fea62133759 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -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)) } diff --git a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs index 73b5a2cc4ad..fe134830d68 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs @@ -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), diff --git a/compiler/rustc_infer/src/infer/lattice.rs b/compiler/rustc_infer/src/infer/lattice.rs index eba65361ae6..6513abd3879 100644 --- a/compiler/rustc_infer/src/infer/lattice.rs +++ b/compiler/rustc_infer/src/infer/lattice.rs @@ -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 diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs index f6bc4db0d59..e0f9220ca5f 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -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) } diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index 524f7a39ebb..495369031d1 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -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 diff --git a/compiler/rustc_infer/src/infer/outlives/components.rs b/compiler/rustc_infer/src/infer/outlives/components.rs index 14ee9f05190..ea3b0efb85b 100644 --- a/compiler/rustc_infer/src/infer/outlives/components.rs +++ b/compiler/rustc_infer/src/infer/outlives/components.rs @@ -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)); }, diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index 6ca884799aa..3fc3e6b09df 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -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), }, ); diff --git a/compiler/rustc_infer/src/infer/sub.rs b/compiler/rustc_infer/src/infer/sub.rs index 79a1afa469e..f05d6614515 100644 --- a/compiler/rustc_infer/src/infer/sub.rs +++ b/compiler/rustc_infer/src/infer/sub.rs @@ -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 | 
