Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
acd6ab8f
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,发现更多精彩内容 >>
提交
acd6ab8f
编写于
5月 15, 2018
作者:
K
Kyle Stachowicz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename `unused_loop_label` to `unused_label` and fix/clean up lint logic
上级
bb867d35
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
42 deletion
+37
-42
src/librustc_lint/lib.rs
src/librustc_lint/lib.rs
+3
-3
src/librustc_lint/unused.rs
src/librustc_lint/unused.rs
+25
-30
src/test/ui/lint/unused_label.rs
src/test/ui/lint/unused_label.rs
+7
-7
src/test/ui/lint/unused_label.stderr
src/test/ui/lint/unused_label.stderr
+2
-2
未找到文件。
src/librustc_lint/lib.rs
浏览文件 @
acd6ab8f
...
...
@@ -110,7 +110,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
add_early_builtin_with_new!
(
sess
,
DeprecatedAttr
,
UnusedL
oopL
abel
,
UnusedLabel
,
);
add_builtin!
(
sess
,
...
...
@@ -178,8 +178,8 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
UNUSED_DOC_COMMENT
,
UNUSED_EXTERN_CRATES
,
UNUSED_FEATURES
,
UNUSED_
PARENS
,
UNUSED_
LOOP_LABEL
);
UNUSED_
LABEL
,
UNUSED_
PARENS
);
add_lint_group!
(
sess
,
"rust_2018_idioms"
,
...
...
src/librustc_lint/unused.rs
浏览文件 @
acd6ab8f
...
...
@@ -25,8 +25,6 @@
use
rustc
::
hir
;
use
std
::
vec
;
declare_lint!
{
pub
UNUSED_MUST_USE
,
Warn
,
...
...
@@ -468,41 +466,38 @@ fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
}
declare_lint!
{
pub
(
super
)
UNUSED_L
OOP_L
ABEL
,
pub
(
super
)
UNUSED_LABEL
,
Warn
,
"warns on unused labels
for loops
"
"warns on unused labels"
}
#[derive(Clone)]
pub
struct
UnusedL
oopLabel
(
pub
vec
::
Vec
<
ast
::
Label
>
);
pub
struct
UnusedL
abel
(
pub
Vec
<
ast
::
Label
>
);
impl
UnusedL
oopL
abel
{
impl
UnusedLabel
{
pub
fn
new
()
->
Self
{
UnusedL
oopL
abel
(
vec!
[])
UnusedLabel
(
vec!
[])
}
}
impl
LintPass
for
UnusedL
oopL
abel
{
impl
LintPass
for
UnusedLabel
{
fn
get_lints
(
&
self
)
->
LintArray
{
lint_array!
(
UNUSED_L
OOP_L
ABEL
)
lint_array!
(
UNUSED_LABEL
)
}
}
impl
EarlyLintPass
for
UnusedL
oopL
abel
{
impl
EarlyLintPass
for
UnusedLabel
{
fn
check_expr
(
&
mut
self
,
_
:
&
EarlyContext
,
expr
:
&
ast
::
Expr
)
{
match
expr
.node
{
ast
::
ExprKind
::
While
(
_
,
_
,
Some
(
ref
label
))
|
ast
::
ExprKind
::
WhileLet
(
_
,
_
,
_
,
Some
(
ref
label
))
|
ast
::
ExprKind
::
ForLoop
(
_
,
_
,
_
,
Some
(
ref
label
))
|
ast
::
ExprKind
::
Loop
(
_
,
Some
(
ref
label
))
=>
{
self
.0
.push
(
*
label
);
ast
::
ExprKind
::
While
(
_
,
_
,
Some
(
label
))
|
ast
::
ExprKind
::
WhileLet
(
_
,
_
,
_
,
Some
(
label
))
|
ast
::
ExprKind
::
ForLoop
(
_
,
_
,
_
,
Some
(
label
))
|
ast
::
ExprKind
::
Loop
(
_
,
Some
(
label
))
=>
{
self
.0
.push
(
label
);
}
ast
::
ExprKind
::
Break
(
Some
(
ref
label
),
_
)
|
ast
::
ExprKind
::
Continue
(
Some
(
ref
label
))
=>
{
'remove_used_label
:
for
i
in
(
0
..
self
.0
.len
())
.rev
()
{
if
self
.0
.get
(
i
)
.unwrap
()
.ident.name
==
label
.ident.name
{
self
.0
.remove
(
i
);
break
'remove_used_label
;
}
ast
::
ExprKind
::
Break
(
Some
(
label
),
_
)
|
ast
::
ExprKind
::
Continue
(
Some
(
label
))
=>
{
if
let
Some
(
index
)
=
self
.0
.iter
()
.rposition
(|
&
l
|
l
.ident
==
label
.ident
)
{
self
.0
.remove
(
index
);
}
}
_
=>
{}
...
...
@@ -511,17 +506,17 @@ fn check_expr(&mut self, _: &EarlyContext, expr: &ast::Expr) {
fn
check_expr_post
(
&
mut
self
,
ctxt
:
&
EarlyContext
,
expr
:
&
ast
::
Expr
)
{
match
expr
.node
{
ast
::
ExprKind
::
While
(
_
,
_
,
Some
(
ref
label
))
|
ast
::
ExprKind
::
WhileLet
(
_
,
_
,
_
,
Some
(
ref
label
))
|
ast
::
ExprKind
::
ForLoop
(
_
,
_
,
_
,
Some
(
ref
label
))
|
ast
::
ExprKind
::
Loop
(
_
,
Some
(
ref
label
))
=>
if
!
self
.0
.is_empty
()
{
{
let
unused_label
=
self
.0
.last
()
.unwrap
();
if
label
.ident.name
==
unused_label
.ident.name
{
ctxt
.span_lint
(
UNUSED_LOOP_LABEL
,
label
.ident.span
,
"unused loop label"
);
ast
::
ExprKind
::
While
(
_
,
_
,
Some
(
label
))
|
ast
::
ExprKind
::
WhileLet
(
_
,
_
,
_
,
Some
(
label
))
|
ast
::
ExprKind
::
ForLoop
(
_
,
_
,
_
,
Some
(
label
))
|
ast
::
ExprKind
::
Loop
(
_
,
Some
(
label
))
=>
{
if
let
Some
(
unused_label
)
=
self
.0
.pop
()
{
if
label
.ident
==
unused_label
.ident
{
ctxt
.span_lint
(
UNUSED_LABEL
,
label
.ident.span
,
"unused label"
);
}
else
{
self
.0
.push
(
unused_label
);
}
}
self
.0
.pop
();
},
_
=>
{}
}
...
...
src/test/ui/lint/unused_label.rs
浏览文件 @
acd6ab8f
...
...
@@ -13,20 +13,20 @@
// within nested loops
// compile-pass
// compile-flags: -W unused
_loop_
label
// compile-flags: -W unused
-
label
fn
main
()
{
'unused_while_label
:
while
0
==
0
{
//~^ WARN unused l
oop l
abel
//~^ WARN unused label
}
let
opt
=
Some
(
0
);
'unused_while_let_label
:
while
let
Some
(
_
)
=
opt
{
//~^ WARN unused l
oop l
abel
//~^ WARN unused label
}
'unused_for_label
:
for
_
in
0
..
10
{
//~^ WARN unused l
oop l
abel
//~^ WARN unused label
}
'used_loop_label
:
loop
{
...
...
@@ -42,14 +42,14 @@ fn main() {
'used_loop_label_outer_2
:
loop
{
'unused_loop_label_inner_2
:
loop
{
//~^ WARN unused l
oop l
abel
//~^ WARN unused label
break
'used_loop_label_outer_2
;
}
}
'unused_loop_label_outer_3
:
loop
{
//~^ WARN unused label
'used_loop_label_inner_3
:
loop
{
//~^ WARN unused loop label
break
'used_loop_label_inner_3
;
}
}
...
...
@@ -57,6 +57,6 @@ fn main() {
// This is diverging, so put it at the end so we don't get
// unreachable_code errors everywhere else
'unused_loop_label
:
loop
{
//~^ WARN unused l
oop l
abel
//~^ WARN unused label
}
}
src/test/ui/lint/unused_label.stderr
浏览文件 @
acd6ab8f
...
...
@@ -25,13 +25,13 @@ LL | 'unused_loop_label_inner_2: loop {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: unused label
--> $DIR/unused_label.rs:50:
9
--> $DIR/unused_label.rs:50:
5
|
LL | 'unused_loop_label_outer_3: loop {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: unused label
--> $DIR/unused_label.rs:5
2
:5
--> $DIR/unused_label.rs:5
9
:5
|
LL | 'unused_loop_label: loop {
| ^^^^^^^^^^^^^^^^^^
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录