diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
commit | 218caa410aa38c29984be31a5229b9fa717560ee (patch) | |
tree | c54bd55eeb6e4c508940a30e94c0032fbd45d677 /compiler/rustc_infer/src/infer/opaque_types.rs | |
parent | Releasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | compiler/rustc_infer/src/infer/opaque_types.rs | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index 524f7a39e..c54c66eab 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -61,12 +61,14 @@ impl<'tcx> InferCtxt<'tcx> { .as_local() .map_or(false, |def_id| self.opaque_type_origin(def_id, span).is_some()) }; - let value = value.fold_with(&mut ty::fold::BottomUpFolder { + let value = value.fold_with(&mut BottomUpFolder { tcx: self.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::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) + 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,13 +106,13 @@ 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::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(_) => { // Check that this is `impl Trait` type is // declared by `parent_def_id` -- i.e., one whose - // value we are inferring. At present, this is + // value we are inferring. At present, this is // always true during the first phase of // type-check, but not always true later on during // NLL. Once we support named opaque types more fully, @@ -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::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }) = *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), }); } @@ -377,7 +380,7 @@ impl<'tcx> InferCtxt<'tcx> { }; let item_kind = &self.tcx.hir().expect_item(def_id).kind; - let hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) = item_kind else { + let hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) = item_kind else { span_bug!( span, "weird opaque type: {:#?}, {:#?}", @@ -437,16 +440,16 @@ where t: &ty::Binder<'tcx, T>, ) -> ControlFlow<Self::BreakTy> { t.super_visit_with(self); - ControlFlow::CONTINUE + ControlFlow::Continue(()) } fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> { match *r { // ignore bound regions, keep visiting - ty::ReLateBound(_, _) => ControlFlow::CONTINUE, + ty::ReLateBound(_, _) => ControlFlow::Continue(()), _ => { (self.op)(r); - ControlFlow::CONTINUE + ControlFlow::Continue(()) } } } @@ -454,7 +457,7 @@ where fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> { // We're only interested in types involving regions if !ty.flags().intersects(ty::TypeFlags::HAS_FREE_REGIONS) { - return ControlFlow::CONTINUE; + return ControlFlow::Continue(()); } match ty.kind() { @@ -475,8 +478,8 @@ where substs.as_generator().resume_ty().visit_with(self); } - ty::Opaque(def_id, ref substs) => { - // Skip lifetime paramters that are not captures. + ty::Alias(ty::Opaque, ty::AliasTy { def_id, ref substs, .. }) => { + // Skip lifetime parameters that are not captures. let variances = self.tcx.variances_of(*def_id); for (v, s) in std::iter::zip(variances, substs.iter()) { @@ -486,11 +489,11 @@ where } } - ty::Projection(proj) - if self.tcx.def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder => + ty::Alias(ty::Projection, proj) + if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder => { - // Skip lifetime paramters that are not captures. - let variances = self.tcx.variances_of(proj.item_def_id); + // Skip lifetime parameters that are not captures. + let variances = self.tcx.variances_of(proj.def_id); for (v, s) in std::iter::zip(variances, proj.substs.iter()) { if *v != ty::Variance::Bivariant { @@ -504,7 +507,7 @@ where } } - ControlFlow::CONTINUE + ControlFlow::Continue(()) } } @@ -563,9 +566,9 @@ 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.item_def_id) + && tcx.def_kind(projection_ty.def_id) != DefKind::ImplTraitPlaceholder => { self.infer_projection( @@ -578,17 +581,16 @@ 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::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) - if def_id.to_def_id() == proj.item_def_id && substs == proj.substs => - { - hidden_ty - } + ty::Alias( + ty::Projection, + ty::AliasTy { def_id: def_id2, substs: substs2, .. }, + ) if def_id.to_def_id() == def_id2 && substs == substs2 => hidden_ty, _ => ty, }, lt_op: |lt| lt, |