From 4a82bc9ea058a3f64e0ffb9f08ce3302a60a0990 Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 4 Apr 2022 10:56:59 +0200 Subject: [PATCH] `bool` to custom enum --- compiler/rustc_middle/src/ty/util.rs | 23 +++++++++++-------- compiler/rustc_typeck/src/check/dropck.rs | 3 ++- compiler/rustc_typeck/src/coherence/orphan.rs | 3 ++- 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 @@ pub fn destructor_constraints(self, def: ty::AdtDef<'tcx>) -> Vec, - 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_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_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: