Gate rustc-specific code under a feature
This commit is contained in:
parent
42f4393824
commit
16bd6ac3ed
4 changed files with 41 additions and 16 deletions
|
@ -8,15 +8,28 @@ edition = "2021"
|
||||||
rustc_apfloat = "0.2.0"
|
rustc_apfloat = "0.2.0"
|
||||||
rustc_arena = { path = "../rustc_arena" }
|
rustc_arena = { path = "../rustc_arena" }
|
||||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||||
rustc_errors = { path = "../rustc_errors" }
|
rustc_errors = { path = "../rustc_errors", optional = true }
|
||||||
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
|
rustc_fluent_macro = { path = "../rustc_fluent_macro", optional = true }
|
||||||
rustc_hir = { path = "../rustc_hir" }
|
rustc_hir = { path = "../rustc_hir", optional = true }
|
||||||
rustc_index = { path = "../rustc_index" }
|
rustc_index = { path = "../rustc_index" }
|
||||||
rustc_macros = { path = "../rustc_macros" }
|
rustc_macros = { path = "../rustc_macros", optional = true }
|
||||||
rustc_middle = { path = "../rustc_middle" }
|
rustc_middle = { path = "../rustc_middle", optional = true }
|
||||||
rustc_session = { path = "../rustc_session" }
|
rustc_session = { path = "../rustc_session", optional = true }
|
||||||
rustc_span = { path = "../rustc_span" }
|
rustc_span = { path = "../rustc_span", optional = true }
|
||||||
rustc_target = { path = "../rustc_target" }
|
rustc_target = { path = "../rustc_target", optional = true }
|
||||||
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
# tidy-alphabetical-end
|
# tidy-alphabetical-end
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["rustc"]
|
||||||
|
rustc = [
|
||||||
|
"dep:rustc_errors",
|
||||||
|
"dep:rustc_fluent_macro",
|
||||||
|
"dep:rustc_hir",
|
||||||
|
"dep:rustc_macros",
|
||||||
|
"dep:rustc_middle",
|
||||||
|
"dep:rustc_session",
|
||||||
|
"dep:rustc_span",
|
||||||
|
"dep:rustc_target",
|
||||||
|
]
|
||||||
|
|
|
@ -266,6 +266,7 @@ pub struct IntRange {
|
||||||
|
|
||||||
impl IntRange {
|
impl IntRange {
|
||||||
/// Best effort; will not know that e.g. `255u8..` is a singleton.
|
/// Best effort; will not know that e.g. `255u8..` is a singleton.
|
||||||
|
#[cfg_attr(not(feature = "rustc"), allow(dead_code))]
|
||||||
pub(crate) fn is_singleton(&self) -> bool {
|
pub(crate) fn is_singleton(&self) -> bool {
|
||||||
// Since `lo` and `hi` can't be the same `Infinity` and `plus_one` never changes from finite
|
// Since `lo` and `hi` can't be the same `Infinity` and `plus_one` never changes from finite
|
||||||
// to infinite, this correctly only detects ranges that contain exacly one `Finite(x)`.
|
// to infinite, this correctly only detects ranges that contain exacly one `Finite(x)`.
|
||||||
|
|
|
@ -1,31 +1,40 @@
|
||||||
//! Analysis of patterns, notably match exhaustiveness checking.
|
//! Analysis of patterns, notably match exhaustiveness checking.
|
||||||
|
|
||||||
pub mod constructor;
|
pub mod constructor;
|
||||||
|
#[cfg(feature = "rustc")]
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
|
#[cfg(feature = "rustc")]
|
||||||
pub(crate) mod lints;
|
pub(crate) mod lints;
|
||||||
pub mod pat;
|
pub mod pat;
|
||||||
|
#[cfg(feature = "rustc")]
|
||||||
pub mod rustc;
|
pub mod rustc;
|
||||||
pub mod usefulness;
|
pub mod usefulness;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate tracing;
|
extern crate tracing;
|
||||||
|
#[cfg(feature = "rustc")]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rustc_middle;
|
extern crate rustc_middle;
|
||||||
|
|
||||||
|
#[cfg(feature = "rustc")]
|
||||||
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use constructor::{Constructor, ConstructorSet};
|
|
||||||
use lints::PatternColumn;
|
|
||||||
use rustc_hir::HirId;
|
|
||||||
use rustc_index::Idx;
|
use rustc_index::Idx;
|
||||||
|
#[cfg(feature = "rustc")]
|
||||||
use rustc_middle::ty::Ty;
|
use rustc_middle::ty::Ty;
|
||||||
use usefulness::{compute_match_usefulness, ValidityConstraint};
|
|
||||||
|
|
||||||
use crate::lints::{lint_nonexhaustive_missing_variants, lint_overlapping_range_endpoints};
|
use crate::constructor::{Constructor, ConstructorSet};
|
||||||
|
#[cfg(feature = "rustc")]
|
||||||
|
use crate::lints::{
|
||||||
|
lint_nonexhaustive_missing_variants, lint_overlapping_range_endpoints, PatternColumn,
|
||||||
|
};
|
||||||
use crate::pat::DeconstructedPat;
|
use crate::pat::DeconstructedPat;
|
||||||
|
#[cfg(feature = "rustc")]
|
||||||
use crate::rustc::RustcCtxt;
|
use crate::rustc::RustcCtxt;
|
||||||
|
#[cfg(feature = "rustc")]
|
||||||
|
use crate::usefulness::{compute_match_usefulness, ValidityConstraint};
|
||||||
|
|
||||||
pub trait MatchCx: Sized + Clone + fmt::Debug {
|
pub trait MatchCx: Sized + Clone + fmt::Debug {
|
||||||
type Ty: Copy + Clone + fmt::Debug; // FIXME: remove Copy
|
type Ty: Copy + Clone + fmt::Debug; // FIXME: remove Copy
|
||||||
|
@ -72,6 +81,7 @@ impl<'p, Cx: MatchCx> Copy for MatchArm<'p, Cx> {}
|
||||||
|
|
||||||
/// The entrypoint for this crate. Computes whether a match is exhaustive and which of its arms are
|
/// The entrypoint for this crate. Computes whether a match is exhaustive and which of its arms are
|
||||||
/// useful, and runs some lints.
|
/// useful, and runs some lints.
|
||||||
|
#[cfg(feature = "rustc")]
|
||||||
pub fn analyze_match<'p, 'tcx>(
|
pub fn analyze_match<'p, 'tcx>(
|
||||||
cx: &RustcCtxt<'p, 'tcx>,
|
cx: &RustcCtxt<'p, 'tcx>,
|
||||||
arms: &[rustc::MatchArm<'p, 'tcx>],
|
arms: &[rustc::MatchArm<'p, 'tcx>],
|
||||||
|
|
|
@ -578,6 +578,7 @@ pub(crate) struct PatCtxt<'a, 'p, Cx: MatchCx> {
|
||||||
|
|
||||||
impl<'a, 'p, Cx: MatchCx> PatCtxt<'a, 'p, Cx> {
|
impl<'a, 'p, Cx: MatchCx> PatCtxt<'a, 'p, Cx> {
|
||||||
/// A `PatCtxt` when code other than `is_useful` needs one.
|
/// A `PatCtxt` when code other than `is_useful` needs one.
|
||||||
|
#[cfg_attr(not(feature = "rustc"), allow(dead_code))]
|
||||||
pub(crate) fn new_dummy(
|
pub(crate) fn new_dummy(
|
||||||
cx: &'a Cx,
|
cx: &'a Cx,
|
||||||
ty: Cx::Ty,
|
ty: Cx::Ty,
|
||||||
|
@ -601,7 +602,7 @@ impl<'a, 'p, Cx: MatchCx> fmt::Debug for PatCtxt<'a, 'p, Cx> {
|
||||||
/// - in the matrix, track whether a given place (aka column) is known to contain a valid value or
|
/// - in the matrix, track whether a given place (aka column) is known to contain a valid value or
|
||||||
/// not.
|
/// not.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub(crate) enum ValidityConstraint {
|
pub enum ValidityConstraint {
|
||||||
ValidOnly,
|
ValidOnly,
|
||||||
MaybeInvalid,
|
MaybeInvalid,
|
||||||
/// Option for backwards compatibility: the place is not known to be valid but we allow omitting
|
/// Option for backwards compatibility: the place is not known to be valid but we allow omitting
|
||||||
|
@ -610,7 +611,7 @@ pub(crate) enum ValidityConstraint {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ValidityConstraint {
|
impl ValidityConstraint {
|
||||||
pub(crate) fn from_bool(is_valid_only: bool) -> Self {
|
pub fn from_bool(is_valid_only: bool) -> Self {
|
||||||
if is_valid_only { ValidOnly } else { MaybeInvalid }
|
if is_valid_only { ValidOnly } else { MaybeInvalid }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1296,7 +1297,7 @@ pub struct UsefulnessReport<'p, Cx: MatchCx> {
|
||||||
|
|
||||||
/// Computes whether a match is exhaustive and which of its arms are useful.
|
/// Computes whether a match is exhaustive and which of its arms are useful.
|
||||||
#[instrument(skip(cx, arms, wildcard_arena), level = "debug")]
|
#[instrument(skip(cx, arms, wildcard_arena), level = "debug")]
|
||||||
pub(crate) fn compute_match_usefulness<'p, Cx: MatchCx>(
|
pub fn compute_match_usefulness<'p, Cx: MatchCx>(
|
||||||
cx: &Cx,
|
cx: &Cx,
|
||||||
arms: &[MatchArm<'p, Cx>],
|
arms: &[MatchArm<'p, Cx>],
|
||||||
scrut_ty: Cx::Ty,
|
scrut_ty: Cx::Ty,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue