about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorlcnr <rust@lcnr.de>2022-04-04 10:56:59 +0200
committerlcnr <rust@lcnr.de>2022-05-20 11:50:07 +0200
commit4a82bc9ea058a3f64e0ffb9f08ce3302a60a0990 (patch)
treefbc8679b52f11d7c85b69398adb2784df729d586 /compiler
parentced65022dae81b46e629262d8458cc3e5ac8cec1 (diff)
downloadrust-4a82bc9ea058a3f64e0ffb9f08ce3302a60a0990.tar.gz
rust-4a82bc9ea058a3f64e0ffb9f08ce3302a60a0990.zip
`bool` to custom enum
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_middle/src/ty/util.rs23
-rw-r--r--compiler/rustc_typeck/src/check/dropck.rs3
-rw-r--r--compiler/rustc_typeck/src/coherence/orphan.rs3
3 files changed, 18 insertions, 11 deletions
diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs
index bf066f65aeb..809e7ce2e74 100644
--- a/compiler/rustc_middle/src/ty/util.rs
+++ b/compiler/rustc_middle/src/ty/util.rs
@@ -30,6 +30,13 @@ pub struct Discr<'tcx> {
     pub ty: Ty<'tcx>,
 }
 
+/// Used as an input to [`TyCtxt::uses_unique_generic_params`].
+#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+pub enum IgnoreRegions {
+    Yes,
+    No,
+}
+
 #[derive(Copy, Clone, Debug)]
 pub enum NotUniqueParam<'tcx> {
     DuplicateParam(ty::GenericArg<'tcx>),
@@ -461,20 +468,18 @@ impl<'tcx> TyCtxt<'tcx> {
     pub fn uses_unique_generic_params(
         self,
         substs: SubstsRef<'tcx>,
-        ignore_regions: bool,
+        ignore_regions: IgnoreRegions,
     ) -> Result<(), NotUniqueParam<'tcx>> {
         let mut seen = GrowableBitSet::default();
         for arg in substs {
             match arg.unpack() {
                 GenericArgKind::Lifetime(lt) => {
-                    if !ignore_regions {
-                        match lt.kind() {
-                            ty::ReEarlyBound(p) => {
-                                if !seen.insert(p.index) {
-                                    return Err(NotUniqueParam::DuplicateParam(lt.into()));
-                                }
-                            }
-                            _ => return Err(NotUniqueParam::NotParam(lt.into())),
+                    if ignore_regions == IgnoreRegions::No {
+                        let ty::ReEarlyBound(p) = lt.kind() else {
+                            return Err(NotUniqueParam::NotParam(lt.into()))
+                        };
+                        if !seen.insert(p.index) {
+                            return Err(NotUniqueParam::DuplicateParam(lt.into()));
                         }
                     }
                 }
diff --git a/compiler/rustc_typeck/src/check/dropck.rs b/compiler/rustc_typeck/src/check/dropck.rs
index 41b895f3bbf..f8853014d2f 100644
--- a/compiler/rustc_typeck/src/check/dropck.rs
+++ b/compiler/rustc_typeck/src/check/dropck.rs
@@ -5,6 +5,7 @@ use rustc_errors::{struct_span_err, ErrorGuaranteed};
 use rustc_middle::ty::error::TypeError;
 use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
 use rustc_middle::ty::subst::SubstsRef;
+use rustc_middle::ty::util::IgnoreRegions;
 use rustc_middle::ty::{self, Predicate, Ty, TyCtxt};
 use rustc_span::Span;
 use rustc_trait_selection::traits::query::dropck_outlives::AtExt;
@@ -66,7 +67,7 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
     self_type_did: DefId,
     drop_impl_substs: SubstsRef<'tcx>,
 ) -> Result<(), ErrorGuaranteed> {
-    let Err(arg) = tcx.uses_unique_generic_params(drop_impl_substs, false) else {
+    let Err(arg) = tcx.uses_unique_generic_params(drop_impl_substs, IgnoreRegions::No) else {
         return Ok(())
     };
 
diff --git a/compiler/rustc_typeck/src/coherence/orphan.rs b/compiler/rustc_typeck/src/coherence/orphan.rs
index f8b3f1ac3df..eb6217f1174 100644
--- a/compiler/rustc_typeck/src/coherence/orphan.rs
+++ b/compiler/rustc_typeck/src/coherence/orphan.rs
@@ -8,6 +8,7 @@ use rustc_hir as hir;
 use rustc_infer::infer::TyCtxtInferExt;
 use rustc_middle::ty::subst::GenericArgKind;
 use rustc_middle::ty::subst::InternalSubsts;
+use rustc_middle::ty::util::IgnoreRegions;
 use rustc_middle::ty::{self, ImplPolarity, Ty, TyCtxt, TypeFoldable, TypeVisitor};
 use rustc_session::lint;
 use rustc_span::def_id::{DefId, LocalDefId};
@@ -354,7 +355,7 @@ fn lint_auto_trait_impls(tcx: TyCtxt<'_>, trait_def_id: DefId, impls: &[LocalDef
         // Impls which completely cover a given root type are fine as they
         // disable auto impls entirely. So only lint if the substs
         // are not a permutation of the identity substs.
-        match tcx.uses_unique_generic_params(substs, true) {
+        match tcx.uses_unique_generic_params(substs, IgnoreRegions::Yes) {
             Ok(()) => {} // ok
             Err(arg) => {
                 // Ideally: