Skip to content

Commit 8582fde

Browse files
committed
Improve the camel case warning a bit.
1 parent 44808fc commit 8582fde

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/librustc/middle/lint.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -827,23 +827,26 @@ fn check_item_non_camel_case_types(cx: &Context, it: &ast::item) {
827827
!ident.contains_char('_')
828828
}
829829

830-
fn check_case(cx: &Context, ident: ast::ident, span: span) {
830+
fn check_case(cx: &Context, sort: &str, ident: ast::ident, span: span) {
831831
if !is_camel_case(cx.tcx, ident) {
832-
cx.span_lint(non_camel_case_types, span,
833-
"type, variant, or trait should have \
834-
a camel case identifier");
832+
cx.span_lint(
833+
non_camel_case_types, span,
834+
fmt!("%s `%s` should have a camel case identifier",
835+
sort, cx.tcx.sess.str_of(ident)));
835836
}
836837
}
837838

838839
match it.node {
839-
ast::item_ty(*) | ast::item_struct(*) |
840+
ast::item_ty(*) | ast::item_struct(*) => {
841+
check_case(cx, "type", it.ident, it.span)
842+
}
840843
ast::item_trait(*) => {
841-
check_case(cx, it.ident, it.span)
844+
check_case(cx, "trait", it.ident, it.span)
842845
}
843846
ast::item_enum(ref enum_definition, _) => {
844-
check_case(cx, it.ident, it.span);
847+
check_case(cx, "type", it.ident, it.span);
845848
for enum_definition.variants.iter().advance |variant| {
846-
check_case(cx, variant.node.name, variant.span);
849+
check_case(cx, "variant", variant.node.name, variant.span);
847850
}
848851
}
849852
_ => ()

src/test/compile-fail/lint-non-camel-case-types.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@
1010

1111
#[forbid(non_camel_case_types)];
1212

13-
struct foo { //~ ERROR type, variant, or trait should have a camel case identifier
13+
struct foo { //~ ERROR type `foo` should have a camel case identifier
1414
bar: int,
1515
}
1616

17-
enum foo2 { //~ ERROR type, variant, or trait should have a camel case identifier
17+
enum foo2 { //~ ERROR type `foo2` should have a camel case identifier
1818
Bar
1919
}
2020

21-
struct foo3 { //~ ERROR type, variant, or trait should have a camel case identifier
21+
struct foo3 { //~ ERROR type `foo3` should have a camel case identifier
2222
bar: int
2323
}
2424

25-
type foo4 = int; //~ ERROR type, variant, or trait should have a camel case identifier
25+
type foo4 = int; //~ ERROR type `foo4` should have a camel case identifier
2626

2727
enum Foo5 {
28-
bar //~ ERROR type, variant, or trait should have a camel case identifier
28+
bar //~ ERROR variant `bar` should have a camel case identifier
2929
}
3030

31-
trait foo6 { //~ ERROR type, variant, or trait should have a camel case identifier
31+
trait foo6 { //~ ERROR trait `foo6` should have a camel case identifier
3232
}
3333

3434
fn main() { }

0 commit comments

Comments
 (0)