Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e444017

Browse files
Consolidate obligation cause codes for where clauses
1 parent ef15976 commit e444017

File tree

25 files changed

+138
-140
lines changed

25 files changed

+138
-140
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,10 +2059,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20592059
// We currently do not store the `DefId` in the `ConstraintCategory`
20602060
// for performances reasons. The error reporting code used by NLL only
20612061
// uses the span, so this doesn't cause any problems at the moment.
2062-
Some(ObligationCauseCode::SpannedWhereClause(
2063-
CRATE_DEF_ID.to_def_id(),
2064-
predicate_span,
2065-
))
2062+
Some(ObligationCauseCode::WhereClause(CRATE_DEF_ID.to_def_id(), predicate_span))
20662063
} else {
20672064
None
20682065
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::mir::*;
1111
use rustc_middle::ty::{self, adjustment::PointerCoercion, Ty, TyCtxt};
1212
use rustc_middle::ty::{Instance, InstanceDef, TypeVisitableExt};
1313
use rustc_mir_dataflow::Analysis;
14-
use rustc_span::{sym, Span, Symbol};
14+
use rustc_span::{sym, Span, Symbol, DUMMY_SP};
1515
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
1616
use rustc_trait_selection::traits::{self, ObligationCauseCode, ObligationCtxt};
1717
use rustc_type_ir::visit::{TypeSuperVisitable, TypeVisitor};
@@ -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::WhereClause(callee),
741+
ObligationCauseCode::WhereClause(callee, DUMMY_SP),
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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
819819
ObligationCause::new(
820820
self.span,
821821
self.body_id,
822-
ObligationCauseCode::SpannedWhereClause(proj.def_id, pred_span),
822+
ObligationCauseCode::WhereClause(proj.def_id, pred_span),
823823
),
824824
self.param_env,
825825
pred,
@@ -2011,11 +2011,7 @@ pub(super) fn check_type_bounds<'tcx>(
20112011
},
20122012
);
20132013
let mk_cause = |span: Span| {
2014-
let code = if span.is_dummy() {
2015-
ObligationCauseCode::WhereClause(trait_ty.def_id)
2016-
} else {
2017-
ObligationCauseCode::SpannedWhereClause(trait_ty.def_id, span)
2018-
};
2014+
let code = ObligationCauseCode::WhereClause(trait_ty.def_id, span);
20192015
ObligationCause::new(impl_ty_span, impl_ty_def_id, code)
20202016
};
20212017

@@ -2251,8 +2247,7 @@ fn try_report_async_mismatch<'tcx>(
22512247
};
22522248

22532249
for error in errors {
2254-
if let ObligationCauseCode::SpannedWhereClause(def_id, _) =
2255-
*error.root_obligation.cause.code()
2250+
if let ObligationCauseCode::WhereClause(def_id, _) = *error.root_obligation.cause.code()
22562251
&& def_id == async_future_def_id
22572252
&& let Some(proj) = error.root_obligation.predicate.to_opt_poly_projection_pred()
22582253
&& let Some(proj) = proj.no_bound_vars()

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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::WhereClause(def_id.to_def_id()),
1553+
ObligationCauseCode::WhereClause(def_id.to_def_id(), DUMMY_SP),
15541554
);
15551555
traits::Obligation::new(tcx, cause, wfcx.param_env, pred)
15561556
});

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

Lines changed: 1 addition & 1 deletion
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::SpannedWhereClause(impl2_node.def_id(), span),
215+
traits::ObligationCauseCode::WhereClause(impl2_node.def_id(), span),
216216
)
217217
},
218218
);

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,11 +1409,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14091409
hir_id: HirId,
14101410
) {
14111411
self.add_required_obligations_with_code(span, def_id, args, |idx, span| {
1412-
if span.is_dummy() {
1413-
ObligationCauseCode::WhereClauseInExpr(def_id, hir_id, idx)
1414-
} else {
1415-
ObligationCauseCode::SpannedWhereClauseInExpr(def_id, span, hir_id, idx)
1416-
}
1412+
ObligationCauseCode::WhereClauseInExpr(def_id, span, hir_id, idx)
14171413
})
14181414
}
14191415

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1414
&self,
1515
error: &mut traits::FulfillmentError<'tcx>,
1616
) -> bool {
17-
let (ObligationCauseCode::WhereClauseInExpr(def_id, hir_id, idx)
18-
| ObligationCauseCode::SpannedWhereClauseInExpr(def_id, _, hir_id, idx)) =
17+
let ObligationCauseCode::WhereClauseInExpr(def_id, _, hir_id, idx) =
1918
*error.obligation.cause.code().peel_derives()
2019
else {
2120
return false;
@@ -512,7 +511,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
512511
expr: &'tcx hir::Expr<'tcx>,
513512
) -> Result<&'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>> {
514513
match obligation_cause_code {
515-
traits::ObligationCauseCode::SpannedWhereClauseInExpr(_, _, _, _) => {
514+
traits::ObligationCauseCode::WhereClauseInExpr(_, _, _, _) => {
516515
// This is the "root"; we assume that the `expr` is already pointing here.
517516
// Therefore, we return `Ok` so that this `expr` can be refined further.
518517
Ok(expr)

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,8 +2013,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20132013
for (span, code) in errors_causecode {
20142014
self.dcx().try_steal_modify_and_emit_err(span, StashKey::MaybeForgetReturn, |err| {
20152015
if let Some(fn_sig) = self.body_fn_sig()
2016-
&& let ObligationCauseCode::SpannedWhereClauseInExpr(_, _, binding_hir_id, ..) =
2017-
code
2016+
&& let ObligationCauseCode::WhereClauseInExpr(_, _, binding_hir_id, ..) = code
20182017
&& !fn_sig.output().is_unit()
20192018
{
20202019
let mut block_num = 0;
@@ -2103,7 +2102,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21032102
//
21042103
// This is because due to normalization, we often register duplicate
21052104
// obligations with misc obligations that are basically impossible to
2106-
// line back up with a useful SpannedWhereClauseInExpr.
2105+
// line back up with a useful WhereClauseInExpr.
21072106
for error in not_adjusted {
21082107
for (span, predicate, cause) in &remap_cause {
21092108
if *predicate == error.obligation.predicate

compiler/rustc_hir_typeck/src/method/confirm.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -564,16 +564,12 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
564564
// `self.add_required_obligations(self.span, def_id, &all_args);`
565565
for obligation in traits::predicates_for_generics(
566566
|idx, span| {
567-
let code = if span.is_dummy() {
568-
ObligationCauseCode::WhereClauseInExpr(def_id, self.call_expr.hir_id, idx)
569-
} else {
570-
ObligationCauseCode::SpannedWhereClauseInExpr(
571-
def_id,
572-
span,
573-
self.call_expr.hir_id,
574-
idx,
575-
)
576-
};
567+
let code = ObligationCauseCode::WhereClauseInExpr(
568+
def_id,
569+
span,
570+
self.call_expr.hir_id,
571+
idx,
572+
);
577573
traits::ObligationCause::new(self.span, self.body_id, code)
578574
},
579575
self.param_env,

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,20 +1401,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14011401
// Convert the bounds into obligations.
14021402
ocx.register_obligations(traits::predicates_for_generics(
14031403
|idx, span| {
1404-
let code = if span.is_dummy() {
1405-
ObligationCauseCode::WhereClauseInExpr(
1406-
impl_def_id,
1407-
self.scope_expr_id,
1408-
idx,
1409-
)
1410-
} else {
1411-
ObligationCauseCode::SpannedWhereClauseInExpr(
1412-
impl_def_id,
1413-
span,
1414-
self.scope_expr_id,
1415-
idx,
1416-
)
1417-
};
1404+
let code = ObligationCauseCode::WhereClauseInExpr(
1405+
impl_def_id,
1406+
span,
1407+
self.scope_expr_id,
1408+
idx,
1409+
);
14181410
ObligationCause::new(self.span, self.body_id, code)
14191411
},
14201412
self.param_env,

0 commit comments

Comments
 (0)