diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2023-12-11 20:59:32 +0100 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2023-12-15 16:58:38 +0100 |
| commit | e646c9f7230becbe739d5c56fbb9952cb0d1b212 (patch) | |
| tree | 39cf2c00b62d7f10ddd5e2bdbba328942eca0595 /compiler/rustc_pattern_analysis/src | |
| parent | 16bd6ac3ed3e63cd6f2464b54026dbeb90ba6bbe (diff) | |
| download | rust-e646c9f7230becbe739d5c56fbb9952cb0d1b212.tar.gz rust-e646c9f7230becbe739d5c56fbb9952cb0d1b212.zip | |
Make the `rustc_data_structures` dependency optional
Diffstat (limited to 'compiler/rustc_pattern_analysis/src')
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/constructor.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/lib.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/pat.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/usefulness.rs | 10 |
4 files changed, 26 insertions, 12 deletions
diff --git a/compiler/rustc_pattern_analysis/src/constructor.rs b/compiler/rustc_pattern_analysis/src/constructor.rs index a3af4eb6d21..65312228801 100644 --- a/compiler/rustc_pattern_analysis/src/constructor.rs +++ b/compiler/rustc_pattern_analysis/src/constructor.rs @@ -155,7 +155,7 @@ use std::iter::once; use smallvec::SmallVec; use rustc_apfloat::ieee::{DoubleS, IeeeFloat, SingleS}; -use rustc_data_structures::fx::FxHashSet; +use rustc_index::bit_set::{BitSet, GrowableBitSet}; use rustc_index::IndexVec; use self::Constructor::*; @@ -546,7 +546,7 @@ impl Slice { // therefore `Presence::Seen` in the column. let mut min_var_len = usize::MAX; // Tracks the fixed-length slices we've seen, to mark them as `Presence::Seen`. - let mut seen_fixed_lens = FxHashSet::default(); + let mut seen_fixed_lens = GrowableBitSet::new_empty(); match &mut max_slice { VarLen(max_prefix_len, max_suffix_len) => { // A length larger than any fixed-length slice encountered. @@ -614,7 +614,7 @@ impl Slice { smaller_lengths.map(FixedLen).chain(once(max_slice)).map(move |kind| { let arity = kind.arity(); - let seen = if min_var_len <= arity || seen_fixed_lens.contains(&arity) { + let seen = if min_var_len <= arity || seen_fixed_lens.contains(arity) { Presence::Seen } else { Presence::Unseen @@ -906,12 +906,15 @@ impl<Cx: MatchCx> ConstructorSet<Cx> { } } ConstructorSet::Variants { variants, non_exhaustive } => { - let seen_set: FxHashSet<_> = seen.iter().map(|c| c.as_variant().unwrap()).collect(); + let mut seen_set: BitSet<_> = BitSet::new_empty(variants.len()); + for idx in seen.iter().map(|c| c.as_variant().unwrap()) { + seen_set.insert(idx); + } let mut skipped_a_hidden_variant = false; for (idx, visibility) in variants.iter_enumerated() { let ctor = Variant(idx); - if seen_set.contains(&idx) { + if seen_set.contains(idx) { present.push(ctor); } else { // We only put visible variants directly into `missing`. diff --git a/compiler/rustc_pattern_analysis/src/lib.rs b/compiler/rustc_pattern_analysis/src/lib.rs index 8b7898af5b1..e54f8d90d0d 100644 --- a/compiler/rustc_pattern_analysis/src/lib.rs +++ b/compiler/rustc_pattern_analysis/src/lib.rs @@ -79,6 +79,13 @@ pub struct MatchArm<'p, Cx: MatchCx> { impl<'p, Cx: MatchCx> Copy for MatchArm<'p, Cx> {} +#[cfg(not(feature = "rustc"))] +pub trait Captures<'a> {} +#[cfg(not(feature = "rustc"))] +impl<'a, T: ?Sized> Captures<'a> for T {} +#[cfg(feature = "rustc")] +pub use rustc_data_structures::captures::Captures; + /// The entrypoint for this crate. Computes whether a match is exhaustive and which of its arms are /// useful, and runs some lints. #[cfg(feature = "rustc")] diff --git a/compiler/rustc_pattern_analysis/src/pat.rs b/compiler/rustc_pattern_analysis/src/pat.rs index c1052c88514..f719cc511fb 100644 --- a/compiler/rustc_pattern_analysis/src/pat.rs +++ b/compiler/rustc_pattern_analysis/src/pat.rs @@ -5,13 +5,11 @@ use std::fmt; use smallvec::{smallvec, SmallVec}; -use rustc_data_structures::captures::Captures; - -use self::Constructor::*; - use crate::constructor::{Constructor, Slice, SliceKind}; use crate::usefulness::PatCtxt; -use crate::MatchCx; +use crate::{Captures, MatchCx}; + +use self::Constructor::*; /// Values and patterns can be represented as a constructor applied to some fields. This represents /// a pattern in this form. diff --git a/compiler/rustc_pattern_analysis/src/usefulness.rs b/compiler/rustc_pattern_analysis/src/usefulness.rs index b1cc0f3c722..01f3962b31f 100644 --- a/compiler/rustc_pattern_analysis/src/usefulness.rs +++ b/compiler/rustc_pattern_analysis/src/usefulness.rs @@ -556,14 +556,20 @@ use smallvec::{smallvec, SmallVec}; use std::fmt; use rustc_arena::TypedArena; -use rustc_data_structures::{captures::Captures, stack::ensure_sufficient_stack}; use crate::constructor::{Constructor, ConstructorSet}; use crate::pat::{DeconstructedPat, WitnessPat}; -use crate::{MatchArm, MatchCx}; +use crate::{Captures, MatchArm, MatchCx}; use self::ValidityConstraint::*; +#[cfg(feature = "rustc")] +use rustc_data_structures::stack::ensure_sufficient_stack; +#[cfg(not(feature = "rustc"))] +pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R { + f() +} + #[derive(Clone)] pub(crate) struct PatCtxt<'a, 'p, Cx: MatchCx> { pub(crate) cx: &'a Cx, |
