Remove unnecessary FulfillmentContext from need_migrate_deref_output_trait_object

This commit is contained in:
Michael Goulet 2022-07-26 04:01:17 +00:00
parent 37d412cff7
commit 61d9b1656d

View File

@ -8,7 +8,7 @@
use hir::LangItem; use hir::LangItem;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; 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_infer::traits::{Obligation, SelectionError, TraitObligation};
use rustc_lint_defs::builtin::DEREF_INTO_DYN_SUPERTRAIT; use rustc_lint_defs::builtin::DEREF_INTO_DYN_SUPERTRAIT;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
@ -706,7 +706,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
fn need_migrate_deref_output_trait_object( fn need_migrate_deref_output_trait_object(
&mut self, &mut self,
ty: Ty<'tcx>, ty: Ty<'tcx>,
cause: &traits::ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
) -> Option<(Ty<'tcx>, DefId)> { ) -> Option<(Ty<'tcx>, DefId)> {
let tcx = self.tcx(); let tcx = self.tcx();
@ -721,7 +720,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}; };
let obligation = traits::Obligation::new( let obligation = traits::Obligation::new(
cause.clone(), ObligationCause::dummy(),
param_env, param_env,
ty::Binder::dummy(trait_ref).without_const().to_predicate(tcx), ty::Binder::dummy(trait_ref).without_const().to_predicate(tcx),
); );
@ -729,24 +728,27 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
return None; return None;
} }
let mut fulfillcx = traits::FulfillmentContext::new_in_snapshot(); let ty = traits::normalize_projection_type(
let normalized_ty = fulfillcx.normalize_projection_type( self,
&self.infcx,
param_env, param_env,
ty::ProjectionTy { ty::ProjectionTy {
item_def_id: tcx.lang_items().deref_target()?, item_def_id: tcx.lang_items().deref_target()?,
substs: trait_ref.substs, 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 { if let ty::Dynamic(data, ..) = ty.kind() {
return None; Some((ty, data.principal_def_id()?))
}; } else {
None
let def_id = data.principal_def_id()?; }
return Some((normalized_ty, def_id));
} }
/// Searches for unsizing that might apply to `obligation`. /// Searches for unsizing that might apply to `obligation`.
@ -807,11 +809,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let target_trait_did = principal_def_id_b.unwrap(); let target_trait_did = principal_def_id_b.unwrap();
let source_trait_ref = principal_a.with_self_ty(self.tcx(), source); let source_trait_ref = principal_a.with_self_ty(self.tcx(), source);
if let Some((deref_output_ty, deref_output_trait_did)) = self if let Some((deref_output_ty, deref_output_trait_did)) = self
.need_migrate_deref_output_trait_object( .need_migrate_deref_output_trait_object(source, obligation.param_env)
source,
&obligation.cause,
obligation.param_env,
)
{ {
if deref_output_trait_did == target_trait_did { if deref_output_trait_did == target_trait_did {
self.tcx().struct_span_lint_hir( self.tcx().struct_span_lint_hir(