Don't select infer -> dyn Trait
This commit is contained in:
parent
abd3637e42
commit
d21a335e8f
@ -235,7 +235,10 @@ fn rematch_unsize<'tcx>(
|
|||||||
goal.param_env,
|
goal.param_env,
|
||||||
&mut nested,
|
&mut nested,
|
||||||
);
|
);
|
||||||
|
|
||||||
match (a_ty.kind(), b_ty.kind()) {
|
match (a_ty.kind(), b_ty.kind()) {
|
||||||
|
// Don't try to coerce `?0` to `dyn Trait`
|
||||||
|
(ty::Infer(ty::TyVar(_)), _) | (_, ty::Infer(ty::TyVar(_))) => Ok(None),
|
||||||
// Stall any ambiguous upcasting goals, since we can't rematch those
|
// Stall any ambiguous upcasting goals, since we can't rematch those
|
||||||
(ty::Dynamic(_, _, ty::Dyn), ty::Dynamic(_, _, ty::Dyn)) => match certainty {
|
(ty::Dynamic(_, _, ty::Dyn), ty::Dynamic(_, _, ty::Dyn)) => match certainty {
|
||||||
Certainty::Yes => Ok(Some(ImplSource::Builtin(source, nested))),
|
Certainty::Yes => Ok(Some(ImplSource::Builtin(source, nested))),
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
// run-pass
|
// check-pass
|
||||||
|
// revisions: current next
|
||||||
|
//[next] compile-flags: -Ztrait-solver=next
|
||||||
|
|
||||||
#![allow(non_upper_case_globals)]
|
#![allow(non_upper_case_globals)]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
17
tests/ui/traits/new-solver/dont-coerce-infer-to-dyn.rs
Normal file
17
tests/ui/traits/new-solver/dont-coerce-infer-to-dyn.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// compile-flags: -Ztrait-solver=next
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
use std::fmt::Display;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
fn mk<T: ?Sized>(t: Option<&T>) -> Rc<T> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut x = None;
|
||||||
|
let y = mk(x);
|
||||||
|
// Don't treat the line below as a unsize coercion `Rc<?0> ~> Rc<dyn Display>`
|
||||||
|
let z: Rc<dyn Display> = y;
|
||||||
|
x = Some(&1 as &dyn Display);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user