Skip to content

Commit 4f42b28

Browse files
committed
Avoid InferOk<'tcx, ()>.
`InferOk<'tcx, T>` wraps a `T` and a `Vec<PredicateObligation<'tcx>>`. A lot of the instances are `InferOk<'tcx, ()>`, which is just a clumsy wrapper for a `Vec<PredicateObligation<'tcx>>`. This commit removes the `InferOk` in those cases, avoiding a lot of boilerplate wrapping/unwrapping code. To help with this, the unused `UnitResult` type is replaced with `UnitInferResult`, which is like `InferResult<'tcx, ()>` but without the useless `InferOk<'tcx, ()>` wrapper.
1 parent 2183738 commit 4f42b28

File tree

23 files changed

+133
-160
lines changed

23 files changed

+133
-160
lines changed

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
890890
let cause = self.misc(span);
891891
// We know the type of `effect` to be `bool`, there will be no opaque type inference.
892892
match self.at(&cause, self.param_env).eq(infer::DefineOpaqueTypes::Yes, effect, param) {
893-
Ok(infer::InferOk { obligations, value: () }) => {
893+
Ok(obligations) => {
894894
self.register_predicates(obligations);
895895
}
896896
Err(e) => {

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
918918
if fcx
919919
.at(&cause, fcx.param_env)
920920
.eq(DefineOpaqueTypes::Yes, src_obj, dst_obj)
921-
.map(|infer_ok| fcx.register_infer_ok_obligations(infer_ok))
921+
.map(|obligations| fcx.register_predicates(obligations))
922922
.is_err()
923923
{
924924
return Err(CastError::DifferingKinds { src_kind, dst_kind });

compiler/rustc_hir_typeck/src/closure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
820820
) {
821821
// Check that E' = S'.
822822
let cause = self.misc(hir_ty.span);
823-
let InferOk { value: (), obligations } = self.at(&cause, self.param_env).eq(
823+
let obligations = self.at(&cause, self.param_env).eq(
824824
DefineOpaqueTypes::Yes,
825825
*expected_ty,
826826
supplied_ty,
@@ -830,7 +830,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
830830

831831
let supplied_output_ty = supplied_sig.output();
832832
let cause = &self.misc(decl.output.span());
833-
let InferOk { value: (), obligations } = self.at(cause, self.param_env).eq(
833+
let obligations = self.at(cause, self.param_env).eq(
834834
DefineOpaqueTypes::Yes,
835835
expected_sigs.liberated_sig.output(),
836836
supplied_output_ty,

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
138138
at.lub(DefineOpaqueTypes::Yes, b, a)
139139
} else {
140140
at.sup(DefineOpaqueTypes::Yes, b, a)
141-
.map(|InferOk { value: (), obligations }| InferOk { value: b, obligations })
141+
.map(|obligations| InferOk { value: b, obligations })
142142
};
143143

144144
// In the new solver, lazy norm may allow us to shallowly equate
@@ -1599,8 +1599,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15991599
expected,
16001600
found,
16011601
)
1602-
.map(|infer_ok| {
1603-
fcx.register_infer_ok_obligations(infer_ok);
1602+
.map(|obligations| {
1603+
fcx.register_predicates(obligations);
16041604
expression_ty
16051605
})
16061606
};

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
190190
) -> Result<(), Diag<'a>> {
191191
self.at(cause, self.param_env)
192192
.sup(DefineOpaqueTypes::Yes, expected, actual)
193-
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
193+
.map(|obligations| self.register_predicates(obligations))
194194
.map_err(|e| self.err_ctxt().report_mismatched_types(cause, expected, actual, e))
195195
}
196196

@@ -217,7 +217,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
217217
) -> Result<(), Diag<'a>> {
218218
self.at(cause, self.param_env)
219219
.eq(DefineOpaqueTypes::Yes, expected, actual)
220-
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
220+
.map(|obligations| self.register_predicates(obligations))
221221
.map_err(|e| self.err_ctxt().report_mismatched_types(cause, expected, actual, e))
222222
}
223223

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_hir::lang_items::LangItem;
1616
use rustc_hir::{ExprKind, HirId, QPath};
1717
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer as _;
1818
use rustc_infer::infer;
19-
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
19+
use rustc_infer::infer::DefineOpaqueTypes;
2020
use rustc_infer::traits::ObligationCause;
2121
use rustc_infer::traits::query::NoSolution;
2222
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
@@ -1832,7 +1832,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18321832
target_ty,
18331833
fru_ty,
18341834
) {
1835-
Ok(InferOk { obligations, value: () }) => {
1835+
Ok(obligations) => {
18361836
self.register_predicates(obligations)
18371837
}
18381838
Err(_) => {

compiler/rustc_hir_typeck/src/fallback.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::unord::{UnordBag, UnordMap, UnordSet};
77
use rustc_hir as hir;
88
use rustc_hir::HirId;
99
use rustc_hir::intravisit::Visitor;
10-
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
10+
use rustc_infer::infer::DefineOpaqueTypes;
1111
use rustc_middle::bug;
1212
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable};
1313
use rustc_session::lint;
@@ -116,7 +116,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
116116
let expected = self.tcx.consts.true_;
117117
let cause = self.misc(DUMMY_SP);
118118
match self.at(&cause, self.param_env).eq(DefineOpaqueTypes::Yes, expected, effect) {
119-
Ok(InferOk { obligations, value: () }) => {
119+
Ok(obligations) => {
120120
self.register_predicates(obligations);
121121
}
122122
Err(e) => {

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -613,12 +613,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
613613
let ty::Infer(ty::InferTy::TyVar(_)) = interior.kind() else {
614614
span_bug!(span, "coroutine interior witness not infer: {:?}", interior.kind())
615615
};
616-
let ok = self
616+
let mut obligations = self
617617
.at(&self.misc(span), self.param_env)
618618
// Will never define opaque types, as all we do is instantiate a type variable.
619619
.eq(DefineOpaqueTypes::Yes, interior, witness)
620620
.expect("Failed to unify coroutine interior type");
621-
let mut obligations = ok.obligations;
622621

623622
// Also collect the obligations that were unstalled by this unification.
624623
obligations
@@ -1386,7 +1385,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13861385
impl_ty,
13871386
self_ty,
13881387
) {
1389-
Ok(ok) => self.register_infer_ok_obligations(ok),
1388+
Ok(obligations) => self.register_predicates(obligations),
13901389
Err(_) => {
13911390
self.dcx().span_bug(
13921391
span,

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt;
1515
use rustc_hir_analysis::check::potentially_plural_count;
1616
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
1717
use rustc_index::IndexVec;
18-
use rustc_infer::infer::{DefineOpaqueTypes, InferOk, TypeTrace};
18+
use rustc_infer::infer::{DefineOpaqueTypes, TypeTrace};
1919
use rustc_middle::ty::adjustment::AllowTwoPhase;
2020
use rustc_middle::ty::error::TypeError;
2121
use rustc_middle::ty::visit::TypeVisitableExt;
@@ -338,7 +338,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
338338

339339
// If neither check failed, the types are compatible
340340
match formal_ty_error {
341-
Ok(InferOk { obligations, value: () }) => {
341+
Ok(obligations) => {
342342
self.register_predicates(obligations);
343343
Compatibility::Compatible
344344
}

compiler/rustc_hir_typeck/src/method/confirm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir_analysis::hir_ty_lowering::generics::{
99
use rustc_hir_analysis::hir_ty_lowering::{
1010
GenericArgsLowerer, HirTyLowerer, IsMethodCall, RegionInferReason,
1111
};
12-
use rustc_infer::infer::{self, DefineOpaqueTypes, InferOk};
12+
use rustc_infer::infer::{self, DefineOpaqueTypes};
1313
use rustc_middle::traits::{ObligationCauseCode, UnifyReceiverContext};
1414
use rustc_middle::ty::adjustment::{
1515
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCoercion,
@@ -512,7 +512,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
512512
})),
513513
);
514514
match self.at(&cause, self.param_env).sup(DefineOpaqueTypes::Yes, method_self_ty, self_ty) {
515-
Ok(InferOk { obligations, value: () }) => {
515+
Ok(obligations) => {
516516
self.register_predicates(obligations);
517517
}
518518
Err(terr) => {

compiler/rustc_infer/src/infer/at.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use rustc_middle::bug;
2929
use rustc_middle::ty::{Const, ImplSubject};
3030

3131
use super::*;
32+
use crate::infer::UnitInferResult;
3233
use crate::infer::relate::{Relate, StructurallyRelateAliases, TypeRelation};
3334
use crate::traits::Obligation;
3435

@@ -105,7 +106,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
105106
define_opaque_types: DefineOpaqueTypes,
106107
expected: T,
107108
actual: T,
108-
) -> InferResult<'tcx, ()>
109+
) -> UnitInferResult<'tcx>
109110
where
110111
T: ToTrace<'tcx>,
111112
{
@@ -116,7 +117,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
116117
define_opaque_types,
117118
);
118119
fields.sup().relate(expected, actual)?;
119-
Ok(InferOk { value: (), obligations: fields.into_obligations() })
120+
Ok(fields.into_obligations())
120121
}
121122

122123
/// Makes `expected <: actual`.
@@ -125,7 +126,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
125126
define_opaque_types: DefineOpaqueTypes,
126127
expected: T,
127128
actual: T,
128-
) -> InferResult<'tcx, ()>
129+
) -> UnitInferResult<'tcx>
129130
where
130131
T: ToTrace<'tcx>,
131132
{
@@ -136,7 +137,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
136137
define_opaque_types,
137138
);
138139
fields.sub().relate(expected, actual)?;
139-
Ok(InferOk { value: (), obligations: fields.into_obligations() })
140+
Ok(fields.into_obligations())
140141
}
141142

142143
/// Makes `expected == actual`.
@@ -145,7 +146,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
145146
define_opaque_types: DefineOpaqueTypes,
146147
expected: T,
147148
actual: T,
148-
) -> InferResult<'tcx, ()>
149+
) -> UnitInferResult<'tcx>
149150
where
150151
T: ToTrace<'tcx>,
151152
{
@@ -164,27 +165,24 @@ impl<'a, 'tcx> At<'a, 'tcx> {
164165
trace: TypeTrace<'tcx>,
165166
expected: T,
166167
actual: T,
167-
) -> InferResult<'tcx, ()>
168+
) -> UnitInferResult<'tcx>
168169
where
169170
T: Relate<TyCtxt<'tcx>>,
170171
{
171172
let mut fields = CombineFields::new(self.infcx, trace, self.param_env, define_opaque_types);
172173
fields.equate(StructurallyRelateAliases::No).relate(expected, actual)?;
173-
Ok(InferOk {
174-
value: (),
175-
obligations: fields
176-
.goals
177-
.into_iter()
178-
.map(|goal| {
179-
Obligation::new(
180-
self.infcx.tcx,
181-
fields.trace.cause.clone(),
182-
goal.param_env,
183-
goal.predicate,
184-
)
185-
})
186-
.collect(),
187-
})
174+
Ok(fields
175+
.goals
176+
.into_iter()
177+
.map(|goal| {
178+
Obligation::new(
179+
self.infcx.tcx,
180+
fields.trace.cause.clone(),
181+
goal.param_env,
182+
goal.predicate,
183+
)
184+
})
185+
.collect())
188186
}
189187

190188
pub fn relate<T>(
@@ -193,7 +191,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
193191
expected: T,
194192
variance: ty::Variance,
195193
actual: T,
196-
) -> InferResult<'tcx, ()>
194+
) -> UnitInferResult<'tcx>
197195
where
198196
T: ToTrace<'tcx>,
199197
{

0 commit comments

Comments
 (0)