Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 07b5c6b

Browse files
Rollup merge of #103415 - compiler-errors:tiny-perf-increase-on-diagnostic, r=TaKO8Ki
filter candidates in pick probe for diagnostics Fixes #103411, though also fine with closing this PR if my opinion (#103411 (comment)) is shared that this doesn't need to be fixed. ``` ~/rust3$ time rustc +nightly ~/test.rs 2>/dev/null real 0m4.853s user 0m4.837s sys 0m0.016s ~/rust3$ time rustc +rust3 ~/test.rs 2>/dev/null real 0m0.193s user 0m0.169s sys 0m0.024s ``` Also fixes #103427.
2 parents 6dd64d3 + 4216cae commit 07b5c6b

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

‎compiler/rustc_hir_typeck/src/demand.rs‎

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -530,24 +530,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
530530
checked_ty: Ty<'tcx>,
531531
hir_id: hir::HirId,
532532
) -> Vec<AssocItem> {
533-
let mut methods =
534-
self.probe_for_return_type(span, probe::Mode::MethodCall, expected, checked_ty, hir_id);
535-
methods.retain(|m| {
536-
self.has_only_self_parameter(m)
537-
&& self
538-
.tcx
539-
// This special internal attribute is used to permit
540-
// "identity-like" conversion methods to be suggested here.
541-
//
542-
// FIXME (#46459 and #46460): ideally
543-
// `std::convert::Into::into` and `std::borrow:ToOwned` would
544-
// also be `#[rustc_conversion_suggestion]`, if not for
545-
// method-probing false-positives and -negatives (respectively).
546-
//
547-
// FIXME? Other potential candidate methods: `as_ref` and
548-
// `as_mut`?
549-
.has_attr(m.def_id, sym::rustc_conversion_suggestion)
550-
});
533+
let methods = self.probe_for_return_type(
534+
span,
535+
probe::Mode::MethodCall,
536+
expected,
537+
checked_ty,
538+
hir_id,
539+
|m| {
540+
self.has_only_self_parameter(m)
541+
&& self
542+
.tcx
543+
// This special internal attribute is used to permit
544+
// "identity-like" conversion methods to be suggested here.
545+
//
546+
// FIXME (#46459 and #46460): ideally
547+
// `std::convert::Into::into` and `std::borrow:ToOwned` would
548+
// also be `#[rustc_conversion_suggestion]`, if not for
549+
// method-probing false-positives and -negatives (respectively).
550+
//
551+
// FIXME? Other potential candidate methods: `as_ref` and
552+
// `as_mut`?
553+
.has_attr(m.def_id, sym::rustc_conversion_suggestion)
554+
},
555+
);
551556

552557
methods
553558
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
252252
/// would result in an error (basically, the same criteria we
253253
/// would use to decide if a method is a plausible fit for
254254
/// ambiguity purposes).
255-
#[instrument(level = "debug", skip(self))]
255+
#[instrument(level = "debug", skip(self, candidate_filter))]
256256
pub fn probe_for_return_type(
257257
&self,
258258
span: Span,
259259
mode: Mode,
260260
return_type: Ty<'tcx>,
261261
self_ty: Ty<'tcx>,
262262
scope_expr_id: hir::HirId,
263+
candidate_filter: impl Fn(&ty::AssocItem) -> bool,
263264
) -> Vec<ty::AssocItem> {
264265
let method_names = self
265266
.probe_op(
@@ -271,7 +272,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
271272
self_ty,
272273
scope_expr_id,
273274
ProbeScope::AllTraits,
274-
|probe_cx| Ok(probe_cx.candidate_method_names()),
275+
|probe_cx| Ok(probe_cx.candidate_method_names(candidate_filter)),
275276
)
276277
.unwrap_or_default();
277278
method_names
@@ -966,12 +967,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
966967
}
967968
}
968969

969-
fn candidate_method_names(&self) -> Vec<Ident> {
970+
fn candidate_method_names(
971+
&self,
972+
candidate_filter: impl Fn(&ty::AssocItem) -> bool,
973+
) -> Vec<Ident> {
970974
let mut set = FxHashSet::default();
971975
let mut names: Vec<_> = self
972976
.inherent_candidates
973977
.iter()
974978
.chain(&self.extension_candidates)
979+
.filter(|candidate| candidate_filter(&candidate.item))
975980
.filter(|candidate| {
976981
if let Some(return_ty) = self.return_type {
977982
self.matches_return_type(&candidate.item, None, return_ty)
@@ -1689,7 +1694,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
16891694
pcx.allow_similar_names = true;
16901695
pcx.assemble_inherent_candidates();
16911696

1692-
let method_names = pcx.candidate_method_names();
1697+
let method_names = pcx.candidate_method_names(|_| true);
16931698
pcx.allow_similar_names = false;
16941699
let applicable_close_candidates: Vec<ty::AssocItem> = method_names
16951700
.iter()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /