Merge pull request #2578 from mikerite/fix_issue_2397_pr_2

Fix enum_glob_use false positives
This commit is contained in:
Oliver Schneider 2018-03-27 07:07:01 +02:00 committed by GitHub
commit 29c449e644
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 12 deletions

View file

@ -1,6 +1,7 @@
//! lint on `use`ing all variants of an enum
use rustc::hir::*;
use rustc::hir::def::Def;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use syntax::ast::NodeId;
use syntax::codemap::Span;
@ -12,8 +13,7 @@ use utils::span_lint;
/// an enumeration variant, rather than importing variants.
///
/// **Known problems:** Old-style enumerations that prefix the variants are
/// still around. May cause problems with modules that are not snake_case (see
/// [#2397](https://github.com/rust-lang-nursery/rust-clippy/issues/2397))
/// still around.
///
/// **Example:**
/// ```rust
@ -48,16 +48,13 @@ impl EnumGlobUse {
return; // re-exports are fine
}
if let ItemUse(ref path, UseKind::Glob) = item.node {
// FIXME: ask jseyfried why the qpath.def for `use std::cmp::Ordering::*;`
// extracted through `ItemUse(ref qpath, UseKind::Glob)` is a `Mod` and not an
// `Enum`
// if let Def::Enum(_) = path.def {
if path.segments
.last()
.and_then(|seg| seg.name.as_str().chars().next())
.map_or(false, char::is_uppercase)
{
span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants");
if let Def::Enum(_) = path.def {
span_lint(
cx,
ENUM_GLOB_USE,
item.span,
"don't use glob imports for enum variants",
);
}
}
}

View file

@ -23,4 +23,10 @@ mod tests {
use super::*;
}
#[allow(non_snake_case)]
mod CamelCaseName {
}
use CamelCaseName::*;
fn main() {}