rust-analyzer/crates/hir_ty/src/diagnostics.rs

96 lines
2.2 KiB
Rust
Raw Normal View History

2021-04-09 12:39:07 +00:00
//! Type inference-based diagnostics.
2020-07-14 08:52:18 +00:00
mod expr;
mod match_check;
2020-07-14 08:52:18 +00:00
mod unsafe_check;
mod decl_check;
2019-11-27 14:46:02 +00:00
use std::fmt;
2019-11-27 14:46:02 +00:00
use base_db::CrateId;
2021-06-12 16:28:19 +00:00
use hir_def::ModuleDefId;
use hir_expand::HirFileId;
use syntax::{ast, AstPtr};
2019-11-27 14:46:02 +00:00
use crate::db::HirDatabase;
2020-07-14 08:28:55 +00:00
pub use crate::diagnostics::{
2021-06-12 16:28:19 +00:00
expr::{
record_literal_missing_fields, record_pattern_missing_fields, BodyValidationDiagnostic,
},
unsafe_check::missing_unsafe,
};
2020-07-14 08:52:18 +00:00
pub fn validate_module_item(
db: &dyn HirDatabase,
krate: CrateId,
owner: ModuleDefId,
) -> Vec<IncorrectCase> {
2020-10-04 06:26:39 +00:00
let _p = profile::span("validate_module_item");
let mut validator = decl_check::DeclValidator::new(db, krate);
validator.validate_item(owner);
validator.sink
}
#[derive(Debug)]
pub enum CaseType {
// `some_var`
LowerSnakeCase,
// `SOME_CONST`
UpperSnakeCase,
// `SomeStruct`
UpperCamelCase,
}
impl fmt::Display for CaseType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let repr = match self {
CaseType::LowerSnakeCase => "snake_case",
CaseType::UpperSnakeCase => "UPPER_SNAKE_CASE",
CaseType::UpperCamelCase => "CamelCase",
};
write!(f, "{}", repr)
}
}
2021-02-05 15:09:45 +00:00
#[derive(Debug)]
pub enum IdentType {
Constant,
Enum,
Field,
Function,
2021-05-31 16:09:44 +00:00
Parameter,
2021-02-05 15:09:45 +00:00
StaticVariable,
Structure,
Variable,
Variant,
}
impl fmt::Display for IdentType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let repr = match self {
IdentType::Constant => "Constant",
IdentType::Enum => "Enum",
IdentType::Field => "Field",
IdentType::Function => "Function",
2021-05-31 16:09:44 +00:00
IdentType::Parameter => "Parameter",
2021-02-05 15:09:45 +00:00
IdentType::StaticVariable => "Static variable",
IdentType::Structure => "Structure",
IdentType::Variable => "Variable",
IdentType::Variant => "Variant",
};
write!(f, "{}", repr)
}
}
#[derive(Debug)]
pub struct IncorrectCase {
pub file: HirFileId,
2020-10-08 06:27:38 +00:00
pub ident: AstPtr<ast::Name>,
pub expected_case: CaseType,
2021-02-05 15:09:45 +00:00
pub ident_type: IdentType,
pub ident_text: String,
pub suggested_text: String,
}