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,
23 diagnostics::DiagnosticSink,
26 use stdx::{always, never};
28 ast::{self, NameOwner},
34 diagnostics::{decl_check::case_conv::*, CaseType, IdentType, IncorrectCase},
38 pub(super) const BAD_STYLE: &str = "bad_style";
39 pub(super) const NONSTANDARD_STYLE: &str = "nonstandard_style";
40 pub(super) const NON_SNAKE_CASE: &str = "non_snake_case";
41 pub(super) const NON_UPPER_CASE_GLOBAL: &str = "non_upper_case_globals";
42 pub(super) const NON_CAMEL_CASE_TYPES: &str = "non_camel_case_types";
45 pub(super) struct DeclValidator<'a, 'b> {
46 db: &'a dyn HirDatabase,
48 sink: &'a mut DiagnosticSink<'b>,
54 suggested_text: String,
55 expected_case: CaseType,
58 impl<'a, 'b> DeclValidator<'a, 'b> {
60 db: &'a dyn HirDatabase,
62 sink: &'a mut DiagnosticSink<'b>,
63 ) -> DeclValidator<'a, 'b> {
64 DeclValidator { db, krate, sink }
67 pub(super) fn validate_item(&mut self, item: ModuleDefId) {
69 ModuleDefId::FunctionId(func) => self.validate_func(func),
70 ModuleDefId::AdtId(adt) => self.validate_adt(adt),
71 ModuleDefId::ConstId(const_id) => self.validate_const(const_id),
72 ModuleDefId::StaticId(static_id) => self.validate_static(static_id),
77 fn validate_adt(&mut self, adt: AdtId) {
79 AdtId::StructId(struct_id) => self.validate_struct(struct_id),
80 AdtId::EnumId(enum_id) => self.validate_enum(enum_id),
81 AdtId::UnionId(_) => {
82 // FIXME: Unions aren't yet supported by this validator.
87 /// Checks whether not following the convention is allowed for this item.
88 fn allowed(&self, id: AttrDefId, allow_name: &str, recursing: bool) -> bool {
89 let is_allowed = |def_id| {
90 let attrs = self.db.attrs(def_id);
91 // don't bug the user about directly no_mangle annotated stuff, they can't do anything about it
92 (!recursing && attrs.by_key("no_mangle").exists())
93 || attrs.by_key("allow").tt_values().any(|tt| {
94 let allows = tt.to_string();
95 allows.contains(allow_name)
96 || allows.contains(allow::BAD_STYLE)
97 || allows.contains(allow::NONSTANDARD_STYLE)
102 // go upwards one step or give up
104 AttrDefId::ModuleId(m) => m.containing_module(self.db.upcast()).map(|v| v.into()),
105 AttrDefId::FunctionId(f) => Some(f.lookup(self.db.upcast()).container.into()),
106 AttrDefId::StaticId(sid) => Some(sid.lookup(self.db.upcast()).container.into()),
107 AttrDefId::ConstId(cid) => Some(cid.lookup(self.db.upcast()).container.into()),
108 AttrDefId::TraitId(tid) => Some(tid.lookup(self.db.upcast()).container.into()),
109 AttrDefId::ImplId(iid) => Some(iid.lookup(self.db.upcast()).container.into()),
110 // These warnings should not explore macro definitions at all
111 AttrDefId::MacroDefId(_) => None,
112 // Will never occur under an enum/struct/union/type alias
113 AttrDefId::AdtId(_) => None,
114 AttrDefId::FieldId(_) => None,
115 AttrDefId::EnumVariantId(_) => None,
116 AttrDefId::TypeAliasId(_) => None,
117 AttrDefId::GenericParamId(_) => None,
119 .map(|mid| self.allowed(mid, allow_name, true))
123 fn validate_func(&mut self, func: FunctionId) {
124 let data = self.db.function_data(func);
125 if data.is_in_extern_block() {
126 cov_mark::hit!(extern_func_incorrect_case_ignored);
130 let body = self.db.body(func.into());
132 // Recursively validate inner scope items, such as static variables and constants.
133 for (_, block_def_map) in body.blocks(self.db.upcast()) {
134 for (_, module) in block_def_map.modules() {
135 for def_id in module.scope.declarations() {
136 let mut validator = DeclValidator::new(self.db, self.krate, self.sink);
137 validator.validate_item(def_id);
142 // Check whether non-snake case identifiers are allowed for this function.
143 if self.allowed(func.into(), allow::NON_SNAKE_CASE, false) {
147 // Check the function name.
148 let function_name = data.name.to_string();
149 let fn_name_replacement = to_lower_snake_case(&function_name).map(|new_name| Replacement {
150 current_name: data.name.clone(),
151 suggested_text: new_name,
152 expected_case: CaseType::LowerSnakeCase,
155 // Check the param names.
156 let fn_param_replacements = body
159 .filter_map(|&id| match &body[id] {
160 Pat::Bind { name, .. } => Some(name),
163 .filter_map(|param_name| {
165 current_name: param_name.clone(),
166 suggested_text: to_lower_snake_case(¶m_name.to_string())?,
167 expected_case: CaseType::LowerSnakeCase,
172 // Check the patterns inside the function body.
173 let pats_replacements = body
176 // We aren't interested in function parameters, we've processed them above.
177 .filter(|(pat_idx, _)| !body.params.contains(&pat_idx))
178 .filter_map(|(id, pat)| match pat {
179 Pat::Bind { name, .. } => Some((id, name)),
182 .filter_map(|(id, bind_name)| {
186 current_name: bind_name.clone(),
187 suggested_text: to_lower_snake_case(&bind_name.to_string())?,
188 expected_case: CaseType::LowerSnakeCase,
194 // If there is at least one element to spawn a warning on, go to the source map and generate a warning.
195 self.create_incorrect_case_diagnostic_for_func(
198 fn_param_replacements,
200 self.create_incorrect_case_diagnostic_for_variables(func, pats_replacements);
203 /// Given the information about incorrect names in the function declaration, looks up into the source code
204 /// for exact locations and adds diagnostics into the sink.
205 fn create_incorrect_case_diagnostic_for_func(
208 fn_name_replacement: Option<Replacement>,
209 fn_param_replacements: Vec<Replacement>,
211 // XXX: only look at sources if we do have incorrect names
212 if fn_name_replacement.is_none() && fn_param_replacements.is_empty() {
216 let fn_loc = func.lookup(self.db.upcast());
217 let fn_src = fn_loc.source(self.db.upcast());
219 // Diagnostic for function name.
220 if let Some(replacement) = fn_name_replacement {
221 let ast_ptr = match fn_src.value.name() {
225 "Replacement ({:?}) was generated for a function without a name: {:?}",
233 let diagnostic = IncorrectCase {
234 file: fn_src.file_id,
235 ident_type: IdentType::Function,
236 ident: AstPtr::new(&ast_ptr),
237 expected_case: replacement.expected_case,
238 ident_text: replacement.current_name.to_string(),
239 suggested_text: replacement.suggested_text,
242 self.sink.push(diagnostic);
245 // Diagnostics for function params.
246 let fn_params_list = match fn_src.value.param_list() {
247 Some(params) => params,
250 fn_param_replacements.is_empty(),
251 "Replacements ({:?}) were generated for a function parameters which had no parameters list: {:?}",
252 fn_param_replacements,
258 let mut fn_params_iter = fn_params_list.params();
259 for param_to_rename in fn_param_replacements {
260 // We assume that parameters in replacement are in the same order as in the
261 // actual params list, but just some of them (ones that named correctly) are skipped.
262 let ast_ptr: ast::Name = loop {
263 match fn_params_iter.next() {
265 if let Some(ast::Pat::IdentPat(pat)) = element.pat() {
266 if pat.to_string() == param_to_rename.current_name.to_string() {
267 if let Some(name) = pat.name() {
270 // This is critical. If we consider this parameter the expected one,
271 // it **must** have a name.
273 "Pattern {:?} equals to expected replacement {:?}, but has no name",
283 "Replacement ({:?}) was generated for a function parameter which was not found: {:?}",
284 param_to_rename, fn_src
291 let diagnostic = IncorrectCase {
292 file: fn_src.file_id,
293 ident_type: IdentType::Argument,
294 ident: AstPtr::new(&ast_ptr),
295 expected_case: param_to_rename.expected_case,
296 ident_text: param_to_rename.current_name.to_string(),
297 suggested_text: param_to_rename.suggested_text,
300 self.sink.push(diagnostic);
304 /// Given the information about incorrect variable names, looks up into the source code
305 /// for exact locations and adds diagnostics into the sink.
306 fn create_incorrect_case_diagnostic_for_variables(
309 pats_replacements: Vec<(PatId, Replacement)>,
311 // XXX: only look at source_map if we do have missing fields
312 if pats_replacements.is_empty() {
316 let (_, source_map) = self.db.body_with_source_map(func.into());
318 for (id, replacement) in pats_replacements {
319 if let Ok(source_ptr) = source_map.pat_syntax(id) {
320 if let Some(expr) = source_ptr.value.as_ref().left() {
321 let root = source_ptr.file_syntax(self.db.upcast());
322 if let ast::Pat::IdentPat(ident_pat) = expr.to_node(&root) {
323 let parent = match ident_pat.syntax().parent() {
324 Some(parent) => parent,
327 let name_ast = match ident_pat.name() {
328 Some(name_ast) => name_ast,
332 // We have to check that it's either `let var = ...` or `var @ Variant(_)` statement,
333 // because e.g. match arms are patterns as well.
334 // In other words, we check that it's a named variable binding.
335 let is_binding = ast::LetStmt::can_cast(parent.kind())
336 || (ast::MatchArm::can_cast(parent.kind())
337 && ident_pat.at_token().is_some());
339 // This pattern is not an actual variable declaration, e.g. `Some(val) => {..}` match arm.
343 let diagnostic = IncorrectCase {
344 file: source_ptr.file_id,
345 ident_type: IdentType::Variable,
346 ident: AstPtr::new(&name_ast),
347 expected_case: replacement.expected_case,
348 ident_text: replacement.current_name.to_string(),
349 suggested_text: replacement.suggested_text,
352 self.sink.push(diagnostic);
359 fn validate_struct(&mut self, struct_id: StructId) {
360 let data = self.db.struct_data(struct_id);
362 let non_camel_case_allowed =
363 self.allowed(struct_id.into(), allow::NON_CAMEL_CASE_TYPES, false);
364 let non_snake_case_allowed = self.allowed(struct_id.into(), allow::NON_SNAKE_CASE, false);
366 // Check the structure name.
367 let struct_name = data.name.to_string();
368 let struct_name_replacement = if !non_camel_case_allowed {
369 to_camel_case(&struct_name).map(|new_name| Replacement {
370 current_name: data.name.clone(),
371 suggested_text: new_name,
372 expected_case: CaseType::UpperCamelCase,
378 // Check the field names.
379 let mut struct_fields_replacements = Vec::new();
381 if !non_snake_case_allowed {
382 if let VariantData::Record(fields) = data.variant_data.as_ref() {
383 for (_, field) in fields.iter() {
384 let field_name = field.name.to_string();
385 if let Some(new_name) = to_lower_snake_case(&field_name) {
386 let replacement = Replacement {
387 current_name: field.name.clone(),
388 suggested_text: new_name,
389 expected_case: CaseType::LowerSnakeCase,
391 struct_fields_replacements.push(replacement);
397 // If there is at least one element to spawn a warning on, go to the source map and generate a warning.
398 self.create_incorrect_case_diagnostic_for_struct(
400 struct_name_replacement,
401 struct_fields_replacements,
405 /// Given the information about incorrect names in the struct declaration, looks up into the source code
406 /// for exact locations and adds diagnostics into the sink.
407 fn create_incorrect_case_diagnostic_for_struct(
410 struct_name_replacement: Option<Replacement>,
411 struct_fields_replacements: Vec<Replacement>,
413 // XXX: only look at sources if we do have incorrect names
414 if struct_name_replacement.is_none() && struct_fields_replacements.is_empty() {
418 let struct_loc = struct_id.lookup(self.db.upcast());
419 let struct_src = struct_loc.source(self.db.upcast());
421 if let Some(replacement) = struct_name_replacement {
422 let ast_ptr = match struct_src.value.name() {
426 "Replacement ({:?}) was generated for a structure without a name: {:?}",
434 let diagnostic = IncorrectCase {
435 file: struct_src.file_id,
436 ident_type: IdentType::Structure,
437 ident: AstPtr::new(&ast_ptr),
438 expected_case: replacement.expected_case,
439 ident_text: replacement.current_name.to_string(),
440 suggested_text: replacement.suggested_text,
443 self.sink.push(diagnostic);
446 let struct_fields_list = match struct_src.value.field_list() {
447 Some(ast::FieldList::RecordFieldList(fields)) => fields,
450 struct_fields_replacements.is_empty(),
451 "Replacements ({:?}) were generated for a structure fields which had no fields list: {:?}",
452 struct_fields_replacements,
458 let mut struct_fields_iter = struct_fields_list.fields();
459 for field_to_rename in struct_fields_replacements {
460 // We assume that parameters in replacement are in the same order as in the
461 // actual params list, but just some of them (ones that named correctly) are skipped.
463 match struct_fields_iter.next().and_then(|field| field.name()) {
464 Some(field_name) => {
465 if field_name.as_name() == field_to_rename.current_name {
471 "Replacement ({:?}) was generated for a structure field which was not found: {:?}",
472 field_to_rename, struct_src
479 let diagnostic = IncorrectCase {
480 file: struct_src.file_id,
481 ident_type: IdentType::Field,
482 ident: AstPtr::new(&ast_ptr),
483 expected_case: field_to_rename.expected_case,
484 ident_text: field_to_rename.current_name.to_string(),
485 suggested_text: field_to_rename.suggested_text,
488 self.sink.push(diagnostic);
492 fn validate_enum(&mut self, enum_id: EnumId) {
493 let data = self.db.enum_data(enum_id);
495 // Check whether non-camel case names are allowed for this enum.
496 if self.allowed(enum_id.into(), allow::NON_CAMEL_CASE_TYPES, false) {
500 // Check the enum name.
501 let enum_name = data.name.to_string();
502 let enum_name_replacement = to_camel_case(&enum_name).map(|new_name| Replacement {
503 current_name: data.name.clone(),
504 suggested_text: new_name,
505 expected_case: CaseType::UpperCamelCase,
508 // Check the field names.
509 let enum_fields_replacements = data
512 .filter_map(|(_, variant)| {
514 current_name: variant.name.clone(),
515 suggested_text: to_camel_case(&variant.name.to_string())?,
516 expected_case: CaseType::UpperCamelCase,
521 // If there is at least one element to spawn a warning on, go to the source map and generate a warning.
522 self.create_incorrect_case_diagnostic_for_enum(
524 enum_name_replacement,
525 enum_fields_replacements,
529 /// Given the information about incorrect names in the struct declaration, looks up into the source code
530 /// for exact locations and adds diagnostics into the sink.
531 fn create_incorrect_case_diagnostic_for_enum(
534 enum_name_replacement: Option<Replacement>,
535 enum_variants_replacements: Vec<Replacement>,
537 // XXX: only look at sources if we do have incorrect names
538 if enum_name_replacement.is_none() && enum_variants_replacements.is_empty() {
542 let enum_loc = enum_id.lookup(self.db.upcast());
543 let enum_src = enum_loc.source(self.db.upcast());
545 if let Some(replacement) = enum_name_replacement {
546 let ast_ptr = match enum_src.value.name() {
550 "Replacement ({:?}) was generated for a enum without a name: {:?}",
558 let diagnostic = IncorrectCase {
559 file: enum_src.file_id,
560 ident_type: IdentType::Enum,
561 ident: AstPtr::new(&ast_ptr),
562 expected_case: replacement.expected_case,
563 ident_text: replacement.current_name.to_string(),
564 suggested_text: replacement.suggested_text,
567 self.sink.push(diagnostic);
570 let enum_variants_list = match enum_src.value.variant_list() {
571 Some(variants) => variants,
574 enum_variants_replacements.is_empty(),
575 "Replacements ({:?}) were generated for a enum variants which had no fields list: {:?}",
576 enum_variants_replacements,
582 let mut enum_variants_iter = enum_variants_list.variants();
583 for variant_to_rename in enum_variants_replacements {
584 // We assume that parameters in replacement are in the same order as in the
585 // actual params list, but just some of them (ones that named correctly) are skipped.
587 match enum_variants_iter.next().and_then(|v| v.name()) {
588 Some(variant_name) => {
589 if variant_name.as_name() == variant_to_rename.current_name {
595 "Replacement ({:?}) was generated for a enum variant which was not found: {:?}",
596 variant_to_rename, enum_src
603 let diagnostic = IncorrectCase {
604 file: enum_src.file_id,
605 ident_type: IdentType::Variant,
606 ident: AstPtr::new(&ast_ptr),
607 expected_case: variant_to_rename.expected_case,
608 ident_text: variant_to_rename.current_name.to_string(),
609 suggested_text: variant_to_rename.suggested_text,
612 self.sink.push(diagnostic);
616 fn validate_const(&mut self, const_id: ConstId) {
617 let data = self.db.const_data(const_id);
619 if self.allowed(const_id.into(), allow::NON_UPPER_CASE_GLOBAL, false) {
623 let name = match &data.name {
628 let const_name = name.to_string();
629 let replacement = if let Some(new_name) = to_upper_snake_case(&const_name) {
631 current_name: name.clone(),
632 suggested_text: new_name,
633 expected_case: CaseType::UpperSnakeCase,
636 // Nothing to do here.
640 let const_loc = const_id.lookup(self.db.upcast());
641 let const_src = const_loc.source(self.db.upcast());
643 let ast_ptr = match const_src.value.name() {
648 let diagnostic = IncorrectCase {
649 file: const_src.file_id,
650 ident_type: IdentType::Constant,
651 ident: AstPtr::new(&ast_ptr),
652 expected_case: replacement.expected_case,
653 ident_text: replacement.current_name.to_string(),
654 suggested_text: replacement.suggested_text,
657 self.sink.push(diagnostic);
660 fn validate_static(&mut self, static_id: StaticId) {
661 let data = self.db.static_data(static_id);
663 cov_mark::hit!(extern_static_incorrect_case_ignored);
667 if self.allowed(static_id.into(), allow::NON_UPPER_CASE_GLOBAL, false) {
671 let name = match &data.name {
676 let static_name = name.to_string();
677 let replacement = if let Some(new_name) = to_upper_snake_case(&static_name) {
679 current_name: name.clone(),
680 suggested_text: new_name,
681 expected_case: CaseType::UpperSnakeCase,
684 // Nothing to do here.
688 let static_loc = static_id.lookup(self.db.upcast());
689 let static_src = static_loc.source(self.db.upcast());
691 let ast_ptr = match static_src.value.name() {
696 let diagnostic = IncorrectCase {
697 file: static_src.file_id,
698 ident_type: IdentType::StaticVariable,
699 ident: AstPtr::new(&ast_ptr),
700 expected_case: replacement.expected_case,
701 ident_text: replacement.current_name.to_string(),
702 suggested_text: replacement.suggested_text,
705 self.sink.push(diagnostic);
711 use crate::diagnostics::tests::check_diagnostics;
714 fn incorrect_function_name() {
717 fn NonSnakeCaseName() {}
718 // ^^^^^^^^^^^^^^^^ Function `NonSnakeCaseName` should have snake_case name, e.g. `non_snake_case_name`
724 fn incorrect_function_params() {
727 fn foo(SomeParam: u8) {}
728 // ^^^^^^^^^ Argument `SomeParam` should have snake_case name, e.g. `some_param`
730 fn foo2(ok_param: &str, CAPS_PARAM: u8) {}
731 // ^^^^^^^^^^ Argument `CAPS_PARAM` should have snake_case name, e.g. `caps_param`
737 fn incorrect_variable_names() {
742 // ^^^^^^^^^^ Variable `SOME_VALUE` should have snake_case name, e.g. `some_value`
743 let AnotherValue = 20;
744 // ^^^^^^^^^^^^ Variable `AnotherValue` should have snake_case name, e.g. `another_value`
751 fn incorrect_struct_names() {
754 struct non_camel_case_name {}
755 // ^^^^^^^^^^^^^^^^^^^ Structure `non_camel_case_name` should have CamelCase name, e.g. `NonCamelCaseName`
757 struct SCREAMING_CASE {}
758 // ^^^^^^^^^^^^^^ Structure `SCREAMING_CASE` should have CamelCase name, e.g. `ScreamingCase`
764 fn no_diagnostic_for_camel_cased_acronyms_in_struct_name() {
773 fn incorrect_struct_field() {
776 struct SomeStruct { SomeField: u8 }
777 // ^^^^^^^^^ Field `SomeField` should have snake_case name, e.g. `some_field`
783 fn incorrect_enum_names() {
786 enum some_enum { Val(u8) }
787 // ^^^^^^^^^ Enum `some_enum` should have CamelCase name, e.g. `SomeEnum`
790 // ^^^^^^^^^ Enum `SOME_ENUM` should have CamelCase name, e.g. `SomeEnum`
796 fn no_diagnostic_for_camel_cased_acronyms_in_enum_name() {
805 fn incorrect_enum_variant_name() {
808 enum SomeEnum { SOME_VARIANT(u8) }
809 // ^^^^^^^^^^^^ Variant `SOME_VARIANT` should have CamelCase name, e.g. `SomeVariant`
815 fn incorrect_const_name() {
818 const some_weird_const: u8 = 10;
819 // ^^^^^^^^^^^^^^^^ Constant `some_weird_const` should have UPPER_SNAKE_CASE name, e.g. `SOME_WEIRD_CONST`
822 const someConstInFunc: &str = "hi there";
823 // ^^^^^^^^^^^^^^^ Constant `someConstInFunc` should have UPPER_SNAKE_CASE name, e.g. `SOME_CONST_IN_FUNC`
831 fn incorrect_static_name() {
834 static some_weird_const: u8 = 10;
835 // ^^^^^^^^^^^^^^^^ Static variable `some_weird_const` should have UPPER_SNAKE_CASE name, e.g. `SOME_WEIRD_CONST`
838 static someConstInFunc: &str = "hi there";
839 // ^^^^^^^^^^^^^^^ Static variable `someConstInFunc` should have UPPER_SNAKE_CASE name, e.g. `SOME_CONST_IN_FUNC`
846 fn fn_inside_impl_struct() {
850 // ^^^^^^^^^^ Structure `someStruct` should have CamelCase name, e.g. `SomeStruct`
854 // ^^^^^^^^ Function `SomeFunc` should have snake_case name, e.g. `some_func`
855 static someConstInFunc: &str = "hi there";
856 // ^^^^^^^^^^^^^^^ Static variable `someConstInFunc` should have UPPER_SNAKE_CASE name, e.g. `SOME_CONST_IN_FUNC`
857 let WHY_VAR_IS_CAPS = 10;
858 // ^^^^^^^^^^^^^^^ Variable `WHY_VAR_IS_CAPS` should have snake_case name, e.g. `why_var_is_caps`
866 fn no_diagnostic_for_enum_varinats() {
869 enum Option { Some, None }
885 enum Option { Some, None }
889 SOME_VAR @ None => (),
890 // ^^^^^^^^ Variable `SOME_VAR` should have snake_case name, e.g. `some_var`
899 fn allow_attributes() {
902 #[allow(non_snake_case)]
903 fn NonSnakeCaseName(SOME_VAR: u8) -> u8{
904 // cov_flags generated output from elsewhere in this file
907 static lower_case: u8;
910 let OtherVar = SOME_VAR + 1;
914 #[allow(nonstandard_style)]
915 mod CheckNonstandardStyle {
916 fn HiImABadFnName() {}
921 fn HiImABadFnName() {}
925 #![allow(non_snake_case)]
926 fn CheckItWorksWithModAttr(BAD_NAME_HI: u8) {}
929 #[allow(non_snake_case, non_camel_case_types)]
930 pub struct some_type {
935 #[allow(non_upper_case_globals)]
936 pub const some_const: u8 = 10;
938 #[allow(non_upper_case_globals)]
939 pub static SomeStatic: u8 = 10;
945 fn allow_attributes_crate_attr() {
948 #![allow(non_snake_case)]
951 fn CheckItWorksWithCrateAttr(BAD_NAME_HI: u8) {}
960 fn bug_trait_inside_fn() {
962 // This is broken, and in fact, should not even be looked at by this
963 // lint in the first place. There's weird stuff going on in the
965 // It's currently being brought in by:
966 // * validate_func on `a` recursing into modules
967 // * then it finds the trait and then the function while iterating
969 // * then validate_func is called on Dirty
970 // * ... which then proceeds to look at some unknown module taking no
971 // attrs from either the impl or the fn a, and then finally to the root
974 // It should find the attribute on the trait, but it *doesn't even see
975 // the trait* as far as I can tell.
983 // this comes out of bitflags, mostly
984 #[allow(non_snake_case)]
986 const HiImAlsoBad: u8 = 2;
988 fn Dirty(&self) -> bool {
1001 fn bug_traits_arent_checked() {
1002 // FIXME: Traits and functions in traits aren't currently checked by
1003 // r-a, even though rustc will complain about them.
1007 // ^^^^^^^^^ Trait `BAD_TRAIT` should have CamelCase name, e.g. `BadTrait`
1009 // ^^^^^^^^^^^^ Function `BAD_FUNCTION` should have snake_case name, e.g. `bad_function`
1011 // ^^^^^^^^^^^^ Function `BadFunction` should have snake_case name, e.g. `bad_function`
1018 fn ignores_extern_items() {
1019 cov_mark::check!(extern_func_incorrect_case_ignored);
1020 cov_mark::check!(extern_static_incorrect_case_ignored);
1024 fn NonSnakeCaseName(SOME_VAR: u8) -> u8;
1025 pub static SomeStatic: u8 = 10;
1032 fn infinite_loop_inner_items() {