Skip to content

Commit

Permalink
lint: Improve camel case suggestion when empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
flugsio committed Aug 24, 2014
1 parent 673c555 commit 9eb9fcd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/librustc/lint/builtin.rs
Expand Up @@ -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: 1 addition & 1 deletion src/test/compile-fail/lint-non-camel-case-types.rs
Expand Up @@ -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() { }

9 comments on commit 9eb9fcd

@bors
Copy link
Contributor

@bors bors commented on 9eb9fcd Aug 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at flugsio@9eb9fcd

@bors
Copy link
Contributor

@bors bors commented on 9eb9fcd Aug 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging flugsio/rust/fix-rustc-ice-lint-underscores-only = 9eb9fcd into auto

@bors
Copy link
Contributor

@bors bors commented on 9eb9fcd Aug 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flugsio/rust/fix-rustc-ice-lint-underscores-only = 9eb9fcd merged ok, testing candidate = 4264ade5

@bors
Copy link
Contributor

@bors bors commented on 9eb9fcd Aug 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 9eb9fcd Aug 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at flugsio@9eb9fcd

@bors
Copy link
Contributor

@bors bors commented on 9eb9fcd Aug 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging flugsio/rust/fix-rustc-ice-lint-underscores-only = 9eb9fcd into auto

@bors
Copy link
Contributor

@bors bors commented on 9eb9fcd Aug 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flugsio/rust/fix-rustc-ice-lint-underscores-only = 9eb9fcd merged ok, testing candidate = e61ec99

@bors
Copy link
Contributor

@bors bors commented on 9eb9fcd Aug 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = e61ec99

Please sign in to comment.