Skip to content

Commit 4d0ebfc

Browse files
committed
Make the rustc_data_structures dependency optional
1 parent 785a664 commit 4d0ebfc

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

compiler/rustc_pattern_analysis/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77
# tidy-alphabetical-start
88
rustc_apfloat = "0.2.0"
99
rustc_arena = { path = "../rustc_arena" }
10-
rustc_data_structures = { path = "../rustc_data_structures" }
10+
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
1111
rustc_errors = { path = "../rustc_errors", optional = true }
1212
rustc_fluent_macro = { path = "../rustc_fluent_macro", optional = true }
1313
rustc_hir = { path = "../rustc_hir", optional = true }
@@ -24,6 +24,7 @@ tracing = "0.1"
2424
[features]
2525
default = ["rustc"]
2626
rustc = [
27+
"dep:rustc_data_structures",
2728
"dep:rustc_errors",
2829
"dep:rustc_fluent_macro",
2930
"dep:rustc_hir",

compiler/rustc_pattern_analysis/src/constructor.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ use std::iter::once;
155155
use smallvec::SmallVec;
156156

157157
use rustc_apfloat::ieee::{DoubleS, IeeeFloat, SingleS};
158-
use rustc_data_structures::fx::FxHashSet;
158+
use rustc_index::bit_set::{BitSet, GrowableBitSet};
159159
use rustc_index::IndexVec;
160160

161161
use self::Constructor::*;
@@ -546,7 +546,7 @@ impl Slice {
546546
// therefore `Presence::Seen` in the column.
547547
let mut min_var_len = usize::MAX;
548548
// Tracks the fixed-length slices we've seen, to mark them as `Presence::Seen`.
549-
let mut seen_fixed_lens = FxHashSet::default();
549+
let mut seen_fixed_lens = GrowableBitSet::new_empty();
550550
match &mut max_slice {
551551
VarLen(max_prefix_len, max_suffix_len) => {
552552
// A length larger than any fixed-length slice encountered.
@@ -614,7 +614,7 @@ impl Slice {
614614

615615
smaller_lengths.map(FixedLen).chain(once(max_slice)).map(move |kind| {
616616
let arity = kind.arity();
617-
let seen = if min_var_len <= arity || seen_fixed_lens.contains(&arity) {
617+
let seen = if min_var_len <= arity || seen_fixed_lens.contains(arity) {
618618
Presence::Seen
619619
} else {
620620
Presence::Unseen
@@ -906,12 +906,15 @@ impl<Cx: MatchCx> ConstructorSet<Cx> {
906906
}
907907
}
908908
ConstructorSet::Variants { variants, non_exhaustive } => {
909-
let seen_set: FxHashSet<_> = seen.iter().map(|c| c.as_variant().unwrap()).collect();
909+
let mut seen_set: BitSet<_> = BitSet::new_empty(variants.len());
910+
for idx in seen.iter().map(|c| c.as_variant().unwrap()) {
911+
seen_set.insert(idx);
912+
}
910913
let mut skipped_a_hidden_variant = false;
911914

912915
for (idx, visibility) in variants.iter_enumerated() {
913916
let ctor = Variant(idx);
914-
if seen_set.contains(&idx) {
917+
if seen_set.contains(idx) {
915918
present.push(ctor);
916919
} else {
917920
// We only put visible variants directly into `missing`.

compiler/rustc_pattern_analysis/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ pub struct MatchArm<'p, Cx: MatchCx> {
7979

8080
impl<'p, Cx: MatchCx> Copy for MatchArm<'p, Cx> {}
8181

82+
#[cfg(not(feature = "rustc"))]
83+
pub trait Captures<'a> {}
84+
#[cfg(not(feature = "rustc"))]
85+
impl<'a, T: ?Sized> Captures<'a> for T {}
86+
#[cfg(feature = "rustc")]
87+
pub use rustc_data_structures::captures::Captures;
88+
8289
/// The entrypoint for this crate. Computes whether a match is exhaustive and which of its arms are
8390
/// useful, and runs some lints.
8491
#[cfg(feature = "rustc")]

compiler/rustc_pattern_analysis/src/pat.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ use std::fmt;
55

66
use smallvec::{smallvec, SmallVec};
77

8-
use rustc_data_structures::captures::Captures;
9-
10-
use self::Constructor::*;
11-
128
use crate::constructor::{Constructor, Slice, SliceKind};
139
use crate::usefulness::PatCtxt;
14-
use crate::MatchCx;
10+
use crate::{Captures, MatchCx};
11+
12+
use self::Constructor::*;
1513

1614
/// Values and patterns can be represented as a constructor applied to some fields. This represents
1715
/// a pattern in this form.

compiler/rustc_pattern_analysis/src/usefulness.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,14 +556,20 @@ use smallvec::{smallvec, SmallVec};
556556
use std::fmt;
557557

558558
use rustc_arena::TypedArena;
559-
use rustc_data_structures::{captures::Captures, stack::ensure_sufficient_stack};
560559

561560
use crate::constructor::{Constructor, ConstructorSet};
562561
use crate::pat::{DeconstructedPat, WitnessPat};
563-
use crate::{MatchArm, MatchCx};
562+
use crate::{Captures, MatchArm, MatchCx};
564563

565564
use self::ValidityConstraint::*;
566565

566+
#[cfg(feature = "rustc")]
567+
use rustc_data_structures::stack::ensure_sufficient_stack;
568+
#[cfg(not(feature = "rustc"))]
569+
pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
570+
f()
571+
}
572+
567573
#[derive(Clone)]
568574
pub(crate) struct PatCtxt<'a, 'p, Cx: MatchCx> {
569575
pub(crate) cx: &'a Cx,

0 commit comments

Comments
 (0)