Skip to content

Commit a5f89d8

Browse files
Use new solver in MIR validator subtyping checks
1 parent c57393e commit a5f89d8

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ pub(super) fn mir_assign_valid_types<'tcx>(
357357
// all normal lifetimes are erased, higher-ranked types with their
358358
// late-bound lifetimes are still around and can lead to type
359359
// differences.
360-
if util::is_subtype(tcx, param_env, src.ty, dest.ty) {
360+
if util::is_subtype(tcx, param_env, src.ty, dest.ty, tcx.next_trait_solver_globally()) {
361361
// Make sure the layout is equal, too -- just to be safe. Miri really
362362
// needs layout equality. For performance reason we skip this check when
363363
// the types are equal. Equal types *can* have different layouts when

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
540540
return true;
541541
}
542542

543-
crate::util::is_subtype(self.tcx, self.param_env, src, dest)
543+
crate::util::is_subtype(self.tcx, self.param_env, src, dest, true)
544544
}
545545
}
546546

compiler/rustc_const_eval/src/util/compare_types.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ pub fn is_equal_up_to_subtyping<'tcx>(
1717
param_env: ParamEnv<'tcx>,
1818
src: Ty<'tcx>,
1919
dest: Ty<'tcx>,
20+
next_trait_solver: bool,
2021
) -> bool {
2122
// Fast path.
2223
if src == dest {
2324
return true;
2425
}
2526

2627
// Check for subtyping in either direction.
27-
is_subtype(tcx, param_env, src, dest) || is_subtype(tcx, param_env, dest, src)
28+
is_subtype(tcx, param_env, src, dest, next_trait_solver)
29+
|| is_subtype(tcx, param_env, dest, src, next_trait_solver)
2830
}
2931

3032
/// Returns whether `src` is a subtype of `dest`, i.e. `src <: dest`.
@@ -36,13 +38,17 @@ pub fn is_subtype<'tcx>(
3638
param_env: ParamEnv<'tcx>,
3739
src: Ty<'tcx>,
3840
dest: Ty<'tcx>,
41+
next_trait_solver: bool,
3942
) -> bool {
4043
if src == dest {
4144
return true;
4245
}
4346

44-
let mut builder =
45-
tcx.infer_ctxt().ignoring_regions().with_opaque_type_inference(DefiningAnchor::Bubble);
47+
let mut builder = tcx
48+
.infer_ctxt()
49+
.ignoring_regions()
50+
.with_next_trait_solver(next_trait_solver)
51+
.with_opaque_type_inference(DefiningAnchor::Bubble);
4652
let infcx = builder.build();
4753
let ocx = ObligationCtxt::new(&infcx);
4854
let cause = ObligationCause::dummy();

compiler/rustc_mir_transform/src/inline.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl<'tcx> Inliner<'tcx> {
218218
// Normally, this shouldn't be required, but trait normalization failure can create a
219219
// validation ICE.
220220
let output_type = callee_body.return_ty();
221-
if !util::is_subtype(self.tcx, self.param_env, output_type, destination_ty) {
221+
if !util::is_subtype(self.tcx, self.param_env, output_type, destination_ty, true) {
222222
trace!(?output_type, ?destination_ty);
223223
return Err("failed to normalize return type");
224224
}
@@ -248,7 +248,7 @@ impl<'tcx> Inliner<'tcx> {
248248
self_arg_ty.into_iter().chain(arg_tuple_tys).zip(callee_body.args_iter())
249249
{
250250
let input_type = callee_body.local_decls[input].ty;
251-
if !util::is_subtype(self.tcx, self.param_env, input_type, arg_ty) {
251+
if !util::is_subtype(self.tcx, self.param_env, input_type, arg_ty, true) {
252252
trace!(?arg_ty, ?input_type);
253253
return Err("failed to normalize tuple argument type");
254254
}
@@ -257,7 +257,7 @@ impl<'tcx> Inliner<'tcx> {
257257
for (arg, input) in args.iter().zip(callee_body.args_iter()) {
258258
let input_type = callee_body.local_decls[input].ty;
259259
let arg_ty = arg.ty(&caller_body.local_decls, self.tcx);
260-
if !util::is_subtype(self.tcx, self.param_env, input_type, arg_ty) {
260+
if !util::is_subtype(self.tcx, self.param_env, input_type, arg_ty, true) {
261261
trace!(?arg_ty, ?input_type);
262262
return Err("failed to normalize argument type");
263263
}

compiler/rustc_trait_selection/src/traits/engine.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ impl<'tcx> TraitEngineExt<'tcx> for dyn TraitEngine<'tcx> {
3636
(TraitSolver::Classic, false) | (TraitSolver::NextCoherence, false) => {
3737
Box::new(FulfillmentContext::new(infcx))
3838
}
39-
(TraitSolver::Next | TraitSolver::NextCoherence, true) => {
40-
Box::new(NextFulfillmentCtxt::new(infcx))
41-
}
39+
(_, true) => Box::new(NextFulfillmentCtxt::new(infcx)),
4240
_ => bug!(
4341
"incompatible combination of -Ztrait-solver flag ({:?}) and InferCtxt::next_trait_solver ({:?})",
4442
infcx.tcx.sess.opts.unstable_opts.trait_solver,

0 commit comments

Comments
 (0)