mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Prefer object candidates over impl candidates in new selection
This commit is contained in:
parent
bd8aabef31
commit
3acaa568c2
@ -173,10 +173,18 @@ fn candidate_should_be_dropped_in_favor_of<'tcx>(
|
|||||||
victim_idx >= other_idx
|
victim_idx >= other_idx
|
||||||
}
|
}
|
||||||
(_, CandidateSource::ParamEnv(_)) => true,
|
(_, CandidateSource::ParamEnv(_)) => true,
|
||||||
|
|
||||||
|
(
|
||||||
|
CandidateSource::BuiltinImpl(BuiltinImplSource::Object),
|
||||||
|
CandidateSource::BuiltinImpl(BuiltinImplSource::Object),
|
||||||
|
) => false,
|
||||||
|
(_, CandidateSource::BuiltinImpl(BuiltinImplSource::Object)) => true,
|
||||||
|
|
||||||
(CandidateSource::Impl(victim_def_id), CandidateSource::Impl(other_def_id)) => {
|
(CandidateSource::Impl(victim_def_id), CandidateSource::Impl(other_def_id)) => {
|
||||||
tcx.specializes((other_def_id, victim_def_id))
|
tcx.specializes((other_def_id, victim_def_id))
|
||||||
&& other.result.value.certainty == Certainty::Yes
|
&& other.result.value.certainty == Certainty::Yes
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
tests/ui/traits/new-solver/dyn-any-dont-prefer-impl.rs
Normal file
13
tests/ui/traits/new-solver/dyn-any-dont-prefer-impl.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// compile-flags: -Ztrait-solver=next
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
use std::any::Any;
|
||||||
|
|
||||||
|
fn needs_usize(_: &usize) {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x: &dyn Any = &1usize;
|
||||||
|
if let Some(x) = x.downcast_ref::<usize>() {
|
||||||
|
needs_usize(x);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user