Skip to content

Commit 12a6992

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 a648626 commit 12a6992

File tree

22 files changed

+130
-157
lines changed

22 files changed

+130
-157
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/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
@@ -1596,8 +1596,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15961596
expected,
15971597
found,
15981598
)
1599-
.map(|infer_ok| {
1600-
fcx.register_infer_ok_obligations(infer_ok);
1599+
.map(|obligations| {
1600+
fcx.register_predicates(obligations);
16011601
expression_ty
16021602
})
16031603
};

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: 19 additions & 21 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

@@ -110,7 +111,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
110111
define_opaque_types: DefineOpaqueTypes,
111112
expected: T,
112113
actual: T,
113-
) -> InferResult<'tcx, ()>
114+
) -> UnitInferResult<'tcx>
114115
where
115116
T: ToTrace<'tcx>,
116117
{
@@ -121,7 +122,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
121122
define_opaque_types,
122123
);
123124
fields.sup().relate(expected, actual)?;
124-
Ok(InferOk { value: (), obligations: fields.into_obligations() })
125+
Ok(fields.into_obligations())
125126
}
126127

127128
/// Makes `expected <: actual`.
@@ -130,7 +131,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
130131
define_opaque_types: DefineOpaqueTypes,
131132
expected: T,
132133
actual: T,
133-
) -> InferResult<'tcx, ()>
134+
) -> UnitInferResult<'tcx>
134135
where
135136
T: ToTrace<'tcx>,
136137
{
@@ -141,7 +142,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
141142
define_opaque_types,
142143
);
143144
fields.sub().relate(expected, actual)?;
144-
Ok(InferOk { value: (), obligations: fields.into_obligations() })
145+
Ok(fields.into_obligations())
145146
}
146147

147148
/// Makes `expected == actual`.
@@ -150,7 +151,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
150151
define_opaque_types: DefineOpaqueTypes,
151152
expected: T,
152153
actual: T,
153-
) -> InferResult<'tcx, ()>
154+
) -> UnitInferResult<'tcx>
154155
where
155156
T: ToTrace<'tcx>,
156157
{
@@ -161,21 +162,18 @@ impl<'a, 'tcx> At<'a, 'tcx> {
161162
define_opaque_types,
162163
);
163164
fields.equate(StructurallyRelateAliases::No).relate(expected, actual)?;
164-
Ok(InferOk {
165-
value: (),
166-
obligations: fields
167-
.goals
168-
.into_iter()
169-
.map(|goal| {
170-
Obligation::new(
171-
self.infcx.tcx,
172-
fields.trace.cause.clone(),
173-
goal.param_env,
174-
goal.predicate,
175-
)
176-
})
177-
.collect(),
178-
})
165+
Ok(fields
166+
.goals
167+
.into_iter()
168+
.map(|goal| {
169+
Obligation::new(
170+
self.infcx.tcx,
171+
fields.trace.cause.clone(),
172+
goal.param_env,
173+
goal.predicate,
174+
)
175+
})
176+
.collect())
179177
}
180178

181179
pub fn relate<T>(
@@ -184,7 +182,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
184182
expected: T,
185183
variance: ty::Variance,
186184
actual: T,
187-
) -> InferResult<'tcx, ()>
185+
) -> UnitInferResult<'tcx>
188186
where
189187
T: ToTrace<'tcx>,
190188
{

0 commit comments

Comments
 (0)