From 12a82b2007b78594369ffd3ce089437dfe62dab5 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 13 Sep 2016 10:19:55 +0200 Subject: [PATCH] also lint private modules for module_inception, as that is the main issue --- clippy_lints/src/enum_variants.rs | 24 ++++++++++++++---------- tests/compile-fail/module_inception.rs | 12 +++--------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index 8211621fa..69ec9911d 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -194,21 +194,25 @@ impl EarlyLintPass for EnumVariantNames { let item_name = item.ident.name.as_str(); let item_name_chars = item_name.chars().count(); let item_camel = to_camel_case(&item_name); - if item.vis == Visibility::Public && !in_macro(cx, item.span) { + if !in_macro(cx, item.span) { if let Some(&(ref mod_name, ref mod_camel)) = self.modules.last() { // constants don't have surrounding modules if !mod_camel.is_empty() { if mod_name == &item_name { - span_lint(cx, MODULE_INCEPTION, item.span, "item has the same name as its containing module"); + if let ItemKind::Mod(..) = item.node { + span_lint(cx, MODULE_INCEPTION, item.span, "module has the same name as its containing module"); + } } - let matching = partial_match(mod_camel, &item_camel); - let rmatching = partial_rmatch(mod_camel, &item_camel); - let nchars = mod_camel.chars().count(); - if matching == nchars { - span_lint(cx, STUTTER, item.span, &format!("Item name ({}) starts with its containing module's name ({})", item_camel, mod_camel)); - } - if rmatching == nchars { - span_lint(cx, STUTTER, item.span, &format!("Item name ({}) ends with its containing module's name ({})", item_camel, mod_camel)); + if item.vis == Visibility::Public { + let matching = partial_match(mod_camel, &item_camel); + let rmatching = partial_rmatch(mod_camel, &item_camel); + let nchars = mod_camel.chars().count(); + if matching == nchars { + span_lint(cx, STUTTER, item.span, "item name starts with its containing module's name"); + } + if rmatching == nchars { + span_lint(cx, STUTTER, item.span, "item name ends with its containing module's name"); + } } } } diff --git a/tests/compile-fail/module_inception.rs b/tests/compile-fail/module_inception.rs index f6228cbb7..861ed504c 100644 --- a/tests/compile-fail/module_inception.rs +++ b/tests/compile-fail/module_inception.rs @@ -4,26 +4,20 @@ mod foo { mod bar { - pub mod bar { //~ ERROR item has the same name as its containing module + mod bar { //~ ERROR module has the same name as its containing module mod foo {} } mod foo {} } - pub mod foo { //~ ERROR item has the same name as its containing module + mod foo { //~ ERROR module has the same name as its containing module mod bar {} } } -mod cake { - mod cake { - // no error, since module is not public - } -} - // No warning. See . mod bar { #[allow(module_inception)] - pub mod bar { + mod bar { } }