Skip to content

Commit 23ffdf9

Browse files
Rename some ObligationCauseCode variants
1 parent 1076c7d commit 23ffdf9

File tree

33 files changed

+187
-247
lines changed

33 files changed

+187
-247
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -2053,15 +2053,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20532053
// We currently do not store the `DefId` in the `ConstraintCategory`
20542054
// for performances reasons. The error reporting code used by NLL only
20552055
// uses the span, so this doesn't cause any problems at the moment.
2056-
Some(ObligationCauseCode::BindingObligation(
2057-
CRATE_DEF_ID.to_def_id(),
2058-
predicate_span,
2059-
))
2056+
Some(ObligationCauseCode::Where(CRATE_DEF_ID.to_def_id(), predicate_span))
20602057
} else {
20612058
None
20622059
}
20632060
})
2064-
.unwrap_or_else(|| ObligationCauseCode::MiscObligation);
2061+
.unwrap_or_else(|| ObligationCauseCode::Misc);
20652062

20662063
// Classify each of the constraints along the path.
20672064
let mut categorized_path: Vec<BlameConstraint<'tcx>> = path

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
738738
let cause = ObligationCause::new(
739739
terminator.source_info.span,
740740
self.body.source.def_id().expect_local(),
741-
ObligationCauseCode::ItemObligation(callee),
741+
ObligationCauseCode::MiscItem(callee),
742742
);
743743
let normalized_predicates = ocx.normalize(&cause, param_env, predicates);
744744
ocx.register_obligations(traits::predicates_for_generics(

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ fn compare_method_predicate_entailment<'tcx>(
176176
let cause = ObligationCause::new(
177177
impl_m_span,
178178
impl_m_def_id,
179-
ObligationCauseCode::CompareImplItemObligation {
179+
ObligationCauseCode::CompareImplItem {
180180
impl_item_def_id: impl_m_def_id,
181181
trait_item_def_id: trait_m.def_id,
182182
kind: impl_m.kind,
@@ -237,7 +237,7 @@ fn compare_method_predicate_entailment<'tcx>(
237237
let cause = ObligationCause::new(
238238
span,
239239
impl_m_def_id,
240-
ObligationCauseCode::CompareImplItemObligation {
240+
ObligationCauseCode::CompareImplItem {
241241
impl_item_def_id: impl_m_def_id,
242242
trait_item_def_id: trait_m.def_id,
243243
kind: impl_m.kind,
@@ -465,7 +465,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
465465
let cause = ObligationCause::new(
466466
return_span,
467467
impl_m_def_id,
468-
ObligationCauseCode::CompareImplItemObligation {
468+
ObligationCauseCode::CompareImplItem {
469469
impl_item_def_id: impl_m_def_id,
470470
trait_item_def_id: trait_m.def_id,
471471
kind: impl_m.kind,
@@ -823,7 +823,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
823823
ObligationCause::new(
824824
self.span,
825825
self.body_id,
826-
ObligationCauseCode::BindingObligation(proj.def_id, pred_span),
826+
ObligationCauseCode::Where(proj.def_id, pred_span),
827827
),
828828
self.param_env,
829829
pred,
@@ -1754,7 +1754,7 @@ fn compare_const_predicate_entailment<'tcx>(
17541754
let impl_ty = tcx.type_of(impl_ct_def_id).instantiate_identity();
17551755

17561756
let trait_ty = tcx.type_of(trait_ct.def_id).instantiate(tcx, trait_to_impl_args);
1757-
let code = ObligationCauseCode::CompareImplItemObligation {
1757+
let code = ObligationCauseCode::CompareImplItem {
17581758
impl_item_def_id: impl_ct_def_id,
17591759
trait_item_def_id: trait_ct.def_id,
17601760
kind: impl_ct.kind,
@@ -1926,7 +1926,7 @@ fn compare_type_predicate_entailment<'tcx>(
19261926
let cause = ObligationCause::new(
19271927
span,
19281928
impl_ty_def_id,
1929-
ObligationCauseCode::CompareImplItemObligation {
1929+
ObligationCauseCode::CompareImplItem {
19301930
impl_item_def_id: impl_ty.def_id.expect_local(),
19311931
trait_item_def_id: trait_ty.def_id,
19321932
kind: impl_ty.kind,
@@ -2014,9 +2014,9 @@ pub(super) fn check_type_bounds<'tcx>(
20142014
);
20152015
let mk_cause = |span: Span| {
20162016
let code = if span.is_dummy() {
2017-
ObligationCauseCode::ItemObligation(trait_ty.def_id)
2017+
ObligationCauseCode::MiscItem(trait_ty.def_id)
20182018
} else {
2019-
ObligationCauseCode::BindingObligation(trait_ty.def_id, span)
2019+
ObligationCauseCode::Where(trait_ty.def_id, span)
20202020
};
20212021
ObligationCause::new(impl_ty_span, impl_ty_def_id, code)
20222022
};
@@ -2253,8 +2253,7 @@ fn try_report_async_mismatch<'tcx>(
22532253
};
22542254

22552255
for error in errors {
2256-
if let ObligationCauseCode::BindingObligation(def_id, _) =
2257-
*error.root_obligation.cause.code()
2256+
if let ObligationCauseCode::Where(def_id, _) = *error.root_obligation.cause.code()
22582257
&& def_id == async_future_def_id
22592258
&& let Some(proj) = error.root_obligation.predicate.to_opt_poly_projection_pred()
22602259
&& let Some(proj) = proj.no_bound_vars()

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ fn check_type_defn<'tcx>(
11611161
let cause = traits::ObligationCause::new(
11621162
tcx.def_span(discr_def_id),
11631163
wfcx.body_def_id,
1164-
ObligationCauseCode::MiscObligation,
1164+
ObligationCauseCode::Misc,
11651165
);
11661166
wfcx.register_obligation(traits::Obligation::new(
11671167
tcx,
@@ -1550,7 +1550,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
15501550
let cause = traits::ObligationCause::new(
15511551
sp,
15521552
wfcx.body_def_id,
1553-
ObligationCauseCode::ItemObligation(def_id.to_def_id()),
1553+
ObligationCauseCode::MiscItem(def_id.to_def_id()),
15541554
);
15551555
traits::Obligation::new(tcx, cause, wfcx.param_env, pred)
15561556
});

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ fn get_impl_args(
212212
traits::ObligationCause::new(
213213
impl1_span,
214214
impl1_def_id,
215-
traits::ObligationCauseCode::BindingObligation(impl2_node.def_id(), span),
215+
traits::ObligationCauseCode::Where(impl2_node.def_id(), span),
216216
)
217217
},
218218
);

compiler/rustc_hir_typeck/src/expr.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -3088,7 +3088,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
30883088
polarity: ty::PredicatePolarity::Positive,
30893089
}),
30903090
|derived| {
3091-
ObligationCauseCode::ImplDerivedObligation(Box::new(
3091+
ObligationCauseCode::ImplDerived(Box::new(
30923092
traits::ImplDerivedObligationCause {
30933093
derived,
30943094
impl_or_alias_def_id: impl_def_id,
@@ -3357,11 +3357,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33573357
let field_ty = self.field_ty(expr.span, field, args);
33583358

33593359
// FIXME: DSTs with static alignment should be allowed
3360-
self.require_type_is_sized(
3361-
field_ty,
3362-
expr.span,
3363-
ObligationCauseCode::MiscObligation,
3364-
);
3360+
self.require_type_is_sized(field_ty, expr.span, ObligationCauseCode::Misc);
33653361

33663362
if field.vis.is_accessible_from(sub_def_scope, self.tcx) {
33673363
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
@@ -3389,11 +3385,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33893385
let field_ty = self.field_ty(expr.span, field, args);
33903386

33913387
// FIXME: DSTs with static alignment should be allowed
3392-
self.require_type_is_sized(
3393-
field_ty,
3394-
expr.span,
3395-
ObligationCauseCode::MiscObligation,
3396-
);
3388+
self.require_type_is_sized(field_ty, expr.span, ObligationCauseCode::Misc);
33973389

33983390
if field.vis.is_accessible_from(def_scope, self.tcx) {
33993391
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
@@ -3414,11 +3406,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
34143406
&& field.name == sym::integer(index)
34153407
{
34163408
for ty in tys.iter().take(index + 1) {
3417-
self.require_type_is_sized(
3418-
ty,
3419-
expr.span,
3420-
ObligationCauseCode::MiscObligation,
3421-
);
3409+
self.require_type_is_sized(ty, expr.span, ObligationCauseCode::Misc);
34223410
}
34233411
if let Some(&field_ty) = tys.get(index) {
34243412
field_indices.push((FIRST_VARIANT, index.into()));

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1413,9 +1413,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14131413
) {
14141414
self.add_required_obligations_with_code(span, def_id, args, |idx, span| {
14151415
if span.is_dummy() {
1416-
ObligationCauseCode::ExprItemObligation(def_id, hir_id, idx)
1416+
ObligationCauseCode::MiscItemInExpr(def_id, hir_id, idx)
14171417
} else {
1418-
ObligationCauseCode::ExprBindingObligation(def_id, span, hir_id, idx)
1418+
ObligationCauseCode::WhereInExpr(def_id, span, hir_id, idx)
14191419
}
14201420
})
14211421
}

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1414
&self,
1515
error: &mut traits::FulfillmentError<'tcx>,
1616
) -> bool {
17-
let (ObligationCauseCode::ExprItemObligation(def_id, hir_id, idx)
18-
| ObligationCauseCode::ExprBindingObligation(def_id, _, hir_id, idx)) =
17+
let (ObligationCauseCode::MiscItemInExpr(def_id, hir_id, idx)
18+
| ObligationCauseCode::WhereInExpr(def_id, _, hir_id, idx)) =
1919
*error.obligation.cause.code().peel_derives()
2020
else {
2121
return false;
@@ -167,7 +167,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
167167
// the method's turbofish segments but still use `FunctionArgumentObligation`
168168
// elsewhere. Hopefully this doesn't break something.
169169
error.obligation.cause.map_code(|parent_code| {
170-
ObligationCauseCode::FunctionArgumentObligation {
170+
ObligationCauseCode::FunctionArg {
171171
arg_hir_id: receiver.hir_id,
172172
call_hir_id: hir_id,
173173
parent_code,
@@ -456,12 +456,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
456456
self.blame_specific_expr_if_possible(error, arg_expr)
457457
}
458458

459-
error.obligation.cause.map_code(|parent_code| {
460-
ObligationCauseCode::FunctionArgumentObligation {
461-
arg_hir_id: arg.hir_id,
462-
call_hir_id,
463-
parent_code,
464-
}
459+
error.obligation.cause.map_code(|parent_code| ObligationCauseCode::FunctionArg {
460+
arg_hir_id: arg.hir_id,
461+
call_hir_id,
462+
parent_code,
465463
});
466464
return true;
467465
} else if args_referencing_param.len() > 0 {
@@ -514,12 +512,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
514512
expr: &'tcx hir::Expr<'tcx>,
515513
) -> Result<&'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>> {
516514
match obligation_cause_code {
517-
traits::ObligationCauseCode::ExprBindingObligation(_, _, _, _) => {
515+
traits::ObligationCauseCode::WhereInExpr(_, _, _, _) => {
518516
// This is the "root"; we assume that the `expr` is already pointing here.
519517
// Therefore, we return `Ok` so that this `expr` can be refined further.
520518
Ok(expr)
521519
}
522-
traits::ObligationCauseCode::ImplDerivedObligation(impl_derived) => self
520+
traits::ObligationCauseCode::ImplDerived(impl_derived) => self
523521
.blame_specific_expr_if_possible_for_derived_predicate_obligation(
524522
impl_derived,
525523
expr,

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
207207
self.register_wf_obligation(
208208
fn_input_ty.into(),
209209
arg_expr.span,
210-
ObligationCauseCode::MiscObligation,
210+
ObligationCauseCode::Misc,
211211
);
212212
}
213213

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
156156
}
157157

158158
pub fn misc(&self, span: Span) -> ObligationCause<'tcx> {
159-
self.cause(span, ObligationCauseCode::MiscObligation)
159+
self.cause(span, ObligationCauseCode::Misc)
160160
}
161161

162162
pub fn sess(&self) -> &Session {

compiler/rustc_hir_typeck/src/method/confirm.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -565,14 +565,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
565565
for obligation in traits::predicates_for_generics(
566566
|idx, span| {
567567
let code = if span.is_dummy() {
568-
ObligationCauseCode::ExprItemObligation(def_id, self.call_expr.hir_id, idx)
568+
ObligationCauseCode::MiscItemInExpr(def_id, self.call_expr.hir_id, idx)
569569
} else {
570-
ObligationCauseCode::ExprBindingObligation(
571-
def_id,
572-
span,
573-
self.call_expr.hir_id,
574-
idx,
575-
)
570+
ObligationCauseCode::WhereInExpr(def_id, span, self.call_expr.hir_id, idx)
576571
};
577572
traits::ObligationCause::new(self.span, self.body_id, code)
578573
},

compiler/rustc_hir_typeck/src/method/probe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1402,13 +1402,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14021402
ocx.register_obligations(traits::predicates_for_generics(
14031403
|idx, span| {
14041404
let code = if span.is_dummy() {
1405-
ObligationCauseCode::ExprItemObligation(
1405+
ObligationCauseCode::MiscItemInExpr(
14061406
impl_def_id,
14071407
self.scope_expr_id,
14081408
idx,
14091409
)
14101410
} else {
1411-
ObligationCauseCode::ExprBindingObligation(
1411+
ObligationCauseCode::WhereInExpr(
14121412
impl_def_id,
14131413
span,
14141414
self.scope_expr_id,

compiler/rustc_hir_typeck/src/method/suggest.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
150150
return false;
151151
};
152152
let trait_ref = ty::TraitRef::new(self.tcx, into_iterator_trait, [ty]);
153-
let cause = ObligationCause::new(span, self.body_id, ObligationCauseCode::MiscObligation);
153+
let cause = ObligationCause::new(span, self.body_id, ObligationCauseCode::Misc);
154154
let obligation = Obligation::new(self.tcx, cause, self.param_env, trait_ref);
155155
if !self.predicate_must_hold_modulo_regions(&obligation) {
156156
return false;
@@ -830,12 +830,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
830830
// Extract the predicate span and parent def id of the cause,
831831
// if we have one.
832832
let (item_def_id, cause_span) = match cause.as_ref().map(|cause| cause.code()) {
833-
Some(ObligationCauseCode::ImplDerivedObligation(data)) => {
833+
Some(ObligationCauseCode::ImplDerived(data)) => {
834834
(data.impl_or_alias_def_id, data.span)
835835
}
836836
Some(
837-
ObligationCauseCode::ExprBindingObligation(def_id, span, _, _)
838-
| ObligationCauseCode::BindingObligation(def_id, span),
837+
ObligationCauseCode::WhereInExpr(def_id, span, _, _)
838+
| ObligationCauseCode::Where(def_id, span),
839839
) => (*def_id, *span),
840840
_ => continue,
841841
};

0 commit comments

Comments
 (0)