9
9
// If you see these lines in the pull request, feel free to call me stupid :P.
10
10
#![ allow( dead_code, unused_imports, unused_variables) ]
11
11
12
+ mod str_helpers;
13
+
12
14
use std:: sync:: Arc ;
13
15
14
16
use hir_def:: {
@@ -18,7 +20,7 @@ use hir_def::{
18
20
item_tree:: ItemTreeNode ,
19
21
resolver:: { resolver_for_expr, ResolveValueResult , ValueNs } ,
20
22
src:: HasSource ,
21
- AdtId , FunctionId , Lookup , ModuleDefId ,
23
+ AdtId , EnumId , FunctionId , Lookup , ModuleDefId , StructId ,
22
24
} ;
23
25
use hir_expand:: { diagnostics:: DiagnosticSink , name:: Name } ;
24
26
use syntax:: {
@@ -28,7 +30,7 @@ use syntax::{
28
30
29
31
use crate :: {
30
32
db:: HirDatabase ,
31
- diagnostics:: { CaseType , IncorrectCase } ,
33
+ diagnostics:: { decl_check :: str_helpers :: * , CaseType , IncorrectCase } ,
32
34
lower:: CallableDefId ,
33
35
ApplicationTy , InferenceResult , Ty , TypeCtor ,
34
36
} ;
@@ -191,41 +193,30 @@ impl<'a, 'b> DeclValidator<'a, 'b> {
191
193
}
192
194
}
193
195
194
- fn validate_adt ( & mut self , db : & dyn HirDatabase , adt : AdtId ) { }
195
- }
196
-
197
- fn pat_equals_to_name ( pat : Option < ast :: Pat > , name : & Name ) -> bool {
198
- if let Some ( ast :: Pat :: IdentPat ( ident ) ) = pat {
199
- ident . to_string ( ) == name . to_string ( )
200
- } else {
201
- false
196
+ fn validate_adt ( & mut self , db : & dyn HirDatabase , adt : AdtId ) {
197
+ match adt {
198
+ AdtId :: StructId ( struct_id ) => self . validate_struct ( db , struct_id ) ,
199
+ AdtId :: EnumId ( enum_id ) => self . validate_enum ( db , enum_id ) ,
200
+ AdtId :: UnionId ( _ ) => {
201
+ // Unions aren't yet supported by this validator.
202
+ }
203
+ }
202
204
}
203
- }
204
205
205
- fn to_lower_snake_case ( ident : & str ) -> Option < String > {
206
- // First, assume that it's UPPER_SNAKE_CASE.
207
- if let Some ( normalized) = to_lower_snake_case_from_upper_snake_case ( ident) {
208
- return Some ( normalized) ;
206
+ fn validate_struct ( & mut self , db : & dyn HirDatabase , struct_id : StructId ) {
207
+ let data = db. struct_data ( struct_id) ;
209
208
}
210
209
211
- // Otherwise, assume that it's CamelCase.
212
- let lower_snake_case = stdx:: to_lower_snake_case ( ident) ;
213
-
214
- if lower_snake_case == ident {
215
- None
216
- } else {
217
- Some ( lower_snake_case)
210
+ fn validate_enum ( & mut self , db : & dyn HirDatabase , enum_id : EnumId ) {
211
+ let data = db. enum_data ( enum_id) ;
218
212
}
219
213
}
220
214
221
- fn to_lower_snake_case_from_upper_snake_case ( ident : & str ) -> Option < String > {
222
- let is_upper_snake_case = ident. chars ( ) . all ( |c| c. is_ascii_uppercase ( ) || c == '_' ) ;
223
-
224
- if is_upper_snake_case {
225
- let string = ident. chars ( ) . map ( |c| c. to_ascii_lowercase ( ) ) . collect ( ) ;
226
- Some ( string)
215
+ fn pat_equals_to_name ( pat : Option < ast:: Pat > , name : & Name ) -> bool {
216
+ if let Some ( ast:: Pat :: IdentPat ( ident) ) = pat {
217
+ ident. to_string ( ) == name. to_string ( )
227
218
} else {
228
- None
219
+ false
229
220
}
230
221
}
231
222
0 commit comments