Skip to content

Commit

Permalink
Delegation: support generics in associated items
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryanskiy committed Jul 18, 2024
1 parent ac0bd3c commit 12fe21b
Show file tree
Hide file tree
Showing 19 changed files with 743 additions and 455 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ hir_analysis_must_implement_not_function_span_note = required by this annotation
hir_analysis_must_implement_one_of_attribute = the `#[rustc_must_implement_one_of]` attribute must be used with at least 2 args
hir_analysis_not_supported_delegation =
{$descr} is not supported yet
{$descr}
.label = callee defined here
hir_analysis_only_current_traits_adt = `{$name}` is not defined in the current crate
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_hir_analysis/src/collect/generics_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
}

// For a delegation item inherit generics from callee.
if let Some(sig_id) = tcx.hir().opt_delegation_sig_id(def_id)
&& let Some(generics) = inherit_generics_for_delegation_item(tcx, def_id, sig_id)
{
return generics;
if let Some(sig_id) = tcx.hir().opt_delegation_sig_id(def_id) {
return inherit_generics_for_delegation_item(tcx, def_id, sig_id);
}

let hir_id = tcx.local_def_id_to_hir_id(def_id);
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::collect::ItemCtxt;
use crate::constrained_generic_params as cgp;
use crate::delegation::inherit_predicates_for_delegation_item;
use crate::hir_ty_lowering::{HirTyLowerer, OnlySelfBounds, PredicateFilter, RegionInferReason};
use crate::hir_ty_lowering::{HirTyLowerer, OnlySelfBounds, PredicateFilter};
use hir::{HirId, Node};
use rustc_data_structures::fx::FxIndexSet;
use rustc_hir as hir;
Expand Down Expand Up @@ -117,10 +116,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
}

// For a delegation item inherit predicates from callee.
if let Some(sig_id) = tcx.hir().opt_delegation_sig_id(def_id)
&& let Some(predicates) = inherit_predicates_for_delegation_item(tcx, def_id, sig_id)
{
return predicates;
if let Some(sig_id) = tcx.hir().opt_delegation_sig_id(def_id) {
return inherit_predicates_for_delegation_item(tcx, def_id, sig_id);
}

let hir_id = tcx.local_def_id_to_hir_id(def_id);
Expand Down
Loading

0 comments on commit 12fe21b

Please sign in to comment.