Improve the camel case warning a bit.

This commit is contained in:
Michael Sullivan 2013-07-25 12:26:38 -07:00
parent 44808fcee6
commit 8582fde150
2 changed files with 17 additions and 14 deletions

View File

@ -827,23 +827,26 @@ fn check_item_non_camel_case_types(cx: &Context, it: &ast::item) {
!ident.contains_char('_')
}
fn check_case(cx: &Context, ident: ast::ident, span: span) {
fn check_case(cx: &Context, sort: &str, ident: ast::ident, span: span) {
if !is_camel_case(cx.tcx, ident) {
cx.span_lint(non_camel_case_types, span,
"type, variant, or trait should have \
a camel case identifier");
cx.span_lint(
non_camel_case_types, span,
fmt!("%s `%s` should have a camel case identifier",
sort, cx.tcx.sess.str_of(ident)));
}
}
match it.node {
ast::item_ty(*) | ast::item_struct(*) |
ast::item_ty(*) | ast::item_struct(*) => {
check_case(cx, "type", it.ident, it.span)
}
ast::item_trait(*) => {
check_case(cx, it.ident, it.span)
check_case(cx, "trait", it.ident, it.span)
}
ast::item_enum(ref enum_definition, _) => {
check_case(cx, it.ident, it.span);
check_case(cx, "type", it.ident, it.span);
for enum_definition.variants.iter().advance |variant| {
check_case(cx, variant.node.name, variant.span);
check_case(cx, "variant", variant.node.name, variant.span);
}
}
_ => ()

View File

@ -10,25 +10,25 @@
#[forbid(non_camel_case_types)];
struct foo { //~ ERROR type, variant, or trait should have a camel case identifier
struct foo { //~ ERROR type `foo` should have a camel case identifier
bar: int,
}
enum foo2 { //~ ERROR type, variant, or trait should have a camel case identifier
enum foo2 { //~ ERROR type `foo2` should have a camel case identifier
Bar
}
struct foo3 { //~ ERROR type, variant, or trait should have a camel case identifier
struct foo3 { //~ ERROR type `foo3` should have a camel case identifier
bar: int
}
type foo4 = int; //~ ERROR type, variant, or trait should have a camel case identifier
type foo4 = int; //~ ERROR type `foo4` should have a camel case identifier
enum Foo5 {
bar //~ ERROR type, variant, or trait should have a camel case identifier
bar //~ ERROR variant `bar` should have a camel case identifier
}
trait foo6 { //~ ERROR type, variant, or trait should have a camel case identifier
trait foo6 { //~ ERROR trait `foo6` should have a camel case identifier
}
fn main() { }