Remove unnecessary DefineOpaqueTypes from lub
This commit is contained in:
parent
da71dfbc51
commit
5d62afd2ba
3 changed files with 16 additions and 44 deletions
|
@ -141,7 +141,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||||
let at = self.at(&self.cause, self.fcx.param_env);
|
let at = self.at(&self.cause, self.fcx.param_env);
|
||||||
|
|
||||||
let res = if self.use_lub {
|
let res = if self.use_lub {
|
||||||
at.lub(DefineOpaqueTypes::Yes, b, a)
|
at.lub(b, a)
|
||||||
} else {
|
} else {
|
||||||
at.sup(DefineOpaqueTypes::Yes, b, a)
|
at.sup(DefineOpaqueTypes::Yes, b, a)
|
||||||
.map(|InferOk { value: (), obligations }| InferOk { value: b, obligations })
|
.map(|InferOk { value: (), obligations }| InferOk { value: b, obligations })
|
||||||
|
@ -1190,13 +1190,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
(ty::FnDef(..), ty::FnDef(..)) => {
|
(ty::FnDef(..), ty::FnDef(..)) => {
|
||||||
// Don't reify if the function types have a LUB, i.e., they
|
// Don't reify if the function types have a LUB, i.e., they
|
||||||
// are the same function and their parameters have a LUB.
|
// are the same function and their parameters have a LUB.
|
||||||
match self.commit_if_ok(|_| {
|
match self
|
||||||
self.at(cause, self.param_env).lub(
|
.commit_if_ok(|_| self.at(cause, self.param_env).lub(prev_ty, new_ty))
|
||||||
DefineOpaqueTypes::Yes,
|
{
|
||||||
prev_ty,
|
|
||||||
new_ty,
|
|
||||||
)
|
|
||||||
}) {
|
|
||||||
// We have a LUB of prev_ty and new_ty, just return it.
|
// We have a LUB of prev_ty and new_ty, just return it.
|
||||||
Ok(ok) => return Ok(self.register_infer_ok_obligations(ok)),
|
Ok(ok) => return Ok(self.register_infer_ok_obligations(ok)),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
@ -1239,7 +1235,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let (a_sig, b_sig) = self.normalize(new.span, (a_sig, b_sig));
|
let (a_sig, b_sig) = self.normalize(new.span, (a_sig, b_sig));
|
||||||
let sig = self
|
let sig = self
|
||||||
.at(cause, self.param_env)
|
.at(cause, self.param_env)
|
||||||
.lub(DefineOpaqueTypes::Yes, a_sig, b_sig)
|
.lub(a_sig, b_sig)
|
||||||
.map(|ok| self.register_infer_ok_obligations(ok))?;
|
.map(|ok| self.register_infer_ok_obligations(ok))?;
|
||||||
|
|
||||||
// Reify both sides and return the reified fn pointer type.
|
// Reify both sides and return the reified fn pointer type.
|
||||||
|
@ -1330,9 +1326,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
);
|
);
|
||||||
|
|
||||||
return Err(self
|
return Err(self
|
||||||
.commit_if_ok(|_| {
|
.commit_if_ok(|_| self.at(cause, self.param_env).lub(prev_ty, new_ty))
|
||||||
self.at(cause, self.param_env).lub(DefineOpaqueTypes::Yes, prev_ty, new_ty)
|
|
||||||
})
|
|
||||||
.unwrap_err());
|
.unwrap_err());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1344,13 +1338,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
Err(e)
|
Err(e)
|
||||||
} else {
|
} else {
|
||||||
Err(self
|
Err(self
|
||||||
.commit_if_ok(|_| {
|
.commit_if_ok(|_| self.at(cause, self.param_env).lub(prev_ty, new_ty))
|
||||||
self.at(cause, self.param_env).lub(
|
|
||||||
DefineOpaqueTypes::Yes,
|
|
||||||
prev_ty,
|
|
||||||
new_ty,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.unwrap_err())
|
.unwrap_err())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,12 +280,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
|
||||||
/// this can result in an error (e.g., if asked to compute LUB of
|
/// this can result in an error (e.g., if asked to compute LUB of
|
||||||
/// u32 and i32), it is meaningful to call one of them the
|
/// u32 and i32), it is meaningful to call one of them the
|
||||||
/// "expected type".
|
/// "expected type".
|
||||||
pub fn lub<T>(
|
pub fn lub<T>(self, expected: T, actual: T) -> InferResult<'tcx, T>
|
||||||
self,
|
|
||||||
define_opaque_types: DefineOpaqueTypes,
|
|
||||||
expected: T,
|
|
||||||
actual: T,
|
|
||||||
) -> InferResult<'tcx, T>
|
|
||||||
where
|
where
|
||||||
T: ToTrace<'tcx>,
|
T: ToTrace<'tcx>,
|
||||||
{
|
{
|
||||||
|
@ -293,7 +288,6 @@ impl<'a, 'tcx> At<'a, 'tcx> {
|
||||||
self.infcx,
|
self.infcx,
|
||||||
ToTrace::to_trace(self.cause, expected, actual),
|
ToTrace::to_trace(self.cause, expected, actual),
|
||||||
self.param_env,
|
self.param_env,
|
||||||
define_opaque_types,
|
|
||||||
LatticeOpKind::Lub,
|
LatticeOpKind::Lub,
|
||||||
);
|
);
|
||||||
let value = op.relate(expected, actual)?;
|
let value = op.relate(expected, actual)?;
|
||||||
|
@ -303,12 +297,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
|
||||||
/// Computes the greatest-lower-bound, or mutual subtype, of two
|
/// Computes the greatest-lower-bound, or mutual subtype, of two
|
||||||
/// values. As with `lub` order doesn't matter, except for error
|
/// values. As with `lub` order doesn't matter, except for error
|
||||||
/// cases.
|
/// cases.
|
||||||
pub fn glb<T>(
|
pub fn glb<T>(self, expected: T, actual: T) -> InferResult<'tcx, T>
|
||||||
self,
|
|
||||||
define_opaque_types: DefineOpaqueTypes,
|
|
||||||
expected: T,
|
|
||||||
actual: T,
|
|
||||||
) -> InferResult<'tcx, T>
|
|
||||||
where
|
where
|
||||||
T: ToTrace<'tcx>,
|
T: ToTrace<'tcx>,
|
||||||
{
|
{
|
||||||
|
@ -316,7 +305,6 @@ impl<'a, 'tcx> At<'a, 'tcx> {
|
||||||
self.infcx,
|
self.infcx,
|
||||||
ToTrace::to_trace(self.cause, expected, actual),
|
ToTrace::to_trace(self.cause, expected, actual),
|
||||||
self.param_env,
|
self.param_env,
|
||||||
define_opaque_types,
|
|
||||||
LatticeOpKind::Glb,
|
LatticeOpKind::Glb,
|
||||||
);
|
);
|
||||||
let value = op.relate(expected, actual)?;
|
let value = op.relate(expected, actual)?;
|
||||||
|
|
|
@ -49,7 +49,6 @@ pub(crate) struct LatticeOp<'infcx, 'tcx> {
|
||||||
// Immutable fields
|
// Immutable fields
|
||||||
trace: TypeTrace<'tcx>,
|
trace: TypeTrace<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
define_opaque_types: DefineOpaqueTypes,
|
|
||||||
// Mutable fields
|
// Mutable fields
|
||||||
kind: LatticeOpKind,
|
kind: LatticeOpKind,
|
||||||
obligations: Vec<PredicateObligation<'tcx>>,
|
obligations: Vec<PredicateObligation<'tcx>>,
|
||||||
|
@ -60,10 +59,9 @@ impl<'infcx, 'tcx> LatticeOp<'infcx, 'tcx> {
|
||||||
infcx: &'infcx InferCtxt<'tcx>,
|
infcx: &'infcx InferCtxt<'tcx>,
|
||||||
trace: TypeTrace<'tcx>,
|
trace: TypeTrace<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
define_opaque_types: DefineOpaqueTypes,
|
|
||||||
kind: LatticeOpKind,
|
kind: LatticeOpKind,
|
||||||
) -> LatticeOp<'infcx, 'tcx> {
|
) -> LatticeOp<'infcx, 'tcx> {
|
||||||
LatticeOp { infcx, trace, param_env, define_opaque_types, kind, obligations: vec![] }
|
LatticeOp { infcx, trace, param_env, kind, obligations: vec![] }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn into_obligations(self) -> Vec<PredicateObligation<'tcx>> {
|
pub(crate) fn into_obligations(self) -> Vec<PredicateObligation<'tcx>> {
|
||||||
|
@ -88,7 +86,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for LatticeOp<'_, 'tcx> {
|
||||||
self.obligations.extend(
|
self.obligations.extend(
|
||||||
self.infcx
|
self.infcx
|
||||||
.at(&self.trace.cause, self.param_env)
|
.at(&self.trace.cause, self.param_env)
|
||||||
.eq_trace(self.define_opaque_types, self.trace.clone(), a, b)?
|
.eq_trace(DefineOpaqueTypes::Yes, self.trace.clone(), a, b)?
|
||||||
.into_obligations(),
|
.into_obligations(),
|
||||||
);
|
);
|
||||||
Ok(a)
|
Ok(a)
|
||||||
|
@ -154,9 +152,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for LatticeOp<'_, 'tcx> {
|
||||||
|
|
||||||
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _)
|
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _)
|
||||||
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
|
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
|
||||||
if self.define_opaque_types == DefineOpaqueTypes::Yes
|
if def_id.is_local() && !infcx.next_trait_solver() =>
|
||||||
&& def_id.is_local()
|
|
||||||
&& !infcx.next_trait_solver() =>
|
|
||||||
{
|
{
|
||||||
self.register_goals(infcx.handle_opaque_type(
|
self.register_goals(infcx.handle_opaque_type(
|
||||||
a,
|
a,
|
||||||
|
@ -235,12 +231,12 @@ impl<'infcx, 'tcx> LatticeOp<'infcx, 'tcx> {
|
||||||
let at = self.infcx.at(&self.trace.cause, self.param_env);
|
let at = self.infcx.at(&self.trace.cause, self.param_env);
|
||||||
match self.kind {
|
match self.kind {
|
||||||
LatticeOpKind::Glb => {
|
LatticeOpKind::Glb => {
|
||||||
self.obligations.extend(at.sub(self.define_opaque_types, v, a)?.into_obligations());
|
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, v, a)?.into_obligations());
|
||||||
self.obligations.extend(at.sub(self.define_opaque_types, v, b)?.into_obligations());
|
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, v, b)?.into_obligations());
|
||||||
}
|
}
|
||||||
LatticeOpKind::Lub => {
|
LatticeOpKind::Lub => {
|
||||||
self.obligations.extend(at.sub(self.define_opaque_types, a, v)?.into_obligations());
|
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, a, v)?.into_obligations());
|
||||||
self.obligations.extend(at.sub(self.define_opaque_types, b, v)?.into_obligations());
|
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, b, v)?.into_obligations());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue