Skip to content

Commit 12a82b2

Browse files
committed
also lint private modules for module_inception, as that is the main issue
1 parent 03fa974 commit 12a82b2

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

clippy_lints/src/enum_variants.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,21 +194,25 @@ impl EarlyLintPass for EnumVariantNames {
194194
let item_name = item.ident.name.as_str();
195195
let item_name_chars = item_name.chars().count();
196196
let item_camel = to_camel_case(&item_name);
197-
if item.vis == Visibility::Public && !in_macro(cx, item.span) {
197+
if !in_macro(cx, item.span) {
198198
if let Some(&(ref mod_name, ref mod_camel)) = self.modules.last() {
199199
// constants don't have surrounding modules
200200
if !mod_camel.is_empty() {
201201
if mod_name == &item_name {
202-
span_lint(cx, MODULE_INCEPTION, item.span, "item has the same name as its containing module");
202+
if let ItemKind::Mod(..) = item.node {
203+
span_lint(cx, MODULE_INCEPTION, item.span, "module has the same name as its containing module");
204+
}
203205
}
204-
let matching = partial_match(mod_camel, &item_camel);
205-
let rmatching = partial_rmatch(mod_camel, &item_camel);
206-
let nchars = mod_camel.chars().count();
207-
if matching == nchars {
208-
span_lint(cx, STUTTER, item.span, &format!("Item name ({}) starts with its containing module's name ({})", item_camel, mod_camel));
209-
}
210-
if rmatching == nchars {
211-
span_lint(cx, STUTTER, item.span, &format!("Item name ({}) ends with its containing module's name ({})", item_camel, mod_camel));
206+
if item.vis == Visibility::Public {
207+
let matching = partial_match(mod_camel, &item_camel);
208+
let rmatching = partial_rmatch(mod_camel, &item_camel);
209+
let nchars = mod_camel.chars().count();
210+
if matching == nchars {
211+
span_lint(cx, STUTTER, item.span, "item name starts with its containing module's name");
212+
}
213+
if rmatching == nchars {
214+
span_lint(cx, STUTTER, item.span, "item name ends with its containing module's name");
215+
}
212216
}
213217
}
214218
}

tests/compile-fail/module_inception.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,20 @@
44

55
mod foo {
66
mod bar {
7-
pub mod bar { //~ ERROR item has the same name as its containing module
7+
mod bar { //~ ERROR module has the same name as its containing module
88
mod foo {}
99
}
1010
mod foo {}
1111
}
12-
pub mod foo { //~ ERROR item has the same name as its containing module
12+
mod foo { //~ ERROR module has the same name as its containing module
1313
mod bar {}
1414
}
1515
}
1616

17-
mod cake {
18-
mod cake {
19-
// no error, since module is not public
20-
}
21-
}
22-
2317
// No warning. See <https://github.com/Manishearth/rust-clippy/issues/1220>.
2418
mod bar {
2519
#[allow(module_inception)]
26-
pub mod bar {
20+
mod bar {
2721
}
2822
}
2923

0 commit comments

Comments
 (0)