Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
59fcac6f
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,发现更多精彩内容 >>
提交
59fcac6f
编写于
7月 30, 2017
作者:
G
Guillaume Gomez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve dead code detection for unions
上级
46fe8e99
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
16 deletion
+32
-16
src/librustc/hir/intravisit.rs
src/librustc/hir/intravisit.rs
+1
-1
src/librustc/middle/dead.rs
src/librustc/middle/dead.rs
+31
-15
未找到文件。
src/librustc/hir/intravisit.rs
浏览文件 @
59fcac6f
...
...
@@ -877,7 +877,7 @@ pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'
pub
fn
walk_struct_def
<
'v
,
V
:
Visitor
<
'v
>>
(
visitor
:
&
mut
V
,
struct_definition
:
&
'v
VariantData
)
{
visitor
.visit_id
(
struct_definition
.id
());
walk_list!
(
visitor
,
visit_struct_field
,
struct_definition
.fields
());
walk_list!
(
visitor
,
visit_struct_field
,
struct_definition
.fields
()
.iter
()
.rev
()
);
}
pub
fn
walk_struct_field
<
'v
,
V
:
Visitor
<
'v
>>
(
visitor
:
&
mut
V
,
struct_field
:
&
'v
StructField
)
{
...
...
src/librustc/middle/dead.rs
浏览文件 @
59fcac6f
...
...
@@ -422,6 +422,7 @@ fn get_struct_ctor_id(item: &hir::Item) -> Option<ast::NodeId> {
struct
DeadVisitor
<
'a
,
'tcx
:
'a
>
{
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
live_symbols
:
Box
<
FxHashSet
<
ast
::
NodeId
>>
,
need_check_next_union_field
:
bool
,
}
impl
<
'a
,
'tcx
>
DeadVisitor
<
'a
,
'tcx
>
{
...
...
@@ -537,6 +538,16 @@ fn visit_item(&mut self, item: &'tcx hir::Item) {
}
}
fn
visit_variant_data
(
&
mut
self
,
s
:
&
'tcx
hir
::
VariantData
,
_
:
ast
::
Name
,
_
:
&
'tcx
hir
::
Generics
,
_
parent_id
:
ast
::
NodeId
,
_
:
syntax_pos
::
Span
)
{
self
.need_check_next_union_field
=
true
;
intravisit
::
walk_struct_def
(
self
,
s
)
}
fn
visit_variant
(
&
mut
self
,
variant
:
&
'tcx
hir
::
Variant
,
g
:
&
'tcx
hir
::
Generics
,
...
...
@@ -557,23 +568,24 @@ fn visit_foreign_item(&mut self, fi: &'tcx hir::ForeignItem) {
}
fn
visit_struct_field
(
&
mut
self
,
field
:
&
'tcx
hir
::
StructField
)
{
if
self
.should_warn_about_field
(
&
field
)
{
let
did
=
self
.tcx.hir
.get_parent_did
(
field
.id
);
if
if
let
Some
(
node_id
)
=
self
.tcx.hir
.as_local_node_id
(
did
)
{
match
self
.tcx.hir
.find
(
node_id
)
{
Some
(
hir_map
::
NodeItem
(
item
))
=>
match
item
.node
{
Item_
::
ItemUnion
(
_
,
_
)
=>
false
,
_
=>
true
,
},
_
=>
true
,
}
}
else
{
true
}
{
if
self
.need_check_next_union_field
{
if
self
.should_warn_about_field
(
&
field
)
{
self
.warn_dead_code
(
field
.id
,
field
.span
,
field
.name
,
"field"
);
}
else
{
let
did
=
self
.tcx.hir
.get_parent_did
(
field
.id
);
if
let
Some
(
node_id
)
=
self
.tcx.hir
.as_local_node_id
(
did
)
{
match
self
.tcx.hir
.find
(
node_id
)
{
Some
(
hir_map
::
NodeItem
(
item
))
=>
match
item
.node
{
// If this is an union's field, it means all previous fields
// have been used as well so no need to check further.
Item_
::
ItemUnion
(
_
,
_
)
=>
self
.need_check_next_union_field
=
false
,
_
=>
{}
},
_
=>
{}
}
}
}
}
intravisit
::
walk_struct_field
(
self
,
field
);
}
...
...
@@ -615,6 +627,10 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
let
access_levels
=
&
tcx
.privacy_access_levels
(
LOCAL_CRATE
);
let
krate
=
tcx
.hir
.krate
();
let
live_symbols
=
find_live
(
tcx
,
access_levels
,
krate
);
let
mut
visitor
=
DeadVisitor
{
tcx
:
tcx
,
live_symbols
:
live_symbols
};
let
mut
visitor
=
DeadVisitor
{
tcx
:
tcx
,
live_symbols
:
live_symbols
,
need_check_next_union_field
:
true
,
};
intravisit
::
walk_crate
(
&
mut
visitor
,
krate
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录