Skip to content

Commit ea66e5b

Browse files
committed
DeepRejectCtxt: unite (Rigid, _) | (_, Rigid) branches
1 parent 77fc853 commit ea66e5b

File tree

1 file changed

+61
-59
lines changed

1 file changed

+61
-59
lines changed

Diff for: compiler/rustc_type_ir/src/fast_reject.rs

+61-59
Original file line numberDiff line numberDiff line change
@@ -232,89 +232,61 @@ impl<I: Interner> DeepRejectCtxt<I> {
232232
(ty::Param(lhs), ty::Param(rhs)) => {
233233
match (self.treat_lhs_params, self.treat_rhs_params) {
234234
(TreatParams::AsRigid, TreatParams::AsRigid) => lhs == rhs,
235-
(TreatParams::InstantiateWithInfer, TreatParams::AsRigid)
236-
| (TreatParams::AsRigid, TreatParams::InstantiateWithInfer)
237-
| (TreatParams::InstantiateWithInfer, TreatParams::InstantiateWithInfer) => {
238-
true
239-
}
235+
(TreatParams::InstantiateWithInfer, _)
236+
| (_, TreatParams::InstantiateWithInfer) => true,
240237
}
241238
}
242-
(ty::Param(_), ty::Placeholder(_)) | (ty::Placeholder(_), ty::Param(_)) => true,
243239
(ty::Param(_), _) => self.treat_lhs_params == TreatParams::InstantiateWithInfer,
244240
(_, ty::Param(_)) => self.treat_rhs_params == TreatParams::InstantiateWithInfer,
245241

246242
// Placeholder types don't unify with anything on their own.
247243
(ty::Placeholder(lhs), ty::Placeholder(rhs)) => lhs == rhs,
248-
(ty::Placeholder(_), _) | (_, ty::Placeholder(_)) => false,
249244

250245
// Purely rigid types, use structural equivalence.
251-
(ty::Bool, ty::Bool) => lhs == rhs,
252-
(ty::Bool, _) | (_, ty::Bool) => false,
253-
254-
(ty::Char, ty::Char) => lhs == rhs,
255-
(ty::Char, _) | (_, ty::Char) => false,
256-
257-
(ty::Int(_), ty::Int(_)) => lhs == rhs,
258-
(ty::Int(_), _) | (_, ty::Int(_)) => false,
259-
260-
(ty::Uint(_), ty::Uint(_)) => lhs == rhs,
261-
(ty::Uint(_), _) | (_, ty::Uint(_)) => false,
262-
263-
(ty::Float(_), ty::Float(_)) => lhs == rhs,
264-
(ty::Float(_), _) | (_, ty::Float(_)) => false,
265-
266-
(ty::Str, ty::Str) => lhs == rhs,
267-
(ty::Str, _) | (_, ty::Str) => false,
268-
269-
(ty::Never, ty::Never) => lhs == rhs,
270-
(ty::Never, _) | (_, ty::Never) => false,
271-
272-
(ty::Foreign(_), ty::Foreign(_)) => lhs == rhs,
273-
(ty::Foreign(_), _) | (_, ty::Foreign(_)) => false,
246+
(ty::Bool, ty::Bool)
247+
| (ty::Char, ty::Char)
248+
| (ty::Int(_), ty::Int(_))
249+
| (ty::Uint(_), ty::Uint(_))
250+
| (ty::Float(_), ty::Float(_))
251+
| (ty::Str, ty::Str)
252+
| (ty::Never, ty::Never)
253+
| (ty::Foreign(_), ty::Foreign(_)) => lhs == rhs,
274254

275255
(ty::Ref(_, lhs_ty, lhs_mutbl), ty::Ref(_, rhs_ty, rhs_mutbl)) => {
276256
lhs_mutbl == rhs_mutbl && self.types_may_unify(lhs_ty, rhs_ty)
277257
}
278-
(ty::Ref(..), _) | (_, ty::Ref(..)) => false,
279258

280259
(ty::Adt(lhs_def, lhs_args), ty::Adt(rhs_def, rhs_args)) => {
281260
lhs_def == rhs_def && self.args_may_unify(lhs_args, rhs_args)
282261
}
283-
(ty::Adt(..), _) | (_, ty::Adt(..)) => false,
284262

285263
(ty::Pat(lhs_ty, _), ty::Pat(rhs_ty, _)) => {
286264
// FIXME(pattern_types): take pattern into account
287265
self.types_may_unify(lhs_ty, rhs_ty)
288266
}
289-
(ty::Pat(..), _) | (_, ty::Pat(..)) => false,
290267

291268
(ty::Slice(lhs_ty), ty::Slice(rhs_ty)) => self.types_may_unify(lhs_ty, rhs_ty),
292-
(ty::Slice(_), _) | (_, ty::Slice(_)) => false,
293269

294270
(ty::Array(lhs_ty, lhs_len), ty::Array(rhs_ty, rhs_len)) => {
295271
self.types_may_unify(lhs_ty, rhs_ty) && self.consts_may_unify(lhs_len, rhs_len)
296272
}
297-
(ty::Array(..), _) | (_, ty::Array(..)) => false,
298273

299274
(ty::Tuple(lhs), ty::Tuple(rhs)) => {
300275
lhs.len() == rhs.len()
301276
&& iter::zip(lhs.iter(), rhs.iter())
302277
.all(|(lhs, rhs)| self.types_may_unify(lhs, rhs))
303278
}
304-
(ty::Tuple(_), _) | (_, ty::Tuple(_)) => false,
305279

306280
(ty::RawPtr(lhs_ty, lhs_mutbl), ty::RawPtr(rhs_ty, rhs_mutbl)) => {
307281
lhs_mutbl == rhs_mutbl && self.types_may_unify(lhs_ty, rhs_ty)
308282
}
309-
(ty::RawPtr(..), _) | (_, ty::RawPtr(..)) => false,
310283

311284
(ty::Dynamic(lhs_preds, ..), ty::Dynamic(rhs_preds, ..)) => {
312285
// Ideally we would walk the existential predicates here or at least
313286
// compare their length. But considering that the relevant `Relate` impl
314287
// actually sorts and deduplicates these, that doesn't work.
315288
lhs_preds.principal_def_id() == rhs_preds.principal_def_id()
316289
}
317-
(ty::Dynamic(..), _) | (_, ty::Dynamic(..)) => false,
318290

319291
(ty::FnPtr(lhs_sig), ty::FnPtr(rhs_sig)) => {
320292
let lhs_sig = lhs_sig.skip_binder();
@@ -327,33 +299,63 @@ impl<I: Interner> DeepRejectCtxt<I> {
327299
&& iter::zip(lhs_sig.inputs_and_output.iter(), rhs_sig.inputs_and_output.iter())
328300
.all(|(lhs, rhs)| self.types_may_unify(lhs, rhs))
329301
}
330-
(ty::FnPtr(..), _) | (_, ty::FnPtr(..)) => false,
331-
332-
(ty::FnDef(lhs_def_id, lhs_args), ty::FnDef(rhs_def_id, rhs_args)) => {
333-
lhs_def_id == rhs_def_id && self.args_may_unify(lhs_args, rhs_args)
334-
}
335-
(ty::FnDef(..), _) | (_, ty::FnDef(..)) => false,
336-
337-
(ty::Closure(lhs_def_id, lhs_args), ty::Closure(rhs_def_id, rhs_args)) => {
338-
lhs_def_id == rhs_def_id && self.args_may_unify(lhs_args, rhs_args)
339-
}
340-
(ty::Closure(..), _) | (_, ty::Closure(..)) => false,
341302

342-
(
303+
(ty::FnDef(lhs_def_id, lhs_args), ty::FnDef(rhs_def_id, rhs_args))
304+
| (ty::Closure(lhs_def_id, lhs_args), ty::Closure(rhs_def_id, rhs_args))
305+
| (
343306
ty::CoroutineClosure(lhs_def_id, lhs_args),
344307
ty::CoroutineClosure(rhs_def_id, rhs_args),
345-
) => lhs_def_id == rhs_def_id && self.args_may_unify(lhs_args, rhs_args),
346-
(ty::CoroutineClosure(..), _) | (_, ty::CoroutineClosure(..)) => false,
347-
348-
(ty::Coroutine(lhs_def_id, lhs_args), ty::Coroutine(rhs_def_id, rhs_args)) => {
349-
lhs_def_id == rhs_def_id && self.args_may_unify(lhs_args, rhs_args)
350-
}
351-
(ty::Coroutine(..), _) | (_, ty::Coroutine(..)) => false,
352-
353-
(
308+
)
309+
| (ty::Coroutine(lhs_def_id, lhs_args), ty::Coroutine(rhs_def_id, rhs_args))
310+
| (
354311
ty::CoroutineWitness(lhs_def_id, lhs_args),
355312
ty::CoroutineWitness(rhs_def_id, rhs_args),
356313
) => lhs_def_id == rhs_def_id && self.args_may_unify(lhs_args, rhs_args),
314+
315+
(ty::Placeholder(_), _)
316+
| (_, ty::Placeholder(_))
317+
| (ty::Bool, _)
318+
| (_, ty::Bool)
319+
| (ty::Char, _)
320+
| (_, ty::Char)
321+
| (ty::Int(_), _)
322+
| (_, ty::Int(_))
323+
| (ty::Uint(_), _)
324+
| (_, ty::Uint(_))
325+
| (ty::Float(_), _)
326+
| (_, ty::Float(_))
327+
| (ty::Str, _)
328+
| (_, ty::Str)
329+
| (ty::Never, _)
330+
| (_, ty::Never)
331+
| (ty::Foreign(_), _)
332+
| (_, ty::Foreign(_))
333+
| (ty::Ref(..), _)
334+
| (_, ty::Ref(..))
335+
| (ty::Adt(..), _)
336+
| (_, ty::Adt(..))
337+
| (ty::Pat(..), _)
338+
| (_, ty::Pat(..))
339+
| (ty::Slice(_), _)
340+
| (_, ty::Slice(_))
341+
| (ty::Array(..), _)
342+
| (_, ty::Array(..))
343+
| (ty::Tuple(_), _)
344+
| (_, ty::Tuple(_))
345+
| (ty::RawPtr(..), _)
346+
| (_, ty::RawPtr(..))
347+
| (ty::Dynamic(..), _)
348+
| (_, ty::Dynamic(..))
349+
| (ty::FnPtr(..), _)
350+
| (_, ty::FnPtr(..))
351+
| (ty::FnDef(..), _)
352+
| (_, ty::FnDef(..))
353+
| (ty::Closure(..), _)
354+
| (_, ty::Closure(..))
355+
| (ty::CoroutineClosure(..), _)
356+
| (_, ty::CoroutineClosure(..))
357+
| (ty::Coroutine(..), _)
358+
| (_, ty::Coroutine(..)) => false,
357359
}
358360
}
359361

0 commit comments

Comments
 (0)