diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-08-08 15:05:49 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-08-08 15:05:49 -0700 |
| commit | d99ca69cf7207e31d7ddffe849a4235cc63899d7 (patch) | |
| tree | 2388ad69e367f34fc430868d9bd5ac7e98820767 /src/rustc | |
| parent | 8d5a51e9d7f51ba9c80a34121b158c8c2ef9cdd7 (diff) | |
lint: Allow trailing underscores in camel case idents
Diffstat (limited to 'src/rustc')
| -rw-r--r-- | src/rustc/middle/lint.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/rustc/middle/lint.rs b/src/rustc/middle/lint.rs index 638c583ba9a..0bfda8798fa 100644 --- a/src/rustc/middle/lint.rs +++ b/src/rustc/middle/lint.rs @@ -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) { |
