Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c0007a2

Browse files
committed
Extract function trait_may_define_assoc_type
1 parent b60a214 commit c0007a2

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use rustc_session::config::{BorrowckMode, CrateType, OutputFilenames};
5151
use rustc_session::lint::{Level, Lint};
5252
use rustc_session::Session;
5353
use rustc_span::source_map::MultiSpan;
54-
use rustc_span::symbol::{kw, sym, Symbol};
54+
use rustc_span::symbol::{kw, sym, Ident, Symbol};
5555
use rustc_span::{Span, DUMMY_SP};
5656
use rustc_target::abi::{Layout, TargetDataLayout, VariantIdx};
5757
use rustc_target::spec::abi;
@@ -2085,6 +2085,16 @@ impl<'tcx> TyCtxt<'tcx> {
20852085
self.mk_fn_ptr(sig.map_bound(|sig| ty::FnSig { unsafety: hir::Unsafety::Unsafe, ..sig }))
20862086
}
20872087

2088+
/// Given the def_id of a Trait `trait_def_id` and the name of an associated item `assoc_name`
2089+
/// returns true if the `trait_def_id` defines an associated item of name `assoc_name`.
2090+
pub fn trait_may_define_assoc_type(self, trait_def_id: DefId, assoc_name: Ident) -> bool {
2091+
self.super_traits_of(trait_def_id).iter().any(|trait_did| {
2092+
self.associated_items(*trait_did)
2093+
.find_by_name_and_kind(self, assoc_name, ty::AssocKind::Type, *trait_did)
2094+
.is_some()
2095+
})
2096+
}
2097+
20882098
/// Given a closure signature, returns an equivalent fn signature. Detuples
20892099
/// and so forth -- so e.g., if we have a sig with `Fn<(u32, i32)>` then
20902100
/// you would get a `fn(u32, i32)`.

compiler/rustc_typeck/src/astconv/mod.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
909909
for ast_bound in ast_bounds {
910910
if let Some(trait_ref) = ast_bound.trait_ref() {
911911
if let Some(trait_did) = trait_ref.trait_def_id() {
912-
if self.trait_may_define_assoc_type(trait_did, assoc_name) {
912+
if self.tcx().trait_may_define_assoc_type(trait_did, assoc_name) {
913913
result.push(ast_bound);
914914
}
915915
}
@@ -919,17 +919,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
919919
self.compute_bounds(param_ty, &result, sized_by_default, span)
920920
}
921921

922-
/// Given the def_id of a Trait `trait_def_id` and the name of an associated item `assoc_name`
923-
/// returns true if the `trait_def_id` defines an associated item of name `assoc_name`.
924-
fn trait_may_define_assoc_type(&self, trait_def_id: DefId, assoc_name: Ident) -> bool {
925-
self.tcx().super_traits_of(trait_def_id).iter().any(|trait_did| {
926-
self.tcx()
927-
.associated_items(*trait_did)
928-
.find_by_name_and_kind(self.tcx(), assoc_name, ty::AssocKind::Type, *trait_did)
929-
.is_some()
930-
})
931-
}
932-
933922
/// Given an HIR binding like `Item = Foo` or `Item: Foo`, pushes the corresponding predicates
934923
/// onto `bounds`.
935924
///

compiler/rustc_typeck/src/collect.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -654,17 +654,7 @@ impl ItemCtxt<'tcx> {
654654
hir::GenericBound::Trait(poly_trait_ref, _) => {
655655
let trait_ref = &poly_trait_ref.trait_ref;
656656
if let Some(trait_did) = trait_ref.trait_def_id() {
657-
self.tcx.super_traits_of(trait_did).iter().any(|trait_did| {
658-
self.tcx
659-
.associated_items(*trait_did)
660-
.find_by_name_and_kind(
661-
self.tcx,
662-
assoc_name,
663-
ty::AssocKind::Type,
664-
*trait_did,
665-
)
666-
.is_some()
667-
})
657+
self.tcx.trait_may_define_assoc_type(trait_did, assoc_name)
668658
} else {
669659
false
670660
}

0 commit comments

Comments
 (0)