Skip to content

Commit 3acaa56

Browse files
Prefer object candidates over impl candidates in new selection
1 parent bd8aabe commit 3acaa56

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,18 @@ fn candidate_should_be_dropped_in_favor_of<'tcx>(
173173
victim_idx >= other_idx
174174
}
175175
(_, CandidateSource::ParamEnv(_)) => true,
176+
177+
(
178+
CandidateSource::BuiltinImpl(BuiltinImplSource::Object),
179+
CandidateSource::BuiltinImpl(BuiltinImplSource::Object),
180+
) => false,
181+
(_, CandidateSource::BuiltinImpl(BuiltinImplSource::Object)) => true,
182+
176183
(CandidateSource::Impl(victim_def_id), CandidateSource::Impl(other_def_id)) => {
177184
tcx.specializes((other_def_id, victim_def_id))
178185
&& other.result.value.certainty == Certainty::Yes
179186
}
187+
180188
_ => false,
181189
}
182190
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// check-pass
3+
4+
use std::any::Any;
5+
6+
fn needs_usize(_: &usize) {}
7+
8+
fn main() {
9+
let x: &dyn Any = &1usize;
10+
if let Some(x) = x.downcast_ref::<usize>() {
11+
needs_usize(x);
12+
}
13+
}

0 commit comments

Comments
 (0)