Skip to content

Commit 55b7a06

Browse files
bors[bot]Veykril
andauthored
Merge #10820
10820: minor: Move incorrect case diagnostic things into their module r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents f2707bc + 69782f5 commit 55b7a06

File tree

4 files changed

+88
-92
lines changed

4 files changed

+88
-92
lines changed

crates/hir/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl ModuleDef {
359359
def.diagnostics(db, &mut acc);
360360
}
361361
None => {
362-
for diag in hir_ty::diagnostics::validate_module_item(db, module.id.krate(), id) {
362+
for diag in hir_ty::diagnostics::incorrect_case(db, module.id.krate(), id) {
363363
acc.push(diag.into())
364364
}
365365
}
@@ -1282,7 +1282,7 @@ impl DefWithBody {
12821282
DefWithBody::Static(it) => it.into(),
12831283
DefWithBody::Const(it) => it.into(),
12841284
};
1285-
for diag in hir_ty::diagnostics::validate_module_item(db, krate, def.into()) {
1285+
for diag in hir_ty::diagnostics::incorrect_case(db, krate, def.into()) {
12861286
acc.push(diag.into())
12871287
}
12881288
}

crates/hir_def/src/path/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
7676
kind = mod_path.kind;
7777

7878
segments.extend(mod_path.segments.iter().cloned().rev());
79-
generic_args.extend(path_generic_args.iter().cloned().rev());
79+
generic_args.extend(Vec::from(path_generic_args).into_iter().rev());
8080

8181
// Insert the type reference (T in the above example) as Self parameter for the trait
8282
let last_segment =

crates/hir_ty/src/diagnostics.rs

Lines changed: 1 addition & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -4,92 +4,10 @@ mod match_check;
44
mod unsafe_check;
55
mod decl_check;
66

7-
use std::fmt;
8-
9-
use base_db::CrateId;
10-
use hir_def::ModuleDefId;
11-
use hir_expand::HirFileId;
12-
use syntax::{ast, AstPtr};
13-
14-
use crate::db::HirDatabase;
15-
167
pub use crate::diagnostics::{
8+
decl_check::{incorrect_case, IncorrectCase},
179
expr::{
1810
record_literal_missing_fields, record_pattern_missing_fields, BodyValidationDiagnostic,
1911
},
2012
unsafe_check::missing_unsafe,
2113
};
22-
23-
pub fn validate_module_item(
24-
db: &dyn HirDatabase,
25-
krate: CrateId,
26-
owner: ModuleDefId,
27-
) -> Vec<IncorrectCase> {
28-
let _p = profile::span("validate_module_item");
29-
let mut validator = decl_check::DeclValidator::new(db, krate);
30-
validator.validate_item(owner);
31-
validator.sink
32-
}
33-
34-
#[derive(Debug)]
35-
pub enum CaseType {
36-
// `some_var`
37-
LowerSnakeCase,
38-
// `SOME_CONST`
39-
UpperSnakeCase,
40-
// `SomeStruct`
41-
UpperCamelCase,
42-
}
43-
44-
impl fmt::Display for CaseType {
45-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46-
let repr = match self {
47-
CaseType::LowerSnakeCase => "snake_case",
48-
CaseType::UpperSnakeCase => "UPPER_SNAKE_CASE",
49-
CaseType::UpperCamelCase => "CamelCase",
50-
};
51-
52-
write!(f, "{}", repr)
53-
}
54-
}
55-
56-
#[derive(Debug)]
57-
pub enum IdentType {
58-
Constant,
59-
Enum,
60-
Field,
61-
Function,
62-
Parameter,
63-
StaticVariable,
64-
Structure,
65-
Variable,
66-
Variant,
67-
}
68-
69-
impl fmt::Display for IdentType {
70-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71-
let repr = match self {
72-
IdentType::Constant => "Constant",
73-
IdentType::Enum => "Enum",
74-
IdentType::Field => "Field",
75-
IdentType::Function => "Function",
76-
IdentType::Parameter => "Parameter",
77-
IdentType::StaticVariable => "Static variable",
78-
IdentType::Structure => "Structure",
79-
IdentType::Variable => "Variable",
80-
IdentType::Variant => "Variant",
81-
};
82-
83-
write!(f, "{}", repr)
84-
}
85-
}
86-
87-
#[derive(Debug)]
88-
pub struct IncorrectCase {
89-
pub file: HirFileId,
90-
pub ident: AstPtr<ast::Name>,
91-
pub expected_case: CaseType,
92-
pub ident_type: IdentType,
93-
pub ident_text: String,
94-
pub suggested_text: String,
95-
}

crates/hir_ty/src/diagnostics/decl_check.rs

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Provides validators for the item declarations.
1+
//! Provides validators for names of declarations.
22
//!
33
//! This includes the following items:
44
//!
@@ -12,24 +12,28 @@
1212
1313
mod case_conv;
1414

15+
use std::fmt;
16+
1517
use base_db::CrateId;
1618
use hir_def::{
1719
adt::VariantData,
1820
expr::{Pat, PatId},
1921
src::HasSource,
2022
AdtId, AttrDefId, ConstId, EnumId, FunctionId, Lookup, ModuleDefId, StaticId, StructId,
2123
};
22-
use hir_expand::name::{AsName, Name};
24+
use hir_expand::{
25+
name::{AsName, Name},
26+
HirFileId,
27+
};
2328
use stdx::{always, never};
2429
use syntax::{
2530
ast::{self, HasName},
2631
AstNode, AstPtr,
2732
};
2833

29-
use crate::{
30-
db::HirDatabase,
31-
diagnostics::{decl_check::case_conv::*, CaseType, IdentType, IncorrectCase},
32-
};
34+
use crate::db::HirDatabase;
35+
36+
use self::case_conv::{to_camel_case, to_lower_snake_case, to_upper_snake_case};
3337

3438
mod allow {
3539
pub(super) const BAD_STYLE: &str = "bad_style";
@@ -39,6 +43,80 @@ mod allow {
3943
pub(super) const NON_CAMEL_CASE_TYPES: &str = "non_camel_case_types";
4044
}
4145

46+
pub fn incorrect_case(
47+
db: &dyn HirDatabase,
48+
krate: CrateId,
49+
owner: ModuleDefId,
50+
) -> Vec<IncorrectCase> {
51+
let _p = profile::span("validate_module_item");
52+
let mut validator = DeclValidator::new(db, krate);
53+
validator.validate_item(owner);
54+
validator.sink
55+
}
56+
57+
#[derive(Debug)]
58+
pub enum CaseType {
59+
// `some_var`
60+
LowerSnakeCase,
61+
// `SOME_CONST`
62+
UpperSnakeCase,
63+
// `SomeStruct`
64+
UpperCamelCase,
65+
}
66+
67+
impl fmt::Display for CaseType {
68+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69+
let repr = match self {
70+
CaseType::LowerSnakeCase => "snake_case",
71+
CaseType::UpperSnakeCase => "UPPER_SNAKE_CASE",
72+
CaseType::UpperCamelCase => "CamelCase",
73+
};
74+
75+
write!(f, "{}", repr)
76+
}
77+
}
78+
79+
#[derive(Debug)]
80+
pub enum IdentType {
81+
Constant,
82+
Enum,
83+
Field,
84+
Function,
85+
Parameter,
86+
StaticVariable,
87+
Structure,
88+
Variable,
89+
Variant,
90+
}
91+
92+
impl fmt::Display for IdentType {
93+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
94+
let repr = match self {
95+
IdentType::Constant => "Constant",
96+
IdentType::Enum => "Enum",
97+
IdentType::Field => "Field",
98+
IdentType::Function => "Function",
99+
IdentType::Parameter => "Parameter",
100+
IdentType::StaticVariable => "Static variable",
101+
IdentType::Structure => "Structure",
102+
IdentType::Variable => "Variable",
103+
IdentType::Variant => "Variant",
104+
};
105+
106+
write!(f, "{}", repr)
107+
}
108+
}
109+
110+
#[derive(Debug)]
111+
pub struct IncorrectCase {
112+
pub file: HirFileId,
113+
pub ident: AstPtr<ast::Name>,
114+
pub expected_case: CaseType,
115+
pub ident_type: IdentType,
116+
pub ident_text: String,
117+
pub suggested_text: String,
118+
}
119+
42120
pub(super) struct DeclValidator<'a> {
43121
db: &'a dyn HirDatabase,
44122
krate: CrateId,

0 commit comments

Comments
 (0)