Don't select infer -> dyn Trait

This commit is contained in:
Michael Goulet 2023-07-31 15:53:31 +00:00
parent abd3637e42
commit d21a335e8f
3 changed files with 23 additions and 1 deletions

View File

@ -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))),

View File

@ -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)]

View 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);
}