Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a841789a
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a841789a
编写于
7月 31, 2012
作者:
B
Brian Anderson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: Add non_camel_case_types lint check
上级
2a3084b5
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
78 addition
and
0 deletion
+78
-0
src/rustc/middle/lint.rs
src/rustc/middle/lint.rs
+41
-0
src/test/compile-fail/lint-non-camel-case-class.rs
src/test/compile-fail/lint-non-camel-case-class.rs
+11
-0
src/test/compile-fail/lint-non-camel-case-enum.rs
src/test/compile-fail/lint-non-camel-case-enum.rs
+7
-0
src/test/compile-fail/lint-non-camel-case-struct.rs
src/test/compile-fail/lint-non-camel-case-struct.rs
+7
-0
src/test/compile-fail/lint-non-camel-case-type.rs
src/test/compile-fail/lint-non-camel-case-type.rs
+5
-0
src/test/compile-fail/lint-non-camel-case-variant.rs
src/test/compile-fail/lint-non-camel-case-variant.rs
+7
-0
未找到文件。
src/rustc/middle/lint.rs
浏览文件 @
a841789a
...
...
@@ -49,6 +49,7 @@ enum lint {
non_implicitly_copyable_typarams
,
vecs_implicitly_copyable
,
deprecated_mode
,
non_camel_case_types
}
// This is pretty unfortunate. We really want some sort of "deriving Enum"
...
...
@@ -64,6 +65,7 @@ fn int_to_lint(i: int) -> lint {
6
{
non_implicitly_copyable_typarams
}
7
{
vecs_implicitly_copyable
}
8
{
deprecated_mode
}
9
{
non_camel_case_types
}
}
}
...
...
@@ -136,6 +138,11 @@ fn get_lint_dict() -> lint_dict {
(
~
"deprecated_mode"
,
@
{
lint
:
deprecated_mode
,
desc
:
~
"warn about deprecated uses of modes"
,
default
:
allow
}),
(
~
"non_camel_case_types"
,
@
{
lint
:
non_camel_case_types
,
desc
:
~
"types, variants and traits must have camel case names"
,
default
:
allow
})
];
hash_from_strs
(
v
)
...
...
@@ -333,6 +340,7 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
check_item_ctypes
(
cx
,
i
);
check_item_while_true
(
cx
,
i
);
check_item_path_statement
(
cx
,
i
);
check_item_non_camel_case_types
(
cx
,
i
);
}
// Take a visitor, and modify it so that it will not proceed past subitems.
...
...
@@ -433,6 +441,39 @@ fn check_item_path_statement(cx: ty::ctxt, it: @ast::item) {
visit
::
visit_item
(
it
,
(),
visit
);
}
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
))
&&
!
ident
.contains_char
(
'_'
)
}
fn
check_case
(
cx
:
ty
::
ctxt
,
ident
:
ast
::
ident
,
expr_id
:
ast
::
node_id
,
item_id
:
ast
::
node_id
,
span
:
span
)
{
if
!
is_camel_case
(
ident
)
{
cx
.sess
.span_lint
(
non_camel_case_types
,
expr_id
,
item_id
,
span
,
~
"type, variant, or trait must be camel case"
);
}
}
alt
it
.node
{
ast
::
item_ty
(
*
)
|
ast
::
item_class
(
*
)
|
ast
::
item_trait
(
*
)
|
ast
::
item_impl
(
*
)
{
check_case
(
cx
,
it
.ident
,
it
.id
,
it
.id
,
it
.span
)
}
ast
::
item_enum
(
variants
,
_
)
{
check_case
(
cx
,
it
.ident
,
it
.id
,
it
.id
,
it
.span
);
for
variants
.each
|
variant
|
{
check_case
(
cx
,
variant
.node.name
,
variant
.node.id
,
it
.id
,
variant
.span
);
}
}
_
{
}
}
}
fn
check_fn
(
tcx
:
ty
::
ctxt
,
fk
:
visit
::
fn_kind
,
decl
:
ast
::
fn_decl
,
_
body
:
ast
::
blk
,
span
:
span
,
id
:
ast
::
node_id
)
{
debug!
{
"lint check_fn fk=%? id=%?"
,
fk
,
id
};
...
...
src/test/compile-fail/lint-non-camel-case-class.rs
0 → 100644
浏览文件 @
a841789a
#[forbid(non_camel_case_types)]
class
foo
{
//~ ERROR type, variant, or trait must be camel case
let
bar
:
int
;
new
()
{
self
.bar
=
0
;
}
}
fn
main
()
{
}
src/test/compile-fail/lint-non-camel-case-enum.rs
0 → 100644
浏览文件 @
a841789a
#[forbid(non_camel_case_types)]
enum
foo
{
//~ ERROR type, variant, or trait must be camel case
Bar
}
fn
main
()
{
}
src/test/compile-fail/lint-non-camel-case-struct.rs
0 → 100644
浏览文件 @
a841789a
#[forbid(non_camel_case_types)]
struct
foo
{
//~ ERROR type, variant, or trait must be camel case
bar
:
int
;
}
fn
main
()
{
}
src/test/compile-fail/lint-non-camel-case-type.rs
0 → 100644
浏览文件 @
a841789a
#[forbid(non_camel_case_types)]
type
foo
=
int
;
//~ ERROR type, variant, or trait must be camel case
fn
main
()
{
}
src/test/compile-fail/lint-non-camel-case-variant.rs
0 → 100644
浏览文件 @
a841789a
#[forbid(non_camel_case_types)]
enum
Foo
{
bar
//~ ERROR type, variant, or trait must be camel case
}
fn
main
()
{
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录