Skip to content

Commit 1076c7d

Browse files
Remove glob imports for ObligationCauseCode
1 parent 477d5b3 commit 1076c7d

File tree

24 files changed

+279
-178
lines changed

24 files changed

+279
-178
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
traits::ItemObligation(trait_ty.def_id)
2017+
ObligationCauseCode::ItemObligation(trait_ty.def_id)
20182018
} else {
2019-
traits::BindingObligation(trait_ty.def_id, span)
2019+
ObligationCauseCode::BindingObligation(trait_ty.def_id, span)
20202020
};
20212021
ObligationCause::new(impl_ty_span, impl_ty_def_id, code)
20222022
};
@@ -2253,7 +2253,8 @@ fn try_report_async_mismatch<'tcx>(
22532253
};
22542254

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

compiler/rustc_hir_analysis/src/check/dropck.rs

Lines changed: 2 additions & 1 deletion
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

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 18 additions & 6 deletions
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
);

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 8 additions & 3 deletions
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},
@@ -118,7 +119,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
118119
};
119120

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

123128
output
124129
}
@@ -532,9 +537,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
532537
self.register_bound(
533538
ty,
534539
self.tcx.require_lang_item(hir::LangItem::Tuple, Some(sp)),
535-
traits::ObligationCause::new(sp, self.body_id, traits::RustCall),
540+
traits::ObligationCause::new(sp, self.body_id, ObligationCauseCode::RustCall),
536541
);
537-
self.require_type_is_sized(ty, sp, traits::RustCall);
542+
self.require_type_is_sized(ty, sp, ObligationCauseCode::RustCall);
538543
} else {
539544
self.dcx().emit_err(errors::RustCallIncorrectArgs { span: sp });
540545
}

compiler/rustc_hir_typeck/src/check.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc_middle::ty::{self, Binder, Ty, TyCtxt};
1515
use rustc_span::def_id::LocalDefId;
1616
use rustc_span::symbol::sym;
1717
use rustc_target::spec::abi::Abi;
18-
use rustc_trait_selection::traits;
1918
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode};
2019

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

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

131138
fcx.is_whole_body.set(true);

compiler/rustc_hir_typeck/src/closure.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
99
use rustc_infer::infer::type_variable::TypeVariableOrigin;
1010
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes};
1111
use rustc_infer::infer::{InferOk, InferResult};
12+
use rustc_infer::traits::ObligationCauseCode;
1213
use rustc_macros::{TypeFoldable, TypeVisitable};
1314
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt};
1415
use rustc_middle::ty::GenericArgs;
@@ -126,7 +127,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
126127
param_def_id: None,
127128
span: expr_span,
128129
});
129-
self.require_type_is_sized(yield_ty, expr_span, traits::SizedYieldType);
130+
self.require_type_is_sized(
131+
yield_ty,
132+
expr_span,
133+
ObligationCauseCode::SizedYieldType,
134+
);
130135
yield_ty
131136
}
132137
// HACK(-Ztrait-solver=next): In the *old* trait solver, we must eagerly
@@ -138,7 +143,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
138143
param_def_id: None,
139144
span: expr_span,
140145
});
141-
self.require_type_is_sized(yield_ty, expr_span, traits::SizedYieldType);
146+
self.require_type_is_sized(
147+
yield_ty,
148+
expr_span,
149+
ObligationCauseCode::SizedYieldType,
150+
);
142151

143152
Ty::new_adt(
144153
tcx,

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
575575
self.require_type_is_sized_deferred(
576576
input,
577577
span,
578-
traits::SizedArgumentType(None),
578+
ObligationCauseCode::SizedArgumentType(None),
579579
);
580580
}
581581
}
@@ -593,7 +593,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
593593
self.require_type_is_sized_deferred(
594594
output,
595595
call.map_or(expr.span, |e| e.span),
596-
traits::SizedCallReturnType,
596+
ObligationCauseCode::SizedCallReturnType,
597597
);
598598
}
599599

@@ -1251,7 +1251,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12511251
}
12521252
});
12531253

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

12561256
if let Err(guar) = (lhs_ty, rhs_ty).error_reported() {
12571257
Ty::new_error(self.tcx, guar)
@@ -1475,7 +1475,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14751475
crate::GatherLocalsVisitor::new(&fcx).visit_body(body);
14761476

14771477
let ty = fcx.check_expr_with_expectation(body.value, expected);
1478-
fcx.require_type_is_sized(ty, body.value.span, traits::ConstSized);
1478+
fcx.require_type_is_sized(ty, body.value.span, ObligationCauseCode::ConstSized);
14791479
fcx.write_ty(block.hir_id, ty);
14801480
ty
14811481
}
@@ -1522,7 +1522,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15221522

15231523
let ty = Ty::new_array_with_const_len(tcx, t, count);
15241524

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

15271527
ty
15281528
}
@@ -1612,7 +1612,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16121612
if let Err(guar) = tuple.error_reported() {
16131613
Ty::new_error(self.tcx, guar)
16141614
} else {
1615-
self.require_type_is_sized(tuple, expr.span, traits::TupleInitializerSized);
1615+
self.require_type_is_sized(
1616+
tuple,
1617+
expr.span,
1618+
ObligationCauseCode::TupleInitializerSized,
1619+
);
16161620
tuple
16171621
}
16181622
}
@@ -1651,7 +1655,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16511655
base_expr,
16521656
);
16531657

1654-
self.require_type_is_sized(adt_ty, expr.span, traits::StructInitializerSized);
1658+
self.require_type_is_sized(adt_ty, expr.span, ObligationCauseCode::StructInitializerSized);
16551659
adt_ty
16561660
}
16571661

@@ -3084,7 +3088,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
30843088
polarity: ty::PredicatePolarity::Positive,
30853089
}),
30863090
|derived| {
3087-
traits::ImplDerivedObligation(Box::new(
3091+
ObligationCauseCode::ImplDerivedObligation(Box::new(
30883092
traits::ImplDerivedObligationCause {
30893093
derived,
30903094
impl_or_alias_def_id: impl_def_id,
@@ -3182,7 +3186,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31823186
fn check_expr_asm_operand(&self, expr: &'tcx hir::Expr<'tcx>, is_input: bool) {
31833187
let needs = if is_input { Needs::None } else { Needs::MutPlace };
31843188
let ty = self.check_expr_with_needs(expr, needs);
3185-
self.require_type_is_sized(ty, expr.span, traits::InlineAsmSized);
3189+
self.require_type_is_sized(ty, expr.span, ObligationCauseCode::InlineAsmSized);
31863190

31873191
if !is_input && !expr.is_syntactic_place_expr() {
31883192
self.dcx()
@@ -3353,7 +3357,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33533357
let field_ty = self.field_ty(expr.span, field, args);
33543358

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

33583366
if field.vis.is_accessible_from(sub_def_scope, self.tcx) {
33593367
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
@@ -3381,7 +3389,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33813389
let field_ty = self.field_ty(expr.span, field, args);
33823390

33833391
// FIXME: DSTs with static alignment should be allowed
3384-
self.require_type_is_sized(field_ty, expr.span, traits::MiscObligation);
3392+
self.require_type_is_sized(
3393+
field_ty,
3394+
expr.span,
3395+
ObligationCauseCode::MiscObligation,
3396+
);
33853397

33863398
if field.vis.is_accessible_from(def_scope, self.tcx) {
33873399
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
@@ -3402,7 +3414,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
34023414
&& field.name == sym::integer(index)
34033415
{
34043416
for ty in tys.iter().take(index + 1) {
3405-
self.require_type_is_sized(ty, expr.span, traits::MiscObligation);
3417+
self.require_type_is_sized(
3418+
ty,
3419+
expr.span,
3420+
ObligationCauseCode::MiscObligation,
3421+
);
34063422
}
34073423
if let Some(&field_ty) = tys.get(index) {
34083424
field_indices.push((FIRST_VARIANT, index.into()));

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 13 additions & 5 deletions
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)