lint: Allow trailing underscores in camel case idents
This commit is contained in:
parent
8d5a51e9d7
commit
d99ca69cf7
@ -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) {
|
||||
|
@ -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() { }
|
Loading…
x
Reference in New Issue
Block a user