Skip to content

Commit 4bde8a8

Browse files
Remove glob imports for ObligationCauseCode
1 parent 04c0494 commit 4bde8a8

File tree

24 files changed

+279
-178
lines changed

24 files changed

+279
-178
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -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::ItemObligation(trait_ty.def_id)
20162016
} else {
2017-
traits::BindingObligation(trait_ty.def_id, span)
2017+
ObligationCauseCode::BindingObligation(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::BindingObligation(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::MiscObligation,
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::ItemObligation(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_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,

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

+28-12
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
573573
self.require_type_is_sized_deferred(
574574
input,
575575
span,
576-
traits::SizedArgumentType(None),
576+
ObligationCauseCode::SizedArgumentType(None),
577577
);
578578
}
579579
}
@@ -591,7 +591,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
591591
self.require_type_is_sized_deferred(
592592
output,
593593
call.map_or(expr.span, |e| e.span),
594-
traits::SizedCallReturnType,
594+
ObligationCauseCode::SizedCallReturnType,
595595
);
596596
}
597597

@@ -1249,7 +1249,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12491249
}
12501250
});
12511251

1252-
self.require_type_is_sized(lhs_ty, lhs.span, traits::AssignmentLhsSized);
1252+
self.require_type_is_sized(lhs_ty, lhs.span, ObligationCauseCode::AssignmentLhsSized);
12531253

12541254
if let Err(guar) = (lhs_ty, rhs_ty).error_reported() {
12551255
Ty::new_error(self.tcx, guar)
@@ -1471,7 +1471,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14711471
crate::GatherLocalsVisitor::new(&fcx).visit_body(body);
14721472

14731473
let ty = fcx.check_expr_with_expectation(body.value, expected);
1474-
fcx.require_type_is_sized(ty, body.value.span, traits::ConstSized);
1474+
fcx.require_type_is_sized(ty, body.value.span, ObligationCauseCode::ConstSized);
14751475
fcx.write_ty(block.hir_id, ty);
14761476
ty
14771477
}
@@ -1517,7 +1517,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15171517

15181518
let ty = Ty::new_array_with_const_len(tcx, t, count);
15191519

1520-
self.register_wf_obligation(ty.into(), expr.span, traits::WellFormed(None));
1520+
self.register_wf_obligation(ty.into(), expr.span, ObligationCauseCode::WellFormed(None));
15211521

15221522
ty
15231523
}
@@ -1607,7 +1607,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16071607
if let Err(guar) = tuple.error_reported() {
16081608
Ty::new_error(self.tcx, guar)
16091609
} else {
1610-
self.require_type_is_sized(tuple, expr.span, traits::TupleInitializerSized);
1610+
self.require_type_is_sized(
1611+
tuple,
1612+
expr.span,
1613+
ObligationCauseCode::TupleInitializerSized,
1614+
);
16111615
tuple
16121616
}
16131617
}
@@ -1646,7 +1650,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16461650
base_expr,
16471651
);
16481652

1649-
self.require_type_is_sized(adt_ty, expr.span, traits::StructInitializerSized);
1653+
self.require_type_is_sized(adt_ty, expr.span, ObligationCauseCode::StructInitializerSized);
16501654
adt_ty
16511655
}
16521656

@@ -3079,7 +3083,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
30793083
polarity: ty::PredicatePolarity::Positive,
30803084
}),
30813085
|derived| {
3082-
traits::ImplDerivedObligation(Box::new(
3086+
ObligationCauseCode::ImplDerivedObligation(Box::new(
30833087
traits::ImplDerivedObligationCause {
30843088
derived,
30853089
impl_or_alias_def_id: impl_def_id,
@@ -3177,7 +3181,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31773181
fn check_expr_asm_operand(&self, expr: &'tcx hir::Expr<'tcx>, is_input: bool) {
31783182
let needs = if is_input { Needs::None } else { Needs::MutPlace };
31793183
let ty = self.check_expr_with_needs(expr, needs);
3180-
self.require_type_is_sized(ty, expr.span, traits::InlineAsmSized);
3184+
self.require_type_is_sized(ty, expr.span, ObligationCauseCode::InlineAsmSized);
31813185

31823186
if !is_input && !expr.is_syntactic_place_expr() {
31833187
self.dcx()
@@ -3348,7 +3352,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33483352
let field_ty = self.field_ty(expr.span, field, args);
33493353

33503354
// FIXME: DSTs with static alignment should be allowed
3351-
self.require_type_is_sized(field_ty, expr.span, traits::MiscObligation);
3355+
self.require_type_is_sized(
3356+
field_ty,
3357+
expr.span,
3358+
ObligationCauseCode::MiscObligation,
3359+
);
33523360

33533361
if field.vis.is_accessible_from(sub_def_scope, self.tcx) {
33543362
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
@@ -3376,7 +3384,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33763384
let field_ty = self.field_ty(expr.span, field, args);
33773385

33783386
// FIXME: DSTs with static alignment should be allowed
3379-
self.require_type_is_sized(field_ty, expr.span, traits::MiscObligation);
3387+
self.require_type_is_sized(
3388+
field_ty,
3389+
expr.span,
3390+
ObligationCauseCode::MiscObligation,
3391+
);
33803392

33813393
if field.vis.is_accessible_from(def_scope, self.tcx) {
33823394
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
@@ -3397,7 +3409,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33973409
&& field.name == sym::integer(index)
33983410
{
33993411
for ty in tys.iter().take(index + 1) {
3400-
self.require_type_is_sized(ty, expr.span, traits::MiscObligation);
3412+
self.require_type_is_sized(
3413+
ty,
3414+
expr.span,
3415+
ObligationCauseCode::MiscObligation,
3416+
);
34013417
}
34023418
if let Some(&field_ty) = tys.get(index) {
34033419
field_indices.push((FIRST_VARIANT, index.into()));

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
409409

410410
pub fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> LoweredTy<'tcx> {
411411
let ty = self.lowerer().lower_ty(hir_ty);
412-
self.register_wf_obligation(ty.into(), hir_ty.span, traits::WellFormed(None));
412+
self.register_wf_obligation(ty.into(), hir_ty.span, ObligationCauseCode::WellFormed(None));
413413
LoweredTy::from_raw(self, hir_ty.span, ty)
414414
}
415415

@@ -520,7 +520,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
520520
for arg in args.iter().filter(|arg| {
521521
matches!(arg.unpack(), GenericArgKind::Type(..) | GenericArgKind::Const(..))
522522
}) {
523-
self.register_wf_obligation(arg, expr.span, traits::WellFormed(None));
523+
self.register_wf_obligation(arg, expr.span, ObligationCauseCode::WellFormed(None));
524524
}
525525
}
526526

@@ -775,7 +775,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
775775
};
776776
if let Some(&cached_result) = self.typeck_results.borrow().type_dependent_defs().get(hir_id)
777777
{
778-
self.register_wf_obligation(ty.raw.into(), qself.span, traits::WellFormed(None));
778+
self.register_wf_obligation(
779+
ty.raw.into(),
780+
qself.span,
781+
ObligationCauseCode::WellFormed(None),
782+
);
779783
// Return directly on cache hit. This is useful to avoid doubly reporting
780784
// errors with default match binding modes. See #44614.
781785
let def = cached_result.map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id));
@@ -814,7 +818,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
814818
self.register_wf_obligation(
815819
ty.raw.into(),
816820
qself.span,
817-
traits::WellFormed(None),
821+
ObligationCauseCode::WellFormed(None),
818822
);
819823
}
820824

@@ -848,7 +852,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
848852
});
849853

850854
if result.is_ok() {
851-
self.register_wf_obligation(ty.raw.into(), qself.span, traits::WellFormed(None));
855+
self.register_wf_obligation(
856+
ty.raw.into(),
857+
qself.span,
858+
ObligationCauseCode::WellFormed(None),
859+
);
852860
}
853861

854862
// Write back the new resolution.

0 commit comments

Comments
 (0)