Skip to content

Commit 2cce088

Browse files
committed
Auto merge of #124952 - compiler-errors:no-error, r=lcnr
Rename some `FulfillmentErrorCode`/`ObligationCauseCode` variants to be less redundant 1. Rename some `FulfillmentErrorCode` variants. 2. Always use `ObligationCauseCode::` to prefix a code, rather than using a glob import and naming them through `traits::`. 3. Rename some `ObligationCauseCode` variants -- I wasn't particularly thorough with thinking of a new names for these, so could workshop them if necessary. 4. Misc stuff from renaming. r? lcnr
2 parents 6a19a87 + 6f77bfe commit 2cce088

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+432
-393
lines changed

Diff for: compiler/rustc_borrowck/src/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13441344
Applicability::MaybeIncorrect,
13451345
);
13461346
for error in errors {
1347-
if let FulfillmentErrorCode::SelectionError(
1347+
if let FulfillmentErrorCode::Select(
13481348
SelectionError::Unimplemented,
13491349
) = error.code
13501350
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(

Diff for: compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
12831283
}
12841284
// The type doesn't implement Clone because of unmet obligations.
12851285
for error in errors {
1286-
if let traits::FulfillmentErrorCode::SelectionError(
1286+
if let traits::FulfillmentErrorCode::Select(
12871287
traits::SelectionError::Unimplemented,
12881288
) = error.code
12891289
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(

Diff for: compiler/rustc_borrowck/src/region_infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2059,15 +2059,15 @@ 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::BindingObligation(
2062+
Some(ObligationCauseCode::SpannedWhereClause(
20632063
CRATE_DEF_ID.to_def_id(),
20642064
predicate_span,
20652065
))
20662066
} else {
20672067
None
20682068
}
20692069
})
2070-
.unwrap_or_else(|| ObligationCauseCode::MiscObligation);
2070+
.unwrap_or_else(|| ObligationCauseCode::Misc);
20712071

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

Diff for: 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::WhereClause(callee),
742742
);
743743
let normalized_predicates = ocx.normalize(&cause, param_env, predicates);
744744
ocx.register_obligations(traits::predicates_for_generics(

Diff for: compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fn compare_method_predicate_entailment<'tcx>(
175175
let cause = ObligationCause::new(
176176
impl_m_span,
177177
impl_m_def_id,
178-
ObligationCauseCode::CompareImplItemObligation {
178+
ObligationCauseCode::CompareImplItem {
179179
impl_item_def_id: impl_m_def_id,
180180
trait_item_def_id: trait_m.def_id,
181181
kind: impl_m.kind,
@@ -236,7 +236,7 @@ fn compare_method_predicate_entailment<'tcx>(
236236
let cause = ObligationCause::new(
237237
span,
238238
impl_m_def_id,
239-
ObligationCauseCode::CompareImplItemObligation {
239+
ObligationCauseCode::CompareImplItem {
240240
impl_item_def_id: impl_m_def_id,
241241
trait_item_def_id: trait_m.def_id,
242242
kind: impl_m.kind,
@@ -464,7 +464,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
464464
let cause = ObligationCause::new(
465465
return_span,
466466
impl_m_def_id,
467-
ObligationCauseCode::CompareImplItemObligation {
467+
ObligationCauseCode::CompareImplItem {
468468
impl_item_def_id: impl_m_def_id,
469469
trait_item_def_id: trait_m.def_id,
470470
kind: impl_m.kind,
@@ -819,7 +819,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
819819
ObligationCause::new(
820820
self.span,
821821
self.body_id,
822-
ObligationCauseCode::BindingObligation(proj.def_id, pred_span),
822+
ObligationCauseCode::SpannedWhereClause(proj.def_id, pred_span),
823823
),
824824
self.param_env,
825825
pred,
@@ -1752,7 +1752,7 @@ fn compare_const_predicate_entailment<'tcx>(
17521752
let impl_ty = tcx.type_of(impl_ct_def_id).instantiate_identity();
17531753

17541754
let trait_ty = tcx.type_of(trait_ct.def_id).instantiate(tcx, trait_to_impl_args);
1755-
let code = ObligationCauseCode::CompareImplItemObligation {
1755+
let code = ObligationCauseCode::CompareImplItem {
17561756
impl_item_def_id: impl_ct_def_id,
17571757
trait_item_def_id: trait_ct.def_id,
17581758
kind: impl_ct.kind,
@@ -1924,7 +1924,7 @@ fn compare_type_predicate_entailment<'tcx>(
19241924
let cause = ObligationCause::new(
19251925
span,
19261926
impl_ty_def_id,
1927-
ObligationCauseCode::CompareImplItemObligation {
1927+
ObligationCauseCode::CompareImplItem {
19281928
impl_item_def_id: impl_ty.def_id.expect_local(),
19291929
trait_item_def_id: trait_ty.def_id,
19301930
kind: impl_ty.kind,
@@ -2012,9 +2012,9 @@ pub(super) fn check_type_bounds<'tcx>(
20122012
);
20132013
let mk_cause = |span: Span| {
20142014
let code = if span.is_dummy() {
2015-
traits::ItemObligation(trait_ty.def_id)
2015+
ObligationCauseCode::WhereClause(trait_ty.def_id)
20162016
} else {
2017-
traits::BindingObligation(trait_ty.def_id, span)
2017+
ObligationCauseCode::SpannedWhereClause(trait_ty.def_id, span)
20182018
};
20192019
ObligationCause::new(impl_ty_span, impl_ty_def_id, code)
20202020
};
@@ -2251,7 +2251,8 @@ fn try_report_async_mismatch<'tcx>(
22512251
};
22522252

22532253
for error in errors {
2254-
if let traits::BindingObligation(def_id, _) = *error.root_obligation.cause.code()
2254+
if let ObligationCauseCode::SpannedWhereClause(def_id, _) =
2255+
*error.root_obligation.cause.code()
22552256
&& def_id == async_future_def_id
22562257
&& let Some(proj) = error.root_obligation.predicate.to_opt_poly_projection_pred()
22572258
&& let Some(proj) = proj.no_bound_vars()

Diff for: compiler/rustc_hir_analysis/src/check/dropck.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_data_structures::fx::FxHashSet;
55
use rustc_errors::{codes::*, struct_span_code_err, ErrorGuaranteed};
66
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
77
use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt};
8+
use rustc_infer::traits::ObligationCauseCode;
89
use rustc_middle::ty::util::CheckRegions;
910
use rustc_middle::ty::GenericArgsRef;
1011
use rustc_middle::ty::{self, TyCtxt};
@@ -139,7 +140,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
139140
for (pred, span) in tcx.predicates_of(drop_impl_def_id).instantiate_identity(tcx) {
140141
let normalize_cause = traits::ObligationCause::misc(span, adt_def_id);
141142
let pred = ocx.normalize(&normalize_cause, param_env, pred);
142-
let cause = traits::ObligationCause::new(span, adt_def_id, traits::DropImpl);
143+
let cause = traits::ObligationCause::new(span, adt_def_id, ObligationCauseCode::DropImpl);
143144
ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, pred));
144145
}
145146

Diff for: compiler/rustc_hir_analysis/src/check/wfcheck.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ fn check_type_defn<'tcx>(
11361136
traits::ObligationCause::new(
11371137
hir_ty.span,
11381138
wfcx.body_def_id,
1139-
traits::FieldSized {
1139+
ObligationCauseCode::FieldSized {
11401140
adt_kind: match &item.kind {
11411141
ItemKind::Struct(..) => AdtKind::Struct,
11421142
ItemKind::Union(..) => AdtKind::Union,
@@ -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-
traits::MiscObligation,
1164+
ObligationCauseCode::Misc,
11651165
);
11661166
wfcx.register_obligation(traits::Obligation::new(
11671167
tcx,
@@ -1278,7 +1278,11 @@ fn check_item_type(
12781278
wfcx.register_wf_obligation(ty_span, Some(WellFormedLoc::Ty(item_id)), item_ty.into());
12791279
if forbid_unsized {
12801280
wfcx.register_bound(
1281-
traits::ObligationCause::new(ty_span, wfcx.body_def_id, traits::WellFormed(None)),
1281+
traits::ObligationCause::new(
1282+
ty_span,
1283+
wfcx.body_def_id,
1284+
ObligationCauseCode::WellFormed(None),
1285+
),
12821286
wfcx.param_env,
12831287
item_ty,
12841288
tcx.require_lang_item(LangItem::Sized, None),
@@ -1293,7 +1297,11 @@ fn check_item_type(
12931297

12941298
if should_check_for_sync {
12951299
wfcx.register_bound(
1296-
traits::ObligationCause::new(ty_span, wfcx.body_def_id, traits::SharedStatic),
1300+
traits::ObligationCause::new(
1301+
ty_span,
1302+
wfcx.body_def_id,
1303+
ObligationCauseCode::SharedStatic,
1304+
),
12971305
wfcx.param_env,
12981306
item_ty,
12991307
tcx.require_lang_item(LangItem::Sync, Some(ty_span)),
@@ -1542,7 +1550,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
15421550
let cause = traits::ObligationCause::new(
15431551
sp,
15441552
wfcx.body_def_id,
1545-
traits::ItemObligation(def_id.to_def_id()),
1553+
ObligationCauseCode::WhereClause(def_id.to_def_id()),
15461554
);
15471555
traits::Obligation::new(tcx, cause, wfcx.param_env, pred)
15481556
});
@@ -1982,7 +1990,11 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
19821990

19831991
let obligation = traits::Obligation::new(
19841992
tcx,
1985-
traits::ObligationCause::new(span, self.body_def_id, traits::TrivialBound),
1993+
traits::ObligationCause::new(
1994+
span,
1995+
self.body_def_id,
1996+
ObligationCauseCode::TrivialBound,
1997+
),
19861998
empty_env,
19871999
pred,
19882000
);

Diff for: 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::SpannedWhereClause(impl2_node.def_id(), span),
216216
)
217217
},
218218
);

Diff for: compiler/rustc_hir_typeck/src/callee.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_hir as hir;
99
use rustc_hir::def::{self, CtorKind, Namespace, Res};
1010
use rustc_hir::def_id::DefId;
1111
use rustc_hir_analysis::autoderef::Autoderef;
12+
use rustc_infer::traits::ObligationCauseCode;
1213
use rustc_infer::{
1314
infer,
1415
traits::{self, Obligation, ObligationCause},
@@ -117,7 +118,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
117118
};
118119

119120
// we must check that return type of called functions is WF:
120-
self.register_wf_obligation(output.into(), call_expr.span, traits::WellFormed(None));
121+
self.register_wf_obligation(
122+
output.into(),
123+
call_expr.span,
124+
ObligationCauseCode::WellFormed(None),
125+
);
121126

122127
output
123128
}
@@ -524,9 +529,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
524529
self.register_bound(
525530
ty,
526531
self.tcx.require_lang_item(hir::LangItem::Tuple, Some(sp)),
527-
traits::ObligationCause::new(sp, self.body_id, traits::RustCall),
532+
traits::ObligationCause::new(sp, self.body_id, ObligationCauseCode::RustCall),
528533
);
529-
self.require_type_is_sized(ty, sp, traits::RustCall);
534+
self.require_type_is_sized(ty, sp, ObligationCauseCode::RustCall);
530535
} else {
531536
self.dcx().emit_err(errors::RustCallIncorrectArgs { span: sp });
532537
}

Diff for: compiler/rustc_hir_typeck/src/check.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc_middle::ty::{self, Binder, Ty, TyCtxt};
1414
use rustc_span::def_id::LocalDefId;
1515
use rustc_span::symbol::sym;
1616
use rustc_target::spec::abi::Abi;
17-
use rustc_trait_selection::traits;
1817
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode};
1918

2019
/// Helper used for fns and closures. Does the grungy work of checking a function
@@ -76,7 +75,7 @@ pub(super) fn check_fn<'a, 'tcx>(
7675
fcx.register_wf_obligation(
7776
param_ty.into(),
7877
param.span,
79-
traits::WellFormed(Some(WellFormedLoc::Param {
78+
ObligationCauseCode::WellFormed(Some(WellFormedLoc::Param {
8079
function: fn_def_id,
8180
param_idx: idx,
8281
})),
@@ -101,7 +100,7 @@ pub(super) fn check_fn<'a, 'tcx>(
101100
param.pat.span,
102101
// ty.span == binding_span iff this is a closure parameter with no type ascription,
103102
// or if it's an implicit `self` parameter
104-
traits::SizedArgumentType(
103+
ObligationCauseCode::SizedArgumentType(
105104
if ty_span == Some(param.span) && tcx.is_closure_like(fn_def_id.into()) {
106105
None
107106
} else {
@@ -121,10 +120,18 @@ pub(super) fn check_fn<'a, 'tcx>(
121120
hir::FnRetTy::Return(ty) => ty.span,
122121
};
123122

124-
fcx.require_type_is_sized(declared_ret_ty, return_or_body_span, traits::SizedReturnType);
123+
fcx.require_type_is_sized(
124+
declared_ret_ty,
125+
return_or_body_span,
126+
ObligationCauseCode::SizedReturnType,
127+
);
125128
// We checked the root's signature during wfcheck, but not the child.
126129
if fcx.tcx.is_typeck_child(fn_def_id.to_def_id()) {
127-
fcx.require_type_is_sized(declared_ret_ty, return_or_body_span, traits::WellFormed(None));
130+
fcx.require_type_is_sized(
131+
declared_ret_ty,
132+
return_or_body_span,
133+
ObligationCauseCode::WellFormed(None),
134+
);
128135
}
129136

130137
fcx.is_whole_body.set(true);

Diff for: compiler/rustc_hir_typeck/src/closure.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_hir::lang_items::LangItem;
88
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
99
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes};
1010
use rustc_infer::infer::{InferOk, InferResult};
11+
use rustc_infer::traits::ObligationCauseCode;
1112
use rustc_macros::{TypeFoldable, TypeVisitable};
1213
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt};
1314
use rustc_middle::ty::GenericArgs;
@@ -119,7 +120,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
119120
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)
120121
| hir::CoroutineKind::Coroutine(_) => {
121122
let yield_ty = self.next_ty_var(expr_span);
122-
self.require_type_is_sized(yield_ty, expr_span, traits::SizedYieldType);
123+
self.require_type_is_sized(
124+
yield_ty,
125+
expr_span,
126+
ObligationCauseCode::SizedYieldType,
127+
);
123128
yield_ty
124129
}
125130
// HACK(-Ztrait-solver=next): In the *old* trait solver, we must eagerly
@@ -128,7 +133,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
128133
// not a problem.
129134
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _) => {
130135
let yield_ty = self.next_ty_var(expr_span);
131-
self.require_type_is_sized(yield_ty, expr_span, traits::SizedYieldType);
136+
self.require_type_is_sized(
137+
yield_ty,
138+
expr_span,
139+
ObligationCauseCode::SizedYieldType,
140+
);
132141

133142
Ty::new_adt(
134143
tcx,

0 commit comments

Comments
 (0)