From 1c30b50c5975c72d8747f2e55b1693808ba5779e Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 18 Dec 2023 23:36:47 +0000 Subject: [PATCH] Use new solver in MIR validator subtyping checks --- .../rustc_const_eval/src/interpret/eval_context.rs | 9 ++++++++- compiler/rustc_const_eval/src/transform/validate.rs | 3 ++- compiler/rustc_const_eval/src/util/compare_types.rs | 13 +++++++++---- compiler/rustc_mir_transform/src/inline.rs | 3 +++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index af8e5e7d15139..affa554051ab7 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -387,7 +387,14 @@ pub(super) fn mir_assign_valid_types<'tcx>( // all normal lifetimes are erased, higher-ranked types with their // late-bound lifetimes are still around and can lead to type // differences. - if util::relate_types(tcx, param_env, Variance::Covariant, src.ty, dest.ty) { + if util::relate_types( + tcx, + param_env, + Variance::Covariant, + src.ty, + dest.ty, + tcx.next_trait_solver_globally(), + ) { // Make sure the layout is equal, too -- just to be safe. Miri really // needs layout equality. For performance reason we skip this check when // the types are equal. Equal types *can* have different layouts when diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index cca5b90abb920..8200ed30b3511 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -634,7 +634,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { Variance::Covariant }; - crate::util::relate_types(self.tcx, self.param_env, variance, src, dest) + crate::util::relate_types(self.tcx, self.param_env, variance, src, dest, true) } } @@ -792,6 +792,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { Variance::Covariant, ty, place_ref.ty(&self.body.local_decls, self.tcx).ty, + true, ) { self.fail( location, diff --git a/compiler/rustc_const_eval/src/util/compare_types.rs b/compiler/rustc_const_eval/src/util/compare_types.rs index 265ca0c7884ce..a8de2654a6369 100644 --- a/compiler/rustc_const_eval/src/util/compare_types.rs +++ b/compiler/rustc_const_eval/src/util/compare_types.rs @@ -17,6 +17,7 @@ pub fn is_equal_up_to_subtyping<'tcx>( param_env: ParamEnv<'tcx>, src: Ty<'tcx>, dest: Ty<'tcx>, + next_trait_solver: bool, ) -> bool { // Fast path. if src == dest { @@ -24,8 +25,8 @@ pub fn is_equal_up_to_subtyping<'tcx>( } // Check for subtyping in either direction. - relate_types(tcx, param_env, Variance::Covariant, src, dest) - || relate_types(tcx, param_env, Variance::Covariant, dest, src) + relate_types(tcx, param_env, Variance::Covariant, src, dest, next_trait_solver) + || relate_types(tcx, param_env, Variance::Covariant, dest, src, next_trait_solver) } /// Returns whether `src` is a subtype of `dest`, i.e. `src <: dest`. @@ -42,13 +43,17 @@ pub fn relate_types<'tcx>( variance: Variance, src: Ty<'tcx>, dest: Ty<'tcx>, + next_trait_solver: bool, ) -> bool { if src == dest { return true; } - let mut builder = - tcx.infer_ctxt().ignoring_regions().with_opaque_type_inference(DefiningAnchor::Bubble); + let mut builder = tcx + .infer_ctxt() + .ignoring_regions() + .with_next_trait_solver(next_trait_solver) + .with_opaque_type_inference(DefiningAnchor::Bubble); let infcx = builder.build(); let ocx = ObligationCtxt::new(&infcx); let cause = ObligationCause::dummy(); diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 8ad804bf3e7aa..20bbb32711fd7 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -220,6 +220,7 @@ impl<'tcx> Inliner<'tcx> { ty::Variance::Covariant, output_type, destination_ty, + true, ) { trace!(?output_type, ?destination_ty); return Err("failed to normalize return type"); @@ -256,6 +257,7 @@ impl<'tcx> Inliner<'tcx> { ty::Variance::Covariant, input_type, arg_ty, + true, ) { trace!(?arg_ty, ?input_type); return Err("failed to normalize tuple argument type"); @@ -271,6 +273,7 @@ impl<'tcx> Inliner<'tcx> { ty::Variance::Covariant, input_type, arg_ty, + true, ) { trace!(?arg_ty, ?input_type); return Err("failed to normalize argument type");