about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorDeadbeef <ent3rm4n@gmail.com>2024-06-25 07:51:44 +0000
committerDeadbeef <ent3rm4n@gmail.com>2024-06-28 10:57:35 +0000
commit3637b153f7cb8de14588ea82a15a28499bcb3b3f (patch)
tree10e7b9f43593906f41ed5ea75142d42359706cf3 /compiler
parentc7d27a15d0a28d66d9a6b279e6005b6fcd861ae2 (diff)
downloadrust-3637b153f7cb8de14588ea82a15a28499bcb3b3f.tar.gz
rust-3637b153f7cb8de14588ea82a15a28499bcb3b3f.zip
move desugaring to item bounds
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_hir_analysis/src/collect/item_bounds.rs26
-rw-r--r--compiler/rustc_hir_analysis/src/collect/predicates_of.rs31
2 files changed, 26 insertions, 31 deletions
diff --git a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs
index 57142414b9d..707a3f2d3c7 100644
--- a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs
+++ b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs
@@ -8,6 +8,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFold
 use rustc_middle::{bug, span_bug};
 use rustc_span::def_id::{DefId, LocalDefId};
 use rustc_span::Span;
+use rustc_type_ir::Upcast;
 
 /// For associated types we include both bounds written on the type
 /// (`type X: Trait`) and predicates from the trait: `where Self::X: Trait`.
@@ -124,6 +125,31 @@ pub(super) fn explicit_item_bounds_with_filter(
         None => {}
     }
 
+    if tcx.is_effects_desugared_assoc_ty(def_id.to_def_id()) {
+        let mut predicates = Vec::new();
+
+        let parent = tcx.local_parent(def_id);
+
+        let identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
+        let preds = tcx.explicit_predicates_of(parent);
+
+        if let ty::AssocItemContainer::TraitContainer = tcx.associated_item(def_id).container {
+            // for traits, emit `type Effects: TyCompat<<(T1::Effects, ..) as Min>::Output>`
+            // TODO do the same for impls
+            let tup = Ty::new(tcx, ty::Tuple(preds.effects_min_tys));
+            // TODO span
+            let span = tcx.def_span(def_id);
+            let assoc = tcx.require_lang_item(hir::LangItem::EffectsMinOutput, Some(span));
+            let proj = Ty::new_projection(tcx, assoc, [tup]);
+            // TODO this is bad
+            let self_proj = Ty::new_projection(tcx, def_id.to_def_id(), identity_args);
+            let trait_ = tcx.require_lang_item(hir::LangItem::EffectsTyCompat, Some(span));
+            let trait_ref = ty::TraitRef::new(tcx, trait_, [self_proj, proj]);
+            predicates.push((ty::Binder::dummy(trait_ref).upcast(tcx), span));
+        }
+        return ty::EarlyBinder::bind(tcx.arena.alloc_from_iter(predicates));
+    }
+
     let bounds = match tcx.hir_node_by_def_id(def_id) {
         hir::Node::TraitItem(hir::TraitItem {
             kind: hir::TraitItemKind::Type(bounds, _),
diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs
index e3d1e1c423e..9a5feaf3d3c 100644
--- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs
+++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs
@@ -57,7 +57,6 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
 #[instrument(level = "trace", skip(tcx), ret)]
 fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::GenericPredicates<'_> {
     use rustc_hir::*;
-    use rustc_middle::ty::Ty; // to override hir::Ty
 
     match tcx.opt_rpitit_info(def_id.to_def_id()) {
         Some(ImplTraitInTraitData::Trait { fn_def_id, .. }) => {
@@ -114,36 +113,6 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
         None => {}
     }
 
-    if tcx.is_effects_desugared_assoc_ty(def_id.to_def_id()) {
-        let mut predicates = Vec::new();
-
-        // Inherit predicates of parent (impl or trait)
-        let parent = tcx.local_parent(def_id);
-
-        let identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
-        let preds = tcx.explicit_predicates_of(parent);
-
-        if let ty::AssocItemContainer::TraitContainer = tcx.associated_item(def_id).container {
-            // for traits, emit `type Effects: TyCompat<<(T1::Effects, ..) as Min>::Output>`
-            // TODO do the same for impls
-            let tup = Ty::new(tcx, ty::Tuple(preds.effects_min_tys));
-            // TODO span
-            let span = tcx.def_span(def_id);
-            let assoc = tcx.require_lang_item(LangItem::EffectsMinOutput, Some(span));
-            let proj = Ty::new_projection(tcx, assoc, [tup]);
-            // TODO this is bad
-            let self_proj = Ty::new_projection(tcx, def_id.to_def_id(), identity_args);
-            let trait_ = tcx.require_lang_item(LangItem::EffectsTyCompat, Some(span));
-            let trait_ref = ty::TraitRef::new(tcx, trait_, [self_proj, proj]);
-            predicates.push((ty::Binder::dummy(trait_ref).upcast(tcx), span));
-        }
-        return ty::GenericPredicates {
-            parent: Some(parent.to_def_id()),
-            predicates: tcx.arena.alloc_from_iter(predicates),
-            effects_min_tys: ty::List::empty(),
-        };
-    }
-
     let hir_id = tcx.local_def_id_to_hir_id(def_id);
     let node = tcx.hir_node(hir_id);