Skip to content

Commit 61b3b02

Browse files
Remove unnecessary DefineOpaqueTypes from lub
1 parent c616402 commit 61b3b02

File tree

3 files changed

+16
-42
lines changed

3 files changed

+16
-42
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

+7-19
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
141141
let at = self.at(&self.cause, self.fcx.param_env);
142142

143143
let res = if self.use_lub {
144-
at.lub(DefineOpaqueTypes::Yes, b, a)
144+
at.lub(b, a)
145145
} else {
146146
at.sup(DefineOpaqueTypes::Yes, b, a)
147147
.map(|InferOk { value: (), obligations }| InferOk { value: b, obligations })
@@ -1190,13 +1190,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11901190
(ty::FnDef(..), ty::FnDef(..)) => {
11911191
// Don't reify if the function types have a LUB, i.e., they
11921192
// are the same function and their parameters have a LUB.
1193-
match self.commit_if_ok(|_| {
1194-
self.at(cause, self.param_env).lub(
1195-
DefineOpaqueTypes::Yes,
1196-
prev_ty,
1197-
new_ty,
1198-
)
1199-
}) {
1193+
match self
1194+
.commit_if_ok(|_| self.at(cause, self.param_env).lub(prev_ty, new_ty))
1195+
{
12001196
// We have a LUB of prev_ty and new_ty, just return it.
12011197
Ok(ok) => return Ok(self.register_infer_ok_obligations(ok)),
12021198
Err(_) => {
@@ -1239,7 +1235,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12391235
let (a_sig, b_sig) = self.normalize(new.span, (a_sig, b_sig));
12401236
let sig = self
12411237
.at(cause, self.param_env)
1242-
.lub(DefineOpaqueTypes::Yes, a_sig, b_sig)
1238+
.lub(a_sig, b_sig)
12431239
.map(|ok| self.register_infer_ok_obligations(ok))?;
12441240

12451241
// Reify both sides and return the reified fn pointer type.
@@ -1330,9 +1326,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13301326
);
13311327

13321328
return Err(self
1333-
.commit_if_ok(|_| {
1334-
self.at(cause, self.param_env).lub(DefineOpaqueTypes::Yes, prev_ty, new_ty)
1335-
})
1329+
.commit_if_ok(|_| self.at(cause, self.param_env).lub(prev_ty, new_ty))
13361330
.unwrap_err());
13371331
}
13381332
}
@@ -1344,13 +1338,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13441338
Err(e)
13451339
} else {
13461340
Err(self
1347-
.commit_if_ok(|_| {
1348-
self.at(cause, self.param_env).lub(
1349-
DefineOpaqueTypes::Yes,
1350-
prev_ty,
1351-
new_ty,
1352-
)
1353-
})
1341+
.commit_if_ok(|_| self.at(cause, self.param_env).lub(prev_ty, new_ty))
13541342
.unwrap_err())
13551343
}
13561344
}

compiler/rustc_infer/src/infer/at.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -281,20 +281,14 @@ impl<'a, 'tcx> At<'a, 'tcx> {
281281
/// this can result in an error (e.g., if asked to compute LUB of
282282
/// u32 and i32), it is meaningful to call one of them the
283283
/// "expected type".
284-
pub fn lub<T>(
285-
self,
286-
define_opaque_types: DefineOpaqueTypes,
287-
expected: T,
288-
actual: T,
289-
) -> InferResult<'tcx, T>
284+
pub fn lub<T>(self, expected: T, actual: T) -> InferResult<'tcx, T>
290285
where
291286
T: ToTrace<'tcx>,
292287
{
293288
let mut op = LatticeOp::new(
294289
self.infcx,
295290
ToTrace::to_trace(self.cause, expected, actual),
296291
self.param_env,
297-
define_opaque_types,
298292
LatticeOpKind::Lub,
299293
);
300294
let value = op.relate(expected, actual)?;
@@ -304,20 +298,14 @@ impl<'a, 'tcx> At<'a, 'tcx> {
304298
/// Computes the greatest-lower-bound, or mutual subtype, of two
305299
/// values. As with `lub` order doesn't matter, except for error
306300
/// cases.
307-
pub fn glb<T>(
308-
self,
309-
define_opaque_types: DefineOpaqueTypes,
310-
expected: T,
311-
actual: T,
312-
) -> InferResult<'tcx, T>
301+
pub fn glb<T>(self, expected: T, actual: T) -> InferResult<'tcx, T>
313302
where
314303
T: ToTrace<'tcx>,
315304
{
316305
let mut op = LatticeOp::new(
317306
self.infcx,
318307
ToTrace::to_trace(self.cause, expected, actual),
319308
self.param_env,
320-
define_opaque_types,
321309
LatticeOpKind::Glb,
322310
);
323311
let value = op.relate(expected, actual)?;

compiler/rustc_infer/src/infer/relate/lattice.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ pub(crate) struct LatticeOp<'infcx, 'tcx> {
4949
// Immutable fields
5050
trace: TypeTrace<'tcx>,
5151
param_env: ty::ParamEnv<'tcx>,
52-
define_opaque_types: DefineOpaqueTypes,
5352
// Mutable fields
5453
//
5554
// Adding any additional field likely requires
@@ -63,10 +62,9 @@ impl<'infcx, 'tcx> LatticeOp<'infcx, 'tcx> {
6362
infcx: &'infcx InferCtxt<'tcx>,
6463
trace: TypeTrace<'tcx>,
6564
param_env: ty::ParamEnv<'tcx>,
66-
define_opaque_types: DefineOpaqueTypes,
6765
kind: LatticeOpKind,
6866
) -> LatticeOp<'infcx, 'tcx> {
69-
LatticeOp { infcx, trace, param_env, define_opaque_types, kind, obligations: vec![] }
67+
LatticeOp { infcx, trace, param_env, kind, obligations: vec![] }
7068
}
7169

7270
pub(crate) fn into_obligations(self) -> Vec<PredicateObligation<'tcx>> {
@@ -91,7 +89,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for LatticeOp<'_, 'tcx> {
9189
self.obligations.extend(
9290
self.infcx
9391
.at(&self.trace.cause, self.param_env)
94-
.eq_trace(self.define_opaque_types, self.trace.clone(), a, b)?
92+
.eq_trace(DefineOpaqueTypes::Yes, self.trace.clone(), a, b)?
9593
.into_obligations(),
9694
);
9795
Ok(a)
@@ -157,7 +155,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for LatticeOp<'_, 'tcx> {
157155

158156
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _)
159157
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
160-
if self.define_opaque_types == DefineOpaqueTypes::Yes
158+
if DefineOpaqueTypes::Yes == DefineOpaqueTypes::Yes
161159
&& def_id.is_local()
162160
&& !infcx.next_trait_solver() =>
163161
{
@@ -238,12 +236,12 @@ impl<'infcx, 'tcx> LatticeOp<'infcx, 'tcx> {
238236
let at = self.infcx.at(&self.trace.cause, self.param_env);
239237
match self.kind {
240238
LatticeOpKind::Glb => {
241-
self.obligations.extend(at.sub(self.define_opaque_types, v, a)?.into_obligations());
242-
self.obligations.extend(at.sub(self.define_opaque_types, v, b)?.into_obligations());
239+
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, v, a)?.into_obligations());
240+
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, v, b)?.into_obligations());
243241
}
244242
LatticeOpKind::Lub => {
245-
self.obligations.extend(at.sub(self.define_opaque_types, a, v)?.into_obligations());
246-
self.obligations.extend(at.sub(self.define_opaque_types, b, v)?.into_obligations());
243+
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, a, v)?.into_obligations());
244+
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, b, v)?.into_obligations());
247245
}
248246
}
249247
Ok(())

0 commit comments

Comments
 (0)