Skip to content

Commit 61d9b16

Browse files
Remove unnecessary FulfillmentContext from need_migrate_deref_output_trait_object
1 parent 37d412c commit 61d9b16

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+19-21
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use hir::LangItem;
99
use rustc_hir as hir;
1010
use rustc_hir::def_id::DefId;
11-
use rustc_infer::traits::TraitEngine;
11+
use rustc_infer::traits::ObligationCause;
1212
use rustc_infer::traits::{Obligation, SelectionError, TraitObligation};
1313
use rustc_lint_defs::builtin::DEREF_INTO_DYN_SUPERTRAIT;
1414
use rustc_middle::ty::print::with_no_trimmed_paths;
@@ -706,7 +706,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
706706
fn need_migrate_deref_output_trait_object(
707707
&mut self,
708708
ty: Ty<'tcx>,
709-
cause: &traits::ObligationCause<'tcx>,
710709
param_env: ty::ParamEnv<'tcx>,
711710
) -> Option<(Ty<'tcx>, DefId)> {
712711
let tcx = self.tcx();
@@ -721,32 +720,35 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
721720
};
722721

723722
let obligation = traits::Obligation::new(
724-
cause.clone(),
723+
ObligationCause::dummy(),
725724
param_env,
726725
ty::Binder::dummy(trait_ref).without_const().to_predicate(tcx),
727726
);
728727
if !self.infcx.predicate_may_hold(&obligation) {
729728
return None;
730729
}
731730

732-
let mut fulfillcx = traits::FulfillmentContext::new_in_snapshot();
733-
let normalized_ty = fulfillcx.normalize_projection_type(
734-
&self.infcx,
731+
let ty = traits::normalize_projection_type(
732+
self,
735733
param_env,
736734
ty::ProjectionTy {
737735
item_def_id: tcx.lang_items().deref_target()?,
738736
substs: trait_ref.substs,
739737
},
740-
cause.clone(),
741-
);
742-
743-
let ty::Dynamic(data, ..) = normalized_ty.kind() else {
744-
return None;
745-
};
746-
747-
let def_id = data.principal_def_id()?;
748-
749-
return Some((normalized_ty, def_id));
738+
ObligationCause::dummy(),
739+
0,
740+
// We're *intentionally* throwing these away,
741+
// since we don't actually use them.
742+
&mut vec![],
743+
)
744+
.ty()
745+
.unwrap();
746+
747+
if let ty::Dynamic(data, ..) = ty.kind() {
748+
Some((ty, data.principal_def_id()?))
749+
} else {
750+
None
751+
}
750752
}
751753

752754
/// Searches for unsizing that might apply to `obligation`.
@@ -807,11 +809,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
807809
let target_trait_did = principal_def_id_b.unwrap();
808810
let source_trait_ref = principal_a.with_self_ty(self.tcx(), source);
809811
if let Some((deref_output_ty, deref_output_trait_did)) = self
810-
.need_migrate_deref_output_trait_object(
811-
source,
812-
&obligation.cause,
813-
obligation.param_env,
814-
)
812+
.need_migrate_deref_output_trait_object(source, obligation.param_env)
815813
{
816814
if deref_output_trait_did == target_trait_did {
817815
self.tcx().struct_span_lint_hir(

0 commit comments

Comments
 (0)