mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Rollup merge of #114199 - compiler-errors:dont-select-unsize-infer, r=lcnr
Don't unsize coerce infer vars in select in new solver Otherwise we're too eagerly preferring the `T -> dyn Trait` branch during coercion. r? `@lcnr`
This commit is contained in:
commit
bb3dee1a8a
@ -235,7 +235,10 @@ fn rematch_unsize<'tcx>(
|
||||
goal.param_env,
|
||||
&mut nested,
|
||||
);
|
||||
|
||||
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
|
||||
(ty::Dynamic(_, _, ty::Dyn), ty::Dynamic(_, _, ty::Dyn)) => match certainty {
|
||||
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(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