Skip to content

Commit

Permalink
Use check_variant for non_camel_case_types lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sanxiyn committed Feb 14, 2017
1 parent 48bc082 commit 255b5ed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/librustc_lint/bad_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCamelCaseTypes {

match it.node {
hir::ItemTy(..) |
hir::ItemEnum(..) |
hir::ItemStruct(..) |
hir::ItemUnion(..) => self.check_case(cx, "type", it.name, it.span),
hir::ItemTrait(..) => self.check_case(cx, "trait", it.name, it.span),
hir::ItemEnum(ref enum_definition, _) => {
if has_extern_repr {
return;
}
self.check_case(cx, "type", it.name, it.span);
for variant in &enum_definition.variants {
self.check_case(cx, "variant", variant.node.name, variant.span);
}
}
_ => (),
}
}

fn check_variant(&mut self, cx: &LateContext, v: &hir::Variant, _: &hir::Generics) {
self.check_case(cx, "variant", v.node.name, v.span);
}

fn check_generics(&mut self, cx: &LateContext, it: &hir::Generics) {
for gen in it.ty_params.iter() {
self.check_case(cx, "type parameter", gen.name, gen.span);
Expand Down
18 changes: 18 additions & 0 deletions src/test/run-pass/test-allow-non-camel-case-variant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![deny(non_camel_case_types)]

pub enum Foo {
#[allow(non_camel_case_types)]
bar
}

fn main() {}

0 comments on commit 255b5ed

Please sign in to comment.