Skip to content

Commit

Permalink
Delegation: support generics in associated delegation items
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryanskiy committed Aug 27, 2024
1 parent 8aeaa5f commit 591d865
Show file tree
Hide file tree
Showing 14 changed files with 492 additions and 271 deletions.
16 changes: 6 additions & 10 deletions compiler/rustc_hir_analysis/src/collect/generics_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
let hir_id = tcx.local_def_id_to_hir_id(def_id);

let node = tcx.hir_node(hir_id);
if let Some(sig) = node.fn_sig()
&& let Some(sig_id) = sig.decl.opt_delegation_sig_id()
{
return inherit_generics_for_delegation_item(tcx, def_id, sig_id);
}

let parent_def_id = match node {
Node::ImplItem(_)
| Node::TraitItem(_)
Expand Down Expand Up @@ -228,16 +234,6 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
// inherit the generics of the item.
Some(parent.to_def_id())
}
ItemKind::Fn(sig, _, _) => {
// For a delegation item inherit generics from callee.
if let Some(sig_id) = sig.decl.opt_delegation_sig_id()
&& let Some(generics) =
inherit_generics_for_delegation_item(tcx, def_id, sig_id)
{
return generics;
}
None
}
_ => None,
},
_ => None,
Expand Down
16 changes: 6 additions & 10 deletions compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
let hir_id = tcx.local_def_id_to_hir_id(def_id);
let node = tcx.hir_node(hir_id);

if let Some(sig) = node.fn_sig()
&& let Some(sig_id) = sig.decl.opt_delegation_sig_id()
{
return inherit_predicates_for_delegation_item(tcx, def_id, sig_id);
}

let mut is_trait = None;
let mut is_default_impl_trait = None;

Expand All @@ -146,16 +152,6 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
ItemKind::Trait(_, _, _, self_bounds, ..) | ItemKind::TraitAlias(_, self_bounds) => {
is_trait = Some(self_bounds);
}

ItemKind::Fn(sig, _, _) => {
// For a delegation item inherit predicates from callee.
if let Some(sig_id) = sig.decl.opt_delegation_sig_id()
&& let Some(predicates) =
inherit_predicates_for_delegation_item(tcx, def_id, sig_id)
{
return predicates;
}
}
_ => {}
}
};
Expand Down
Loading

0 comments on commit 591d865

Please sign in to comment.