Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
98b046e1
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,发现更多精彩内容 >>
提交
98b046e1
编写于
11月 17, 2015
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Various straight-forward ports that override `visit_nested_items`
to do "in-situ" visits.
上级
ac38021d
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
229 addition
and
162 deletion
+229
-162
src/librustc/lint/context.rs
src/librustc/lint/context.rs
+14
-4
src/librustc/lint/mod.rs
src/librustc/lint/mod.rs
+2
-2
src/librustc/middle/dead.rs
src/librustc/middle/dead.rs
+32
-30
src/librustc/middle/stability.rs
src/librustc/middle/stability.rs
+30
-18
src/librustc_back/svh.rs
src/librustc_back/svh.rs
+37
-32
src/librustc_privacy/lib.rs
src/librustc_privacy/lib.rs
+68
-38
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+8
-4
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+38
-34
未找到文件。
src/librustc/lint/context.rs
浏览文件 @
98b046e1
...
...
@@ -44,7 +44,7 @@
use
syntax
::
ast
;
use
rustc_front
::
hir
;
use
rustc_front
::
util
;
use
rustc_front
::
visit
as
hir_visit
;
use
rustc_front
::
intra
visit
as
hir_visit
;
use
syntax
::
visit
as
ast_visit
;
use
syntax
::
diagnostic
;
...
...
@@ -606,10 +606,12 @@ fn level_stack(&mut self) -> &mut Vec<(LintId, LevelSource)> {
}
fn
enter_attrs
(
&
mut
self
,
attrs
:
&
[
ast
::
Attribute
])
{
debug!
(
"late context: enter_attrs({:?})"
,
attrs
);
run_lints!
(
self
,
enter_lint_attrs
,
late_passes
,
attrs
);
}
fn
exit_attrs
(
&
mut
self
,
attrs
:
&
[
ast
::
Attribute
])
{
debug!
(
"late context: exit_attrs({:?})"
,
attrs
);
run_lints!
(
self
,
exit_lint_attrs
,
late_passes
,
attrs
);
}
}
...
...
@@ -633,15 +635,24 @@ fn level_stack(&mut self) -> &mut Vec<(LintId, LevelSource)> {
}
fn
enter_attrs
(
&
mut
self
,
attrs
:
&
[
ast
::
Attribute
])
{
debug!
(
"early context: exit_attrs({:?})"
,
attrs
);
run_lints!
(
self
,
enter_lint_attrs
,
early_passes
,
attrs
);
}
fn
exit_attrs
(
&
mut
self
,
attrs
:
&
[
ast
::
Attribute
])
{
debug!
(
"early context: exit_attrs({:?})"
,
attrs
);
run_lints!
(
self
,
exit_lint_attrs
,
early_passes
,
attrs
);
}
}
impl
<
'a
,
'tcx
,
'v
>
hir_visit
::
Visitor
<
'v
>
for
LateContext
<
'a
,
'tcx
>
{
/// Because lints are scoped lexically, we want to walk nested
/// items in the context of the outer item, so enable
/// deep-walking.
fn
visit_nested_item
(
&
mut
self
,
item
:
hir
::
ItemId
)
{
self
.visit_item
(
self
.tcx.map
.expect_item
(
item
.id
))
}
fn
visit_item
(
&
mut
self
,
it
:
&
hir
::
Item
)
{
self
.with_lint_attrs
(
&
it
.attrs
,
|
cx
|
{
run_lints!
(
cx
,
check_item
,
late_passes
,
it
);
...
...
@@ -947,6 +958,7 @@ fn visit_id(&mut self, id: ast::NodeId) {
match
self
.sess
()
.lints
.borrow_mut
()
.remove
(
&
id
)
{
None
=>
{}
Some
(
lints
)
=>
{
debug!
(
"LateContext::visit_id: id={:?} lints={:?}"
,
id
,
lints
);
for
(
lint_id
,
span
,
msg
)
in
lints
{
self
.span_lint
(
lint_id
.lint
,
span
,
&
msg
[
..
])
}
...
...
@@ -1003,16 +1015,14 @@ fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
///
/// Consumes the `lint_store` field of the `Session`.
pub
fn
check_crate
(
tcx
:
&
ty
::
ctxt
,
krate
:
&
hir
::
Crate
,
exported_items
:
&
ExportedItems
)
{
let
krate
=
tcx
.map
.krate
();
let
mut
cx
=
LateContext
::
new
(
tcx
,
krate
,
exported_items
);
// Visit the whole crate.
cx
.with_lint_attrs
(
&
krate
.attrs
,
|
cx
|
{
cx
.visit_id
(
ast
::
CRATE_NODE_ID
);
cx
.visit_ids
(|
v
|
{
v
.visited_outermost
=
true
;
hir_visit
::
walk_crate
(
v
,
krate
);
});
...
...
src/librustc/lint/mod.rs
浏览文件 @
98b046e1
...
...
@@ -34,7 +34,7 @@
use
std
::
hash
;
use
std
::
ascii
::
AsciiExt
;
use
syntax
::
codemap
::
Span
;
use
rustc_front
::
visit
::
FnKind
;
use
rustc_front
::
intra
visit
::
FnKind
;
use
syntax
::
visit
as
ast_visit
;
use
syntax
::
ast
;
use
rustc_front
::
hir
;
...
...
@@ -218,7 +218,7 @@ fn exit_lint_attrs(&mut self, _: &EarlyContext, _: &[ast::Attribute]) { }
pub
type
LateLintPassObject
=
Box
<
LateLintPass
+
'static
>
;
/// Identifies a lint known to the compiler.
#[derive(Clone,
Copy)]
#[derive(Clone,
Copy
,
Debug
)]
pub
struct
LintId
{
// Identity is based on pointer equality of this field.
lint
:
&
'static
Lint
,
...
...
src/librustc/middle/dead.rs
浏览文件 @
98b046e1
...
...
@@ -14,7 +14,7 @@
use
front
::
map
as
ast_map
;
use
rustc_front
::
hir
;
use
rustc_front
::
visit
::{
self
,
Visitor
};
use
rustc_front
::
intra
visit
::{
self
,
Visitor
};
use
middle
::{
def
,
pat_util
,
privacy
,
ty
};
use
middle
::
def_id
::{
DefId
};
...
...
@@ -182,29 +182,29 @@ fn visit_node(&mut self, node: &ast_map::Node) {
.contains
(
&
attr
::
ReprExtern
)
});
visit
::
walk_item
(
self
,
&*
item
);
intra
visit
::
walk_item
(
self
,
&*
item
);
}
hir
::
ItemEnum
(
..
)
=>
{
self
.inherited_pub_visibility
=
item
.vis
==
hir
::
Public
;
visit
::
walk_item
(
self
,
&*
item
);
intra
visit
::
walk_item
(
self
,
&*
item
);
}
hir
::
ItemFn
(
..
)
|
hir
::
ItemTy
(
..
)
|
hir
::
ItemStatic
(
..
)
|
hir
::
ItemConst
(
..
)
=>
{
visit
::
walk_item
(
self
,
&*
item
);
intra
visit
::
walk_item
(
self
,
&*
item
);
}
_
=>
()
}
}
ast_map
::
NodeTraitItem
(
trait_item
)
=>
{
visit
::
walk_trait_item
(
self
,
trait_item
);
intra
visit
::
walk_trait_item
(
self
,
trait_item
);
}
ast_map
::
NodeImplItem
(
impl_item
)
=>
{
visit
::
walk_impl_item
(
self
,
impl_item
);
intra
visit
::
walk_impl_item
(
self
,
impl_item
);
}
ast_map
::
NodeForeignItem
(
foreign_item
)
=>
{
visit
::
walk_foreign_item
(
self
,
&*
foreign_item
);
intra
visit
::
walk_foreign_item
(
self
,
&*
foreign_item
);
}
_
=>
()
}
...
...
@@ -227,7 +227,7 @@ fn visit_variant_data(&mut self, def: &hir::VariantData, _: ast::Name,
});
self
.live_symbols
.extend
(
live_fields
.map
(|
f
|
f
.node.id
));
visit
::
walk_struct_def
(
self
,
def
);
intra
visit
::
walk_struct_def
(
self
,
def
);
}
fn
visit_expr
(
&
mut
self
,
expr
:
&
hir
::
Expr
)
{
...
...
@@ -244,7 +244,7 @@ fn visit_expr(&mut self, expr: &hir::Expr) {
_
=>
()
}
visit
::
walk_expr
(
self
,
expr
);
intra
visit
::
walk_expr
(
self
,
expr
);
}
fn
visit_arm
(
&
mut
self
,
arm
:
&
hir
::
Arm
)
{
...
...
@@ -257,10 +257,10 @@ fn visit_arm(&mut self, arm: &hir::Arm) {
// can't be reached unless the variant is constructed elsewhere.
let
len
=
self
.ignore_variant_stack
.len
();
self
.ignore_variant_stack
.push_all
(
&*
variants
);
visit
::
walk_arm
(
self
,
arm
);
intra
visit
::
walk_arm
(
self
,
arm
);
self
.ignore_variant_stack
.truncate
(
len
);
}
else
{
visit
::
walk_arm
(
self
,
arm
);
intra
visit
::
walk_arm
(
self
,
arm
);
}
}
...
...
@@ -278,23 +278,18 @@ fn visit_pat(&mut self, pat: &hir::Pat) {
}
self
.ignore_non_const_paths
=
true
;
visit
::
walk_pat
(
self
,
pat
);
intra
visit
::
walk_pat
(
self
,
pat
);
self
.ignore_non_const_paths
=
false
;
}
fn
visit_path
(
&
mut
self
,
path
:
&
hir
::
Path
,
id
:
ast
::
NodeId
)
{
self
.lookup_and_handle_definition
(
&
id
);
visit
::
walk_path
(
self
,
path
);
intra
visit
::
walk_path
(
self
,
path
);
}
fn
visit_path_list_item
(
&
mut
self
,
path
:
&
hir
::
Path
,
item
:
&
hir
::
PathListItem
)
{
self
.lookup_and_handle_definition
(
&
item
.node
.id
());
visit
::
walk_path_list_item
(
self
,
path
,
item
);
}
fn
visit_item
(
&
mut
self
,
_
:
&
hir
::
Item
)
{
// Do not recurse into items. These items will be added to the
// worklist and recursed into manually if necessary.
intravisit
::
walk_path_list_item
(
self
,
path
,
item
);
}
}
...
...
@@ -371,7 +366,6 @@ fn visit_item(&mut self, item: &hir::Item) {
}
_
=>
()
}
visit
::
walk_item
(
self
,
item
);
}
}
...
...
@@ -408,7 +402,7 @@ fn create_and_seed_worklist(tcx: &ty::ctxt,
let
mut
life_seeder
=
LifeSeeder
{
worklist
:
worklist
};
visit
::
walk_crate
(
&
mut
life_seeder
,
krate
);
krate
.visit_all_items
(
&
mut
life_seeder
);
return
life_seeder
.worklist
;
}
...
...
@@ -530,6 +524,14 @@ fn warn_dead_code(&mut self,
}
impl
<
'a
,
'tcx
,
'v
>
Visitor
<
'v
>
for
DeadVisitor
<
'a
,
'tcx
>
{
/// Walk nested items in place so that we don't report dead-code
/// on inner functions when the outer function is already getting
/// an error. We could do this also by checking the parents, but
/// this is how the code is setup and it seems harmless enough.
fn
visit_nested_item
(
&
mut
self
,
item
:
hir
::
ItemId
)
{
self
.visit_item
(
self
.tcx.map
.expect_item
(
item
.id
))
}
fn
visit_item
(
&
mut
self
,
item
:
&
hir
::
Item
)
{
if
self
.should_warn_about_item
(
item
)
{
self
.warn_dead_code
(
...
...
@@ -540,7 +542,7 @@ fn visit_item(&mut self, item: &hir::Item) {
);
}
else
{
// Only continue if we didn't warn
visit
::
walk_item
(
self
,
item
);
intra
visit
::
walk_item
(
self
,
item
);
}
}
...
...
@@ -549,7 +551,7 @@ fn visit_variant(&mut self, variant: &hir::Variant, g: &hir::Generics, id: ast::
self
.warn_dead_code
(
variant
.node.data
.id
(),
variant
.span
,
variant
.node.name
,
"variant"
);
}
else
{
visit
::
walk_variant
(
self
,
variant
,
g
,
id
);
intra
visit
::
walk_variant
(
self
,
variant
,
g
,
id
);
}
}
...
...
@@ -557,7 +559,7 @@ fn visit_foreign_item(&mut self, fi: &hir::ForeignItem) {
if
!
self
.symbol_is_live
(
fi
.id
,
None
)
{
self
.warn_dead_code
(
fi
.id
,
fi
.span
,
fi
.name
,
fi
.node
.descriptive_variant
());
}
visit
::
walk_foreign_item
(
self
,
fi
);
intra
visit
::
walk_foreign_item
(
self
,
fi
);
}
fn
visit_struct_field
(
&
mut
self
,
field
:
&
hir
::
StructField
)
{
...
...
@@ -566,7 +568,7 @@ fn visit_struct_field(&mut self, field: &hir::StructField) {
field
.node
.name
()
.unwrap
(),
"struct field"
);
}
visit
::
walk_struct_field
(
self
,
field
);
intra
visit
::
walk_struct_field
(
self
,
field
);
}
fn
visit_impl_item
(
&
mut
self
,
impl_item
:
&
hir
::
ImplItem
)
{
...
...
@@ -576,14 +578,14 @@ fn visit_impl_item(&mut self, impl_item: &hir::ImplItem) {
self
.warn_dead_code
(
impl_item
.id
,
impl_item
.span
,
impl_item
.name
,
"associated const"
);
}
visit
::
walk_expr
(
self
,
expr
)
intra
visit
::
walk_expr
(
self
,
expr
)
}
hir
::
ImplItemKind
::
Method
(
_
,
ref
body
)
=>
{
if
!
self
.symbol_is_live
(
impl_item
.id
,
None
)
{
self
.warn_dead_code
(
impl_item
.id
,
impl_item
.span
,
impl_item
.name
,
"method"
);
}
visit
::
walk_block
(
self
,
body
)
intra
visit
::
walk_block
(
self
,
body
)
}
hir
::
ImplItemKind
::
Type
(
..
)
=>
{}
}
...
...
@@ -593,10 +595,10 @@ fn visit_impl_item(&mut self, impl_item: &hir::ImplItem) {
fn
visit_trait_item
(
&
mut
self
,
trait_item
:
&
hir
::
TraitItem
)
{
match
trait_item
.node
{
hir
::
ConstTraitItem
(
_
,
Some
(
ref
expr
))
=>
{
visit
::
walk_expr
(
self
,
expr
)
intra
visit
::
walk_expr
(
self
,
expr
)
}
hir
::
MethodTraitItem
(
_
,
Some
(
ref
body
))
=>
{
visit
::
walk_block
(
self
,
body
)
intra
visit
::
walk_block
(
self
,
body
)
}
hir
::
ConstTraitItem
(
_
,
None
)
|
hir
::
MethodTraitItem
(
_
,
None
)
|
...
...
@@ -612,5 +614,5 @@ pub fn check_crate(tcx: &ty::ctxt,
let
live_symbols
=
find_live
(
tcx
,
exported_items
,
reachable_symbols
,
krate
);
let
mut
visitor
=
DeadVisitor
{
tcx
:
tcx
,
live_symbols
:
live_symbols
};
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
intra
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
}
src/librustc/middle/stability.rs
浏览文件 @
98b046e1
...
...
@@ -31,7 +31,7 @@
use
rustc_front
::
hir
;
use
rustc_front
::
hir
::{
Block
,
Crate
,
Item
,
Generics
,
StructField
,
Variant
};
use
rustc_front
::
visit
::{
self
,
Visitor
};
use
rustc_front
::
intra
visit
::{
self
,
Visitor
};
use
std
::
mem
::
replace
;
use
std
::
cmp
::
Ordering
;
...
...
@@ -174,6 +174,13 @@ fn annotate<F>(&mut self, id: NodeId, attrs: &Vec<Attribute>,
}
impl
<
'a
,
'tcx
,
'v
>
Visitor
<
'v
>
for
Annotator
<
'a
,
'tcx
>
{
/// Because stability levels are scoped lexically, we want to walk
/// nested items in the context of the outer item, so enable
/// deep-walking.
fn
visit_nested_item
(
&
mut
self
,
item
:
hir
::
ItemId
)
{
self
.visit_item
(
self
.tcx.map
.expect_item
(
item
.id
))
}
fn
visit_item
(
&
mut
self
,
i
:
&
Item
)
{
let
orig_in_trait_impl
=
self
.in_trait_impl
;
let
orig_in_enum
=
self
.in_enum
;
...
...
@@ -203,7 +210,7 @@ fn visit_item(&mut self, i: &Item) {
}
self
.annotate
(
i
.id
,
&
i
.attrs
,
i
.span
,
kind
,
|
v
|
{
visit
::
walk_item
(
v
,
i
)
intra
visit
::
walk_item
(
v
,
i
)
});
self
.in_trait_impl
=
orig_in_trait_impl
;
self
.in_enum
=
orig_in_enum
;
...
...
@@ -211,7 +218,7 @@ fn visit_item(&mut self, i: &Item) {
fn
visit_trait_item
(
&
mut
self
,
ti
:
&
hir
::
TraitItem
)
{
self
.annotate
(
ti
.id
,
&
ti
.attrs
,
ti
.span
,
AnnotationKind
::
Required
,
|
v
|
{
visit
::
walk_trait_item
(
v
,
ti
);
intra
visit
::
walk_trait_item
(
v
,
ti
);
});
}
...
...
@@ -222,13 +229,13 @@ fn visit_impl_item(&mut self, ii: &hir::ImplItem) {
AnnotationKind
::
Required
};
self
.annotate
(
ii
.id
,
&
ii
.attrs
,
ii
.span
,
kind
,
|
v
|
{
visit
::
walk_impl_item
(
v
,
ii
);
intra
visit
::
walk_impl_item
(
v
,
ii
);
});
}
fn
visit_variant
(
&
mut
self
,
var
:
&
Variant
,
g
:
&
'v
Generics
,
item_id
:
NodeId
)
{
self
.annotate
(
var
.node.data
.id
(),
&
var
.node.attrs
,
var
.span
,
AnnotationKind
::
Required
,
|
v
|
{
visit
::
walk_variant
(
v
,
var
,
g
,
item_id
);
intra
visit
::
walk_variant
(
v
,
var
,
g
,
item_id
);
})
}
...
...
@@ -240,13 +247,13 @@ fn visit_struct_field(&mut self, s: &StructField) {
AnnotationKind
::
Required
};
self
.annotate
(
s
.node.id
,
&
s
.node.attrs
,
s
.span
,
kind
,
|
v
|
{
visit
::
walk_struct_field
(
v
,
s
);
intra
visit
::
walk_struct_field
(
v
,
s
);
});
}
fn
visit_foreign_item
(
&
mut
self
,
i
:
&
hir
::
ForeignItem
)
{
self
.annotate
(
i
.id
,
&
i
.attrs
,
i
.span
,
AnnotationKind
::
Required
,
|
v
|
{
visit
::
walk_foreign_item
(
v
,
i
);
intra
visit
::
walk_foreign_item
(
v
,
i
);
});
}
...
...
@@ -259,7 +266,7 @@ fn visit_macro_def(&mut self, md: &'v hir::MacroDef) {
impl
<
'tcx
>
Index
<
'tcx
>
{
/// Construct the stability index for a crate being compiled.
pub
fn
build
(
&
mut
self
,
tcx
:
&
ty
::
ctxt
<
'tcx
>
,
krate
:
&
Crate
,
export_map
:
&
PublicItems
)
{
pub
fn
build
(
&
mut
self
,
tcx
:
&
ty
::
ctxt
<
'tcx
>
,
krate
:
&
'tcx
Crate
,
export_map
:
&
PublicItems
)
{
let
mut
annotator
=
Annotator
{
tcx
:
tcx
,
index
:
self
,
...
...
@@ -269,7 +276,7 @@ pub fn build(&mut self, tcx: &ty::ctxt<'tcx>, krate: &Crate, export_map: &Public
in_enum
:
false
,
};
annotator
.annotate
(
ast
::
CRATE_NODE_ID
,
&
krate
.attrs
,
krate
.span
,
AnnotationKind
::
Required
,
|
v
|
visit
::
walk_crate
(
v
,
krate
));
|
v
|
intra
visit
::
walk_crate
(
v
,
krate
));
}
pub
fn
new
(
krate
:
&
Crate
)
->
Index
{
...
...
@@ -308,9 +315,7 @@ pub fn check_unstable_api_usage(tcx: &ty::ctxt)
used_features
:
FnvHashMap
(),
in_skip_block
:
0
,
};
let
krate
=
tcx
.map
.krate
();
visit
::
walk_crate
(
&
mut
checker
,
krate
);
intravisit
::
walk_crate
(
&
mut
checker
,
tcx
.map
.krate
());
let
used_features
=
checker
.used_features
;
return
used_features
;
...
...
@@ -379,6 +384,13 @@ fn check(&mut self, id: DefId, span: Span, stab: &Option<&Stability>) {
}
impl
<
'a
,
'v
,
'tcx
>
Visitor
<
'v
>
for
Checker
<
'a
,
'tcx
>
{
/// Because stability levels are scoped lexically, we want to walk
/// nested items in the context of the outer item, so enable
/// deep-walking.
fn
visit_nested_item
(
&
mut
self
,
item
:
hir
::
ItemId
)
{
self
.visit_item
(
self
.tcx.map
.expect_item
(
item
.id
))
}
fn
visit_item
(
&
mut
self
,
item
:
&
hir
::
Item
)
{
// When compiling with --test we don't enforce stability on the
// compiler-generated test module, demarcated with `DUMMY_SP` plus the
...
...
@@ -387,31 +399,31 @@ fn visit_item(&mut self, item: &hir::Item) {
check_item
(
self
.tcx
,
item
,
true
,
&
mut
|
id
,
sp
,
stab
|
self
.check
(
id
,
sp
,
stab
));
visit
::
walk_item
(
self
,
item
);
intra
visit
::
walk_item
(
self
,
item
);
}
fn
visit_expr
(
&
mut
self
,
ex
:
&
hir
::
Expr
)
{
check_expr
(
self
.tcx
,
ex
,
&
mut
|
id
,
sp
,
stab
|
self
.check
(
id
,
sp
,
stab
));
visit
::
walk_expr
(
self
,
ex
);
intra
visit
::
walk_expr
(
self
,
ex
);
}
fn
visit_path
(
&
mut
self
,
path
:
&
hir
::
Path
,
id
:
ast
::
NodeId
)
{
check_path
(
self
.tcx
,
path
,
id
,
&
mut
|
id
,
sp
,
stab
|
self
.check
(
id
,
sp
,
stab
));
visit
::
walk_path
(
self
,
path
)
intra
visit
::
walk_path
(
self
,
path
)
}
fn
visit_path_list_item
(
&
mut
self
,
prefix
:
&
hir
::
Path
,
item
:
&
hir
::
PathListItem
)
{
check_path_list_item
(
self
.tcx
,
item
,
&
mut
|
id
,
sp
,
stab
|
self
.check
(
id
,
sp
,
stab
));
visit
::
walk_path_list_item
(
self
,
prefix
,
item
)
intra
visit
::
walk_path_list_item
(
self
,
prefix
,
item
)
}
fn
visit_pat
(
&
mut
self
,
pat
:
&
hir
::
Pat
)
{
check_pat
(
self
.tcx
,
pat
,
&
mut
|
id
,
sp
,
stab
|
self
.check
(
id
,
sp
,
stab
));
visit
::
walk_pat
(
self
,
pat
)
intra
visit
::
walk_pat
(
self
,
pat
)
}
fn
visit_block
(
&
mut
self
,
b
:
&
hir
::
Block
)
{
...
...
@@ -425,7 +437,7 @@ fn visit_block(&mut self, b: &hir::Block) {
}
_
=>
{}
}
visit
::
walk_block
(
self
,
b
);
intra
visit
::
walk_block
(
self
,
b
);
self
.in_skip_block
=
old_skip_count
;
}
}
...
...
src/librustc_back/svh.rs
浏览文件 @
98b046e1
...
...
@@ -49,7 +49,7 @@
use
std
::
fmt
;
use
std
::
hash
::{
Hash
,
SipHasher
,
Hasher
};
use
rustc_front
::
hir
;
use
rustc_front
::
visit
;
use
rustc_front
::
intravisit
as
visit
;
#[derive(Clone,
PartialEq,
Debug)]
pub
struct
Svh
{
...
...
@@ -83,7 +83,7 @@ pub fn calculate(metadata: &Vec<String>, krate: &hir::Crate) -> Svh {
}
{
let
mut
visit
=
svh_visitor
::
make
(
&
mut
state
);
let
mut
visit
=
svh_visitor
::
make
(
&
mut
state
,
krate
);
visit
::
walk_crate
(
&
mut
visit
,
krate
);
}
...
...
@@ -134,19 +134,20 @@ mod svh_visitor {
use
syntax
::
ast
::{
self
,
Name
,
NodeId
};
use
syntax
::
codemap
::
Span
;
use
syntax
::
parse
::
token
;
use
rustc_front
::
visit
;
use
rustc_front
::
visit
::{
Visitor
,
FnKind
};
use
rustc_front
::
intravisit
as
visit
;
use
rustc_front
::
intra
visit
::{
Visitor
,
FnKind
};
use
rustc_front
::
hir
::
*
;
use
rustc_front
::
hir
;
use
std
::
hash
::{
Hash
,
SipHasher
};
pub
struct
StrictVersionHashVisitor
<
'a
>
{
pub
krate
:
&
'a
Crate
,
pub
st
:
&
'a
mut
SipHasher
,
}
pub
fn
make
<
'a
>
(
st
:
&
'a
mut
SipHasher
)
->
StrictVersionHashVisitor
<
'a
>
{
StrictVersionHashVisitor
{
st
:
st
}
pub
fn
make
<
'a
>
(
st
:
&
'a
mut
SipHasher
,
krate
:
&
'a
Crate
)
->
StrictVersionHashVisitor
<
'a
>
{
StrictVersionHashVisitor
{
st
:
st
,
krate
:
krate
}
}
// To off-load the bulk of the hash-computation on #[derive(Hash)],
...
...
@@ -300,15 +301,19 @@ fn saw_stmt(node: &Stmt_) -> SawStmtComponent {
}
}
impl
<
'a
,
'v
>
Visitor
<
'v
>
for
StrictVersionHashVisitor
<
'a
>
{
fn
visit_variant_data
(
&
mut
self
,
s
:
&
VariantData
,
name
:
Name
,
g
:
&
Generics
,
_
:
NodeId
,
_
:
Span
)
{
impl
<
'a
>
Visitor
<
'a
>
for
StrictVersionHashVisitor
<
'a
>
{
fn
visit_nested_item
(
&
mut
self
,
item
:
ItemId
)
{
self
.visit_item
(
self
.krate
.item
(
item
.id
))
}
fn
visit_variant_data
(
&
mut
self
,
s
:
&
'a
VariantData
,
name
:
Name
,
g
:
&
'a
Generics
,
_
:
NodeId
,
_
:
Span
)
{
SawStructDef
(
name
.as_str
())
.hash
(
self
.st
);
visit
::
walk_generics
(
self
,
g
);
visit
::
walk_struct_def
(
self
,
s
)
}
fn
visit_variant
(
&
mut
self
,
v
:
&
Variant
,
g
:
&
Generics
,
item_id
:
NodeId
)
{
fn
visit_variant
(
&
mut
self
,
v
:
&
'a
Variant
,
g
:
&
'a
Generics
,
item_id
:
NodeId
)
{
SawVariant
.hash
(
self
.st
);
// walk_variant does not call walk_generics, so do it here.
visit
::
walk_generics
(
self
,
g
);
...
...
@@ -333,11 +338,11 @@ fn visit_name(&mut self, _: Span, name: Name) {
SawIdent
(
name
.as_str
())
.hash
(
self
.st
);
}
fn
visit_lifetime
(
&
mut
self
,
l
:
&
Lifetime
)
{
fn
visit_lifetime
(
&
mut
self
,
l
:
&
'a
Lifetime
)
{
SawLifetime
(
l
.name
.as_str
())
.hash
(
self
.st
);
}
fn
visit_lifetime_def
(
&
mut
self
,
l
:
&
LifetimeDef
)
{
fn
visit_lifetime_def
(
&
mut
self
,
l
:
&
'a
LifetimeDef
)
{
SawLifetimeDef
(
l
.lifetime.name
.as_str
())
.hash
(
self
.st
);
}
...
...
@@ -346,15 +351,15 @@ fn visit_lifetime_def(&mut self, l: &LifetimeDef) {
// monomorphization and cross-crate inlining generally implies
// that a change to a crate body will require downstream
// crates to be recompiled.
fn
visit_expr
(
&
mut
self
,
ex
:
&
Expr
)
{
fn
visit_expr
(
&
mut
self
,
ex
:
&
'a
Expr
)
{
SawExpr
(
saw_expr
(
&
ex
.node
))
.hash
(
self
.st
);
visit
::
walk_expr
(
self
,
ex
)
}
fn
visit_stmt
(
&
mut
self
,
s
:
&
Stmt
)
{
fn
visit_stmt
(
&
mut
self
,
s
:
&
'a
Stmt
)
{
SawStmt
(
saw_stmt
(
&
s
.node
))
.hash
(
self
.st
);
visit
::
walk_stmt
(
self
,
s
)
}
fn
visit_foreign_item
(
&
mut
self
,
i
:
&
ForeignItem
)
{
fn
visit_foreign_item
(
&
mut
self
,
i
:
&
'a
ForeignItem
)
{
// FIXME (#14132) ideally we would incorporate privacy (or
// perhaps reachability) somewhere here, so foreign items
// that do not leak into downstream crates would not be
...
...
@@ -362,7 +367,7 @@ fn visit_foreign_item(&mut self, i: &ForeignItem) {
SawForeignItem
.hash
(
self
.st
);
visit
::
walk_foreign_item
(
self
,
i
)
}
fn
visit_item
(
&
mut
self
,
i
:
&
Item
)
{
fn
visit_item
(
&
mut
self
,
i
:
&
'a
Item
)
{
// FIXME (#14132) ideally would incorporate reachability
// analysis somewhere here, so items that never leak into
// downstream crates (e.g. via monomorphisation or
...
...
@@ -370,64 +375,64 @@ fn visit_item(&mut self, i: &Item) {
SawItem
.hash
(
self
.st
);
visit
::
walk_item
(
self
,
i
)
}
fn
visit_mod
(
&
mut
self
,
m
:
&
Mod
,
_
s
:
Span
,
_
n
:
NodeId
)
{
fn
visit_mod
(
&
mut
self
,
m
:
&
'a
Mod
,
_
s
:
Span
,
_
n
:
NodeId
)
{
SawMod
.hash
(
self
.st
);
visit
::
walk_mod
(
self
,
m
)
}
fn
visit_decl
(
&
mut
self
,
d
:
&
Decl
)
{
fn
visit_decl
(
&
mut
self
,
d
:
&
'a
Decl
)
{
SawDecl
.hash
(
self
.st
);
visit
::
walk_decl
(
self
,
d
)
}
fn
visit_ty
(
&
mut
self
,
t
:
&
Ty
)
{
fn
visit_ty
(
&
mut
self
,
t
:
&
'a
Ty
)
{
SawTy
.hash
(
self
.st
);
visit
::
walk_ty
(
self
,
t
)
}
fn
visit_generics
(
&
mut
self
,
g
:
&
Generics
)
{
fn
visit_generics
(
&
mut
self
,
g
:
&
'a
Generics
)
{
SawGenerics
.hash
(
self
.st
);
visit
::
walk_generics
(
self
,
g
)
}
fn
visit_fn
(
&
mut
self
,
fk
:
FnKind
<
'
v
>
,
fd
:
&
'v
FnDecl
,
b
:
&
'
v
Block
,
s
:
Span
,
_
:
NodeId
)
{
fn
visit_fn
(
&
mut
self
,
fk
:
FnKind
<
'
a
>
,
fd
:
&
'a
FnDecl
,
b
:
&
'
a
Block
,
s
:
Span
,
_
:
NodeId
)
{
SawFn
.hash
(
self
.st
);
visit
::
walk_fn
(
self
,
fk
,
fd
,
b
,
s
)
}
fn
visit_trait_item
(
&
mut
self
,
ti
:
&
TraitItem
)
{
fn
visit_trait_item
(
&
mut
self
,
ti
:
&
'a
TraitItem
)
{
SawTraitItem
.hash
(
self
.st
);
visit
::
walk_trait_item
(
self
,
ti
)
}
fn
visit_impl_item
(
&
mut
self
,
ii
:
&
ImplItem
)
{
fn
visit_impl_item
(
&
mut
self
,
ii
:
&
'a
ImplItem
)
{
SawImplItem
.hash
(
self
.st
);
visit
::
walk_impl_item
(
self
,
ii
)
}
fn
visit_struct_field
(
&
mut
self
,
s
:
&
StructField
)
{
fn
visit_struct_field
(
&
mut
self
,
s
:
&
'a
StructField
)
{
SawStructField
.hash
(
self
.st
);
visit
::
walk_struct_field
(
self
,
s
)
}
fn
visit_explicit_self
(
&
mut
self
,
es
:
&
ExplicitSelf
)
{
fn
visit_explicit_self
(
&
mut
self
,
es
:
&
'a
ExplicitSelf
)
{
SawExplicitSelf
.hash
(
self
.st
);
visit
::
walk_explicit_self
(
self
,
es
)
}
fn
visit_path
(
&
mut
self
,
path
:
&
Path
,
_
:
ast
::
NodeId
)
{
fn
visit_path
(
&
mut
self
,
path
:
&
'a
Path
,
_
:
ast
::
NodeId
)
{
SawPath
.hash
(
self
.st
);
visit
::
walk_path
(
self
,
path
)
}
fn
visit_path_list_item
(
&
mut
self
,
prefix
:
&
Path
,
item
:
&
'v
PathListItem
)
{
fn
visit_path_list_item
(
&
mut
self
,
prefix
:
&
'a
Path
,
item
:
&
'a
PathListItem
)
{
SawPath
.hash
(
self
.st
);
visit
::
walk_path_list_item
(
self
,
prefix
,
item
)
}
fn
visit_block
(
&
mut
self
,
b
:
&
Block
)
{
fn
visit_block
(
&
mut
self
,
b
:
&
'a
Block
)
{
SawBlock
.hash
(
self
.st
);
visit
::
walk_block
(
self
,
b
)
}
fn
visit_pat
(
&
mut
self
,
p
:
&
Pat
)
{
fn
visit_pat
(
&
mut
self
,
p
:
&
'a
Pat
)
{
SawPat
.hash
(
self
.st
);
visit
::
walk_pat
(
self
,
p
)
}
fn
visit_local
(
&
mut
self
,
l
:
&
Local
)
{
fn
visit_local
(
&
mut
self
,
l
:
&
'a
Local
)
{
SawLocal
.hash
(
self
.st
);
visit
::
walk_local
(
self
,
l
)
}
fn
visit_arm
(
&
mut
self
,
a
:
&
Arm
)
{
fn
visit_arm
(
&
mut
self
,
a
:
&
'a
Arm
)
{
SawArm
.hash
(
self
.st
);
visit
::
walk_arm
(
self
,
a
)
}
}
...
...
src/librustc_privacy/lib.rs
浏览文件 @
98b046e1
...
...
@@ -35,7 +35,7 @@
use
std
::
mem
::
replace
;
use
rustc_front
::
hir
;
use
rustc_front
::
visit
::{
self
,
Visitor
};
use
rustc_front
::
intra
visit
::{
self
,
Visitor
};
use
rustc
::
middle
::
def
;
use
rustc
::
middle
::
def_id
::
DefId
;
...
...
@@ -63,12 +63,18 @@
/// The parent visitor, used to determine what's the parent of what (node-wise)
////////////////////////////////////////////////////////////////////////////////
struct
ParentVisitor
{
struct
ParentVisitor
<
'a
,
'tcx
:
'a
>
{
tcx
:
&
'a
ty
::
ctxt
<
'tcx
>
,
parents
:
NodeMap
<
ast
::
NodeId
>
,
curparent
:
ast
::
NodeId
,
}
impl
<
'v
>
Visitor
<
'v
>
for
ParentVisitor
{
impl
<
'a
,
'tcx
,
'v
>
Visitor
<
'v
>
for
ParentVisitor
<
'a
,
'tcx
>
{
/// We want to visit items in the context of their containing
/// module and so forth, so supply a crate for doing a deep walk.
fn
visit_nested_item
(
&
mut
self
,
item
:
hir
::
ItemId
)
{
self
.visit_item
(
self
.tcx.map
.expect_item
(
item
.id
))
}
fn
visit_item
(
&
mut
self
,
item
:
&
hir
::
Item
)
{
self
.parents
.insert
(
item
.id
,
self
.curparent
);
...
...
@@ -99,16 +105,16 @@ fn visit_item(&mut self, item: &hir::Item) {
_
=>
{}
}
visit
::
walk_item
(
self
,
item
);
intra
visit
::
walk_item
(
self
,
item
);
self
.curparent
=
prev
;
}
fn
visit_foreign_item
(
&
mut
self
,
a
:
&
hir
::
ForeignItem
)
{
self
.parents
.insert
(
a
.id
,
self
.curparent
);
visit
::
walk_foreign_item
(
self
,
a
);
intra
visit
::
walk_foreign_item
(
self
,
a
);
}
fn
visit_fn
(
&
mut
self
,
a
:
visit
::
FnKind
<
'v
>
,
b
:
&
'v
hir
::
FnDecl
,
fn
visit_fn
(
&
mut
self
,
a
:
intra
visit
::
FnKind
<
'v
>
,
b
:
&
'v
hir
::
FnDecl
,
c
:
&
'v
hir
::
Block
,
d
:
Span
,
id
:
ast
::
NodeId
)
{
// We already took care of some trait methods above, otherwise things
// like impl methods and pub trait methods are parented to the
...
...
@@ -116,7 +122,7 @@ fn visit_fn(&mut self, a: visit::FnKind<'v>, b: &'v hir::FnDecl,
if
!
self
.parents
.contains_key
(
&
id
)
{
self
.parents
.insert
(
id
,
self
.curparent
);
}
visit
::
walk_fn
(
self
,
a
,
b
,
c
,
d
);
intra
visit
::
walk_fn
(
self
,
a
,
b
,
c
,
d
);
}
fn
visit_impl_item
(
&
mut
self
,
ii
:
&
'v
hir
::
ImplItem
)
{
...
...
@@ -125,7 +131,7 @@ fn visit_impl_item(&mut self, ii: &'v hir::ImplItem) {
if
!
self
.parents
.contains_key
(
&
ii
.id
)
{
self
.parents
.insert
(
ii
.id
,
self
.curparent
);
}
visit
::
walk_impl_item
(
self
,
ii
);
intra
visit
::
walk_impl_item
(
self
,
ii
);
}
fn
visit_variant_data
(
&
mut
self
,
s
:
&
hir
::
VariantData
,
_
:
ast
::
Name
,
...
...
@@ -141,7 +147,7 @@ fn visit_variant_data(&mut self, s: &hir::VariantData, _: ast::Name,
for
field
in
s
.fields
()
{
self
.parents
.insert
(
field
.node.id
,
self
.curparent
);
}
visit
::
walk_struct_def
(
self
,
s
)
intra
visit
::
walk_struct_def
(
self
,
s
)
}
}
...
...
@@ -216,6 +222,11 @@ fn maybe_insert_id(&mut self, id: ast::NodeId) {
}
impl
<
'a
,
'tcx
,
'v
>
Visitor
<
'v
>
for
EmbargoVisitor
<
'a
,
'tcx
>
{
/// We want to visit items in the context of their containing
/// module and so forth, so supply a crate for doing a deep walk.
fn
visit_nested_item
(
&
mut
self
,
item
:
hir
::
ItemId
)
{
self
.visit_item
(
self
.tcx.map
.expect_item
(
item
.id
))
}
fn
visit_item
(
&
mut
self
,
item
:
&
hir
::
Item
)
{
let
orig_all_public
=
self
.prev_public
;
let
orig_all_exported
=
self
.prev_exported
;
...
...
@@ -362,7 +373,7 @@ fn visit_item(&mut self, item: &hir::Item) {
_
=>
{}
}
visit
::
walk_item
(
self
,
item
);
intra
visit
::
walk_item
(
self
,
item
);
self
.prev_public
=
orig_all_public
;
self
.prev_exported
=
orig_all_exported
;
...
...
@@ -375,7 +386,7 @@ fn visit_block(&mut self, b: &'v hir::Block) {
// Blocks can have exported and public items, for example impls, but they always
// start as non-public and non-exported regardless of publicity of a function,
// constant, type, field, etc. in which this block resides
visit
::
walk_block
(
self
,
b
);
intra
visit
::
walk_block
(
self
,
b
);
self
.prev_public
=
orig_all_public
;
self
.prev_exported
=
orig_all_exported
;
...
...
@@ -392,7 +403,7 @@ fn visit_mod(&mut self, m: &hir::Mod, _sp: Span, id: ast::NodeId) {
}
}
}
visit
::
walk_mod
(
self
,
m
)
intra
visit
::
walk_mod
(
self
,
m
)
}
fn
visit_macro_def
(
&
mut
self
,
md
:
&
'v
hir
::
MacroDef
)
{
...
...
@@ -895,9 +906,15 @@ fn check_method(&mut self, span: Span, method_def_id: DefId,
}
impl
<
'a
,
'tcx
,
'v
>
Visitor
<
'v
>
for
PrivacyVisitor
<
'a
,
'tcx
>
{
/// We want to visit items in the context of their containing
/// module and so forth, so supply a crate for doing a deep walk.
fn
visit_nested_item
(
&
mut
self
,
item
:
hir
::
ItemId
)
{
self
.visit_item
(
self
.tcx.map
.expect_item
(
item
.id
))
}
fn
visit_item
(
&
mut
self
,
item
:
&
hir
::
Item
)
{
let
orig_curitem
=
replace
(
&
mut
self
.curitem
,
item
.id
);
visit
::
walk_item
(
self
,
item
);
intra
visit
::
walk_item
(
self
,
item
);
self
.curitem
=
orig_curitem
;
}
...
...
@@ -958,7 +975,7 @@ fn visit_expr(&mut self, expr: &hir::Expr) {
_
=>
{}
}
visit
::
walk_expr
(
self
,
expr
);
intra
visit
::
walk_expr
(
self
,
expr
);
}
fn
visit_pat
(
&
mut
self
,
pattern
:
&
hir
::
Pat
)
{
...
...
@@ -1004,19 +1021,19 @@ fn visit_pat(&mut self, pattern: &hir::Pat) {
_
=>
{}
}
visit
::
walk_pat
(
self
,
pattern
);
intra
visit
::
walk_pat
(
self
,
pattern
);
}
fn
visit_foreign_item
(
&
mut
self
,
fi
:
&
hir
::
ForeignItem
)
{
self
.in_foreign
=
true
;
visit
::
walk_foreign_item
(
self
,
fi
);
intra
visit
::
walk_foreign_item
(
self
,
fi
);
self
.in_foreign
=
false
;
}
fn
visit_path
(
&
mut
self
,
path
:
&
hir
::
Path
,
id
:
ast
::
NodeId
)
{
if
!
path
.segments
.is_empty
()
{
self
.check_path
(
path
.span
,
id
,
path
.segments
.last
()
.unwrap
()
.identifier.name
);
visit
::
walk_path
(
self
,
path
);
intra
visit
::
walk_path
(
self
,
path
);
}
}
...
...
@@ -1029,7 +1046,7 @@ fn visit_path_list_item(&mut self, prefix: &hir::Path, item: &hir::PathListItem)
self
.tcx.sess
.bug
(
"`self` import in an import list with empty prefix"
);
};
self
.check_path
(
item
.span
,
item
.node
.id
(),
name
);
visit
::
walk_path_list_item
(
self
,
prefix
,
item
);
intra
visit
::
walk_path_list_item
(
self
,
prefix
,
item
);
}
}
...
...
@@ -1043,6 +1060,12 @@ struct SanePrivacyVisitor<'a, 'tcx: 'a> {
}
impl
<
'a
,
'tcx
,
'v
>
Visitor
<
'v
>
for
SanePrivacyVisitor
<
'a
,
'tcx
>
{
/// We want to visit items in the context of their containing
/// module and so forth, so supply a crate for doing a deep walk.
fn
visit_nested_item
(
&
mut
self
,
item
:
hir
::
ItemId
)
{
self
.visit_item
(
self
.tcx.map
.expect_item
(
item
.id
))
}
fn
visit_item
(
&
mut
self
,
item
:
&
hir
::
Item
)
{
self
.check_sane_privacy
(
item
);
if
self
.in_block
{
...
...
@@ -1054,13 +1077,13 @@ fn visit_item(&mut self, item: &hir::Item) {
// Modules turn privacy back on, otherwise we inherit
self
.in_block
=
if
let
hir
::
ItemMod
(
..
)
=
item
.node
{
false
}
else
{
orig_in_block
};
visit
::
walk_item
(
self
,
item
);
intra
visit
::
walk_item
(
self
,
item
);
self
.in_block
=
orig_in_block
;
}
fn
visit_block
(
&
mut
self
,
b
:
&
'v
hir
::
Block
)
{
let
orig_in_block
=
replace
(
&
mut
self
.in_block
,
true
);
visit
::
walk_block
(
self
,
b
);
intra
visit
::
walk_block
(
self
,
b
);
self
.in_block
=
orig_in_block
;
}
}
...
...
@@ -1220,7 +1243,7 @@ fn visit_ty(&mut self, ty: &hir::Ty) {
}
}
self
.at_outer_type
=
false
;
visit
::
walk_ty
(
self
,
ty
)
intra
visit
::
walk_ty
(
self
,
ty
)
}
// don't want to recurse into [, .. expr]
...
...
@@ -1228,6 +1251,12 @@ fn visit_expr(&mut self, _: &hir::Expr) {}
}
impl
<
'a
,
'tcx
,
'v
>
Visitor
<
'v
>
for
VisiblePrivateTypesVisitor
<
'a
,
'tcx
>
{
/// We want to visit items in the context of their containing
/// module and so forth, so supply a crate for doing a deep walk.
fn
visit_nested_item
(
&
mut
self
,
item
:
hir
::
ItemId
)
{
self
.visit_item
(
self
.tcx.map
.expect_item
(
item
.id
))
}
fn
visit_item
(
&
mut
self
,
item
:
&
hir
::
Item
)
{
match
item
.node
{
// contents of a private mod can be reexported, so we need
...
...
@@ -1313,7 +1342,7 @@ fn visit_item(&mut self, item: &hir::Item) {
not_private_trait
&&
trait_or_some_public_method
{
visit
::
walk_generics
(
self
,
g
);
intra
visit
::
walk_generics
(
self
,
g
);
match
*
trait_ref
{
None
=>
{
...
...
@@ -1328,10 +1357,10 @@ fn visit_item(&mut self, item: &hir::Item) {
hir
::
ImplItemKind
::
Method
(
..
)
if
self
.item_is_public
(
&
impl_item
.id
,
impl_item
.vis
)
=>
{
visit
::
walk_impl_item
(
self
,
impl_item
)
intra
visit
::
walk_impl_item
(
self
,
impl_item
)
}
hir
::
ImplItemKind
::
Type
(
..
)
=>
{
visit
::
walk_impl_item
(
self
,
impl_item
)
intra
visit
::
walk_impl_item
(
self
,
impl_item
)
}
_
=>
{}
}
...
...
@@ -1351,7 +1380,7 @@ fn visit_item(&mut self, item: &hir::Item) {
//
// Those in 2. are warned via walk_generics and this
// call here.
visit
::
walk_path
(
self
,
&
tr
.path
);
intra
visit
::
walk_path
(
self
,
&
tr
.path
);
// Those in 3. are warned with this call.
for
impl_item
in
impl_items
{
...
...
@@ -1370,21 +1399,21 @@ fn visit_item(&mut self, item: &hir::Item) {
hir
::
ImplItemKind
::
Const
(
..
)
=>
{
if
self
.item_is_public
(
&
impl_item
.id
,
impl_item
.vis
)
{
found_pub_static
=
true
;
visit
::
walk_impl_item
(
self
,
impl_item
);
intra
visit
::
walk_impl_item
(
self
,
impl_item
);
}
}
hir
::
ImplItemKind
::
Method
(
ref
sig
,
_
)
=>
{
if
sig
.explicit_self.node
==
hir
::
SelfStatic
&&
self
.item_is_public
(
&
impl_item
.id
,
impl_item
.vis
)
{
found_pub_static
=
true
;
visit
::
walk_impl_item
(
self
,
impl_item
);
intra
visit
::
walk_impl_item
(
self
,
impl_item
);
}
}
_
=>
{}
}
}
if
found_pub_static
{
visit
::
walk_generics
(
self
,
g
)
intra
visit
::
walk_generics
(
self
,
g
)
}
}
return
...
...
@@ -1407,7 +1436,7 @@ fn visit_item(&mut self, item: &hir::Item) {
// public signatures, i.e. things that we're interested in for
// this visitor.
debug!
(
"VisiblePrivateTypesVisitor entering item {:?}"
,
item
);
visit
::
walk_item
(
self
,
item
);
intra
visit
::
walk_item
(
self
,
item
);
}
fn
visit_generics
(
&
mut
self
,
generics
:
&
hir
::
Generics
)
{
...
...
@@ -1433,7 +1462,7 @@ fn visit_generics(&mut self, generics: &hir::Generics) {
fn
visit_foreign_item
(
&
mut
self
,
item
:
&
hir
::
ForeignItem
)
{
if
self
.exported_items
.contains
(
&
item
.id
)
{
visit
::
walk_foreign_item
(
self
,
item
)
intra
visit
::
walk_foreign_item
(
self
,
item
)
}
}
...
...
@@ -1446,13 +1475,13 @@ fn visit_ty(&mut self, t: &hir::Ty) {
"private type in exported type signature"
);
}
}
visit
::
walk_ty
(
self
,
t
)
intra
visit
::
walk_ty
(
self
,
t
)
}
fn
visit_variant
(
&
mut
self
,
v
:
&
hir
::
Variant
,
g
:
&
hir
::
Generics
,
item_id
:
ast
::
NodeId
)
{
if
self
.exported_items
.contains
(
&
v
.node.data
.id
())
{
self
.in_variant
=
true
;
visit
::
walk_variant
(
self
,
v
,
g
,
item_id
);
intra
visit
::
walk_variant
(
self
,
v
,
g
,
item_id
);
self
.in_variant
=
false
;
}
}
...
...
@@ -1462,7 +1491,7 @@ fn visit_struct_field(&mut self, s: &hir::StructField) {
hir
::
NamedField
(
_
,
vis
)
|
hir
::
UnnamedField
(
vis
)
=>
vis
};
if
vis
==
hir
::
Public
||
self
.in_variant
{
visit
::
walk_struct_field
(
self
,
s
);
intra
visit
::
walk_struct_field
(
self
,
s
);
}
}
...
...
@@ -1489,14 +1518,15 @@ pub fn check_crate(tcx: &ty::ctxt,
tcx
:
tcx
,
in_block
:
false
,
};
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
intra
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
// Figure out who everyone's parent is
let
mut
visitor
=
ParentVisitor
{
tcx
:
tcx
,
parents
:
NodeMap
(),
curparent
:
ast
::
DUMMY_NODE_ID
,
};
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
intra
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
// Use the parent map to check the privacy of everything
let
mut
visitor
=
PrivacyVisitor
{
...
...
@@ -1506,7 +1536,7 @@ pub fn check_crate(tcx: &ty::ctxt,
parents
:
visitor
.parents
,
external_exports
:
external_exports
,
};
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
intra
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
tcx
.sess
.abort_if_errors
();
...
...
@@ -1524,7 +1554,7 @@ pub fn check_crate(tcx: &ty::ctxt,
visitor
.public_items
.insert
(
ast
::
CRATE_NODE_ID
);
loop
{
let
before
=
(
visitor
.exported_items
.len
(),
visitor
.public_items
.len
());
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
intra
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
let
after
=
(
visitor
.exported_items
.len
(),
visitor
.public_items
.len
());
if
after
==
before
{
break
...
...
@@ -1540,7 +1570,7 @@ pub fn check_crate(tcx: &ty::ctxt,
public_items
:
&
public_items
,
in_variant
:
false
,
};
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
intra
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
}
return
(
exported_items
,
public_items
);
}
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
98b046e1
...
...
@@ -52,7 +52,7 @@
use
rustc_front
::
hir
::
UnnamedField
;
use
rustc_front
::
hir
::{
Variant
,
ViewPathGlob
,
ViewPathList
,
ViewPathSimple
};
use
rustc_front
::
hir
::
Visibility
;
use
rustc_front
::
visit
::{
self
,
Visitor
};
use
rustc_front
::
intra
visit
::{
self
,
Visitor
};
use
std
::
mem
::
replace
;
use
std
::
ops
::{
Deref
,
DerefMut
};
...
...
@@ -111,7 +111,7 @@ fn build_reduced_graph(self, krate: &hir::Crate) {
builder
:
self
,
parent
:
parent
,
};
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
intra
visit
::
walk_crate
(
&
mut
visitor
,
krate
);
}
/// Adds a new child item to the module definition of the parent node and
...
...
@@ -1051,10 +1051,14 @@ struct BuildReducedGraphVisitor<'a, 'b: 'a, 'tcx: 'b> {
}
impl
<
'a
,
'b
,
'v
,
'tcx
>
Visitor
<
'v
>
for
BuildReducedGraphVisitor
<
'a
,
'b
,
'tcx
>
{
fn
visit_nested_item
(
&
mut
self
,
item
:
hir
::
ItemId
)
{
self
.visit_item
(
self
.builder.resolver.ast_map
.expect_item
(
item
.id
))
}
fn
visit_item
(
&
mut
self
,
item
:
&
Item
)
{
let
p
=
self
.builder
.build_reduced_graph_for_item
(
item
,
&
self
.parent
);
let
old_parent
=
replace
(
&
mut
self
.parent
,
p
);
visit
::
walk_item
(
self
,
item
);
intra
visit
::
walk_item
(
self
,
item
);
self
.parent
=
old_parent
;
}
...
...
@@ -1065,7 +1069,7 @@ fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
fn
visit_block
(
&
mut
self
,
block
:
&
Block
)
{
let
np
=
self
.builder
.build_reduced_graph_for_block
(
block
,
&
self
.parent
);
let
old_parent
=
replace
(
&
mut
self
.parent
,
np
);
visit
::
walk_block
(
self
,
block
);
intra
visit
::
walk_block
(
self
,
block
);
self
.parent
=
old_parent
;
}
}
...
...
src/librustc_resolve/lib.rs
浏览文件 @
98b046e1
...
...
@@ -76,7 +76,7 @@
use
syntax
::
ptr
::
P
;
use
syntax
::
codemap
::{
self
,
Span
,
Pos
};
use
rustc_front
::
visit
::{
self
,
FnKind
,
Visitor
};
use
rustc_front
::
intra
visit
::{
self
,
FnKind
,
Visitor
};
use
rustc_front
::
hir
;
use
rustc_front
::
hir
::{
Arm
,
BindByRef
,
BindByValue
,
BindingMode
,
Block
};
use
rustc_front
::
hir
::
Crate
;
...
...
@@ -541,6 +541,9 @@ enum NameDefinition {
}
impl
<
'a
,
'v
,
'tcx
>
Visitor
<
'v
>
for
Resolver
<
'a
,
'tcx
>
{
fn
visit_nested_item
(
&
mut
self
,
item
:
hir
::
ItemId
)
{
self
.visit_item
(
self
.ast_map
.expect_item
(
item
.id
))
}
fn
visit_item
(
&
mut
self
,
item
:
&
Item
)
{
execute_callback!
(
hir_map
::
Node
::
NodeItem
(
item
),
self
);
self
.resolve_item
(
item
);
...
...
@@ -573,7 +576,7 @@ fn visit_poly_trait_ref(&mut self, tref: &hir::PolyTraitRef, m: &hir::TraitBound
// error already reported
}
}
visit
::
walk_poly_trait_ref
(
self
,
tref
,
m
);
intra
visit
::
walk_poly_trait_ref
(
self
,
tref
,
m
);
}
fn
visit_variant
(
&
mut
self
,
variant
:
&
hir
::
Variant
,
...
...
@@ -583,11 +586,11 @@ fn visit_variant(&mut self,
if
let
Some
(
ref
dis_expr
)
=
variant
.node.disr_expr
{
// resolve the discriminator expr as a constant
self
.with_constant_rib
(|
this
|
{
this
.visit_expr
(
&**
dis_expr
);
this
.visit_expr
(
dis_expr
);
});
}
// `visit::walk_variant` without the discriminant expression.
// `
intra
visit::walk_variant` without the discriminant expression.
self
.visit_variant_data
(
&
variant
.node.data
,
variant
.node.name
,
generics
,
...
...
@@ -603,7 +606,7 @@ fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem) {
ForeignItemStatic
(
..
)
=>
NoTypeParameters
,
};
self
.with_type_parameter_rib
(
type_parameters
,
|
this
|
{
visit
::
walk_foreign_item
(
this
,
foreign_item
);
intra
visit
::
walk_foreign_item
(
this
,
foreign_item
);
});
}
fn
visit_fn
(
&
mut
self
,
...
...
@@ -2047,7 +2050,7 @@ fn search_label(&self, name: Name) -> Option<DefLike> {
fn
resolve_crate
(
&
mut
self
,
krate
:
&
hir
::
Crate
)
{
debug!
(
"(resolving crate) starting"
);
visit
::
walk_crate
(
self
,
krate
);
intra
visit
::
walk_crate
(
self
,
krate
);
}
fn
check_if_primitive_type_name
(
&
self
,
name
:
Name
,
span
:
Span
)
{
...
...
@@ -2071,11 +2074,11 @@ fn resolve_item(&mut self, item: &Item) {
self
.check_if_primitive_type_name
(
name
,
item
.span
);
self
.with_type_parameter_rib
(
HasTypeParameters
(
generics
,
TypeSpace
,
ItemRibKind
),
|
this
|
visit
::
walk_item
(
this
,
item
));
|
this
|
intra
visit
::
walk_item
(
this
,
item
));
}
ItemFn
(
_
,
_
,
_
,
_
,
ref
generics
,
_
)
=>
{
self
.with_type_parameter_rib
(
HasTypeParameters
(
generics
,
FnSpace
,
ItemRibKind
),
|
this
|
visit
::
walk_item
(
this
,
item
));
|
this
|
intra
visit
::
walk_item
(
this
,
item
));
}
ItemDefaultImpl
(
_
,
ref
trait_ref
)
=>
{
...
...
@@ -2110,10 +2113,10 @@ fn resolve_item(&mut self, item: &Item) {
// expression in a provided default.
if
default
.is_some
()
{
this
.with_constant_rib
(|
this
|
{
visit
::
walk_trait_item
(
this
,
trait_item
)
intra
visit
::
walk_trait_item
(
this
,
trait_item
)
});
}
else
{
visit
::
walk_trait_item
(
this
,
trait_item
)
intra
visit
::
walk_trait_item
(
this
,
trait_item
)
}
}
hir
::
MethodTraitItem
(
ref
sig
,
_
)
=>
{
...
...
@@ -2122,14 +2125,14 @@ fn resolve_item(&mut self, item: &Item) {
FnSpace
,
MethodRibKind
);
this
.with_type_parameter_rib
(
type_parameters
,
|
this
|
{
visit
::
walk_trait_item
(
this
,
trait_item
)
intra
visit
::
walk_trait_item
(
this
,
trait_item
)
});
}
hir
::
TypeTraitItem
(
..
)
=>
{
this
.check_if_primitive_type_name
(
trait_item
.name
,
trait_item
.span
);
this
.with_type_parameter_rib
(
NoTypeParameters
,
|
this
|
{
visit
::
walk_trait_item
(
this
,
trait_item
)
intra
visit
::
walk_trait_item
(
this
,
trait_item
)
});
}
};
...
...
@@ -2140,13 +2143,13 @@ fn resolve_item(&mut self, item: &Item) {
ItemMod
(
_
)
|
ItemForeignMod
(
_
)
=>
{
self
.with_scope
(
Some
(
name
),
|
this
|
{
visit
::
walk_item
(
this
,
item
);
intra
visit
::
walk_item
(
this
,
item
);
});
}
ItemConst
(
..
)
|
ItemStatic
(
..
)
=>
{
self
.with_constant_rib
(|
this
|
{
visit
::
walk_item
(
this
,
item
);
intra
visit
::
walk_item
(
this
,
item
);
});
}
...
...
@@ -2283,10 +2286,10 @@ fn resolve_function(&mut self, rib_kind: RibKind, declaration: &FnDecl, block: &
debug!
(
"(resolving function) recorded argument"
);
}
visit
::
walk_fn_ret_ty
(
self
,
&
declaration
.output
);
intra
visit
::
walk_fn_ret_ty
(
self
,
&
declaration
.output
);
// Resolve the function body.
self
.visit_block
(
&*
block
);
self
.visit_block
(
block
);
debug!
(
"(resolving function) leaving function"
);
...
...
@@ -2347,7 +2350,7 @@ fn resolve_generics(&mut self, generics: &Generics) {
}
}
}
visit
::
walk_generics
(
self
,
generics
);
intra
visit
::
walk_generics
(
self
,
generics
);
}
fn
with_current_self_type
<
T
,
F
>
(
&
mut
self
,
self_type
:
&
Ty
,
f
:
F
)
->
T
...
...
@@ -2374,7 +2377,7 @@ fn with_optional_trait_ref<T, F>(&mut self, opt_trait_ref: Option<&TraitRef>, f:
new_val
=
Some
((
path_res
.base_def
.def_id
(),
trait_ref
.clone
()));
new_id
=
Some
(
path_res
.base_def
.def_id
());
}
visit
::
walk_trait_ref
(
self
,
trait_ref
);
intra
visit
::
walk_trait_ref
(
self
,
trait_ref
);
}
let
original_trait_ref
=
replace
(
&
mut
self
.current_trait_ref
,
new_val
);
let
result
=
f
(
self
,
new_id
);
...
...
@@ -2427,7 +2430,7 @@ fn resolve_implementation(&mut self,
impl_item
.span
,
|
n
,
s
|
ResolutionError
::
ConstNotMemberOfTrait
(
n
,
s
));
this
.with_constant_rib
(|
this
|
{
visit
::
walk_impl_item
(
this
,
impl_item
);
intra
visit
::
walk_impl_item
(
this
,
impl_item
);
});
}
hir
::
ImplItemKind
::
Method
(
ref
sig
,
_
)
=>
{
...
...
@@ -2444,7 +2447,7 @@ fn resolve_implementation(&mut self,
FnSpace
,
MethodRibKind
);
this
.with_type_parameter_rib
(
type_parameters
,
|
this
|
{
visit
::
walk_impl_item
(
this
,
impl_item
);
intra
visit
::
walk_impl_item
(
this
,
impl_item
);
});
}
hir
::
ImplItemKind
::
Type
(
ref
ty
)
=>
{
...
...
@@ -2583,7 +2586,8 @@ fn resolve_block(&mut self, block: &Block) {
let
mut
found_non_item
=
false
;
for
statement
in
&
block
.stmts
{
if
let
hir
::
StmtDecl
(
ref
declaration
,
_
)
=
statement
.node
{
if
let
hir
::
DeclItem
(
ref
i
)
=
declaration
.node
{
if
let
hir
::
DeclItem
(
i
)
=
declaration
.node
{
let
i
=
self
.ast_map
.expect_item
(
i
.id
);
match
i
.node
{
ItemExternCrate
(
_
)
|
ItemUse
(
_
)
if
found_non_item
=>
{
span_err!
(
self
.session
,
...
...
@@ -2602,7 +2606,7 @@ fn resolve_block(&mut self, block: &Block) {
}
// Descend into the block.
visit
::
walk_block
(
self
,
block
);
intra
visit
::
walk_block
(
self
,
block
);
// Move back up.
if
!
self
.resolved
{
...
...
@@ -2623,7 +2627,7 @@ fn resolve_type(&mut self, ty: &Ty) {
// `<T>::a::b::c` is resolved by typeck alone.
TypecheckRequired
=>
{
// Resolve embedded types.
visit
::
walk_ty
(
self
,
ty
);
intra
visit
::
walk_ty
(
self
,
ty
);
return
;
}
ResolveAttempt
(
resolution
)
=>
resolution
,
...
...
@@ -2674,7 +2678,7 @@ fn resolve_type(&mut self, ty: &Ty) {
_
=>
{}
}
// Resolve embedded types.
visit
::
walk_ty
(
self
,
ty
);
intra
visit
::
walk_ty
(
self
,
ty
);
}
fn
resolve_pattern
(
&
mut
self
,
...
...
@@ -2862,7 +2866,7 @@ fn resolve_pattern(&mut self,
&
path
.segments
.last
()
.unwrap
()
.identifier.name
.as_str
())
);
}
visit
::
walk_path
(
self
,
path
);
intra
visit
::
walk_path
(
self
,
path
);
}
PatQPath
(
ref
qself
,
ref
path
)
=>
{
...
...
@@ -2883,7 +2887,7 @@ fn resolve_pattern(&mut self,
.name
;
let
traits
=
self
.get_traits_containing_item
(
const_name
);
self
.trait_map
.insert
(
pattern
.id
,
traits
);
visit
::
walk_pat
(
self
,
pattern
);
intra
visit
::
walk_pat
(
self
,
pattern
);
return
true
;
}
ResolveAttempt
(
resolution
)
=>
resolution
,
...
...
@@ -2915,7 +2919,7 @@ fn resolve_pattern(&mut self,
.name
.as_str
()));
}
visit
::
walk_pat
(
self
,
pattern
);
intra
visit
::
walk_pat
(
self
,
pattern
);
}
PatStruct
(
ref
path
,
_
,
_
)
=>
{
...
...
@@ -2933,11 +2937,11 @@ fn resolve_pattern(&mut self,
);
}
}
visit
::
walk_path
(
self
,
path
);
intra
visit
::
walk_path
(
self
,
path
);
}
PatLit
(
_
)
|
PatRange
(
..
)
=>
{
visit
::
walk_pat
(
self
,
pattern
);
intra
visit
::
walk_pat
(
self
,
pattern
);
}
_
=>
{
...
...
@@ -3665,7 +3669,7 @@ fn resolve_expr(&mut self, expr: &Expr) {
let
method_name
=
path
.segments
.last
()
.unwrap
()
.identifier.name
;
let
traits
=
self
.get_traits_containing_item
(
method_name
);
self
.trait_map
.insert
(
expr
.id
,
traits
);
visit
::
walk_expr
(
self
,
expr
);
intra
visit
::
walk_expr
(
self
,
expr
);
return
;
}
ResolveAttempt
(
resolution
)
=>
resolution
,
...
...
@@ -3777,7 +3781,7 @@ fn resolve_expr(&mut self, expr: &Expr) {
}
}
visit
::
walk_expr
(
self
,
expr
);
intra
visit
::
walk_expr
(
self
,
expr
);
}
ExprStruct
(
ref
path
,
_
,
_
)
=>
{
...
...
@@ -3797,7 +3801,7 @@ fn resolve_expr(&mut self, expr: &Expr) {
}
}
visit
::
walk_expr
(
self
,
expr
);
intra
visit
::
walk_expr
(
self
,
expr
);
}
ExprLoop
(
_
,
Some
(
label
))
|
ExprWhile
(
_
,
_
,
Some
(
label
))
=>
{
...
...
@@ -3810,7 +3814,7 @@ fn resolve_expr(&mut self, expr: &Expr) {
rib
.bindings
.insert
(
renamed
,
def_like
);
}
visit
::
walk_expr
(
this
,
expr
);
intra
visit
::
walk_expr
(
this
,
expr
);
})
}
...
...
@@ -3838,7 +3842,7 @@ fn resolve_expr(&mut self, expr: &Expr) {
}
_
=>
{
visit
::
walk_expr
(
self
,
expr
);
intra
visit
::
walk_expr
(
self
,
expr
);
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录