Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/lint-non-camel-case-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ struct foo7 {
bar: int,
}

type __ = int; //~ ERROR type `__` should have a camel case name such as `CamelCase`

fn main() { }