Skip to content

Commit 4a82bc9

Browse files
committed
bool to custom enum
1 parent ced6502 commit 4a82bc9

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

compiler/rustc_middle/src/ty/util.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ pub struct Discr<'tcx> {
3030
pub ty: Ty<'tcx>,
3131
}
3232

33+
/// Used as an input to [`TyCtxt::uses_unique_generic_params`].
34+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
35+
pub enum IgnoreRegions {
36+
Yes,
37+
No,
38+
}
39+
3340
#[derive(Copy, Clone, Debug)]
3441
pub enum NotUniqueParam<'tcx> {
3542
DuplicateParam(ty::GenericArg<'tcx>),
@@ -461,20 +468,18 @@ impl<'tcx> TyCtxt<'tcx> {
461468
pub fn uses_unique_generic_params(
462469
self,
463470
substs: SubstsRef<'tcx>,
464-
ignore_regions: bool,
471+
ignore_regions: IgnoreRegions,
465472
) -> Result<(), NotUniqueParam<'tcx>> {
466473
let mut seen = GrowableBitSet::default();
467474
for arg in substs {
468475
match arg.unpack() {
469476
GenericArgKind::Lifetime(lt) => {
470-
if !ignore_regions {
471-
match lt.kind() {
472-
ty::ReEarlyBound(p) => {
473-
if !seen.insert(p.index) {
474-
return Err(NotUniqueParam::DuplicateParam(lt.into()));
475-
}
476-
}
477-
_ => return Err(NotUniqueParam::NotParam(lt.into())),
477+
if ignore_regions == IgnoreRegions::No {
478+
let ty::ReEarlyBound(p) = lt.kind() else {
479+
return Err(NotUniqueParam::NotParam(lt.into()))
480+
};
481+
if !seen.insert(p.index) {
482+
return Err(NotUniqueParam::DuplicateParam(lt.into()));
478483
}
479484
}
480485
}

compiler/rustc_typeck/src/check/dropck.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_errors::{struct_span_err, ErrorGuaranteed};
55
use rustc_middle::ty::error::TypeError;
66
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
77
use rustc_middle::ty::subst::SubstsRef;
8+
use rustc_middle::ty::util::IgnoreRegions;
89
use rustc_middle::ty::{self, Predicate, Ty, TyCtxt};
910
use rustc_span::Span;
1011
use rustc_trait_selection::traits::query::dropck_outlives::AtExt;
@@ -66,7 +67,7 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
6667
self_type_did: DefId,
6768
drop_impl_substs: SubstsRef<'tcx>,
6869
) -> Result<(), ErrorGuaranteed> {
69-
let Err(arg) = tcx.uses_unique_generic_params(drop_impl_substs, false) else {
70+
let Err(arg) = tcx.uses_unique_generic_params(drop_impl_substs, IgnoreRegions::No) else {
7071
return Ok(())
7172
};
7273

compiler/rustc_typeck/src/coherence/orphan.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_hir as hir;
88
use rustc_infer::infer::TyCtxtInferExt;
99
use rustc_middle::ty::subst::GenericArgKind;
1010
use rustc_middle::ty::subst::InternalSubsts;
11+
use rustc_middle::ty::util::IgnoreRegions;
1112
use rustc_middle::ty::{self, ImplPolarity, Ty, TyCtxt, TypeFoldable, TypeVisitor};
1213
use rustc_session::lint;
1314
use rustc_span::def_id::{DefId, LocalDefId};
@@ -354,7 +355,7 @@ fn lint_auto_trait_impls(tcx: TyCtxt<'_>, trait_def_id: DefId, impls: &[LocalDef
354355
// Impls which completely cover a given root type are fine as they
355356
// disable auto impls entirely. So only lint if the substs
356357
// are not a permutation of the identity substs.
357-
match tcx.uses_unique_generic_params(substs, true) {
358+
match tcx.uses_unique_generic_params(substs, IgnoreRegions::Yes) {
358359
Ok(()) => {} // ok
359360
Err(arg) => {
360361
// Ideally:

0 commit comments

Comments
 (0)