Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't unsize coerce infer vars in select in new solver #114199

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/inference/type-infer-generalize-ty-var.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/traits/new-solver/dont-coerce-infer-to-dyn.rs
Original file line number Diff line number Diff line change
@@ -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