Skip to content

Commit c6922aa

Browse files
Prefer lower vtable candidates in select in new solver
1 parent d7ea278 commit c6922aa

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ impl<'tcx> inspect::ProofTreeVisitor<'tcx> for Select {
5858
)));
5959
}
6060

61+
// Don't winnow until `Certainty::Yes` -- we don't need to winnow until
62+
// codegen, technically, and all goals should hold in codegen.
63+
if matches!(goal.result().unwrap(), Certainty::Maybe(..)) {
64+
return ControlFlow::Break(Ok(None));
65+
}
66+
6167
// We need to winnow. See comments on `candidate_should_be_dropped_in_favor_of`.
6268
let mut i = 0;
6369
while i < candidates.len() {
@@ -85,12 +91,6 @@ fn candidate_should_be_dropped_in_favor_of<'tcx>(
8591
victim: &inspect::InspectCandidate<'_, 'tcx>,
8692
other: &inspect::InspectCandidate<'_, 'tcx>,
8793
) -> bool {
88-
// Don't winnow until `Certainty::Yes` -- we don't need to winnow until
89-
// codegen, technically.
90-
if matches!(other.result().unwrap(), Certainty::Maybe(..)) {
91-
return false;
92-
}
93-
9494
let inspect::ProbeKind::TraitCandidate { source: victim_source, result: _ } = victim.kind()
9595
else {
9696
return false;
@@ -105,12 +105,14 @@ fn candidate_should_be_dropped_in_favor_of<'tcx>(
105105
bug!("should not have assembled a CoherenceUnknowable candidate")
106106
}
107107

108+
// In the old trait solver, we arbitrarily choose lower vtable candidates
109+
// over higher ones.
110+
(
111+
CandidateSource::BuiltinImpl(BuiltinImplSource::Object { vtable_base: a }),
112+
CandidateSource::BuiltinImpl(BuiltinImplSource::Object { vtable_base: b }),
113+
) => a >= b,
108114
// Prefer dyn candidates over non-dyn candidates. This is necessary to
109115
// handle the unsoundness between `impl<T: ?Sized> Any for T` and `dyn Any: Any`.
110-
(
111-
CandidateSource::BuiltinImpl(BuiltinImplSource::Object { .. }),
112-
CandidateSource::BuiltinImpl(BuiltinImplSource::Object { .. }),
113-
) => false,
114116
(
115117
CandidateSource::Impl(_) | CandidateSource::ParamEnv(_) | CandidateSource::AliasBound,
116118
CandidateSource::BuiltinImpl(BuiltinImplSource::Object { .. }),

tests/ui/traits/normalize-supertrait.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
// comparing the supertrait `Derived<()>` to the expected trait.
55

66
//@ build-pass
7+
//@ revisions: current next
8+
//@ ignore-compare-mode-next-solver (explicit revisions)
9+
//@[next] compile-flags: -Znext-solver
710

811
trait Proj {
912
type S;

0 commit comments

Comments
 (0)