lint: Allow trailing underscores in camel case idents

This commit is contained in:
Brian Anderson 2012-08-08 15:05:49 -07:00
parent 8d5a51e9d7
commit d99ca69cf7
2 changed files with 18 additions and 1 deletions

View File

@ -452,10 +452,21 @@ fn check_item_path_statement(cx: ty::ctxt, it: @ast::item) {
fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) {
fn is_camel_case(ident: ast::ident) -> bool {
assert ident.is_not_empty();
char::is_uppercase(str::char_at(*ident, 0)) &&
let ident = ident_without_trailing_underscores(ident);
char::is_uppercase(str::char_at(ident, 0)) &&
!ident.contains_char('_')
}
fn ident_without_trailing_underscores(ident: ast::ident) -> ~str {
match str::rfind(*ident, |c| c != '_') {
some(idx) => (*ident).slice(0, idx + 1),
none => {
// all underscores
*ident
}
}
}
fn check_case(cx: ty::ctxt, ident: ast::ident,
expr_id: ast::node_id, item_id: ast::node_id,
span: span) {

View File

@ -0,0 +1,6 @@
// This is ok because we often use the trailing underscore to mean 'prime'
#[forbid(non_camel_case_types)]
type Foo_ = int;
fn main() { }