1 //! Provides validators for the item declarations.
3 //! This includes the following items:
5 //! - variable bindings (e.g. `let x = foo();`)
6 //! - struct fields (e.g. `struct Foo { field: u8 }`)
7 //! - enum variants (e.g. `enum Foo { Variant { field: u8 } }`)
8 //! - function/method arguments (e.g. `fn foo(arg: u8)`)
9 //! - constants (e.g. `const FOO: u8 = 10;`)
10 //! - static items (e.g. `static FOO: u8 = 10;`)
11 //! - match arm bindings (e.g. `foo @ Some(_)`)
20 AdtId, AttrDefId, ConstId, EnumId, FunctionId, Lookup, ModuleDefId, StaticId, StructId,
22 use hir_expand::name::{AsName, Name};
23 use stdx::{always, never};
25 ast::{self, NameOwner},
31 diagnostics::{decl_check::case_conv::*, CaseType, IdentType, IncorrectCase},
32 diagnostics_sink::DiagnosticSink,
36 pub(super) const BAD_STYLE: &str = "bad_style";
37 pub(super) const NONSTANDARD_STYLE: &str = "nonstandard_style";
38 pub(super) const NON_SNAKE_CASE: &str = "non_snake_case";
39 pub(super) const NON_UPPER_CASE_GLOBAL: &str = "non_upper_case_globals";
40 pub(super) const NON_CAMEL_CASE_TYPES: &str = "non_camel_case_types";
43 pub(super) struct DeclValidator<'a, 'b> {
44 db: &'a dyn HirDatabase,
46 sink: &'a mut DiagnosticSink<'b>,
52 suggested_text: String,
53 expected_case: CaseType,
56 impl<'a, 'b> DeclValidator<'a, 'b> {
58 db: &'a dyn HirDatabase,
60 sink: &'a mut DiagnosticSink<'b>,
61 ) -> DeclValidator<'a, 'b> {
62 DeclValidator { db, krate, sink }
65 pub(super) fn validate_item(&mut self, item: ModuleDefId) {
67 ModuleDefId::FunctionId(func) => self.validate_func(func),
68 ModuleDefId::AdtId(adt) => self.validate_adt(adt),
69 ModuleDefId::ConstId(const_id) => self.validate_const(const_id),
70 ModuleDefId::StaticId(static_id) => self.validate_static(static_id),
75 fn validate_adt(&mut self, adt: AdtId) {
77 AdtId::StructId(struct_id) => self.validate_struct(struct_id),
78 AdtId::EnumId(enum_id) => self.validate_enum(enum_id),
79 AdtId::UnionId(_) => {
80 // FIXME: Unions aren't yet supported by this validator.
85 /// Checks whether not following the convention is allowed for this item.
86 fn allowed(&self, id: AttrDefId, allow_name: &str, recursing: bool) -> bool {
87 let is_allowed = |def_id| {
88 let attrs = self.db.attrs(def_id);
89 // don't bug the user about directly no_mangle annotated stuff, they can't do anything about it
90 (!recursing && attrs.by_key("no_mangle").exists())
91 || attrs.by_key("allow").tt_values().any(|tt| {
92 let allows = tt.to_string();
93 allows.contains(allow_name)
94 || allows.contains(allow::BAD_STYLE)
95 || allows.contains(allow::NONSTANDARD_STYLE)
100 // go upwards one step or give up
102 AttrDefId::ModuleId(m) => m.containing_module(self.db.upcast()).map(|v| v.into()),
103 AttrDefId::FunctionId(f) => Some(f.lookup(self.db.upcast()).container.into()),
104 AttrDefId::StaticId(sid) => Some(sid.lookup(self.db.upcast()).container.into()),
105 AttrDefId::ConstId(cid) => Some(cid.lookup(self.db.upcast()).container.into()),
106 AttrDefId::TraitId(tid) => Some(tid.lookup(self.db.upcast()).container.into()),
107 AttrDefId::ImplId(iid) => Some(iid.lookup(self.db.upcast()).container.into()),
108 // These warnings should not explore macro definitions at all
109 AttrDefId::MacroDefId(_) => None,
110 // Will never occur under an enum/struct/union/type alias
111 AttrDefId::AdtId(_) => None,
112 AttrDefId::FieldId(_) => None,
113 AttrDefId::EnumVariantId(_) => None,
114 AttrDefId::TypeAliasId(_) => None,
115 AttrDefId::GenericParamId(_) => None,
117 .map(|mid| self.allowed(mid, allow_name, true))
121 fn validate_func(&mut self, func: FunctionId) {
122 let data = self.db.function_data(func);
123 if data.is_in_extern_block() {
124 cov_mark::hit!(extern_func_incorrect_case_ignored);
128 let body = self.db.body(func.into());
130 // Recursively validate inner scope items, such as static variables and constants.
131 for (_, block_def_map) in body.blocks(self.db.upcast()) {
132 for (_, module) in block_def_map.modules() {
133 for def_id in module.scope.declarations() {
134 let mut validator = DeclValidator::new(self.db, self.krate, self.sink);
135 validator.validate_item(def_id);
140 // Check whether non-snake case identifiers are allowed for this function.
141 if self.allowed(func.into(), allow::NON_SNAKE_CASE, false) {
145 // Check the function name.
146 let function_name = data.name.to_string();
147 let fn_name_replacement = to_lower_snake_case(&function_name).map(|new_name| Replacement {
148 current_name: data.name.clone(),
149 suggested_text: new_name,
150 expected_case: CaseType::LowerSnakeCase,
153 // Check the param names.
154 let fn_param_replacements = body
157 .filter_map(|&id| match &body[id] {
158 Pat::Bind { name, .. } => Some(name),
161 .filter_map(|param_name| {
163 current_name: param_name.clone(),
164 suggested_text: to_lower_snake_case(¶m_name.to_string())?,
165 expected_case: CaseType::LowerSnakeCase,
170 // Check the patterns inside the function body.
171 let pats_replacements = body
174 // We aren't interested in function parameters, we've processed them above.
175 .filter(|(pat_idx, _)| !body.params.contains(&pat_idx))
176 .filter_map(|(id, pat)| match pat {
177 Pat::Bind { name, .. } => Some((id, name)),
180 .filter_map(|(id, bind_name)| {
184 current_name: bind_name.clone(),
185 suggested_text: to_lower_snake_case(&bind_name.to_string())?,
186 expected_case: CaseType::LowerSnakeCase,
192 // If there is at least one element to spawn a warning on, go to the source map and generate a warning.
193 self.create_incorrect_case_diagnostic_for_func(
196 fn_param_replacements,
198 self.create_incorrect_case_diagnostic_for_variables(func, pats_replacements);
201 /// Given the information about incorrect names in the function declaration, looks up into the source code
202 /// for exact locations and adds diagnostics into the sink.
203 fn create_incorrect_case_diagnostic_for_func(
206 fn_name_replacement: Option<Replacement>,
207 fn_param_replacements: Vec<Replacement>,
209 // XXX: only look at sources if we do have incorrect names
210 if fn_name_replacement.is_none() && fn_param_replacements.is_empty() {
214 let fn_loc = func.lookup(self.db.upcast());
215 let fn_src = fn_loc.source(self.db.upcast());
217 // Diagnostic for function name.
218 if let Some(replacement) = fn_name_replacement {
219 let ast_ptr = match fn_src.value.name() {
223 "Replacement ({:?}) was generated for a function without a name: {:?}",
231 let diagnostic = IncorrectCase {
232 file: fn_src.file_id,
233 ident_type: IdentType::Function,
234 ident: AstPtr::new(&ast_ptr),
235 expected_case: replacement.expected_case,
236 ident_text: replacement.current_name.to_string(),
237 suggested_text: replacement.suggested_text,
240 self.sink.push(diagnostic);
243 // Diagnostics for function params.
244 let fn_params_list = match fn_src.value.param_list() {
245 Some(params) => params,
248 fn_param_replacements.is_empty(),
249 "Replacements ({:?}) were generated for a function parameters which had no parameters list: {:?}",
250 fn_param_replacements,
256 let mut fn_params_iter = fn_params_list.params();
257 for param_to_rename in fn_param_replacements {
258 // We assume that parameters in replacement are in the same order as in the
259 // actual params list, but just some of them (ones that named correctly) are skipped.
260 let ast_ptr: ast::Name = loop {
261 match fn_params_iter.next() {
263 if let Some(ast::Pat::IdentPat(pat)) = element.pat() {
264 if pat.to_string() == param_to_rename.current_name.to_string() {
265 if let Some(name) = pat.name() {
268 // This is critical. If we consider this parameter the expected one,
269 // it **must** have a name.
271 "Pattern {:?} equals to expected replacement {:?}, but has no name",
281 "Replacement ({:?}) was generated for a function parameter which was not found: {:?}",
282 param_to_rename, fn_src
289 let diagnostic = IncorrectCase {
290 file: fn_src.file_id,
291 ident_type: IdentType::Argument,
292 ident: AstPtr::new(&ast_ptr),
293 expected_case: param_to_rename.expected_case,
294 ident_text: param_to_rename.current_name.to_string(),
295 suggested_text: param_to_rename.suggested_text,
298 self.sink.push(diagnostic);
302 /// Given the information about incorrect variable names, looks up into the source code
303 /// for exact locations and adds diagnostics into the sink.
304 fn create_incorrect_case_diagnostic_for_variables(
307 pats_replacements: Vec<(PatId, Replacement)>,
309 // XXX: only look at source_map if we do have missing fields
310 if pats_replacements.is_empty() {
314 let (_, source_map) = self.db.body_with_source_map(func.into());
316 for (id, replacement) in pats_replacements {
317 if let Ok(source_ptr) = source_map.pat_syntax(id) {
318 if let Some(expr) = source_ptr.value.as_ref().left() {
319 let root = source_ptr.file_syntax(self.db.upcast());
320 if let ast::Pat::IdentPat(ident_pat) = expr.to_node(&root) {
321 let parent = match ident_pat.syntax().parent() {
322 Some(parent) => parent,
325 let name_ast = match ident_pat.name() {
326 Some(name_ast) => name_ast,
330 // We have to check that it's either `let var = ...` or `var @ Variant(_)` statement,
331 // because e.g. match arms are patterns as well.
332 // In other words, we check that it's a named variable binding.
333 let is_binding = ast::LetStmt::can_cast(parent.kind())
334 || (ast::MatchArm::can_cast(parent.kind())
335 && ident_pat.at_token().is_some());
337 // This pattern is not an actual variable declaration, e.g. `Some(val) => {..}` match arm.
341 let diagnostic = IncorrectCase {
342 file: source_ptr.file_id,
343 ident_type: IdentType::Variable,
344 ident: AstPtr::new(&name_ast),
345 expected_case: replacement.expected_case,
346 ident_text: replacement.current_name.to_string(),
347 suggested_text: replacement.suggested_text,
350 self.sink.push(diagnostic);
357 fn validate_struct(&mut self, struct_id: StructId) {
358 let data = self.db.struct_data(struct_id);
360 let non_camel_case_allowed =
361 self.allowed(struct_id.into(), allow::NON_CAMEL_CASE_TYPES, false);
362 let non_snake_case_allowed = self.allowed(struct_id.into(), allow::NON_SNAKE_CASE, false);
364 // Check the structure name.
365 let struct_name = data.name.to_string();
366 let struct_name_replacement = if !non_camel_case_allowed {
367 to_camel_case(&struct_name).map(|new_name| Replacement {
368 current_name: data.name.clone(),
369 suggested_text: new_name,
370 expected_case: CaseType::UpperCamelCase,
376 // Check the field names.
377 let mut struct_fields_replacements = Vec::new();
379 if !non_snake_case_allowed {
380 if let VariantData::Record(fields) = data.variant_data.as_ref() {
381 for (_, field) in fields.iter() {
382 let field_name = field.name.to_string();
383 if let Some(new_name) = to_lower_snake_case(&field_name) {
384 let replacement = Replacement {
385 current_name: field.name.clone(),
386 suggested_text: new_name,
387 expected_case: CaseType::LowerSnakeCase,
389 struct_fields_replacements.push(replacement);
395 // If there is at least one element to spawn a warning on, go to the source map and generate a warning.
396 self.create_incorrect_case_diagnostic_for_struct(
398 struct_name_replacement,
399 struct_fields_replacements,
403 /// Given the information about incorrect names in the struct declaration, looks up into the source code
404 /// for exact locations and adds diagnostics into the sink.
405 fn create_incorrect_case_diagnostic_for_struct(
408 struct_name_replacement: Option<Replacement>,
409 struct_fields_replacements: Vec<Replacement>,
411 // XXX: only look at sources if we do have incorrect names
412 if struct_name_replacement.is_none() && struct_fields_replacements.is_empty() {
416 let struct_loc = struct_id.lookup(self.db.upcast());
417 let struct_src = struct_loc.source(self.db.upcast());
419 if let Some(replacement) = struct_name_replacement {
420 let ast_ptr = match struct_src.value.name() {
424 "Replacement ({:?}) was generated for a structure without a name: {:?}",
432 let diagnostic = IncorrectCase {
433 file: struct_src.file_id,
434 ident_type: IdentType::Structure,
435 ident: AstPtr::new(&ast_ptr),
436 expected_case: replacement.expected_case,
437 ident_text: replacement.current_name.to_string(),
438 suggested_text: replacement.suggested_text,
441 self.sink.push(diagnostic);
444 let struct_fields_list = match struct_src.value.field_list() {
445 Some(ast::FieldList::RecordFieldList(fields)) => fields,
448 struct_fields_replacements.is_empty(),
449 "Replacements ({:?}) were generated for a structure fields which had no fields list: {:?}",
450 struct_fields_replacements,
456 let mut struct_fields_iter = struct_fields_list.fields();
457 for field_to_rename in struct_fields_replacements {
458 // We assume that parameters in replacement are in the same order as in the
459 // actual params list, but just some of them (ones that named correctly) are skipped.
461 match struct_fields_iter.next().and_then(|field| field.name()) {
462 Some(field_name) => {
463 if field_name.as_name() == field_to_rename.current_name {
469 "Replacement ({:?}) was generated for a structure field which was not found: {:?}",
470 field_to_rename, struct_src
477 let diagnostic = IncorrectCase {
478 file: struct_src.file_id,
479 ident_type: IdentType::Field,
480 ident: AstPtr::new(&ast_ptr),
481 expected_case: field_to_rename.expected_case,
482 ident_text: field_to_rename.current_name.to_string(),
483 suggested_text: field_to_rename.suggested_text,
486 self.sink.push(diagnostic);
490 fn validate_enum(&mut self, enum_id: EnumId) {
491 let data = self.db.enum_data(enum_id);
493 // Check whether non-camel case names are allowed for this enum.
494 if self.allowed(enum_id.into(), allow::NON_CAMEL_CASE_TYPES, false) {
498 // Check the enum name.
499 let enum_name = data.name.to_string();
500 let enum_name_replacement = to_camel_case(&enum_name).map(|new_name| Replacement {
501 current_name: data.name.clone(),
502 suggested_text: new_name,
503 expected_case: CaseType::UpperCamelCase,
506 // Check the field names.
507 let enum_fields_replacements = data
510 .filter_map(|(_, variant)| {
512 current_name: variant.name.clone(),
513 suggested_text: to_camel_case(&variant.name.to_string())?,
514 expected_case: CaseType::UpperCamelCase,
519 // If there is at least one element to spawn a warning on, go to the source map and generate a warning.
520 self.create_incorrect_case_diagnostic_for_enum(
522 enum_name_replacement,
523 enum_fields_replacements,
527 /// Given the information about incorrect names in the struct declaration, looks up into the source code
528 /// for exact locations and adds diagnostics into the sink.
529 fn create_incorrect_case_diagnostic_for_enum(
532 enum_name_replacement: Option<Replacement>,
533 enum_variants_replacements: Vec<Replacement>,
535 // XXX: only look at sources if we do have incorrect names
536 if enum_name_replacement.is_none() && enum_variants_replacements.is_empty() {
540 let enum_loc = enum_id.lookup(self.db.upcast());
541 let enum_src = enum_loc.source(self.db.upcast());
543 if let Some(replacement) = enum_name_replacement {
544 let ast_ptr = match enum_src.value.name() {
548 "Replacement ({:?}) was generated for a enum without a name: {:?}",
556 let diagnostic = IncorrectCase {
557 file: enum_src.file_id,
558 ident_type: IdentType::Enum,
559 ident: AstPtr::new(&ast_ptr),
560 expected_case: replacement.expected_case,
561 ident_text: replacement.current_name.to_string(),
562 suggested_text: replacement.suggested_text,
565 self.sink.push(diagnostic);
568 let enum_variants_list = match enum_src.value.variant_list() {
569 Some(variants) => variants,
572 enum_variants_replacements.is_empty(),
573 "Replacements ({:?}) were generated for a enum variants which had no fields list: {:?}",
574 enum_variants_replacements,
580 let mut enum_variants_iter = enum_variants_list.variants();
581 for variant_to_rename in enum_variants_replacements {
582 // We assume that parameters in replacement are in the same order as in the
583 // actual params list, but just some of them (ones that named correctly) are skipped.
585 match enum_variants_iter.next().and_then(|v| v.name()) {
586 Some(variant_name) => {
587 if variant_name.as_name() == variant_to_rename.current_name {
593 "Replacement ({:?}) was generated for a enum variant which was not found: {:?}",
594 variant_to_rename, enum_src
601 let diagnostic = IncorrectCase {
602 file: enum_src.file_id,
603 ident_type: IdentType::Variant,
604 ident: AstPtr::new(&ast_ptr),
605 expected_case: variant_to_rename.expected_case,
606 ident_text: variant_to_rename.current_name.to_string(),
607 suggested_text: variant_to_rename.suggested_text,
610 self.sink.push(diagnostic);
614 fn validate_const(&mut self, const_id: ConstId) {
615 let data = self.db.const_data(const_id);
617 if self.allowed(const_id.into(), allow::NON_UPPER_CASE_GLOBAL, false) {
621 let name = match &data.name {
626 let const_name = name.to_string();
627 let replacement = if let Some(new_name) = to_upper_snake_case(&const_name) {
629 current_name: name.clone(),
630 suggested_text: new_name,
631 expected_case: CaseType::UpperSnakeCase,
634 // Nothing to do here.
638 let const_loc = const_id.lookup(self.db.upcast());
639 let const_src = const_loc.source(self.db.upcast());
641 let ast_ptr = match const_src.value.name() {
646 let diagnostic = IncorrectCase {
647 file: const_src.file_id,
648 ident_type: IdentType::Constant,
649 ident: AstPtr::new(&ast_ptr),
650 expected_case: replacement.expected_case,
651 ident_text: replacement.current_name.to_string(),
652 suggested_text: replacement.suggested_text,
655 self.sink.push(diagnostic);
658 fn validate_static(&mut self, static_id: StaticId) {
659 let data = self.db.static_data(static_id);
661 cov_mark::hit!(extern_static_incorrect_case_ignored);
665 if self.allowed(static_id.into(), allow::NON_UPPER_CASE_GLOBAL, false) {
669 let name = match &data.name {
674 let static_name = name.to_string();
675 let replacement = if let Some(new_name) = to_upper_snake_case(&static_name) {
677 current_name: name.clone(),
678 suggested_text: new_name,
679 expected_case: CaseType::UpperSnakeCase,
682 // Nothing to do here.
686 let static_loc = static_id.lookup(self.db.upcast());
687 let static_src = static_loc.source(self.db.upcast());
689 let ast_ptr = match static_src.value.name() {
694 let diagnostic = IncorrectCase {
695 file: static_src.file_id,
696 ident_type: IdentType::StaticVariable,
697 ident: AstPtr::new(&ast_ptr),
698 expected_case: replacement.expected_case,
699 ident_text: replacement.current_name.to_string(),
700 suggested_text: replacement.suggested_text,
703 self.sink.push(diagnostic);
709 use crate::diagnostics::tests::check_diagnostics;
712 fn incorrect_function_name() {
715 fn NonSnakeCaseName() {}
716 // ^^^^^^^^^^^^^^^^ Function `NonSnakeCaseName` should have snake_case name, e.g. `non_snake_case_name`
722 fn incorrect_function_params() {
725 fn foo(SomeParam: u8) {}
726 // ^^^^^^^^^ Argument `SomeParam` should have snake_case name, e.g. `some_param`
728 fn foo2(ok_param: &str, CAPS_PARAM: u8) {}
729 // ^^^^^^^^^^ Argument `CAPS_PARAM` should have snake_case name, e.g. `caps_param`
735 fn incorrect_variable_names() {
740 // ^^^^^^^^^^ Variable `SOME_VALUE` should have snake_case name, e.g. `some_value`
741 let AnotherValue = 20;
742 // ^^^^^^^^^^^^ Variable `AnotherValue` should have snake_case name, e.g. `another_value`
749 fn incorrect_struct_names() {
752 struct non_camel_case_name {}
753 // ^^^^^^^^^^^^^^^^^^^ Structure `non_camel_case_name` should have CamelCase name, e.g. `NonCamelCaseName`
755 struct SCREAMING_CASE {}
756 // ^^^^^^^^^^^^^^ Structure `SCREAMING_CASE` should have CamelCase name, e.g. `ScreamingCase`
762 fn no_diagnostic_for_camel_cased_acronyms_in_struct_name() {
771 fn incorrect_struct_field() {
774 struct SomeStruct { SomeField: u8 }
775 // ^^^^^^^^^ Field `SomeField` should have snake_case name, e.g. `some_field`
781 fn incorrect_enum_names() {
784 enum some_enum { Val(u8) }
785 // ^^^^^^^^^ Enum `some_enum` should have CamelCase name, e.g. `SomeEnum`
788 // ^^^^^^^^^ Enum `SOME_ENUM` should have CamelCase name, e.g. `SomeEnum`
794 fn no_diagnostic_for_camel_cased_acronyms_in_enum_name() {
803 fn incorrect_enum_variant_name() {
806 enum SomeEnum { SOME_VARIANT(u8) }
807 // ^^^^^^^^^^^^ Variant `SOME_VARIANT` should have CamelCase name, e.g. `SomeVariant`
813 fn incorrect_const_name() {
816 const some_weird_const: u8 = 10;
817 // ^^^^^^^^^^^^^^^^ Constant `some_weird_const` should have UPPER_SNAKE_CASE name, e.g. `SOME_WEIRD_CONST`
820 const someConstInFunc: &str = "hi there";
821 // ^^^^^^^^^^^^^^^ Constant `someConstInFunc` should have UPPER_SNAKE_CASE name, e.g. `SOME_CONST_IN_FUNC`
829 fn incorrect_static_name() {
832 static some_weird_const: u8 = 10;
833 // ^^^^^^^^^^^^^^^^ Static variable `some_weird_const` should have UPPER_SNAKE_CASE name, e.g. `SOME_WEIRD_CONST`
836 static someConstInFunc: &str = "hi there";
837 // ^^^^^^^^^^^^^^^ Static variable `someConstInFunc` should have UPPER_SNAKE_CASE name, e.g. `SOME_CONST_IN_FUNC`
844 fn fn_inside_impl_struct() {
848 // ^^^^^^^^^^ Structure `someStruct` should have CamelCase name, e.g. `SomeStruct`
852 // ^^^^^^^^ Function `SomeFunc` should have snake_case name, e.g. `some_func`
853 static someConstInFunc: &str = "hi there";
854 // ^^^^^^^^^^^^^^^ Static variable `someConstInFunc` should have UPPER_SNAKE_CASE name, e.g. `SOME_CONST_IN_FUNC`
855 let WHY_VAR_IS_CAPS = 10;
856 // ^^^^^^^^^^^^^^^ Variable `WHY_VAR_IS_CAPS` should have snake_case name, e.g. `why_var_is_caps`
864 fn no_diagnostic_for_enum_varinats() {
867 enum Option { Some, None }
883 enum Option { Some, None }
887 SOME_VAR @ None => (),
888 // ^^^^^^^^ Variable `SOME_VAR` should have snake_case name, e.g. `some_var`
897 fn allow_attributes() {
900 #[allow(non_snake_case)]
901 fn NonSnakeCaseName(SOME_VAR: u8) -> u8{
902 // cov_flags generated output from elsewhere in this file
905 static lower_case: u8;
908 let OtherVar = SOME_VAR + 1;
912 #[allow(nonstandard_style)]
913 mod CheckNonstandardStyle {
914 fn HiImABadFnName() {}
919 fn HiImABadFnName() {}
923 #![allow(non_snake_case)]
924 fn CheckItWorksWithModAttr(BAD_NAME_HI: u8) {}
927 #[allow(non_snake_case, non_camel_case_types)]
928 pub struct some_type {
933 #[allow(non_upper_case_globals)]
934 pub const some_const: u8 = 10;
936 #[allow(non_upper_case_globals)]
937 pub static SomeStatic: u8 = 10;
943 fn allow_attributes_crate_attr() {
946 #![allow(non_snake_case)]
949 fn CheckItWorksWithCrateAttr(BAD_NAME_HI: u8) {}
957 fn bug_trait_inside_fn() {
959 // This is broken, and in fact, should not even be looked at by this
960 // lint in the first place. There's weird stuff going on in the
962 // It's currently being brought in by:
963 // * validate_func on `a` recursing into modules
964 // * then it finds the trait and then the function while iterating
966 // * then validate_func is called on Dirty
967 // * ... which then proceeds to look at some unknown module taking no
968 // attrs from either the impl or the fn a, and then finally to the root
971 // It should find the attribute on the trait, but it *doesn't even see
972 // the trait* as far as I can tell.
980 // this comes out of bitflags, mostly
981 #[allow(non_snake_case)]
983 const HiImAlsoBad: u8 = 2;
985 fn Dirty(&self) -> bool {
998 fn bug_traits_arent_checked() {
999 // FIXME: Traits and functions in traits aren't currently checked by
1000 // r-a, even though rustc will complain about them.
1004 // ^^^^^^^^^ Trait `BAD_TRAIT` should have CamelCase name, e.g. `BadTrait`
1006 // ^^^^^^^^^^^^ Function `BAD_FUNCTION` should have snake_case name, e.g. `bad_function`
1008 // ^^^^^^^^^^^^ Function `BadFunction` should have snake_case name, e.g. `bad_function`
1015 fn ignores_extern_items() {
1016 cov_mark::check!(extern_func_incorrect_case_ignored);
1017 cov_mark::check!(extern_static_incorrect_case_ignored);
1021 fn NonSnakeCaseName(SOME_VAR: u8) -> u8;
1022 pub static SomeStatic: u8 = 10;
1029 fn infinite_loop_inner_items() {