Skip to content

Commit d99ca69

Browse files
committed
lint: Allow trailing underscores in camel case idents
1 parent 8d5a51e commit d99ca69

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/rustc/middle/lint.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,21 @@ fn check_item_path_statement(cx: ty::ctxt, it: @ast::item) {
452452
fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) {
453453
fn is_camel_case(ident: ast::ident) -> bool {
454454
assert ident.is_not_empty();
455-
char::is_uppercase(str::char_at(*ident, 0)) &&
455+
let ident = ident_without_trailing_underscores(ident);
456+
char::is_uppercase(str::char_at(ident, 0)) &&
456457
!ident.contains_char('_')
457458
}
458459

460+
fn ident_without_trailing_underscores(ident: ast::ident) -> ~str {
461+
match str::rfind(*ident, |c| c != '_') {
462+
some(idx) => (*ident).slice(0, idx + 1),
463+
none => {
464+
// all underscores
465+
*ident
466+
}
467+
}
468+
}
469+
459470
fn check_case(cx: ty::ctxt, ident: ast::ident,
460471
expr_id: ast::node_id, item_id: ast::node_id,
461472
span: span) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This is ok because we often use the trailing underscore to mean 'prime'
2+
3+
#[forbid(non_camel_case_types)]
4+
type Foo_ = int;
5+
6+
fn main() { }

0 commit comments

Comments
 (0)