Skip to content

Commit ab3579d

Browse files
committed
dont assemble shadowed impl candidates
1 parent c55b6af commit ab3579d

File tree

1 file changed

+22
-3
lines changed
  • compiler/rustc_next_trait_solver/src/solve/assembly

1 file changed

+22
-3
lines changed

compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::delegate::SolverDelegate;
2121
use crate::solve::inspect::ProbeKind;
2222
use crate::solve::{
2323
BuiltinImplSource, CandidateSource, CanonicalResponse, Certainty, EvalCtxt, Goal, GoalSource,
24-
MaybeCause, NoSolution, ParamEnvSource, QueryResult,
24+
MaybeCause, NoSolution, ParamEnvSource, QueryResult, has_no_inference_or_external_constraints,
2525
};
2626

2727
enum AliasBoundKind {
@@ -394,9 +394,28 @@ where
394394

395395
match assemble_from {
396396
AssembleCandidatesFrom::All => {
397-
self.assemble_impl_candidates(goal, &mut candidates);
398397
self.assemble_builtin_impl_candidates(goal, &mut candidates);
399-
self.assemble_object_bound_candidates(goal, &mut candidates);
398+
// For performance we only assemble impls if there are no candidates
399+
// which would shadow them. This is necessary to avoid hangs in rayon.
400+
//
401+
// We always assemble builtin impls as trivial builtin impls have a higher
402+
// priority than where-clauses.
403+
//
404+
// We only do this if any such candidate applies without any constraints
405+
// as we may want to weaken inference guidance in the future and don't want
406+
// to worry about causing major performance regressions when doing so.
407+
if TypingMode::Coherence == self.typing_mode()
408+
|| !candidates.iter().any(|c| {
409+
matches!(
410+
c.source,
411+
CandidateSource::ParamEnv(ParamEnvSource::NonGlobal)
412+
| CandidateSource::AliasBound
413+
) && has_no_inference_or_external_constraints(c.result)
414+
})
415+
{
416+
self.assemble_impl_candidates(goal, &mut candidates);
417+
self.assemble_object_bound_candidates(goal, &mut candidates);
418+
}
400419
}
401420
AssembleCandidatesFrom::EnvAndBounds => {}
402421
}

0 commit comments

Comments
 (0)