about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_pattern_analysis/Cargo.toml3
-rw-r--r--compiler/rustc_pattern_analysis/src/constructor.rs13
-rw-r--r--compiler/rustc_pattern_analysis/src/lib.rs7
-rw-r--r--compiler/rustc_pattern_analysis/src/pat.rs8
-rw-r--r--compiler/rustc_pattern_analysis/src/usefulness.rs10
5 files changed, 28 insertions, 13 deletions
diff --git a/compiler/rustc_pattern_analysis/Cargo.toml b/compiler/rustc_pattern_analysis/Cargo.toml
index 0ce1d1686f9..4c374056183 100644
--- a/compiler/rustc_pattern_analysis/Cargo.toml
+++ b/compiler/rustc_pattern_analysis/Cargo.toml
@@ -7,7 +7,7 @@ edition = "2021"
 # tidy-alphabetical-start
 rustc_apfloat = "0.2.0"
 rustc_arena = { path = "../rustc_arena" }
-rustc_data_structures = { path = "../rustc_data_structures" }
+rustc_data_structures = { path = "../rustc_data_structures", optional = true }
 rustc_errors = { path = "../rustc_errors", optional = true }
 rustc_fluent_macro = { path = "../rustc_fluent_macro", optional = true }
 rustc_hir = { path = "../rustc_hir", optional = true }
@@ -24,6 +24,7 @@ tracing = "0.1"
 [features]
 default = ["rustc"]
 rustc = [
+    "dep:rustc_data_structures",
     "dep:rustc_errors",
     "dep:rustc_fluent_macro",
     "dep:rustc_hir",
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,