Skip to content

Commit

Permalink
Make ObligationCtxt::normalize take cause by borrow
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Nov 28, 2022
1 parent ce409b5 commit 1e236ac
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ where
// the former fails to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs` test.
// Check after #85499 lands to see if its fixes have erased this difference.
let (param_env, value) = key.into_parts();
let _ = ocx.normalize(cause, param_env, value.value);
let _ = ocx.normalize(&cause, param_env, value.value);

try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
hir_id,
ObligationCauseCode::ItemObligation(callee),
);
let normalized_predicates =
ocx.normalize(cause.clone(), param_env, predicates);
let normalized_predicates = ocx.normalize(&cause, param_env, predicates);
ocx.register_obligations(traits::predicates_for_generics(
|_, _| cause.clone(),
self.param_env,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/util/compare_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ pub fn is_subtype<'tcx>(
let infcx = builder.build();
let ocx = ObligationCtxt::new(&infcx);
let cause = ObligationCause::dummy();
let src = ocx.normalize(cause.clone(), param_env, src);
let dest = ocx.normalize(cause.clone(), param_env, dest);
let src = ocx.normalize(&cause, param_env, src);
let dest = ocx.normalize(&cause, param_env, dest);
match ocx.sub(&cause, param_env, src, dest) {
Ok(()) => {}
Err(_) => return false,
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_hir_analysis/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ fn compare_predicate_entailment<'tcx>(
let impl_m_own_bounds = impl_m_predicates.instantiate_own(tcx, impl_to_placeholder_substs);
for (predicate, span) in iter::zip(impl_m_own_bounds.predicates, impl_m_own_bounds.spans) {
let normalize_cause = traits::ObligationCause::misc(span, impl_m_hir_id);
let predicate = ocx.normalize(normalize_cause, param_env, predicate);
let predicate = ocx.normalize(&normalize_cause, param_env, predicate);

let cause = ObligationCause::new(
span,
Expand Down Expand Up @@ -260,7 +260,7 @@ fn compare_predicate_entailment<'tcx>(
);

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

Expand All @@ -271,7 +271,7 @@ fn compare_predicate_entailment<'tcx>(
// we have to do this before normalization, since the normalized ty may
// not contain the input parameters. See issue #87748.
wf_tys.extend(trait_sig.inputs_and_output.iter());
let trait_sig = ocx.normalize(norm_cause, param_env, trait_sig);
let trait_sig = ocx.normalize(&norm_cause, param_env, trait_sig);
// We also have to add the normalized trait signature
// as we don't normalize during implied bounds computation.
wf_tys.extend(trait_sig.inputs_and_output.iter());
Expand Down Expand Up @@ -366,7 +366,7 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
// Normalize the impl signature with fresh variables for lifetime inference.
let norm_cause = ObligationCause::misc(return_span, impl_m_hir_id);
let impl_sig = ocx.normalize(
norm_cause.clone(),
&norm_cause,
param_env,
infcx.replace_bound_vars_with_fresh_vars(
return_span,
Expand All @@ -387,7 +387,7 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
tcx.bound_fn_sig(trait_m.def_id).subst(tcx, trait_to_placeholder_substs),
)
.fold_with(&mut collector);
let trait_sig = ocx.normalize(norm_cause.clone(), param_env, unnormalized_trait_sig);
let trait_sig = ocx.normalize(&norm_cause, param_env, unnormalized_trait_sig);
let trait_return_ty = trait_sig.output();

let wf_tys = FxIndexSet::from_iter(
Expand Down Expand Up @@ -592,7 +592,7 @@ impl<'tcx> TypeFolder<'tcx> for ImplTraitInTraitCollector<'_, 'tcx> {
for (pred, pred_span) in self.tcx().bound_explicit_item_bounds(proj.item_def_id).subst_iter_copied(self.tcx(), proj.substs) {
let pred = pred.fold_with(self);
let pred = self.ocx.normalize(
ObligationCause::misc(self.span, self.body_id),
&ObligationCause::misc(self.span, self.body_id),
self.param_env,
pred,
);
Expand Down Expand Up @@ -1403,11 +1403,11 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
);

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

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

let trait_ty = ocx.normalize(cause.clone(), param_env, trait_ty);
let trait_ty = ocx.normalize(&cause, param_env, trait_ty);

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

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

let cause = ObligationCause::new(
span,
Expand Down Expand Up @@ -1778,7 +1778,7 @@ pub fn check_type_bounds<'tcx>(

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

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
T: TypeFoldable<'tcx>,
{
self.ocx.normalize(
ObligationCause::new(span, self.body_id, ObligationCauseCode::WellFormed(loc)),
&ObligationCause::new(span, self.body_id, ObligationCauseCode::WellFormed(loc)),
self.param_env,
value,
)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
ObligationCauseCode::MainFunctionType,
);
let ocx = traits::ObligationCtxt::new(&infcx);
let norm_return_ty = ocx.normalize(cause.clone(), param_env, return_ty);
let norm_return_ty = ocx.normalize(&cause, param_env, return_ty);
ocx.register_bound(cause, param_env, norm_return_ty, term_did);
let errors = ocx.select_all_or_error();
if !errors.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/inherited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl<'tcx> Inherited<'tcx> {
infcx.probe(|_| {
let ocx = ObligationCtxt::new_in_snapshot(infcx);
let normalized_fn_sig = ocx.normalize(
ObligationCause::dummy(),
&ObligationCause::dummy(),
// FIXME(compiler-errors): This is probably not the right param-env...
infcx.tcx.param_env(def_id),
fn_sig,
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_trait_selection/src/traits/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {

pub fn normalize<T: TypeFoldable<'tcx>>(
&self,
// FIXME(compiler-errors): Make this borrow
cause: ObligationCause<'tcx>,
cause: &ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>,
value: T,
) -> T {
Expand Down Expand Up @@ -186,7 +185,7 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
// sound and then uncomment this line again.

// implied_bounds.insert(ty);
let normalized = self.normalize(cause.clone(), param_env, ty);
let normalized = self.normalize(&cause, param_env, ty);
implied_bounds.insert(normalized);
}
implied_bounds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ pub fn recompute_applicable_impls<'tcx>(
let placeholder_obligation =
infcx.replace_bound_vars_with_placeholders(obligation.predicate);
let obligation_trait_ref =
ocx.normalize(dummy_cause.clone(), param_env, placeholder_obligation.trait_ref);
ocx.normalize(&dummy_cause, param_env, placeholder_obligation.trait_ref);

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

if let Err(_) = ocx.eq(&dummy_cause, param_env, obligation_trait_ref, impl_trait_ref) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_trait_selection/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ pub use self::object_safety::astconv_object_safety_violations;
pub use self::object_safety::is_vtable_safe_method;
pub use self::object_safety::MethodViolationCode;
pub use self::object_safety::ObjectSafetyViolation;
pub use self::project::{NormalizeExt, normalize_projection_type};
pub(crate) use self::project::{normalize, normalize_to};
pub use self::project::{normalize_projection_type, NormalizeExt};
pub use self::select::{EvaluationCache, SelectionCache, SelectionContext};
pub use self::select::{EvaluationResult, IntercrateAmbiguityCause, OverflowError};
pub use self::specialize::specialization_graph::FutureCompatOverlapError;
Expand Down Expand Up @@ -387,7 +387,7 @@ where
{
let ocx = ObligationCtxt::new(infcx);
debug!(?value);
let normalized_value = ocx.normalize(cause, param_env, value);
let normalized_value = ocx.normalize(&cause, param_env, value);
debug!(?normalized_value);
debug!("select_all_or_error start");
let errors = ocx.select_all_or_error();
Expand Down Expand Up @@ -454,7 +454,7 @@ pub fn impossible_predicates<'tcx>(
let infcx = tcx.infer_ctxt().build();
let param_env = ty::ParamEnv::reveal_all();
let ocx = ObligationCtxt::new(&infcx);
let predicates = ocx.normalize(ObligationCause::dummy(), param_env, predicates);
let predicates = ocx.normalize(&ObligationCause::dummy(), param_env, predicates);
for predicate in predicates {
let obligation = Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate);
ocx.register_obligation(obligation);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_traits/src/type_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn type_op_ascribe_user_type_with_span<'tcx>(
let cause = ObligationCause::dummy_with_span(span);

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

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

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

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

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

Expand Down

0 comments on commit 1e236ac

Please sign in to comment.