Skip to content

Avoid InferOk<'tcx, ()> #131134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let cause = self.misc(span);
// We know the type of `effect` to be `bool`, there will be no opaque type inference.
match self.at(&cause, self.param_env).eq(infer::DefineOpaqueTypes::Yes, effect, param) {
Ok(infer::InferOk { obligations, value: () }) => {
Ok(obligations) => {
self.register_predicates(obligations);
}
Err(e) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
if fcx
.at(&cause, fcx.param_env)
.eq(DefineOpaqueTypes::Yes, src_obj, dst_obj)
.map(|infer_ok| fcx.register_infer_ok_obligations(infer_ok))
.map(|obligations| fcx.register_predicates(obligations))
.is_err()
{
return Err(CastError::DifferingKinds { src_kind, dst_kind });
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) {
// Check that E' = S'.
let cause = self.misc(hir_ty.span);
let InferOk { value: (), obligations } = self.at(&cause, self.param_env).eq(
let obligations = self.at(&cause, self.param_env).eq(
DefineOpaqueTypes::Yes,
*expected_ty,
supplied_ty,
Expand All @@ -830,7 +830,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let supplied_output_ty = supplied_sig.output();
let cause = &self.misc(decl.output.span());
let InferOk { value: (), obligations } = self.at(cause, self.param_env).eq(
let obligations = self.at(cause, self.param_env).eq(
DefineOpaqueTypes::Yes,
expected_sigs.liberated_sig.output(),
supplied_output_ty,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
at.lub(DefineOpaqueTypes::Yes, b, a)
} else {
at.sup(DefineOpaqueTypes::Yes, b, a)
.map(|InferOk { value: (), obligations }| InferOk { value: b, obligations })
.map(|obligations| InferOk { value: b, obligations })
};

// In the new solver, lazy norm may allow us to shallowly equate
Expand Down Expand Up @@ -1599,8 +1599,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
expected,
found,
)
.map(|infer_ok| {
fcx.register_infer_ok_obligations(infer_ok);
.map(|obligations| {
fcx.register_predicates(obligations);
expression_ty
})
};
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) -> Result<(), Diag<'a>> {
self.at(cause, self.param_env)
.sup(DefineOpaqueTypes::Yes, expected, actual)
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok))
.map(|obligations| self.register_predicates(obligations))
.map_err(|e| self.err_ctxt().report_mismatched_types(cause, expected, actual, e))
}

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

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_hir::lang_items::LangItem;
use rustc_hir::{ExprKind, HirId, QPath};
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer as _;
use rustc_infer::infer;
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
use rustc_infer::infer::DefineOpaqueTypes;
use rustc_infer::traits::ObligationCause;
use rustc_infer::traits::query::NoSolution;
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
Expand Down Expand Up @@ -1832,7 +1832,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
target_ty,
fru_ty,
) {
Ok(InferOk { obligations, value: () }) => {
Ok(obligations) => {
self.register_predicates(obligations)
}
Err(_) => {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_data_structures::unord::{UnordBag, UnordMap, UnordSet};
use rustc_hir as hir;
use rustc_hir::HirId;
use rustc_hir::intravisit::Visitor;
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
use rustc_infer::infer::DefineOpaqueTypes;
use rustc_middle::bug;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable};
use rustc_session::lint;
Expand Down Expand Up @@ -116,7 +116,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
let expected = self.tcx.consts.true_;
let cause = self.misc(DUMMY_SP);
match self.at(&cause, self.param_env).eq(DefineOpaqueTypes::Yes, expected, effect) {
Ok(InferOk { obligations, value: () }) => {
Ok(obligations) => {
self.register_predicates(obligations);
}
Err(e) => {
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty::Infer(ty::InferTy::TyVar(_)) = interior.kind() else {
span_bug!(span, "coroutine interior witness not infer: {:?}", interior.kind())
};
let ok = self
let mut obligations = self
.at(&self.misc(span), self.param_env)
// Will never define opaque types, as all we do is instantiate a type variable.
.eq(DefineOpaqueTypes::Yes, interior, witness)
.expect("Failed to unify coroutine interior type");
let mut obligations = ok.obligations;

// Also collect the obligations that were unstalled by this unification.
obligations
Expand Down Expand Up @@ -1386,7 +1385,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
impl_ty,
self_ty,
) {
Ok(ok) => self.register_infer_ok_obligations(ok),
Ok(obligations) => self.register_predicates(obligations),
Err(_) => {
self.dcx().span_bug(
span,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt;
use rustc_hir_analysis::check::potentially_plural_count;
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
use rustc_index::IndexVec;
use rustc_infer::infer::{DefineOpaqueTypes, InferOk, TypeTrace};
use rustc_infer::infer::{DefineOpaqueTypes, TypeTrace};
use rustc_middle::ty::adjustment::AllowTwoPhase;
use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::visit::TypeVisitableExt;
Expand Down Expand Up @@ -338,7 +338,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// If neither check failed, the types are compatible
match formal_ty_error {
Ok(InferOk { obligations, value: () }) => {
Ok(obligations) => {
self.register_predicates(obligations);
Compatibility::Compatible
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_hir_analysis::hir_ty_lowering::generics::{
use rustc_hir_analysis::hir_ty_lowering::{
GenericArgsLowerer, HirTyLowerer, IsMethodCall, RegionInferReason,
};
use rustc_infer::infer::{self, DefineOpaqueTypes, InferOk};
use rustc_infer::infer::{self, DefineOpaqueTypes};
use rustc_middle::traits::{ObligationCauseCode, UnifyReceiverContext};
use rustc_middle::ty::adjustment::{
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCoercion,
Expand Down Expand Up @@ -512,7 +512,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
})),
);
match self.at(&cause, self.param_env).sup(DefineOpaqueTypes::Yes, method_self_ty, self_ty) {
Ok(InferOk { obligations, value: () }) => {
Ok(obligations) => {
self.register_predicates(obligations);
}
Err(terr) => {
Expand Down
64 changes: 20 additions & 44 deletions compiler/rustc_infer/src/infer/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use rustc_middle::bug;
use rustc_middle::ty::{Const, ImplSubject};

use super::*;
use crate::infer::UnitInferResult;
use crate::infer::relate::{Relate, StructurallyRelateAliases, TypeRelation};
use crate::traits::Obligation;

Expand Down Expand Up @@ -105,7 +106,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
define_opaque_types: DefineOpaqueTypes,
expected: T,
actual: T,
) -> InferResult<'tcx, ()>
) -> UnitInferResult<'tcx>
where
T: ToTrace<'tcx>,
{
Expand All @@ -116,7 +117,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
define_opaque_types,
);
fields.sup().relate(expected, actual)?;
Ok(InferOk { value: (), obligations: fields.into_obligations() })
Ok(fields.into_obligations())
}

/// Makes `expected <: actual`.
Expand All @@ -125,7 +126,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
define_opaque_types: DefineOpaqueTypes,
expected: T,
actual: T,
) -> InferResult<'tcx, ()>
) -> UnitInferResult<'tcx>
where
T: ToTrace<'tcx>,
{
Expand All @@ -136,7 +137,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
define_opaque_types,
);
fields.sub().relate(expected, actual)?;
Ok(InferOk { value: (), obligations: fields.into_obligations() })
Ok(fields.into_obligations())
}

/// Makes `expected == actual`.
Expand All @@ -145,7 +146,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
define_opaque_types: DefineOpaqueTypes,
expected: T,
actual: T,
) -> InferResult<'tcx, ()>
) -> UnitInferResult<'tcx>
where
T: ToTrace<'tcx>,
{
Expand All @@ -164,49 +165,24 @@ impl<'a, 'tcx> At<'a, 'tcx> {
trace: TypeTrace<'tcx>,
expected: T,
actual: T,
) -> InferResult<'tcx, ()>
) -> UnitInferResult<'tcx>
where
T: Relate<TyCtxt<'tcx>>,
{
let mut fields = CombineFields::new(self.infcx, trace, self.param_env, define_opaque_types);
fields.equate(StructurallyRelateAliases::No).relate(expected, actual)?;
Ok(InferOk {
value: (),
obligations: fields
.goals
.into_iter()
.map(|goal| {
Obligation::new(
self.infcx.tcx,
fields.trace.cause.clone(),
goal.param_env,
goal.predicate,
)
})
.collect(),
})
}

/// Equates `expected` and `found` while structurally relating aliases.
/// This should only be used inside of the next generation trait solver
/// when relating rigid aliases.
pub fn eq_structurally_relating_aliases<T>(
self,
expected: T,
actual: T,
) -> InferResult<'tcx, ()>
where
T: ToTrace<'tcx>,
{
assert!(self.infcx.next_trait_solver());
let mut fields = CombineFields::new(
self.infcx,
ToTrace::to_trace(self.cause, expected, actual),
self.param_env,
DefineOpaqueTypes::Yes,
);
fields.equate(StructurallyRelateAliases::Yes).relate(expected, actual)?;
Ok(InferOk { value: (), obligations: fields.into_obligations() })
Ok(fields
.goals
.into_iter()
.map(|goal| {
Obligation::new(
self.infcx.tcx,
fields.trace.cause.clone(),
goal.param_env,
goal.predicate,
)
})
.collect())
}

pub fn relate<T>(
Expand All @@ -215,7 +191,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
expected: T,
variance: ty::Variance,
actual: T,
) -> InferResult<'tcx, ()>
) -> UnitInferResult<'tcx>
where
T: ToTrace<'tcx>,
{
Expand Down
Loading
Loading