]> git.lizzy.rs Git - rust.git/commitdiff
Improve the camel case warning a bit.
authorMichael Sullivan <sully@msully.net>
Thu, 25 Jul 2013 19:26:38 +0000 (12:26 -0700)
committerMichael Sullivan <sully@msully.net>
Fri, 26 Jul 2013 23:42:03 +0000 (16:42 -0700)
src/librustc/middle/lint.rs
src/test/compile-fail/lint-non-camel-case-types.rs

index d6e6db8354a0f35ce55665bc8f1d42a6731ed968..aaf0460a4e1a35a97d231a5b9f50b77e09f7fa03 100644 (file)
@@ -827,23 +827,26 @@ fn is_camel_case(cx: ty::ctxt, ident: ast::ident) -> bool {
             !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);
             }
         }
         _ => ()
index 27c9ca64a93c64ff64aeb5f6b22acddb9d600abb..2cabdfe5bb0981be0fd6ff0fa3d6850da5598a76 100644 (file)
 
 #[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() { }