mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Reduce visibility
This commit is contained in:
parent
45ec95caf6
commit
7b2ce1a54f
1 changed files with 82 additions and 84 deletions
|
@ -272,7 +272,7 @@ impl From<&PatId> for PatIdOrWild {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum MatchCheckErr {
|
pub(super) enum MatchCheckErr {
|
||||||
NotImplemented,
|
NotImplemented,
|
||||||
MalformedMatchArm,
|
MalformedMatchArm,
|
||||||
/// Used when type inference cannot resolve the type of
|
/// Used when type inference cannot resolve the type of
|
||||||
|
@ -287,21 +287,21 @@ pub enum MatchCheckErr {
|
||||||
///
|
///
|
||||||
/// The `std::result::Result` type is used here rather than a custom enum
|
/// The `std::result::Result` type is used here rather than a custom enum
|
||||||
/// to allow the use of `?`.
|
/// to allow the use of `?`.
|
||||||
pub type MatchCheckResult<T> = Result<T, MatchCheckErr>;
|
pub(super) type MatchCheckResult<T> = Result<T, MatchCheckErr>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
/// A row in a Matrix.
|
/// A row in a Matrix.
|
||||||
///
|
///
|
||||||
/// This type is modeled from the struct of the same name in `rustc`.
|
/// This type is modeled from the struct of the same name in `rustc`.
|
||||||
pub(crate) struct PatStack(PatStackInner);
|
pub(super) struct PatStack(PatStackInner);
|
||||||
type PatStackInner = SmallVec<[PatIdOrWild; 2]>;
|
type PatStackInner = SmallVec<[PatIdOrWild; 2]>;
|
||||||
|
|
||||||
impl PatStack {
|
impl PatStack {
|
||||||
pub(crate) fn from_pattern(pat_id: PatId) -> PatStack {
|
pub(super) fn from_pattern(pat_id: PatId) -> PatStack {
|
||||||
Self(smallvec!(pat_id.into()))
|
Self(smallvec!(pat_id.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_wild() -> PatStack {
|
pub(super) fn from_wild() -> PatStack {
|
||||||
Self(smallvec!(PatIdOrWild::Wild))
|
Self(smallvec!(PatIdOrWild::Wild))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -510,14 +510,14 @@ impl PatStack {
|
||||||
/// A collection of PatStack.
|
/// A collection of PatStack.
|
||||||
///
|
///
|
||||||
/// This type is modeled from the struct of the same name in `rustc`.
|
/// This type is modeled from the struct of the same name in `rustc`.
|
||||||
pub(crate) struct Matrix(Vec<PatStack>);
|
pub(super) struct Matrix(Vec<PatStack>);
|
||||||
|
|
||||||
impl Matrix {
|
impl Matrix {
|
||||||
pub(crate) fn empty() -> Self {
|
pub(super) fn empty() -> Self {
|
||||||
Self(vec![])
|
Self(vec![])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn push(&mut self, cx: &MatchCheckCtx, row: PatStack) {
|
pub(super) fn push(&mut self, cx: &MatchCheckCtx, row: PatStack) {
|
||||||
if let Some(Pat::Or(pat_ids)) = row.get_head().map(|pat_id| pat_id.as_pat(cx)) {
|
if let Some(Pat::Or(pat_ids)) = row.get_head().map(|pat_id| pat_id.as_pat(cx)) {
|
||||||
// Or patterns are expanded here
|
// Or patterns are expanded here
|
||||||
for pat_id in pat_ids {
|
for pat_id in pat_ids {
|
||||||
|
@ -579,16 +579,16 @@ impl Matrix {
|
||||||
/// not matched by an prior match arms.
|
/// not matched by an prior match arms.
|
||||||
///
|
///
|
||||||
/// We may eventually need an `Unknown` variant here.
|
/// We may eventually need an `Unknown` variant here.
|
||||||
pub enum Usefulness {
|
pub(super) enum Usefulness {
|
||||||
Useful,
|
Useful,
|
||||||
NotUseful,
|
NotUseful,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MatchCheckCtx<'a> {
|
pub(super) struct MatchCheckCtx<'a> {
|
||||||
pub match_expr: Idx<Expr>,
|
pub(super) match_expr: Idx<Expr>,
|
||||||
pub body: Arc<Body>,
|
pub(super) body: Arc<Body>,
|
||||||
pub infer: Arc<InferenceResult>,
|
pub(super) infer: Arc<InferenceResult>,
|
||||||
pub db: &'a dyn HirDatabase,
|
pub(super) db: &'a dyn HirDatabase,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given a set of patterns `matrix`, and pattern to consider `v`, determines
|
/// Given a set of patterns `matrix`, and pattern to consider `v`, determines
|
||||||
|
@ -599,7 +599,7 @@ pub struct MatchCheckCtx<'a> {
|
||||||
/// expected that you have already type checked the match arms. All patterns in
|
/// expected that you have already type checked the match arms. All patterns in
|
||||||
/// matrix should be the same type as v, as well as they should all be the same
|
/// matrix should be the same type as v, as well as they should all be the same
|
||||||
/// type as the match expression.
|
/// type as the match expression.
|
||||||
pub(crate) fn is_useful(
|
pub(super) fn is_useful(
|
||||||
cx: &MatchCheckCtx,
|
cx: &MatchCheckCtx,
|
||||||
matrix: &Matrix,
|
matrix: &Matrix,
|
||||||
v: &PatStack,
|
v: &PatStack,
|
||||||
|
@ -837,23 +837,23 @@ fn enum_variant_matches(cx: &MatchCheckCtx, pat_id: PatId, enum_variant_id: Enum
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
pub(super) use insta::assert_snapshot;
|
use insta::assert_snapshot;
|
||||||
pub(super) use ra_db::fixture::WithFixture;
|
use ra_db::fixture::WithFixture;
|
||||||
|
|
||||||
pub(super) use crate::{diagnostics::MissingMatchArms, test_db::TestDB};
|
use crate::{diagnostics::MissingMatchArms, test_db::TestDB};
|
||||||
|
|
||||||
pub(super) fn check_diagnostic_message(ra_fixture: &str) -> String {
|
fn check_diagnostic_message(ra_fixture: &str) -> String {
|
||||||
TestDB::with_single_file(ra_fixture).0.diagnostic::<MissingMatchArms>().0
|
TestDB::with_single_file(ra_fixture).0.diagnostic::<MissingMatchArms>().0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn check_diagnostic(ra_fixture: &str) {
|
fn check_diagnostic(ra_fixture: &str) {
|
||||||
let diagnostic_count =
|
let diagnostic_count =
|
||||||
TestDB::with_single_file(ra_fixture).0.diagnostic::<MissingMatchArms>().1;
|
TestDB::with_single_file(ra_fixture).0.diagnostic::<MissingMatchArms>().1;
|
||||||
|
|
||||||
assert_eq!(1, diagnostic_count, "no diagnostic reported");
|
assert_eq!(1, diagnostic_count, "no diagnostic reported");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn check_no_diagnostic(ra_fixture: &str) {
|
fn check_no_diagnostic(ra_fixture: &str) {
|
||||||
let (s, diagnostic_count) =
|
let (s, diagnostic_count) =
|
||||||
TestDB::with_single_file(ra_fixture).0.diagnostic::<MissingMatchArms>();
|
TestDB::with_single_file(ra_fixture).0.diagnostic::<MissingMatchArms>();
|
||||||
|
|
||||||
|
@ -2036,9 +2036,7 @@ mod tests {
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod false_negatives {
|
mod false_negatives {
|
||||||
//! The implementation of match checking here is a work in progress. As we roll this out, we
|
//! The implementation of match checking here is a work in progress. As we roll this out, we
|
||||||
//! prefer false negatives to false positives (ideally there would be no false positives). This
|
//! prefer false negatives to false positives (ideally there would be no false positives). This
|
||||||
|
@ -2049,8 +2047,7 @@ mod false_negatives {
|
||||||
//!
|
//!
|
||||||
//! 1. It acts as a backlog of work that can be done to improve the behavior of the system.
|
//! 1. It acts as a backlog of work that can be done to improve the behavior of the system.
|
||||||
//! 2. It ensures the code doesn't panic when handling these cases.
|
//! 2. It ensures the code doesn't panic when handling these cases.
|
||||||
|
use super::*;
|
||||||
use super::tests::*;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn integers() {
|
fn integers() {
|
||||||
|
@ -2156,3 +2153,4 @@ mod false_negatives {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue