remove questionable calls to commit_if_ok

This commit is contained in:
lcnr 2024-02-13 05:34:09 +01:00
parent 0a5b998c57
commit ae92334c0f
4 changed files with 59 additions and 69 deletions

View File

@ -285,13 +285,11 @@ pub fn sub<T>(self, define_opaque_types: DefineOpaqueTypes, a: T, b: T) -> Infer
T: Relate<'tcx>,
{
let Trace { at, trace, a_is_expected } = self;
at.infcx.commit_if_ok(|_| {
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
fields
.sub(a_is_expected)
.relate(a, b)
.map(move |_| InferOk { value: (), obligations: fields.obligations })
})
}
/// Makes `a == b`; the expectation is set by the call to
@ -302,13 +300,11 @@ pub fn eq<T>(self, define_opaque_types: DefineOpaqueTypes, a: T, b: T) -> InferR
T: Relate<'tcx>,
{
let Trace { at, trace, a_is_expected } = self;
at.infcx.commit_if_ok(|_| {
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
fields
.equate(a_is_expected)
.relate(a, b)
.map(move |_| InferOk { value: (), obligations: fields.obligations })
})
}
#[instrument(skip(self), level = "debug")]
@ -317,13 +313,11 @@ pub fn lub<T>(self, define_opaque_types: DefineOpaqueTypes, a: T, b: T) -> Infer
T: Relate<'tcx>,
{
let Trace { at, trace, a_is_expected } = self;
at.infcx.commit_if_ok(|_| {
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
fields
.lub(a_is_expected)
.relate(a, b)
.map(move |t| InferOk { value: t, obligations: fields.obligations })
})
}
#[instrument(skip(self), level = "debug")]
@ -332,13 +326,11 @@ pub fn glb<T>(self, define_opaque_types: DefineOpaqueTypes, a: T, b: T) -> Infer
T: Relate<'tcx>,
{
let Trace { at, trace, a_is_expected } = self;
at.infcx.commit_if_ok(|_| {
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
fields
.glb(a_is_expected)
.relate(a, b)
.map(move |t| InferOk { value: t, obligations: fields.obligations })
})
}
}

View File

@ -620,7 +620,6 @@ fn unify_canonical_vars(
variables1: &OriginalQueryValues<'tcx>,
variables2: impl Fn(BoundVar) -> GenericArg<'tcx>,
) -> InferResult<'tcx, ()> {
self.commit_if_ok(|_| {
let mut obligations = vec![];
for (index, value1) in variables1.var_values.iter().enumerate() {
let value2 = variables2(BoundVar::new(index));
@ -655,7 +654,6 @@ fn unify_canonical_vars(
}
}
Ok(InferOk { value: (), obligations })
})
}
}

View File

@ -192,13 +192,13 @@ fn confirm_projection_candidate(
&mut obligations,
);
obligations.extend(self.infcx.commit_if_ok(|_| {
obligations.extend(
self.infcx
.at(&obligation.cause, obligation.param_env)
.sup(DefineOpaqueTypes::No, placeholder_trait_predicate, candidate)
.map(|InferOk { obligations, .. }| obligations)
.map_err(|_| Unimplemented)
})?);
.map_err(|_| Unimplemented)?,
);
// FIXME(compiler-errors): I don't think this is needed.
if let ty::Alias(ty::Projection, alias_ty) = placeholder_self_ty.kind() {
@ -532,13 +532,13 @@ fn confirm_object_candidate(
&mut nested,
);
nested.extend(self.infcx.commit_if_ok(|_| {
nested.extend(
self.infcx
.at(&obligation.cause, obligation.param_env)
.sup(DefineOpaqueTypes::No, obligation_trait_ref, upcast_trait_ref)
.map(|InferOk { obligations, .. }| obligations)
.map_err(|_| Unimplemented)
})?);
.map_err(|_| Unimplemented)?,
);
// Check supertraits hold. This is so that their associated type bounds
// will be checked in the code below.

View File

@ -9,8 +9,8 @@ LL | |
LL | | });
| |______^ expected due to this
|
= note: expected closure signature `fn(_, _) -> _`
found closure signature `fn(u32, i32) -> _`
= note: expected closure signature `fn(_, u32) -> _`
found closure signature `fn(_, i32) -> _`
note: required by a bound in `with_closure`
--> $DIR/expect-infer-var-appearing-twice.rs:2:14
|