Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
3530e4a6
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,发现更多精彩内容 >>
提交
3530e4a6
编写于
9月 20, 2014
作者:
J
Jakub Wieczorek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use more descriptive names in dead code messages
上级
2ec795b4
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
59 addition
and
31 deletion
+59
-31
src/librustc/middle/dead.rs
src/librustc/middle/dead.rs
+10
-7
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+25
-0
src/test/compile-fail-fulldeps/syntax-extension-regex-unused-static.rs
...ile-fail-fulldeps/syntax-extension-regex-unused-static.rs
+1
-1
src/test/compile-fail/fail-no-dead-code-core.rs
src/test/compile-fail/fail-no-dead-code-core.rs
+1
-1
src/test/compile-fail/fail-no-dead-code.rs
src/test/compile-fail/fail-no-dead-code.rs
+1
-1
src/test/compile-fail/lint-dead-code-1.rs
src/test/compile-fail/lint-dead-code-1.rs
+8
-8
src/test/compile-fail/lint-dead-code-2.rs
src/test/compile-fail/lint-dead-code-2.rs
+3
-3
src/test/compile-fail/lint-dead-code-3.rs
src/test/compile-fail/lint-dead-code-3.rs
+6
-6
src/test/compile-fail/lint-dead-code-4.rs
src/test/compile-fail/lint-dead-code-4.rs
+3
-3
src/test/compile-fail/lint-dead-code-5.rs
src/test/compile-fail/lint-dead-code-5.rs
+1
-1
未找到文件。
src/librustc/middle/dead.rs
浏览文件 @
3530e4a6
...
...
@@ -507,7 +507,8 @@ fn symbol_is_live(&mut self, id: ast::NodeId,
fn
warn_dead_code
(
&
mut
self
,
id
:
ast
::
NodeId
,
span
:
codemap
::
Span
,
ident
:
ast
::
Ident
)
{
ident
:
ast
::
Ident
,
node_type
:
&
str
)
{
let
name
=
ident
.as_str
();
if
!
name
.starts_with
(
"_"
)
{
self
.tcx
...
...
@@ -515,7 +516,7 @@ fn warn_dead_code(&mut self,
.add_lint
(
lint
::
builtin
::
DEAD_CODE
,
id
,
span
,
format!
(
"
code is never used: `{}`"
,
name
));
format!
(
"
{} is never used: `{}`"
,
node_type
,
name
));
}
}
}
...
...
@@ -523,13 +524,14 @@ fn warn_dead_code(&mut self,
impl
<
'a
,
'tcx
,
'v
>
Visitor
<
'v
>
for
DeadVisitor
<
'a
,
'tcx
>
{
fn
visit_item
(
&
mut
self
,
item
:
&
ast
::
Item
)
{
if
self
.should_warn_about_item
(
item
)
{
self
.warn_dead_code
(
item
.id
,
item
.span
,
item
.ident
);
self
.warn_dead_code
(
item
.id
,
item
.span
,
item
.ident
,
item
.node
.descriptive_variant
()
);
}
else
{
match
item
.node
{
ast
::
ItemEnum
(
ref
enum_def
,
_
)
=>
{
for
variant
in
enum_def
.variants
.iter
()
{
if
self
.should_warn_about_variant
(
&
variant
.node
)
{
self
.warn_dead_code
(
variant
.node.id
,
variant
.span
,
variant
.node.name
);
self
.warn_dead_code
(
variant
.node.id
,
variant
.span
,
variant
.node.name
,
"variant"
);
}
}
},
...
...
@@ -541,7 +543,7 @@ fn visit_item(&mut self, item: &ast::Item) {
fn
visit_foreign_item
(
&
mut
self
,
fi
:
&
ast
::
ForeignItem
)
{
if
!
self
.symbol_is_live
(
fi
.id
,
None
)
{
self
.warn_dead_code
(
fi
.id
,
fi
.span
,
fi
.ident
);
self
.warn_dead_code
(
fi
.id
,
fi
.span
,
fi
.ident
,
fi
.node
.descriptive_variant
()
);
}
visit
::
walk_foreign_item
(
self
,
fi
);
}
...
...
@@ -553,7 +555,7 @@ fn visit_fn(&mut self, fk: visit::FnKind<'v>,
match
fk
{
visit
::
FkMethod
(
name
,
_
,
_
)
=>
{
if
!
self
.symbol_is_live
(
id
,
None
)
{
self
.warn_dead_code
(
id
,
span
,
name
);
self
.warn_dead_code
(
id
,
span
,
name
,
"method"
);
}
}
_
=>
()
...
...
@@ -563,7 +565,8 @@ fn visit_fn(&mut self, fk: visit::FnKind<'v>,
fn
visit_struct_field
(
&
mut
self
,
field
:
&
ast
::
StructField
)
{
if
self
.should_warn_about_field
(
&
field
.node
)
{
self
.warn_dead_code
(
field
.node.id
,
field
.span
,
field
.node
.ident
()
.unwrap
());
self
.warn_dead_code
(
field
.node.id
,
field
.span
,
field
.node
.ident
()
.unwrap
(),
"struct field"
);
}
visit
::
walk_struct_field
(
self
,
field
);
...
...
src/libsyntax/ast.rs
浏览文件 @
3530e4a6
...
...
@@ -1323,6 +1323,22 @@ pub enum Item_ {
ItemMac
(
Mac
),
}
impl
Item_
{
pub
fn
descriptive_variant
(
&
self
)
->
&
str
{
match
*
self
{
ItemStatic
(
..
)
=>
"static item"
,
ItemFn
(
..
)
=>
"function"
,
ItemMod
(
..
)
=>
"module"
,
ItemForeignMod
(
..
)
=>
"foreign module"
,
ItemTy
(
..
)
=>
"type alias"
,
ItemEnum
(
..
)
=>
"enum"
,
ItemStruct
(
..
)
=>
"struct"
,
ItemTrait
(
..
)
=>
"trait"
,
_
=>
"item"
}
}
}
#[deriving(Clone,
PartialEq,
Eq,
Encodable,
Decodable,
Hash,
Show)]
pub
struct
ForeignItem
{
pub
ident
:
Ident
,
...
...
@@ -1339,6 +1355,15 @@ pub enum ForeignItem_ {
ForeignItemStatic
(
P
<
Ty
>
,
/* is_mutbl */
bool
),
}
impl
ForeignItem_
{
pub
fn
descriptive_variant
(
&
self
)
->
&
str
{
match
*
self
{
ForeignItemFn
(
..
)
=>
"foreign function"
,
ForeignItemStatic
(
..
)
=>
"foreign static item"
}
}
}
#[deriving(Clone,
PartialEq,
Eq,
Encodable,
Decodable,
Hash,
Show)]
pub
enum
UnboxedClosureKind
{
FnUnboxedClosureKind
,
...
...
src/test/compile-fail-fulldeps/syntax-extension-regex-unused-static.rs
浏览文件 @
3530e4a6
...
...
@@ -26,5 +26,5 @@
// unused variable warning).
fn
main
()
{
static
fubar
:
regex
::
Regex
=
regex!
(
"abc"
);
//~ ERROR
code
is never used: `fubar`
static
fubar
:
regex
::
Regex
=
regex!
(
"abc"
);
//~ ERROR
static item
is never used: `fubar`
}
src/test/compile-fail/fail-no-dead-code-core.rs
浏览文件 @
3530e4a6
...
...
@@ -15,7 +15,7 @@
#[phase(link,
plugin)]
extern
crate
core
;
fn
foo
()
{
//~ ERROR
code
is never used
fn
foo
()
{
//~ ERROR
function
is never used
// none of these should have any dead_code exposed to the user
fail
!
();
...
...
src/test/compile-fail/fail-no-dead-code.rs
浏览文件 @
3530e4a6
...
...
@@ -11,7 +11,7 @@
#![deny(dead_code)]
#![allow(unreachable_code)]
fn
foo
()
{
//~ ERROR
code
is never used
fn
foo
()
{
//~ ERROR
function
is never used
// none of these should have any dead_code exposed to the user
fail
!
();
...
...
src/test/compile-fail/lint-dead-code-1.rs
浏览文件 @
3530e4a6
...
...
@@ -22,7 +22,7 @@
pub
trait
Sized
{}
mod
foo
{
pub
struct
Bar
;
//~ ERROR:
code
is never used
pub
struct
Bar
;
//~ ERROR:
struct
is never used
}
mod
foo2
{
...
...
@@ -30,7 +30,7 @@ mod foo2 {
}
pub
static
pub_static
:
int
=
0
;
static
priv_static
:
int
=
0
;
//~ ERROR:
code
is never used
static
priv_static
:
int
=
0
;
//~ ERROR:
static item
is never used
static
used_static
:
int
=
0
;
pub
static
used_static2
:
int
=
used_static
;
static
USED_STATIC
:
int
=
0
;
...
...
@@ -38,7 +38,7 @@ mod foo2 {
pub
type
typ
=
*
const
UsedStruct4
;
pub
struct
PubStruct
;
struct
PrivStruct
;
//~ ERROR:
code
is never used
struct
PrivStruct
;
//~ ERROR:
struct
is never used
struct
UsedStruct1
{
#[allow(dead_code)]
x
:
int
...
...
@@ -64,10 +64,10 @@ pub enum pub_enum { foo1, bar1 }
pub
enum
pub_enum2
{
a
(
*
const
StructUsedInEnum
)
}
pub
enum
pub_enum3
{
Foo
=
STATIC_USED_IN_ENUM_DISCRIMINANT
}
enum
priv_enum
{
foo2
,
bar2
}
//~ ERROR:
code
is never used
enum
priv_enum
{
foo2
,
bar2
}
//~ ERROR:
enum
is never used
enum
used_enum
{
foo3
,
bar3
//~ ERROR
code
is never used
bar3
//~ ERROR
variant
is never used
}
fn
f
<
T
>
()
{}
...
...
@@ -87,17 +87,17 @@ pub fn pub_fn() {
}
f
::
<
StructUsedInGeneric
>
();
}
fn
priv_fn
()
{
//~ ERROR:
code
is never used
fn
priv_fn
()
{
//~ ERROR:
function
is never used
let
unused_struct
=
PrivStruct
;
}
fn
used_fn
()
{}
fn
foo
()
{
//~ ERROR:
code
is never used
fn
foo
()
{
//~ ERROR:
function
is never used
bar
();
let
unused_enum
=
foo2
;
}
fn
bar
()
{
//~ ERROR:
code
is never used
fn
bar
()
{
//~ ERROR:
function
is never used
foo
();
}
...
...
src/test/compile-fail/lint-dead-code-2.rs
浏览文件 @
3530e4a6
...
...
@@ -28,10 +28,10 @@ fn bar1(&self) {
fn
live_fn
()
{}
fn
dead_fn
()
{}
//~ ERROR:
code
is never used
fn
dead_fn
()
{}
//~ ERROR:
function
is never used
#[main]
fn
dead_fn2
()
{}
//~ ERROR:
code
is never used
fn
dead_fn2
()
{}
//~ ERROR:
function
is never used
fn
used_fn
()
{}
...
...
@@ -44,7 +44,7 @@ fn start(_: int, _: *const *const u8) -> int {
}
// this is not main
fn
main
()
{
//~ ERROR:
code
is never used
fn
main
()
{
//~ ERROR:
function
is never used
dead_fn
();
dead_fn2
();
}
src/test/compile-fail/lint-dead-code-3.rs
浏览文件 @
3530e4a6
...
...
@@ -21,15 +21,15 @@
fn
extern_foo
();
}
struct
Foo
;
//~ ERROR:
code
is never used
struct
Foo
;
//~ ERROR:
struct
is never used
impl
Foo
{
fn
foo
(
&
self
)
{
//~ ERROR:
code
is never used
fn
foo
(
&
self
)
{
//~ ERROR:
method
is never used
bar
()
}
}
fn
bar
()
{
//~ ERROR:
code
is never used
fn
baz
()
{}
//~ ERROR:
code
is never used
fn
bar
()
{
//~ ERROR:
function
is never used
fn
baz
()
{}
//~ ERROR:
function
is never used
Foo
.foo
();
baz
();
...
...
@@ -68,9 +68,9 @@ pub fn baz() {
}
}
enum
c_void
{}
//~ ERROR:
code
is never used
enum
c_void
{}
//~ ERROR:
enum
is never used
extern
{
fn
free
(
p
:
*
const
c_void
);
//~ ERROR:
code
is never used
fn
free
(
p
:
*
const
c_void
);
//~ ERROR:
foreign function
is never used
}
// Check provided method
...
...
src/test/compile-fail/lint-dead-code-4.rs
浏览文件 @
3530e4a6
...
...
@@ -19,7 +19,7 @@
struct
Foo
{
x
:
uint
,
b
:
bool
,
//~ ERROR:
code
is never used
b
:
bool
,
//~ ERROR:
struct field
is never used
marker
:
std
::
kinds
::
marker
::
NoCopy
}
...
...
@@ -31,7 +31,7 @@ enum XYZ {
X
,
//~ ERROR variant is never used
Y
{
//~ ERROR variant is never used
a
:
String
,
b
:
int
//~ ERROR:
code
is never used
b
:
int
//~ ERROR:
struct field
is never used
},
Z
}
...
...
@@ -44,7 +44,7 @@ fn field_match_in_patterns(b: XYZ) -> String {
}
struct
Bar
{
x
:
uint
,
//~ ERROR:
code
is never used
x
:
uint
,
//~ ERROR:
struct field
is never used
b
:
bool
,
_
guard
:
()
}
...
...
src/test/compile-fail/lint-dead-code-5.rs
浏览文件 @
3530e4a6
...
...
@@ -14,7 +14,7 @@
enum
Enum1
{
Variant1
(
int
),
Variant2
//~ ERROR:
code
is never used
Variant2
//~ ERROR:
variant
is never used
}
enum
Enum2
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录