Skip to content

Commit

Permalink
cool beans
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Oct 29, 2024
1 parent 2065cb7 commit dc50c64
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.flat_map(Result::transpose)
.collect::<Result<Vec<_>, _>>()?;

debug!(?stack, ?candidates, "winnowed to {} candidates", candidates.len());
debug!(?stack, ?candidates, "{} potentially applicable candidates", candidates.len());
// If there are *NO* candidates, then there are no impls --
// that we know of, anyway. Note that in the case where there
// are unbound type variables within the obligation, it might
Expand Down Expand Up @@ -1896,7 +1896,33 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
}
}
if let Some((def_id, _evaluation)) = impl_candidate {
return Some(ImplCandidate(def_id));
// Don't use impl candidates which overlap with other candidates.
// This should pretty much only ever happen with malformed impls.
if candidates.iter().all(|c| match c.candidate {
BuiltinCandidate { has_nested: _ }
| TransmutabilityCandidate
| AutoImplCandidate
| ClosureCandidate { .. }
| AsyncClosureCandidate
| AsyncFnKindHelperCandidate
| CoroutineCandidate
| FutureCandidate
| IteratorCandidate
| AsyncIteratorCandidate
| FnPointerCandidate
| TraitAliasCandidate
| TraitUpcastingUnsizeCandidate(_)
| BuiltinObjectCandidate
| BuiltinUnsizeCandidate => false,
// Non-global param candidates have already been handled, global
// where-bounds get ignored.
ParamCandidate(_) | ImplCandidate(_) => true,
ProjectionCandidate(_) | ObjectCandidate(_) => unreachable!(),
}) {
return Some(ImplCandidate(def_id));
} else {
return None;
}
}

// Also try ignoring all global where-bounds and check whether we end
Expand Down

0 comments on commit dc50c64

Please sign in to comment.