Skip to content

Commit 16bd6ac

Browse files
committed
Gate rustc-specific code under a feature
1 parent 42f4393 commit 16bd6ac

File tree

4 files changed

+41
-16
lines changed

4 files changed

+41
-16
lines changed

compiler/rustc_pattern_analysis/Cargo.toml

+21-8
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,28 @@ edition = "2021"
88
rustc_apfloat = "0.2.0"
99
rustc_arena = { path = "../rustc_arena" }
1010
rustc_data_structures = { path = "../rustc_data_structures" }
11-
rustc_errors = { path = "../rustc_errors" }
12-
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
13-
rustc_hir = { path = "../rustc_hir" }
11+
rustc_errors = { path = "../rustc_errors", optional = true }
12+
rustc_fluent_macro = { path = "../rustc_fluent_macro", optional = true }
13+
rustc_hir = { path = "../rustc_hir", optional = true }
1414
rustc_index = { path = "../rustc_index" }
15-
rustc_macros = { path = "../rustc_macros" }
16-
rustc_middle = { path = "../rustc_middle" }
17-
rustc_session = { path = "../rustc_session" }
18-
rustc_span = { path = "../rustc_span" }
19-
rustc_target = { path = "../rustc_target" }
15+
rustc_macros = { path = "../rustc_macros", optional = true }
16+
rustc_middle = { path = "../rustc_middle", optional = true }
17+
rustc_session = { path = "../rustc_session", optional = true }
18+
rustc_span = { path = "../rustc_span", optional = true }
19+
rustc_target = { path = "../rustc_target", optional = true }
2020
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2121
tracing = "0.1"
2222
# tidy-alphabetical-end
23+
24+
[features]
25+
default = ["rustc"]
26+
rustc = [
27+
"dep:rustc_errors",
28+
"dep:rustc_fluent_macro",
29+
"dep:rustc_hir",
30+
"dep:rustc_macros",
31+
"dep:rustc_middle",
32+
"dep:rustc_session",
33+
"dep:rustc_span",
34+
"dep:rustc_target",
35+
]

compiler/rustc_pattern_analysis/src/constructor.rs

+1
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ pub struct IntRange {
266266

267267
impl IntRange {
268268
/// Best effort; will not know that e.g. `255u8..` is a singleton.
269+
#[cfg_attr(not(feature = "rustc"), allow(dead_code))]
269270
pub(crate) fn is_singleton(&self) -> bool {
270271
// Since `lo` and `hi` can't be the same `Infinity` and `plus_one` never changes from finite
271272
// to infinite, this correctly only detects ranges that contain exacly one `Finite(x)`.

compiler/rustc_pattern_analysis/src/lib.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
11
//! Analysis of patterns, notably match exhaustiveness checking.
22
33
pub mod constructor;
4+
#[cfg(feature = "rustc")]
45
pub mod errors;
6+
#[cfg(feature = "rustc")]
57
pub(crate) mod lints;
68
pub mod pat;
9+
#[cfg(feature = "rustc")]
710
pub mod rustc;
811
pub mod usefulness;
912

1013
#[macro_use]
1114
extern crate tracing;
15+
#[cfg(feature = "rustc")]
1216
#[macro_use]
1317
extern crate rustc_middle;
1418

19+
#[cfg(feature = "rustc")]
1520
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
1621

1722
use std::fmt;
1823

19-
use constructor::{Constructor, ConstructorSet};
20-
use lints::PatternColumn;
21-
use rustc_hir::HirId;
2224
use rustc_index::Idx;
25+
#[cfg(feature = "rustc")]
2326
use rustc_middle::ty::Ty;
24-
use usefulness::{compute_match_usefulness, ValidityConstraint};
2527

26-
use crate::lints::{lint_nonexhaustive_missing_variants, lint_overlapping_range_endpoints};
28+
use crate::constructor::{Constructor, ConstructorSet};
29+
#[cfg(feature = "rustc")]
30+
use crate::lints::{
31+
lint_nonexhaustive_missing_variants, lint_overlapping_range_endpoints, PatternColumn,
32+
};
2733
use crate::pat::DeconstructedPat;
34+
#[cfg(feature = "rustc")]
2835
use crate::rustc::RustcCtxt;
36+
#[cfg(feature = "rustc")]
37+
use crate::usefulness::{compute_match_usefulness, ValidityConstraint};
2938

3039
pub trait MatchCx: Sized + Clone + fmt::Debug {
3140
type Ty: Copy + Clone + fmt::Debug; // FIXME: remove Copy
@@ -72,6 +81,7 @@ impl<'p, Cx: MatchCx> Copy for MatchArm<'p, Cx> {}
7281

7382
/// The entrypoint for this crate. Computes whether a match is exhaustive and which of its arms are
7483
/// useful, and runs some lints.
84+
#[cfg(feature = "rustc")]
7585
pub fn analyze_match<'p, 'tcx>(
7686
cx: &RustcCtxt<'p, 'tcx>,
7787
arms: &[rustc::MatchArm<'p, 'tcx>],

compiler/rustc_pattern_analysis/src/usefulness.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ pub(crate) struct PatCtxt<'a, 'p, Cx: MatchCx> {
578578

579579
impl<'a, 'p, Cx: MatchCx> PatCtxt<'a, 'p, Cx> {
580580
/// A `PatCtxt` when code other than `is_useful` needs one.
581+
#[cfg_attr(not(feature = "rustc"), allow(dead_code))]
581582
pub(crate) fn new_dummy(
582583
cx: &'a Cx,
583584
ty: Cx::Ty,
@@ -601,7 +602,7 @@ impl<'a, 'p, Cx: MatchCx> fmt::Debug for PatCtxt<'a, 'p, Cx> {
601602
/// - in the matrix, track whether a given place (aka column) is known to contain a valid value or
602603
/// not.
603604
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
604-
pub(crate) enum ValidityConstraint {
605+
pub enum ValidityConstraint {
605606
ValidOnly,
606607
MaybeInvalid,
607608
/// Option for backwards compatibility: the place is not known to be valid but we allow omitting
@@ -610,7 +611,7 @@ pub(crate) enum ValidityConstraint {
610611
}
611612

612613
impl ValidityConstraint {
613-
pub(crate) fn from_bool(is_valid_only: bool) -> Self {
614+
pub fn from_bool(is_valid_only: bool) -> Self {
614615
if is_valid_only { ValidOnly } else { MaybeInvalid }
615616
}
616617

@@ -1296,7 +1297,7 @@ pub struct UsefulnessReport<'p, Cx: MatchCx> {
12961297

12971298
/// Computes whether a match is exhaustive and which of its arms are useful.
12981299
#[instrument(skip(cx, arms, wildcard_arena), level = "debug")]
1299-
pub(crate) fn compute_match_usefulness<'p, Cx: MatchCx>(
1300+
pub fn compute_match_usefulness<'p, Cx: MatchCx>(
13001301
cx: &Cx,
13011302
arms: &[MatchArm<'p, Cx>],
13021303
scrut_ty: Cx::Ty,

0 commit comments

Comments
 (0)