Skip to content

Commit 5d62afd

Browse files
Remove unnecessary DefineOpaqueTypes from lub
1 parent da71dfb commit 5d62afd

File tree

3 files changed

+16
-44
lines changed

3 files changed

+16
-44
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
@@ -280,20 +280,14 @@ impl<'a, 'tcx> At<'a, 'tcx> {
280280
/// this can result in an error (e.g., if asked to compute LUB of
281281
/// u32 and i32), it is meaningful to call one of them the
282282
/// "expected type".
283-
pub fn lub<T>(
284-
self,
285-
define_opaque_types: DefineOpaqueTypes,
286-
expected: T,
287-
actual: T,
288-
) -> InferResult<'tcx, T>
283+
pub fn lub<T>(self, expected: T, actual: T) -> InferResult<'tcx, T>
289284
where
290285
T: ToTrace<'tcx>,
291286
{
292287
let mut op = LatticeOp::new(
293288
self.infcx,
294289
ToTrace::to_trace(self.cause, expected, actual),
295290
self.param_env,
296-
define_opaque_types,
297291
LatticeOpKind::Lub,
298292
);
299293
let value = op.relate(expected, actual)?;
@@ -303,20 +297,14 @@ impl<'a, 'tcx> At<'a, 'tcx> {
303297
/// Computes the greatest-lower-bound, or mutual subtype, of two
304298
/// values. As with `lub` order doesn't matter, except for error
305299
/// cases.
306-
pub fn glb<T>(
307-
self,
308-
define_opaque_types: DefineOpaqueTypes,
309-
expected: T,
310-
actual: T,
311-
) -> InferResult<'tcx, T>
300+
pub fn glb<T>(self, expected: T, actual: T) -> InferResult<'tcx, T>
312301
where
313302
T: ToTrace<'tcx>,
314303
{
315304
let mut op = LatticeOp::new(
316305
self.infcx,
317306
ToTrace::to_trace(self.cause, expected, actual),
318307
self.param_env,
319-
define_opaque_types,
320308
LatticeOpKind::Glb,
321309
);
322310
let value = op.relate(expected, actual)?;

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

+7-11
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
kind: LatticeOpKind,
5554
obligations: Vec<PredicateObligation<'tcx>>,
@@ -60,10 +59,9 @@ impl<'infcx, 'tcx> LatticeOp<'infcx, 'tcx> {
6059
infcx: &'infcx InferCtxt<'tcx>,
6160
trace: TypeTrace<'tcx>,
6261
param_env: ty::ParamEnv<'tcx>,
63-
define_opaque_types: DefineOpaqueTypes,
6462
kind: LatticeOpKind,
6563
) -> LatticeOp<'infcx, 'tcx> {
66-
LatticeOp { infcx, trace, param_env, define_opaque_types, kind, obligations: vec![] }
64+
LatticeOp { infcx, trace, param_env, kind, obligations: vec![] }
6765
}
6866

6967
pub(crate) fn into_obligations(self) -> Vec<PredicateObligation<'tcx>> {
@@ -88,7 +86,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for LatticeOp<'_, 'tcx> {
8886
self.obligations.extend(
8987
self.infcx
9088
.at(&self.trace.cause, self.param_env)
91-
.eq_trace(self.define_opaque_types, self.trace.clone(), a, b)?
89+
.eq_trace(DefineOpaqueTypes::Yes, self.trace.clone(), a, b)?
9290
.into_obligations(),
9391
);
9492
Ok(a)
@@ -154,9 +152,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for LatticeOp<'_, 'tcx> {
154152

155153
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _)
156154
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
157-
if self.define_opaque_types == DefineOpaqueTypes::Yes
158-
&& def_id.is_local()
159-
&& !infcx.next_trait_solver() =>
155+
if def_id.is_local() && !infcx.next_trait_solver() =>
160156
{
161157
self.register_goals(infcx.handle_opaque_type(
162158
a,
@@ -235,12 +231,12 @@ impl<'infcx, 'tcx> LatticeOp<'infcx, 'tcx> {
235231
let at = self.infcx.at(&self.trace.cause, self.param_env);
236232
match self.kind {
237233
LatticeOpKind::Glb => {
238-
self.obligations.extend(at.sub(self.define_opaque_types, v, a)?.into_obligations());
239-
self.obligations.extend(at.sub(self.define_opaque_types, v, b)?.into_obligations());
234+
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, v, a)?.into_obligations());
235+
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, v, b)?.into_obligations());
240236
}
241237
LatticeOpKind::Lub => {
242-
self.obligations.extend(at.sub(self.define_opaque_types, a, v)?.into_obligations());
243-
self.obligations.extend(at.sub(self.define_opaque_types, b, v)?.into_obligations());
238+
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, a, v)?.into_obligations());
239+
self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, b, v)?.into_obligations());
244240
}
245241
}
246242
Ok(())

0 commit comments

Comments
 (0)