提交 8582fde1 编写于 作者: M Michael Sullivan

Improve the camel case warning a bit.

上级 44808fce
......@@ -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);
}
}
_ => ()
......
......@@ -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() { }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册