Skip to content

Commit 79bb8b1

Browse files
committed
Auto merge of rust-lang#126161 - Bryanskiy:delegation-generics-4, r=<try>
Delegation: support generics in associated delegation items This is a continuation of rust-lang#125929. [design](https://github.com/Bryanskiy/posts/blob/master/delegation%20in%20generic%20contexts.md) Generic parameters inheritance was implemented in all contexts. Generic arguments are not yet supported. r? `@petrochenkov`
2 parents 842d6fc + 9f07683 commit 79bb8b1

16 files changed

+778
-444
lines changed

compiler/rustc_hir_analysis/src/collect/generics_of.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
5959
let hir_id = tcx.local_def_id_to_hir_id(def_id);
6060

6161
let node = tcx.hir_node(hir_id);
62+
if let Some(sig) = node.fn_sig()
63+
&& let Some(sig_id) = sig.decl.opt_delegation_sig_id()
64+
{
65+
return inherit_generics_for_delegation_item(tcx, def_id, sig_id);
66+
}
67+
6268
let parent_def_id = match node {
6369
Node::ImplItem(_)
6470
| Node::TraitItem(_)
@@ -229,16 +235,6 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
229235
// inherit the generics of the item.
230236
Some(parent.to_def_id())
231237
}
232-
ItemKind::Fn(sig, _, _) => {
233-
// For a delegation item inherit generics from callee.
234-
if let Some(sig_id) = sig.decl.opt_delegation_sig_id()
235-
&& let Some(generics) =
236-
inherit_generics_for_delegation_item(tcx, def_id, sig_id)
237-
{
238-
return generics;
239-
}
240-
None
241-
}
242238
_ => None,
243239
},
244240
_ => None,

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
138138
let hir_id = tcx.local_def_id_to_hir_id(def_id);
139139
let node = tcx.hir_node(hir_id);
140140

141+
if let Some(sig) = node.fn_sig()
142+
&& let Some(sig_id) = sig.decl.opt_delegation_sig_id()
143+
{
144+
return inherit_predicates_for_delegation_item(tcx, def_id, sig_id);
145+
}
146+
141147
let mut is_trait = None;
142148
let mut is_default_impl_trait = None;
143149

@@ -164,16 +170,6 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
164170
ItemKind::Trait(_, _, _, self_bounds, ..) | ItemKind::TraitAlias(_, self_bounds) => {
165171
is_trait = Some(self_bounds);
166172
}
167-
168-
ItemKind::Fn(sig, _, _) => {
169-
// For a delegation item inherit predicates from callee.
170-
if let Some(sig_id) = sig.decl.opt_delegation_sig_id()
171-
&& let Some(predicates) =
172-
inherit_predicates_for_delegation_item(tcx, def_id, sig_id)
173-
{
174-
return predicates;
175-
}
176-
}
177173
_ => {}
178174
}
179175
};

0 commit comments

Comments
 (0)