Skip to content

Commit 7054287

Browse files
committedNov 28, 2022
Move helper closure to method.
1 parent 2582e36 commit 7054287

File tree

1 file changed

+12
-8
lines changed
  • compiler/rustc_hir_typeck/src/method

1 file changed

+12
-8
lines changed
 

‎compiler/rustc_hir_typeck/src/method/probe.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -1875,24 +1875,28 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18751875
self.tcx.erase_late_bound_regions(value)
18761876
}
18771877

1878+
/// Determine if the given associated item type is relevant in the current context.
1879+
fn is_relevant_kind_for_mode(&self, kind: ty::AssocKind) -> bool {
1880+
match (self.mode, kind) {
1881+
(Mode::MethodCall, ty::AssocKind::Fn) => true,
1882+
(Mode::Path, ty::AssocKind::Const | ty::AssocKind::Fn) => true,
1883+
_ => false,
1884+
}
1885+
}
1886+
18781887
/// Finds the method with the appropriate name (or return type, as the case may be). If
18791888
/// `allow_similar_names` is set, find methods with close-matching names.
18801889
// The length of the returned iterator is nearly always 0 or 1 and this
18811890
// method is fairly hot.
18821891
fn impl_or_trait_item(&self, def_id: DefId) -> SmallVec<[ty::AssocItem; 1]> {
1883-
let relevant_kind_for_mode = |kind| match (self.mode, kind) {
1884-
(Mode::MethodCall, ty::AssocKind::Fn) => true,
1885-
(Mode::Path, ty::AssocKind::Const | ty::AssocKind::Fn) => true,
1886-
_ => false,
1887-
};
18881892
if let Some(name) = self.method_name {
18891893
if self.allow_similar_names {
18901894
let max_dist = max(name.as_str().len(), 3) / 3;
18911895
self.tcx
18921896
.associated_items(def_id)
18931897
.in_definition_order()
18941898
.filter(|x| {
1895-
if !relevant_kind_for_mode(x.kind) {
1899+
if !self.is_relevant_kind_for_mode(x.kind) {
18961900
return false;
18971901
}
18981902
match lev_distance_with_substrings(name.as_str(), x.name.as_str(), max_dist)
@@ -1906,14 +1910,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
19061910
} else {
19071911
self.fcx
19081912
.associated_value(def_id, name)
1909-
.filter(|x| relevant_kind_for_mode(x.kind))
1913+
.filter(|x| self.is_relevant_kind_for_mode(x.kind))
19101914
.map_or_else(SmallVec::new, |x| SmallVec::from_buf([x]))
19111915
}
19121916
} else {
19131917
self.tcx
19141918
.associated_items(def_id)
19151919
.in_definition_order()
1916-
.filter(|x| relevant_kind_for_mode(x.kind))
1920+
.filter(|x| self.is_relevant_kind_for_mode(x.kind))
19171921
.copied()
19181922
.collect()
19191923
}

0 commit comments

Comments
 (0)
Please sign in to comment.