about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2023-03-03 12:35:53 -0300
committerSantiago Pastorino <spastorino@gmail.com>2023-03-06 14:49:48 -0300
commite10034c6360916c0fdddf092bb3b7db3c98e436f (patch)
tree8c33b87d0e5de43de717b3d77b59e969cde55668
parent83c0ff8fa5eb1789b9d5caa1d5bb2b344165e897 (diff)
downloadrust-e10034c6360916c0fdddf092bb3b7db3c98e436f.tar.gz
rust-e10034c6360916c0fdddf092bb3b7db3c98e436f.zip
Properly implement explicit_item_bounds for RPITITs trait assoc ty
-rw-r--r--compiler/rustc_hir_analysis/src/collect/item_bounds.rs34
-rw-r--r--compiler/rustc_ty_utils/src/assoc.rs3
2 files changed, 23 insertions, 14 deletions
diff --git a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs
index 6f6f993f727..7dce29cc0bb 100644
--- a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs
+++ b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs
@@ -3,7 +3,7 @@ use crate::astconv::AstConv;
 use rustc_hir as hir;
 use rustc_infer::traits::util;
 use rustc_middle::ty::subst::InternalSubsts;
-use rustc_middle::ty::{self, TyCtxt};
+use rustc_middle::ty::{self, ImplTraitInTraitData, Ty, TyCtxt};
 use rustc_span::def_id::DefId;
 use rustc_span::Span;
 
@@ -58,17 +58,10 @@ fn opaque_type_bounds<'tcx>(
     tcx: TyCtxt<'tcx>,
     opaque_def_id: DefId,
     ast_bounds: &'tcx [hir::GenericBound<'tcx>],
+    item_ty: Ty<'tcx>,
     span: Span,
-    in_trait: bool,
 ) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
     ty::print::with_no_queries!({
-        let substs = InternalSubsts::identity_for_item(tcx, opaque_def_id);
-        let item_ty = if in_trait {
-            tcx.mk_projection(opaque_def_id, substs)
-        } else {
-            tcx.mk_opaque(opaque_def_id, substs)
-        };
-
         let icx = ItemCtxt::new(tcx, opaque_def_id);
         let mut bounds = icx.astconv().compute_bounds(item_ty, ast_bounds);
         // Opaque types are implicitly sized unless a `?Sized` bound is found
@@ -83,7 +76,18 @@ pub(super) fn explicit_item_bounds(
     tcx: TyCtxt<'_>,
     def_id: DefId,
 ) -> &'_ [(ty::Predicate<'_>, Span)] {
-    let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
+    // If the def_id is about an RPITIT, delegate explicit_item_bounds to the opaque_def_id that
+    // generated the synthesized associate type.
+    let rpitit_info = if let Some(ImplTraitInTraitData::Trait { opaque_def_id, .. }) =
+        tcx.opt_rpitit_info(def_id)
+    {
+        Some(opaque_def_id)
+    } else {
+        None
+    };
+
+    let bounds_def_id = rpitit_info.unwrap_or(def_id);
+    let hir_id = tcx.hir().local_def_id_to_hir_id(bounds_def_id.expect_local());
     match tcx.hir().get(hir_id) {
         hir::Node::TraitItem(hir::TraitItem {
             kind: hir::TraitItemKind::Type(bounds, _),
@@ -94,7 +98,15 @@ pub(super) fn explicit_item_bounds(
             kind: hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, in_trait, .. }),
             span,
             ..
-        }) => opaque_type_bounds(tcx, def_id, bounds, *span, *in_trait),
+        }) => {
+            let substs = InternalSubsts::identity_for_item(tcx, def_id);
+            let item_ty = if *in_trait || rpitit_info.is_some() {
+                tcx.mk_projection(def_id, substs)
+            } else {
+                tcx.mk_opaque(def_id, substs)
+            };
+            opaque_type_bounds(tcx, bounds_def_id, bounds, item_ty, *span)
+        }
         _ => bug!("item_bounds called on {:?}", def_id),
     }
 }
diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs
index 050fd566049..f67566a7d0e 100644
--- a/compiler/rustc_ty_utils/src/assoc.rs
+++ b/compiler/rustc_ty_utils/src/assoc.rs
@@ -302,9 +302,6 @@ fn associated_item_for_impl_trait_in_trait(
     // There are no inferred outlives for the synthesized associated type.
     trait_assoc_ty.inferred_outlives_of(&[]);
 
-    // FIXME implement this.
-    trait_assoc_ty.explicit_item_bounds(&[]);
-
     local_def_id
 }