Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
cfb63d54
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,发现更多精彩内容 >>
提交
cfb63d54
编写于
12月 23, 2014
作者:
E
Eduard Burtescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: fix fallout of merging ast::ViewItem into ast::Item.
上级
e389ab18
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
99 addition
and
132 deletion
+99
-132
src/librustc/lint/builtin.rs
src/librustc/lint/builtin.rs
+16
-21
src/librustc/lint/context.rs
src/librustc/lint/context.rs
+0
-8
src/librustc/lint/mod.rs
src/librustc/lint/mod.rs
+0
-1
src/librustc/metadata/creader.rs
src/librustc/metadata/creader.rs
+25
-31
src/librustc/metadata/encoder.rs
src/librustc/metadata/encoder.rs
+2
-2
src/librustc/middle/astencode.rs
src/librustc/middle/astencode.rs
+0
-2
src/librustc/middle/reachable.rs
src/librustc/middle/reachable.rs
+1
-0
src/librustc/middle/resolve_lifetime.rs
src/librustc/middle/resolve_lifetime.rs
+2
-0
src/librustc/plugin/load.rs
src/librustc/plugin/load.rs
+16
-8
src/librustc_privacy/lib.rs
src/librustc_privacy/lib.rs
+37
-59
未找到文件。
src/librustc/lint/builtin.rs
浏览文件 @
cfb63d54
...
...
@@ -1202,17 +1202,17 @@ fn get_lints(&self) -> LintArray {
lint_array!
(
UNUSED_IMPORT_BRACES
)
}
fn
check_
view_item
(
&
mut
self
,
cx
:
&
Context
,
view_item
:
&
ast
::
View
Item
)
{
match
view_
item
.node
{
ast
::
View
ItemUse
(
ref
view_path
)
=>
{
fn
check_
item
(
&
mut
self
,
cx
:
&
Context
,
item
:
&
ast
::
Item
)
{
match
item
.node
{
ast
::
ItemUse
(
ref
view_path
)
=>
{
match
view_path
.node
{
ast
::
ViewPathList
(
_
,
ref
items
,
_
)
=>
{
ast
::
ViewPathList
(
_
,
ref
items
)
=>
{
if
items
.len
()
==
1
{
match
items
[
0
]
.node
{
ast
::
PathListIdent
{
ref
name
,
..
}
=>
{
let
m
=
format!
(
"braces around {} is unnecessary"
,
token
::
get_ident
(
*
name
)
.get
());
cx
.span_lint
(
UNUSED_IMPORT_BRACES
,
view_
item
.span
,
cx
.span_lint
(
UNUSED_IMPORT_BRACES
,
item
.span
,
&
m
[]);
},
_
=>
()
...
...
@@ -1709,22 +1709,6 @@ fn check_crate(&mut self, _: &Context, c: &ast::Crate) {
}
}
fn
check_view_item
(
&
mut
self
,
cx
:
&
Context
,
item
:
&
ast
::
ViewItem
)
{
// compiler-generated `extern crate` statements have a dummy span.
if
item
.span
==
DUMMY_SP
{
return
}
let
id
=
match
item
.node
{
ast
::
ViewItemExternCrate
(
_
,
_
,
id
)
=>
id
,
ast
::
ViewItemUse
(
..
)
=>
return
,
};
let
cnum
=
match
cx
.tcx.sess.cstore
.find_extern_mod_stmt_cnum
(
id
)
{
Some
(
cnum
)
=>
cnum
,
None
=>
return
,
};
let
id
=
ast
::
DefId
{
krate
:
cnum
,
node
:
ast
::
CRATE_NODE_ID
};
self
.lint
(
cx
,
id
,
item
.span
);
}
fn
check_expr
(
&
mut
self
,
cx
:
&
Context
,
e
:
&
ast
::
Expr
)
{
if
self
.is_internal
(
cx
,
e
.span
)
{
return
;
}
...
...
@@ -1776,6 +1760,17 @@ fn check_item(&mut self, cx: &Context, item: &ast::Item) {
if
self
.is_internal
(
cx
,
item
.span
)
{
return
}
match
item
.node
{
ast
::
ItemExternCrate
(
_
)
=>
{
// compiler-generated `extern crate` items have a dummy span.
if
item
.span
==
DUMMY_SP
{
return
}
let
cnum
=
match
cx
.tcx.sess.cstore
.find_extern_mod_stmt_cnum
(
item
.id
)
{
Some
(
cnum
)
=>
cnum
,
None
=>
return
,
};
let
id
=
ast
::
DefId
{
krate
:
cnum
,
node
:
ast
::
CRATE_NODE_ID
};
self
.lint
(
cx
,
id
,
item
.span
);
}
ast
::
ItemTrait
(
_
,
_
,
ref
supertraits
,
_
)
=>
{
for
t
in
supertraits
.iter
()
{
if
let
ast
::
TraitTyParamBound
(
ref
t
,
_
)
=
*
t
{
...
...
src/librustc/lint/context.rs
浏览文件 @
cfb63d54
...
...
@@ -603,14 +603,6 @@ fn visit_foreign_item(&mut self, it: &ast::ForeignItem) {
})
}
fn
visit_view_item
(
&
mut
self
,
i
:
&
ast
::
ViewItem
)
{
self
.with_lint_attrs
(
&
i
.attrs
[],
|
cx
|
{
run_lints!
(
cx
,
check_view_item
,
i
);
cx
.visit_ids
(|
v
|
v
.visit_view_item
(
i
));
visit
::
walk_view_item
(
cx
,
i
);
})
}
fn
visit_pat
(
&
mut
self
,
p
:
&
ast
::
Pat
)
{
run_lints!
(
self
,
check_pat
,
p
);
visit
::
walk_pat
(
self
,
p
);
...
...
src/librustc/lint/mod.rs
浏览文件 @
cfb63d54
...
...
@@ -128,7 +128,6 @@ pub trait LintPass {
fn
check_crate
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Crate
)
{
}
fn
check_ident
(
&
mut
self
,
_
:
&
Context
,
_
:
Span
,
_
:
ast
::
Ident
)
{
}
fn
check_mod
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Mod
,
_
:
Span
,
_
:
ast
::
NodeId
)
{
}
fn
check_view_item
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
ViewItem
)
{
}
fn
check_foreign_item
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
ForeignItem
)
{
}
fn
check_item
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Item
)
{
}
fn
check_local
(
&
mut
self
,
_
:
&
Context
,
_
:
&
ast
::
Local
)
{
}
...
...
src/librustc/metadata/creader.rs
浏览文件 @
cfb63d54
...
...
@@ -40,10 +40,6 @@ pub struct CrateReader<'a> {
}
impl
<
'a
,
'v
>
visit
::
Visitor
<
'v
>
for
CrateReader
<
'a
>
{
fn
visit_view_item
(
&
mut
self
,
a
:
&
ast
::
ViewItem
)
{
self
.process_view_item
(
a
);
visit
::
walk_view_item
(
self
,
a
);
}
fn
visit_item
(
&
mut
self
,
a
:
&
ast
::
Item
)
{
self
.process_item
(
a
);
visit
::
walk_item
(
self
,
a
);
...
...
@@ -64,9 +60,8 @@ fn dump_crates(cstore: &CStore) {
})
}
fn
should_link
(
i
:
&
ast
::
View
Item
)
->
bool
{
fn
should_link
(
i
:
&
ast
::
Item
)
->
bool
{
!
attr
::
contains_name
(
&
i
.attrs
[],
"no_link"
)
}
struct
CrateInfo
{
...
...
@@ -181,29 +176,10 @@ fn process_crate(&self, c: &ast::Crate) {
}
}
fn
process_view_item
(
&
mut
self
,
i
:
&
ast
::
ViewItem
)
{
if
!
should_link
(
i
)
{
return
;
}
match
self
.extract_crate_info
(
i
)
{
Some
(
info
)
=>
{
let
(
cnum
,
_
,
_
)
=
self
.resolve_crate
(
&
None
,
&
info
.ident
[],
&
info
.name
[],
None
,
i
.span
,
PathKind
::
Crate
);
self
.sess.cstore
.add_extern_mod_stmt_cnum
(
info
.id
,
cnum
);
}
None
=>
()
}
}
fn
extract_crate_info
(
&
self
,
i
:
&
ast
::
ViewItem
)
->
Option
<
CrateInfo
>
{
fn
extract_crate_info
(
&
self
,
i
:
&
ast
::
Item
)
->
Option
<
CrateInfo
>
{
match
i
.node
{
ast
::
ViewItemExternCrate
(
ident
,
ref
path_opt
,
id
)
=>
{
let
ident
=
token
::
get_ident
(
ident
);
ast
::
ItemExternCrate
(
ref
path_opt
)
=>
{
let
ident
=
token
::
get_ident
(
i
.i
dent
);
debug!
(
"resolving extern crate stmt. ident: {} path_opt: {:?}"
,
ident
,
path_opt
);
let
name
=
match
*
path_opt
{
...
...
@@ -218,7 +194,7 @@ fn extract_crate_info(&self, i: &ast::ViewItem) -> Option<CrateInfo> {
Some
(
CrateInfo
{
ident
:
ident
.get
()
.to_string
(),
name
:
name
,
id
:
id
,
id
:
i
.i
d
,
should_link
:
should_link
(
i
),
})
}
...
...
@@ -226,8 +202,26 @@ fn extract_crate_info(&self, i: &ast::ViewItem) -> Option<CrateInfo> {
}
}
fn
process_item
(
&
self
,
i
:
&
ast
::
Item
)
{
fn
process_item
(
&
mut
self
,
i
:
&
ast
::
Item
)
{
match
i
.node
{
ast
::
ItemExternCrate
(
_
)
=>
{
if
!
should_link
(
i
)
{
return
;
}
match
self
.extract_crate_info
(
i
)
{
Some
(
info
)
=>
{
let
(
cnum
,
_
,
_
)
=
self
.resolve_crate
(
&
None
,
&
info
.ident
[],
&
info
.name
[],
None
,
i
.span
,
PathKind
::
Crate
);
self
.sess.cstore
.add_extern_mod_stmt_cnum
(
info
.id
,
cnum
);
}
None
=>
()
}
}
ast
::
ItemForeignMod
(
ref
fm
)
=>
{
if
fm
.abi
==
abi
::
Rust
||
fm
.abi
==
abi
::
RustIntrinsic
{
return
;
...
...
@@ -533,7 +527,7 @@ pub fn read_plugin_metadata<'b>(&'b mut self,
#[derive(Copy)]
pub
enum
CrateOrString
<
'a
>
{
Krate
(
&
'a
ast
::
View
Item
),
Krate
(
&
'a
ast
::
Item
),
Str
(
&
'a
str
)
}
...
...
src/librustc/metadata/encoder.rs
浏览文件 @
cfb63d54
...
...
@@ -1456,8 +1456,8 @@ fn add_to_index(item: &ast::Item, rbml_w: &Encoder,
rbml_w
.end_tag
();
}
}
ast
::
ItemMac
(
..
)
=>
{
//
macros
are encoded separately
ast
::
Item
ExternCrate
(
_
)
|
ast
::
ItemUse
(
_
)
|
ast
::
Item
Mac
(
..
)
=>
{
//
these
are encoded separately
}
}
}
...
...
src/librustc/middle/astencode.rs
浏览文件 @
cfb63d54
...
...
@@ -332,8 +332,6 @@ fn fold_block(&mut self, blk: P<ast::Block>) -> P<ast::Block> {
}
})
.collect
();
let
blk_sans_items
=
P
(
ast
::
Block
{
view_items
:
Vec
::
new
(),
// I don't know if we need the view_items
// here, but it doesn't break tests!
stmts
:
stmts_sans_items
,
expr
:
expr
,
id
:
id
,
...
...
src/librustc/middle/reachable.rs
浏览文件 @
cfb63d54
...
...
@@ -297,6 +297,7 @@ fn propagate_node(&mut self, node: &ast_map::Node,
// These are normal, nothing reachable about these
// inherently and their children are already in the
// worklist, as determined by the privacy pass
ast
::
ItemExternCrate
(
_
)
|
ast
::
ItemUse
(
_
)
|
ast
::
ItemTy
(
..
)
|
ast
::
ItemStatic
(
_
,
_
,
_
)
|
ast
::
ItemMod
(
..
)
|
ast
::
ItemForeignMod
(
..
)
|
ast
::
ItemImpl
(
..
)
|
ast
::
ItemTrait
(
..
)
|
...
...
src/librustc/middle/resolve_lifetime.rs
浏览文件 @
cfb63d54
...
...
@@ -94,6 +94,8 @@ fn visit_item(&mut self, item: &ast::Item) {
// Fn lifetimes get added in visit_fn below:
visit
::
walk_item
(
this
,
item
);
}
ast
::
ItemExternCrate
(
_
)
|
ast
::
ItemUse
(
_
)
|
ast
::
ItemMod
(
..
)
|
ast
::
ItemMac
(
..
)
|
ast
::
ItemForeignMod
(
..
)
|
...
...
src/librustc/plugin/load.rs
浏览文件 @
cfb63d54
...
...
@@ -73,8 +73,10 @@ pub fn load_plugins(sess: &Session, krate: &ast::Crate,
// We need to error on `#[macro_use] extern crate` when it isn't at the
// crate root, because `$crate` won't work properly. Identify these by
// spans, because the crate map isn't set up yet.
for
vi
in
krate
.module.view_items
.iter
()
{
loader
.span_whitelist
.insert
(
vi
.span
);
for
item
in
krate
.module.items
.iter
()
{
if
let
ast
::
ItemExternCrate
(
_
)
=
item
.node
{
loader
.span_whitelist
.insert
(
item
.span
);
}
}
visit
::
walk_crate
(
&
mut
loader
,
krate
);
...
...
@@ -91,18 +93,21 @@ pub fn load_plugins(sess: &Session, krate: &ast::Crate,
// note that macros aren't expanded yet, and therefore macros can't add plugins.
impl
<
'a
,
'v
>
Visitor
<
'v
>
for
PluginLoader
<
'a
>
{
fn
visit_
view_item
(
&
mut
self
,
vi
:
&
ast
::
View
Item
)
{
fn
visit_
item
(
&
mut
self
,
item
:
&
ast
::
Item
)
{
// We're only interested in `extern crate`.
match
vi
.node
{
ast
::
ViewItemExternCrate
(
..
)
=>
(),
_
=>
return
,
match
item
.node
{
ast
::
ItemExternCrate
(
_
)
=>
{}
_
=>
{
visit
::
walk_item
(
self
,
item
);
return
;
}
}
// Parse the attributes relating to macro / plugin loading.
let
mut
plugin_attr
=
None
;
let
mut
macro_selection
=
Some
(
HashSet
::
new
());
// None => load all
let
mut
reexport
=
HashSet
::
new
();
for
attr
in
vi
.attrs
.iter
()
{
for
attr
in
item
.attrs
.iter
()
{
let
mut
used
=
true
;
match
attr
.name
()
.get
()
{
"phase"
=>
{
...
...
@@ -155,7 +160,10 @@ fn visit_view_item(&mut self, vi: &ast::ViewItem) {
}
}
self
.load_plugin
(
CrateOrString
::
Krate
(
vi
),
plugin_attr
,
macro_selection
,
Some
(
reexport
))
self
.load_plugin
(
CrateOrString
::
Krate
(
item
),
plugin_attr
,
macro_selection
,
Some
(
reexport
))
}
fn
visit_mac
(
&
mut
self
,
_
:
&
ast
::
Mac
)
{
...
...
src/librustc_privacy/lib.rs
浏览文件 @
cfb63d54
...
...
@@ -830,6 +830,38 @@ fn check_method(&mut self, span: Span, origin: &MethodOrigin,
impl
<
'a
,
'tcx
,
'v
>
Visitor
<
'v
>
for
PrivacyVisitor
<
'a
,
'tcx
>
{
fn
visit_item
(
&
mut
self
,
item
:
&
ast
::
Item
)
{
match
item
.node
{
ast
::
ItemUse
(
ref
vpath
)
=>
{
match
vpath
.node
{
ast
::
ViewPathSimple
(
..
)
|
ast
::
ViewPathGlob
(
..
)
=>
{}
ast
::
ViewPathList
(
ref
prefix
,
ref
list
)
=>
{
for
pid
in
list
.iter
()
{
match
pid
.node
{
ast
::
PathListIdent
{
id
,
name
}
=>
{
debug!
(
"privacy - ident item {}"
,
id
);
let
seg
=
ast
::
PathSegment
{
identifier
:
name
,
parameters
:
ast
::
PathParameters
::
none
(),
};
let
segs
=
vec!
[
seg
];
let
path
=
ast
::
Path
{
global
:
false
,
span
:
pid
.span
,
segments
:
segs
,
};
self
.check_path
(
pid
.span
,
id
,
&
path
);
}
ast
::
PathListMod
{
id
}
=>
{
debug!
(
"privacy - mod item {}"
,
id
);
self
.check_path
(
pid
.span
,
id
,
prefix
);
}
}
}
}
}
}
_
=>
{}
}
let
orig_curitem
=
replace
(
&
mut
self
.curitem
,
item
.id
);
visit
::
walk_item
(
self
,
item
);
self
.curitem
=
orig_curitem
;
...
...
@@ -926,42 +958,6 @@ struct type?!"),
visit
::
walk_expr
(
self
,
expr
);
}
fn
visit_view_item
(
&
mut
self
,
a
:
&
ast
::
ViewItem
)
{
match
a
.node
{
ast
::
ViewItemExternCrate
(
..
)
=>
{}
ast
::
ViewItemUse
(
ref
vpath
)
=>
{
match
vpath
.node
{
ast
::
ViewPathSimple
(
..
)
|
ast
::
ViewPathGlob
(
..
)
=>
{}
ast
::
ViewPathList
(
ref
prefix
,
ref
list
,
_
)
=>
{
for
pid
in
list
.iter
()
{
match
pid
.node
{
ast
::
PathListIdent
{
id
,
name
}
=>
{
debug!
(
"privacy - ident item {}"
,
id
);
let
seg
=
ast
::
PathSegment
{
identifier
:
name
,
parameters
:
ast
::
PathParameters
::
none
(),
};
let
segs
=
vec!
[
seg
];
let
path
=
ast
::
Path
{
global
:
false
,
span
:
pid
.span
,
segments
:
segs
,
};
self
.check_path
(
pid
.span
,
id
,
&
path
);
}
ast
::
PathListMod
{
id
}
=>
{
debug!
(
"privacy - mod item {}"
,
id
);
self
.check_path
(
pid
.span
,
id
,
prefix
);
}
}
}
}
}
}
}
visit
::
walk_view_item
(
self
,
a
);
}
fn
visit_pat
(
&
mut
self
,
pattern
:
&
ast
::
Pat
)
{
// Foreign functions do not have their patterns mapped in the def_map,
// and there's nothing really relevant there anyway, so don't bother
...
...
@@ -1069,23 +1065,6 @@ fn visit_fn(&mut self, fk: visit::FnKind<'v>, fd: &'v ast::FnDecl,
visit
::
walk_fn
(
self
,
fk
,
fd
,
b
,
s
);
self
.in_fn
=
orig_in_fn
;
}
fn
visit_view_item
(
&
mut
self
,
i
:
&
ast
::
ViewItem
)
{
match
i
.vis
{
ast
::
Inherited
=>
{}
ast
::
Public
=>
{
if
self
.in_fn
{
self
.tcx.sess
.span_err
(
i
.span
,
"unnecessary `pub`, imports
\
in functions are never
\
reachable"
);
}
else
if
let
ast
::
ViewItemExternCrate
(
..
)
=
i
.node
{
self
.tcx.sess
.span_err
(
i
.span
,
"`pub` visibility
\
is not allowed"
);
}
}
}
visit
::
walk_view_item
(
self
,
i
);
}
}
impl
<
'a
,
'tcx
>
SanePrivacyVisitor
<
'a
,
'tcx
>
{
...
...
@@ -1162,7 +1141,7 @@ fn check_sane_privacy(&self, item: &ast::Item) {
ast
::
ItemConst
(
..
)
|
ast
::
ItemStatic
(
..
)
|
ast
::
ItemStruct
(
..
)
|
ast
::
ItemFn
(
..
)
|
ast
::
ItemMod
(
..
)
|
ast
::
ItemTy
(
..
)
|
ast
::
ItemMac
(
..
)
=>
{}
ast
::
Item
ExternCrate
(
_
)
|
ast
::
ItemUse
(
_
)
|
ast
::
Item
Mac
(
..
)
=>
{}
}
}
...
...
@@ -1219,6 +1198,7 @@ fn check_inherited(tcx: &ty::ctxt, sp: Span, vis: ast::Visibility) {
}
}
ast
::
ItemExternCrate
(
_
)
|
ast
::
ItemUse
(
_
)
|
ast
::
ItemStatic
(
..
)
|
ast
::
ItemConst
(
..
)
|
ast
::
ItemFn
(
..
)
|
ast
::
ItemMod
(
..
)
|
ast
::
ItemTy
(
..
)
|
ast
::
ItemMac
(
..
)
=>
{}
...
...
@@ -1521,11 +1501,9 @@ fn visit_struct_field(&mut self, s: &ast::StructField) {
// we don't need to introspect into these at all: an
// expression/block context can't possibly contain exported
// things, and neither do view_items. (Making them no-ops stops us
// from traversing the whole AST without having to be super
// careful about our `walk_...` calls above.)
fn
visit_view_item
(
&
mut
self
,
_
:
&
ast
::
ViewItem
)
{}
// expression/block context can't possibly contain exported things.
// (Making them no-ops stops us from traversing the whole AST without
// having to be super careful about our `walk_...` calls above.)
fn
visit_block
(
&
mut
self
,
_
:
&
ast
::
Block
)
{}
fn
visit_expr
(
&
mut
self
,
_
:
&
ast
::
Expr
)
{}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录