From 673c5554437fe50d8c45f71ad8f97e769591b038 Mon Sep 17 00:00:00 2001 From: Jimmie Elvenmark Date: Sat, 23 Aug 2014 16:03:28 +0200 Subject: [PATCH 1/2] librustc: Don't ICE with type when name only contain underscores. --- src/librustc/lint/builtin.rs | 2 +- src/test/compile-fail/lint-non-camel-case-types.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 80b4764014673..1fa4c53832f1b 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -754,7 +754,7 @@ impl LintPass for NonCamelCaseTypes { // start with a non-lowercase letter rather than non-uppercase // ones (some scripts don't have a concept of upper/lowercase) - !ident.char_at(0).is_lowercase() && !ident.contains_char('_') + ident.len() > 0 && !ident.char_at(0).is_lowercase() && !ident.contains_char('_') } fn to_camel_case(s: &str) -> String { diff --git a/src/test/compile-fail/lint-non-camel-case-types.rs b/src/test/compile-fail/lint-non-camel-case-types.rs index 784930003d047..03a2d63e123e4 100644 --- a/src/test/compile-fail/lint-non-camel-case-types.rs +++ b/src/test/compile-fail/lint-non-camel-case-types.rs @@ -37,4 +37,6 @@ struct foo7 { bar: int, } +type __ = int; //~ ERROR type `__` should have a camel case name such as `` + fn main() { } From 9eb9fcd71962fae50c63431d63caab923c68182e Mon Sep 17 00:00:00 2001 From: Jimmie Elvenmark Date: Sun, 24 Aug 2014 09:07:19 +0200 Subject: [PATCH 2/2] lint: Improve camel case suggestion when empty. --- src/librustc/lint/builtin.rs | 10 +++++++--- src/test/compile-fail/lint-non-camel-case-types.rs | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 1fa4c53832f1b..68061a94dc8ed 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -768,9 +768,13 @@ impl LintPass for NonCamelCaseTypes { let s = token::get_ident(ident); if !is_camel_case(ident) { - cx.span_lint(NON_CAMEL_CASE_TYPES, span, - format!("{} `{}` should have a camel case name such as `{}`", - sort, s, to_camel_case(s.get())).as_slice()); + let c = to_camel_case(s.get()); + let m = if c.is_empty() { + format!("{} `{}` should have a camel case name such as `CamelCase`", sort, s) + } else { + format!("{} `{}` should have a camel case name such as `{}`", sort, s, c) + }; + cx.span_lint(NON_CAMEL_CASE_TYPES, span, m.as_slice()); } } diff --git a/src/test/compile-fail/lint-non-camel-case-types.rs b/src/test/compile-fail/lint-non-camel-case-types.rs index 03a2d63e123e4..f33c7956a1418 100644 --- a/src/test/compile-fail/lint-non-camel-case-types.rs +++ b/src/test/compile-fail/lint-non-camel-case-types.rs @@ -37,6 +37,6 @@ struct foo7 { bar: int, } -type __ = int; //~ ERROR type `__` should have a camel case name such as `` +type __ = int; //~ ERROR type `__` should have a camel case name such as `CamelCase` fn main() { }