Skip to content

Commit 9eb9fcd

Browse files
committed
lint: Improve camel case suggestion when empty.
1 parent 673c555 commit 9eb9fcd

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/librustc/lint/builtin.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,13 @@ impl LintPass for NonCamelCaseTypes {
768768
let s = token::get_ident(ident);
769769

770770
if !is_camel_case(ident) {
771-
cx.span_lint(NON_CAMEL_CASE_TYPES, span,
772-
format!("{} `{}` should have a camel case name such as `{}`",
773-
sort, s, to_camel_case(s.get())).as_slice());
771+
let c = to_camel_case(s.get());
772+
let m = if c.is_empty() {
773+
format!("{} `{}` should have a camel case name such as `CamelCase`", sort, s)
774+
} else {
775+
format!("{} `{}` should have a camel case name such as `{}`", sort, s, c)
776+
};
777+
cx.span_lint(NON_CAMEL_CASE_TYPES, span, m.as_slice());
774778
}
775779
}
776780

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ struct foo7 {
3737
bar: int,
3838
}
3939

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

4242
fn main() { }

0 commit comments

Comments
 (0)