Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
21e7b936
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
21e7b936
编写于
6月 13, 2014
作者:
K
Keegan McAllister
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use names in Lint structs in an ASCII-case-insensitive way
In preparation for the next commit.
上级
609552e1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
13 deletion
+27
-13
src/librustc/driver/mod.rs
src/librustc/driver/mod.rs
+2
-1
src/librustc/lint/context.rs
src/librustc/lint/context.rs
+7
-6
src/librustc/lint/mod.rs
src/librustc/lint/mod.rs
+18
-6
未找到文件。
src/librustc/driver/mod.rs
浏览文件 @
21e7b936
...
...
@@ -146,6 +146,7 @@ fn sort_lints(lints: Vec<(&'static Lint, bool)>) -> Vec<&'static Lint> {
let
mut
lints
:
Vec
<
_
>
=
lints
.move_iter
()
.map
(|(
x
,
_
)|
x
)
.collect
();
lints
.sort_by
(|
x
:
&&
Lint
,
y
:
&&
Lint
|
{
match
x
.default_level
.cmp
(
&
y
.default_level
)
{
// The sort doesn't case-fold but it's doubtful we care.
Equal
=>
x
.name
.cmp
(
&
y
.name
),
r
=>
r
,
}
...
...
@@ -172,7 +173,7 @@ fn sort_lints(lints: Vec<(&'static Lint, bool)>) -> Vec<&'static Lint> {
let
print_lints
=
|
lints
:
Vec
<&
Lint
>
|
{
for
lint
in
lints
.move_iter
()
{
let
name
=
lint
.name
.replace
(
"_"
,
"-"
);
let
name
=
lint
.name
_lower
()
.replace
(
"_"
,
"-"
);
println!
(
" {} {:7.7s} {}"
,
padded
(
name
.as_slice
()),
lint
.default_level
.as_str
(),
lint
.desc
);
}
...
...
src/librustc/lint/context.rs
浏览文件 @
21e7b936
...
...
@@ -61,7 +61,7 @@ pub struct LintStore {
passes
:
Option
<
Vec
<
LintPassObject
>>
,
/// Lints indexed by name.
by_name
:
HashMap
<
&
'static
str
,
LintId
>
,
by_name
:
HashMap
<
String
,
LintId
>
,
/// Current levels of each lint, and where they were set.
levels
:
HashMap
<
LintId
,
LevelSource
>
,
...
...
@@ -102,8 +102,8 @@ pub fn register_pass(&mut self, sess: Option<&Session>,
self
.lints
.push
((
lint
,
from_plugin
));
let
id
=
LintId
::
of
(
lint
);
if
!
self
.by_name
.insert
(
lint
.name
,
id
)
{
let
msg
=
format!
(
"duplicate specification of lint {}"
,
lint
.name
);
if
!
self
.by_name
.insert
(
lint
.name
_lower
()
,
id
)
{
let
msg
=
format!
(
"duplicate specification of lint {}"
,
lint
.name
_lower
()
);
match
(
sess
,
from_plugin
)
{
// We load builtin lints first, so a duplicate is a compiler bug.
// Use early_error when handling -W help with no crate.
...
...
@@ -205,18 +205,19 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint,
let
(
mut
level
,
source
)
=
lvlsrc
;
if
level
==
Allow
{
return
}
let
name
=
lint
.name_lower
();
let
mut
note
=
None
;
let
msg
=
match
source
{
Default
=>
{
format!
(
"{}, #[{}({})] on by default"
,
msg
,
level
.as_str
(),
lint
.
name
)
level
.as_str
(),
name
)
},
CommandLine
=>
{
format!
(
"{} [-{} {}]"
,
msg
,
match
level
{
Warn
=>
'W'
,
Deny
=>
'D'
,
Forbid
=>
'F'
,
Allow
=>
fail!
()
},
lint
.
name
.replace
(
"_"
,
"-"
))
},
name
.replace
(
"_"
,
"-"
))
},
Node
(
src
)
=>
{
note
=
Some
(
src
);
...
...
@@ -355,7 +356,7 @@ fn gather_lint_attrs(&mut self, attrs: &[ast::Attribute]) -> Vec<(LintId, Level,
for
meta
in
metas
.iter
()
{
match
meta
.node
{
ast
::
MetaWord
(
ref
lint_name
)
=>
{
match
self
.lints.by_name
.find_equiv
(
lint_name
)
{
match
self
.lints.by_name
.find_equiv
(
&
lint_name
.get
()
)
{
Some
(
lint_id
)
=>
out
.push
((
*
lint_id
,
level
,
meta
.span
)),
None
=>
self
.span_lint
(
builtin
::
unrecognized_lint
,
...
...
src/librustc/lint/mod.rs
浏览文件 @
21e7b936
...
...
@@ -31,6 +31,7 @@
use
middle
::
privacy
::
ExportedItems
;
use
std
::
hash
;
use
std
::
ascii
::
StrAsciiExt
;
use
syntax
::
codemap
::
Span
;
use
syntax
::
visit
::
FnKind
;
use
syntax
::
ast
;
...
...
@@ -41,10 +42,14 @@
pub
struct
Lint
{
/// A string identifier for the lint.
///
/// Written with underscores, e.g. "unused_imports".
/// This identifies the lint in attributes and in
/// command-line arguments. On the command line,
/// underscores become dashes.
/// This identifies the lint in attributes and in command-line arguments.
/// In those contexts it is always lowercase, but this field is compared
/// in a way which is case-insensitive for ASCII characters. This allows
/// `declare_lint!()` invocations to follow the convention of upper-case
/// statics without repeating the name.
///
/// The name is written with underscores, e.g. "unused_imports".
/// On the command line, underscores become dashes.
pub
name
:
&
'static
str
,
/// Default level for the lint.
...
...
@@ -56,6 +61,13 @@ pub struct Lint {
pub
desc
:
&
'static
str
,
}
impl
Lint
{
/// Get the lint's name, with ASCII letters converted to lowercase.
pub
fn
name_lower
(
&
self
)
->
String
{
self
.name
.to_ascii_lower
()
}
}
/// Build a `Lint` initializer.
#[macro_export]
macro_rules!
lint_initializer
(
...
...
@@ -186,8 +198,8 @@ pub fn of(lint: &'static Lint) -> LintId {
}
/// Get the name of the lint.
pub
fn
as_str
(
&
self
)
->
&
'static
str
{
self
.lint.name
pub
fn
as_str
(
&
self
)
->
String
{
self
.lint
.name
_lower
()
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录