Skip to content

Commit 1e236ac

Browse files
Make ObligationCtxt::normalize take cause by borrow
1 parent ce409b5 commit 1e236ac

File tree

11 files changed

+27
-29
lines changed

11 files changed

+27
-29
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ where
295295
// the former fails to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test.
296296
// Check after #85499 lands to see if its fixes have erased this difference.
297297
let (param_env, value) = key.into_parts();
298-
let _ = ocx.normalize(cause, param_env, value.value);
298+
let _ = ocx.normalize(&cause, param_env, value.value);
299299

300300
try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)
301301
}

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
761761
hir_id,
762762
ObligationCauseCode::ItemObligation(callee),
763763
);
764-
let normalized_predicates =
765-
ocx.normalize(cause.clone(), param_env, predicates);
764+
let normalized_predicates = ocx.normalize(&cause, param_env, predicates);
766765
ocx.register_obligations(traits::predicates_for_generics(
767766
|_, _| cause.clone(),
768767
self.param_env,

compiler/rustc_const_eval/src/util/compare_types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ pub fn is_subtype<'tcx>(
4646
let infcx = builder.build();
4747
let ocx = ObligationCtxt::new(&infcx);
4848
let cause = ObligationCause::dummy();
49-
let src = ocx.normalize(cause.clone(), param_env, src);
50-
let dest = ocx.normalize(cause.clone(), param_env, dest);
49+
let src = ocx.normalize(&cause, param_env, src);
50+
let dest = ocx.normalize(&cause, param_env, dest);
5151
match ocx.sub(&cause, param_env, src, dest) {
5252
Ok(()) => {}
5353
Err(_) => return false,

compiler/rustc_hir_analysis/src/check/compare_method.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ fn compare_predicate_entailment<'tcx>(
221221
let impl_m_own_bounds = impl_m_predicates.instantiate_own(tcx, impl_to_placeholder_substs);
222222
for (predicate, span) in iter::zip(impl_m_own_bounds.predicates, impl_m_own_bounds.spans) {
223223
let normalize_cause = traits::ObligationCause::misc(span, impl_m_hir_id);
224-
let predicate = ocx.normalize(normalize_cause, param_env, predicate);
224+
let predicate = ocx.normalize(&normalize_cause, param_env, predicate);
225225

226226
let cause = ObligationCause::new(
227227
span,
@@ -260,7 +260,7 @@ fn compare_predicate_entailment<'tcx>(
260260
);
261261

262262
let norm_cause = ObligationCause::misc(impl_m_span, impl_m_hir_id);
263-
let impl_sig = ocx.normalize(norm_cause.clone(), param_env, impl_sig);
263+
let impl_sig = ocx.normalize(&norm_cause, param_env, impl_sig);
264264
let impl_fty = tcx.mk_fn_ptr(ty::Binder::dummy(impl_sig));
265265
debug!("compare_impl_method: impl_fty={:?}", impl_fty);
266266

@@ -271,7 +271,7 @@ fn compare_predicate_entailment<'tcx>(
271271
// we have to do this before normalization, since the normalized ty may
272272
// not contain the input parameters. See issue #87748.
273273
wf_tys.extend(trait_sig.inputs_and_output.iter());
274-
let trait_sig = ocx.normalize(norm_cause, param_env, trait_sig);
274+
let trait_sig = ocx.normalize(&norm_cause, param_env, trait_sig);
275275
// We also have to add the normalized trait signature
276276
// as we don't normalize during implied bounds computation.
277277
wf_tys.extend(trait_sig.inputs_and_output.iter());
@@ -366,7 +366,7 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
366366
// Normalize the impl signature with fresh variables for lifetime inference.
367367
let norm_cause = ObligationCause::misc(return_span, impl_m_hir_id);
368368
let impl_sig = ocx.normalize(
369-
norm_cause.clone(),
369+
&norm_cause,
370370
param_env,
371371
infcx.replace_bound_vars_with_fresh_vars(
372372
return_span,
@@ -387,7 +387,7 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
387387
tcx.bound_fn_sig(trait_m.def_id).subst(tcx, trait_to_placeholder_substs),
388388
)
389389
.fold_with(&mut collector);
390-
let trait_sig = ocx.normalize(norm_cause.clone(), param_env, unnormalized_trait_sig);
390+
let trait_sig = ocx.normalize(&norm_cause, param_env, unnormalized_trait_sig);
391391
let trait_return_ty = trait_sig.output();
392392

393393
let wf_tys = FxIndexSet::from_iter(
@@ -592,7 +592,7 @@ impl<'tcx> TypeFolder<'tcx> for ImplTraitInTraitCollector<'_, 'tcx> {
592592
for (pred, pred_span) in self.tcx().bound_explicit_item_bounds(proj.item_def_id).subst_iter_copied(self.tcx(), proj.substs) {
593593
let pred = pred.fold_with(self);
594594
let pred = self.ocx.normalize(
595-
ObligationCause::misc(self.span, self.body_id),
595+
&ObligationCause::misc(self.span, self.body_id),
596596
self.param_env,
597597
pred,
598598
);
@@ -1403,11 +1403,11 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
14031403
);
14041404

14051405
// There is no "body" here, so just pass dummy id.
1406-
let impl_ty = ocx.normalize(cause.clone(), param_env, impl_ty);
1406+
let impl_ty = ocx.normalize(&cause, param_env, impl_ty);
14071407

14081408
debug!("compare_const_impl: impl_ty={:?}", impl_ty);
14091409

1410-
let trait_ty = ocx.normalize(cause.clone(), param_env, trait_ty);
1410+
let trait_ty = ocx.normalize(&cause, param_env, trait_ty);
14111411

14121412
debug!("compare_const_impl: trait_ty={:?}", trait_ty);
14131413

@@ -1556,7 +1556,7 @@ fn compare_type_predicate_entailment<'tcx>(
15561556
for (span, predicate) in std::iter::zip(impl_ty_own_bounds.spans, impl_ty_own_bounds.predicates)
15571557
{
15581558
let cause = ObligationCause::misc(span, impl_ty_hir_id);
1559-
let predicate = ocx.normalize(cause, param_env, predicate);
1559+
let predicate = ocx.normalize(&cause, param_env, predicate);
15601560

15611561
let cause = ObligationCause::new(
15621562
span,
@@ -1778,7 +1778,7 @@ pub fn check_type_bounds<'tcx>(
17781778

17791779
for mut obligation in util::elaborate_obligations(tcx, obligations) {
17801780
let normalized_predicate =
1781-
ocx.normalize(normalize_cause.clone(), normalize_param_env, obligation.predicate);
1781+
ocx.normalize(&normalize_cause, normalize_param_env, obligation.predicate);
17821782
debug!("compare_projection_bounds: normalized predicate = {:?}", normalized_predicate);
17831783
obligation.predicate = normalized_predicate;
17841784

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
6060
T: TypeFoldable<'tcx>,
6161
{
6262
self.ocx.normalize(
63-
ObligationCause::new(span, self.body_id, ObligationCauseCode::WellFormed(loc)),
63+
&ObligationCause::new(span, self.body_id, ObligationCauseCode::WellFormed(loc)),
6464
self.param_env,
6565
value,
6666
)

compiler/rustc_hir_analysis/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
332332
ObligationCauseCode::MainFunctionType,
333333
);
334334
let ocx = traits::ObligationCtxt::new(&infcx);
335-
let norm_return_ty = ocx.normalize(cause.clone(), param_env, return_ty);
335+
let norm_return_ty = ocx.normalize(&cause, param_env, return_ty);
336336
ocx.register_bound(cause, param_env, norm_return_ty, term_did);
337337
let errors = ocx.select_all_or_error();
338338
if !errors.is_empty() {

compiler/rustc_hir_typeck/src/inherited.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'tcx> Inherited<'tcx> {
100100
infcx.probe(|_| {
101101
let ocx = ObligationCtxt::new_in_snapshot(infcx);
102102
let normalized_fn_sig = ocx.normalize(
103-
ObligationCause::dummy(),
103+
&ObligationCause::dummy(),
104104
// FIXME(compiler-errors): This is probably not the right param-env...
105105
infcx.tcx.param_env(def_id),
106106
fn_sig,

compiler/rustc_trait_selection/src/traits/engine.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
104104

105105
pub fn normalize<T: TypeFoldable<'tcx>>(
106106
&self,
107-
// FIXME(compiler-errors): Make this borrow
108-
cause: ObligationCause<'tcx>,
107+
cause: &ObligationCause<'tcx>,
109108
param_env: ty::ParamEnv<'tcx>,
110109
value: T,
111110
) -> T {
@@ -186,7 +185,7 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
186185
// sound and then uncomment this line again.
187186

188187
// implied_bounds.insert(ty);
189-
let normalized = self.normalize(cause.clone(), param_env, ty);
188+
let normalized = self.normalize(&cause, param_env, ty);
190189
implied_bounds.insert(normalized);
191190
}
192191
implied_bounds

compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ pub fn recompute_applicable_impls<'tcx>(
1717
let placeholder_obligation =
1818
infcx.replace_bound_vars_with_placeholders(obligation.predicate);
1919
let obligation_trait_ref =
20-
ocx.normalize(dummy_cause.clone(), param_env, placeholder_obligation.trait_ref);
20+
ocx.normalize(&dummy_cause, param_env, placeholder_obligation.trait_ref);
2121

2222
let impl_substs = infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id);
2323
let impl_trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap().subst(tcx, impl_substs);
24-
let impl_trait_ref = ocx.normalize(ObligationCause::dummy(), param_env, impl_trait_ref);
24+
let impl_trait_ref = ocx.normalize(&ObligationCause::dummy(), param_env, impl_trait_ref);
2525

2626
if let Err(_) = ocx.eq(&dummy_cause, param_env, obligation_trait_ref, impl_trait_ref) {
2727
return false;

compiler/rustc_trait_selection/src/traits/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ pub use self::object_safety::astconv_object_safety_violations;
5656
pub use self::object_safety::is_vtable_safe_method;
5757
pub use self::object_safety::MethodViolationCode;
5858
pub use self::object_safety::ObjectSafetyViolation;
59-
pub use self::project::{NormalizeExt, normalize_projection_type};
6059
pub(crate) use self::project::{normalize, normalize_to};
60+
pub use self::project::{normalize_projection_type, NormalizeExt};
6161
pub use self::select::{EvaluationCache, SelectionCache, SelectionContext};
6262
pub use self::select::{EvaluationResult, IntercrateAmbiguityCause, OverflowError};
6363
pub use self::specialize::specialization_graph::FutureCompatOverlapError;
@@ -387,7 +387,7 @@ where
387387
{
388388
let ocx = ObligationCtxt::new(infcx);
389389
debug!(?value);
390-
let normalized_value = ocx.normalize(cause, param_env, value);
390+
let normalized_value = ocx.normalize(&cause, param_env, value);
391391
debug!(?normalized_value);
392392
debug!("select_all_or_error start");
393393
let errors = ocx.select_all_or_error();
@@ -454,7 +454,7 @@ pub fn impossible_predicates<'tcx>(
454454
let infcx = tcx.infer_ctxt().build();
455455
let param_env = ty::ParamEnv::reveal_all();
456456
let ocx = ObligationCtxt::new(&infcx);
457-
let predicates = ocx.normalize(ObligationCause::dummy(), param_env, predicates);
457+
let predicates = ocx.normalize(&ObligationCause::dummy(), param_env, predicates);
458458
for predicate in predicates {
459459
let obligation = Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate);
460460
ocx.register_obligation(obligation);

compiler/rustc_traits/src/type_op.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn type_op_ascribe_user_type_with_span<'tcx>(
6262
let cause = ObligationCause::dummy_with_span(span);
6363

6464
let ty = tcx.bound_type_of(def_id).subst(tcx, substs);
65-
let ty = ocx.normalize(cause.clone(), param_env, ty);
65+
let ty = ocx.normalize(&cause, param_env, ty);
6666
debug!("relate_type_and_user_type: ty of def-id is {:?}", ty);
6767

6868
ocx.eq(&cause, param_env, mir_ty, ty)?;
@@ -85,14 +85,14 @@ pub fn type_op_ascribe_user_type_with_span<'tcx>(
8585
ObligationCauseCode::AscribeUserTypeProvePredicate(predicate_span),
8686
);
8787
let instantiated_predicate =
88-
ocx.normalize(cause.clone(), param_env, instantiated_predicate);
88+
ocx.normalize(&cause.clone(), param_env, instantiated_predicate);
8989

9090
ocx.register_obligation(Obligation::new(tcx, cause, param_env, instantiated_predicate));
9191
}
9292

9393
if let Some(UserSelfTy { impl_def_id, self_ty }) = user_self_ty {
9494
let impl_self_ty = tcx.bound_type_of(impl_def_id).subst(tcx, substs);
95-
let impl_self_ty = ocx.normalize(cause.clone(), param_env, impl_self_ty);
95+
let impl_self_ty = ocx.normalize(&cause, param_env, impl_self_ty);
9696

9797
ocx.eq(&cause, param_env, self_ty, impl_self_ty)?;
9898

0 commit comments

Comments
 (0)