Skip to content

Commit 3637b15

Browse files
committed
move desugaring to item bounds
1 parent c7d27a1 commit 3637b15

File tree

2 files changed

+26
-31
lines changed

2 files changed

+26
-31
lines changed

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFold
88
use rustc_middle::{bug, span_bug};
99
use rustc_span::def_id::{DefId, LocalDefId};
1010
use rustc_span::Span;
11+
use rustc_type_ir::Upcast;
1112

1213
/// For associated types we include both bounds written on the type
1314
/// (`type X: Trait`) and predicates from the trait: `where Self::X: Trait`.
@@ -124,6 +125,31 @@ pub(super) fn explicit_item_bounds_with_filter(
124125
None => {}
125126
}
126127

128+
if tcx.is_effects_desugared_assoc_ty(def_id.to_def_id()) {
129+
let mut predicates = Vec::new();
130+
131+
let parent = tcx.local_parent(def_id);
132+
133+
let identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
134+
let preds = tcx.explicit_predicates_of(parent);
135+
136+
if let ty::AssocItemContainer::TraitContainer = tcx.associated_item(def_id).container {
137+
// for traits, emit `type Effects: TyCompat<<(T1::Effects, ..) as Min>::Output>`
138+
// TODO do the same for impls
139+
let tup = Ty::new(tcx, ty::Tuple(preds.effects_min_tys));
140+
// TODO span
141+
let span = tcx.def_span(def_id);
142+
let assoc = tcx.require_lang_item(hir::LangItem::EffectsMinOutput, Some(span));
143+
let proj = Ty::new_projection(tcx, assoc, [tup]);
144+
// TODO this is bad
145+
let self_proj = Ty::new_projection(tcx, def_id.to_def_id(), identity_args);
146+
let trait_ = tcx.require_lang_item(hir::LangItem::EffectsTyCompat, Some(span));
147+
let trait_ref = ty::TraitRef::new(tcx, trait_, [self_proj, proj]);
148+
predicates.push((ty::Binder::dummy(trait_ref).upcast(tcx), span));
149+
}
150+
return ty::EarlyBinder::bind(tcx.arena.alloc_from_iter(predicates));
151+
}
152+
127153
let bounds = match tcx.hir_node_by_def_id(def_id) {
128154
hir::Node::TraitItem(hir::TraitItem {
129155
kind: hir::TraitItemKind::Type(bounds, _),

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
5757
#[instrument(level = "trace", skip(tcx), ret)]
5858
fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::GenericPredicates<'_> {
5959
use rustc_hir::*;
60-
use rustc_middle::ty::Ty; // to override hir::Ty
6160

6261
match tcx.opt_rpitit_info(def_id.to_def_id()) {
6362
Some(ImplTraitInTraitData::Trait { fn_def_id, .. }) => {
@@ -114,36 +113,6 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
114113
None => {}
115114
}
116115

117-
if tcx.is_effects_desugared_assoc_ty(def_id.to_def_id()) {
118-
let mut predicates = Vec::new();
119-
120-
// Inherit predicates of parent (impl or trait)
121-
let parent = tcx.local_parent(def_id);
122-
123-
let identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
124-
let preds = tcx.explicit_predicates_of(parent);
125-
126-
if let ty::AssocItemContainer::TraitContainer = tcx.associated_item(def_id).container {
127-
// for traits, emit `type Effects: TyCompat<<(T1::Effects, ..) as Min>::Output>`
128-
// TODO do the same for impls
129-
let tup = Ty::new(tcx, ty::Tuple(preds.effects_min_tys));
130-
// TODO span
131-
let span = tcx.def_span(def_id);
132-
let assoc = tcx.require_lang_item(LangItem::EffectsMinOutput, Some(span));
133-
let proj = Ty::new_projection(tcx, assoc, [tup]);
134-
// TODO this is bad
135-
let self_proj = Ty::new_projection(tcx, def_id.to_def_id(), identity_args);
136-
let trait_ = tcx.require_lang_item(LangItem::EffectsTyCompat, Some(span));
137-
let trait_ref = ty::TraitRef::new(tcx, trait_, [self_proj, proj]);
138-
predicates.push((ty::Binder::dummy(trait_ref).upcast(tcx), span));
139-
}
140-
return ty::GenericPredicates {
141-
parent: Some(parent.to_def_id()),
142-
predicates: tcx.arena.alloc_from_iter(predicates),
143-
effects_min_tys: ty::List::empty(),
144-
};
145-
}
146-
147116
let hir_id = tcx.local_def_id_to_hir_id(def_id);
148117
let node = tcx.hir_node(hir_id);
149118

0 commit comments

Comments
 (0)