From 61d9b1656dba91122d308637d9611e0bd7ea68b4 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 26 Jul 2022 04:01:17 +0000 Subject: [PATCH] Remove unnecessary FulfillmentContext from need_migrate_deref_output_trait_object --- .../src/traits/select/candidate_assembly.rs | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index a60ce0f3437e..b296dadec9d9 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -8,7 +8,7 @@ use hir::LangItem; use rustc_hir as hir; use rustc_hir::def_id::DefId; -use rustc_infer::traits::TraitEngine; +use rustc_infer::traits::ObligationCause; use rustc_infer::traits::{Obligation, SelectionError, TraitObligation}; use rustc_lint_defs::builtin::DEREF_INTO_DYN_SUPERTRAIT; use rustc_middle::ty::print::with_no_trimmed_paths; @@ -706,7 +706,6 @@ fn assemble_candidates_from_object_ty( fn need_migrate_deref_output_trait_object( &mut self, ty: Ty<'tcx>, - cause: &traits::ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, ) -> Option<(Ty<'tcx>, DefId)> { let tcx = self.tcx(); @@ -721,7 +720,7 @@ fn need_migrate_deref_output_trait_object( }; let obligation = traits::Obligation::new( - cause.clone(), + ObligationCause::dummy(), param_env, ty::Binder::dummy(trait_ref).without_const().to_predicate(tcx), ); @@ -729,24 +728,27 @@ fn need_migrate_deref_output_trait_object( return None; } - let mut fulfillcx = traits::FulfillmentContext::new_in_snapshot(); - let normalized_ty = fulfillcx.normalize_projection_type( - &self.infcx, + let ty = traits::normalize_projection_type( + self, param_env, ty::ProjectionTy { item_def_id: tcx.lang_items().deref_target()?, substs: trait_ref.substs, }, - cause.clone(), - ); + ObligationCause::dummy(), + 0, + // We're *intentionally* throwing these away, + // since we don't actually use them. + &mut vec![], + ) + .ty() + .unwrap(); - let ty::Dynamic(data, ..) = normalized_ty.kind() else { - return None; - }; - - let def_id = data.principal_def_id()?; - - return Some((normalized_ty, def_id)); + if let ty::Dynamic(data, ..) = ty.kind() { + Some((ty, data.principal_def_id()?)) + } else { + None + } } /// Searches for unsizing that might apply to `obligation`. @@ -807,11 +809,7 @@ fn assemble_candidates_for_unsizing( let target_trait_did = principal_def_id_b.unwrap(); let source_trait_ref = principal_a.with_self_ty(self.tcx(), source); if let Some((deref_output_ty, deref_output_trait_did)) = self - .need_migrate_deref_output_trait_object( - source, - &obligation.cause, - obligation.param_env, - ) + .need_migrate_deref_output_trait_object(source, obligation.param_env) { if deref_output_trait_did == target_trait_did { self.tcx().struct_span_lint_hir(