Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1bdd2f69
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,发现更多精彩内容 >>
提交
1bdd2f69
编写于
1月 17, 2019
作者:
J
John Kåre Alsaker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Conditionally skip two passes if their related attributes were not found
上级
ec504def
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
44 addition
and
19 deletion
+44
-19
Cargo.lock
Cargo.lock
+1
-0
src/librustc_driver/driver.rs
src/librustc_driver/driver.rs
+17
-14
src/librustc_passes/Cargo.toml
src/librustc_passes/Cargo.toml
+1
-0
src/librustc_passes/ast_validation.rs
src/librustc_passes/ast_validation.rs
+19
-3
src/librustc_passes/lib.rs
src/librustc_passes/lib.rs
+1
-0
src/libsyntax_ext/proc_macro_decls.rs
src/libsyntax_ext/proc_macro_decls.rs
+5
-2
未找到文件。
Cargo.lock
浏览文件 @
1bdd2f69
...
...
@@ -2722,6 +2722,7 @@ dependencies = [
"rustc_errors 0.0.0",
"rustc_mir 0.0.0",
"syntax 0.0.0",
"syntax_ext 0.0.0",
"syntax_pos 0.0.0",
]
...
...
src/librustc_driver/driver.rs
浏览文件 @
1bdd2f69
...
...
@@ -1017,6 +1017,10 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(
krate
=
ReplaceBodyWithLoop
::
new
(
sess
)
.fold_crate
(
krate
);
}
let
(
has_proc_macro_decls
,
has_global_allocator
)
=
time
(
sess
,
"AST validation"
,
||
{
ast_validation
::
check_crate
(
sess
,
&
krate
)
});
// If we're in rustdoc we're always compiling as an rlib, but that'll trip a
// bunch of checks in the `modify` function below. For now just skip this
// step entirely if we're rustdoc as it's not too useful anyway.
...
...
@@ -1031,6 +1035,7 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(
&
mut
resolver
,
krate
,
is_proc_macro_crate
,
has_proc_macro_decls
,
is_test_crate
,
num_crate_types
,
sess
.diagnostic
(),
...
...
@@ -1038,16 +1043,18 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(
});
}
// Expand global allocators, which are treated as an in-tree proc macro
krate
=
time
(
sess
,
"creating allocators"
,
||
{
allocator
::
expand
::
modify
(
&
sess
.parse_sess
,
&
mut
resolver
,
krate
,
crate_name
.to_string
(),
sess
.diagnostic
(),
)
});
if
has_global_allocator
{
// Expand global allocators, which are treated as an in-tree proc macro
krate
=
time
(
sess
,
"creating allocators"
,
||
{
allocator
::
expand
::
modify
(
&
sess
.parse_sess
,
&
mut
resolver
,
krate
,
crate_name
.to_string
(),
sess
.diagnostic
(),
)
});
}
// Done with macro expansion!
...
...
@@ -1065,10 +1072,6 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(
println!
(
"{}"
,
json
::
as_json
(
&
krate
));
}
time
(
sess
,
"AST validation"
,
||
{
ast_validation
::
check_crate
(
sess
,
&
krate
)
});
time
(
sess
,
"name resolution"
,
||
{
resolver
.resolve_crate
(
&
krate
);
});
...
...
src/librustc_passes/Cargo.toml
浏览文件 @
1bdd2f69
...
...
@@ -14,5 +14,6 @@ rustc = { path = "../librustc" }
rustc_mir
=
{
path
=
"../librustc_mir"
}
rustc_data_structures
=
{
path
=
"../librustc_data_structures"
}
syntax
=
{
path
=
"../libsyntax"
}
syntax_ext
=
{
path
=
"../libsyntax_ext"
}
syntax_pos
=
{
path
=
"../libsyntax_pos"
}
rustc_errors
=
{
path
=
"../librustc_errors"
}
src/librustc_passes/ast_validation.rs
浏览文件 @
1bdd2f69
...
...
@@ -15,12 +15,15 @@
use
syntax
::
symbol
::
keywords
;
use
syntax
::
ptr
::
P
;
use
syntax
::
visit
::{
self
,
Visitor
};
use
syntax_ext
::
proc_macro_decls
::
is_proc_macro_attr
;
use
syntax_pos
::
Span
;
use
errors
;
use
errors
::
Applicability
;
struct
AstValidator
<
'a
>
{
session
:
&
'a
Session
,
has_proc_macro_decls
:
bool
,
has_global_allocator
:
bool
,
// Used to ban nested `impl Trait`, e.g., `impl Into<impl Debug>`.
// Nested `impl Trait` _is_ allowed in associated type position,
...
...
@@ -367,6 +370,14 @@ fn visit_lifetime(&mut self, lifetime: &'a Lifetime) {
}
fn
visit_item
(
&
mut
self
,
item
:
&
'a
Item
)
{
if
item
.attrs
.iter
()
.any
(|
attr
|
is_proc_macro_attr
(
attr
)
)
{
self
.has_proc_macro_decls
=
true
;
}
if
attr
::
contains_name
(
&
item
.attrs
,
"global_allocator"
)
{
self
.has_global_allocator
=
true
;
}
match
item
.node
{
ItemKind
::
Impl
(
unsafety
,
polarity
,
_
,
_
,
Some
(
..
),
ref
ty
,
ref
impl_items
)
=>
{
self
.invalid_visibility
(
&
item
.vis
,
None
);
...
...
@@ -590,10 +601,15 @@ fn visit_mac(&mut self, mac: &Spanned<Mac_>) {
}
}
pub
fn
check_crate
(
session
:
&
Session
,
krate
:
&
Crate
)
{
visit
::
walk_crate
(
&
mut
AstValidator
{
pub
fn
check_crate
(
session
:
&
Session
,
krate
:
&
Crate
)
->
(
bool
,
bool
)
{
let
mut
validator
=
AstValidator
{
session
,
has_proc_macro_decls
:
false
,
has_global_allocator
:
false
,
outer_impl_trait
:
None
,
is_impl_trait_banned
:
false
,
},
krate
)
};
visit
::
walk_crate
(
&
mut
validator
,
krate
);
(
validator
.has_proc_macro_decls
,
validator
.has_global_allocator
)
}
src/librustc_passes/lib.rs
浏览文件 @
1bdd2f69
...
...
@@ -22,6 +22,7 @@
extern
crate
log
;
#[macro_use]
extern
crate
syntax
;
extern
crate
syntax_ext
;
extern
crate
syntax_pos
;
extern
crate
rustc_errors
as
errors
;
...
...
src/libsyntax_ext/proc_macro_decls.rs
浏览文件 @
1bdd2f69
...
...
@@ -48,6 +48,7 @@ pub fn modify(sess: &ParseSess,
resolver
:
&
mut
dyn
(::
syntax
::
ext
::
base
::
Resolver
),
mut
krate
:
ast
::
Crate
,
is_proc_macro_crate
:
bool
,
has_proc_macro_decls
:
bool
,
is_test_crate
:
bool
,
num_crate_types
:
usize
,
handler
:
&
errors
::
Handler
)
->
ast
::
Crate
{
...
...
@@ -64,7 +65,9 @@ pub fn modify(sess: &ParseSess,
is_proc_macro_crate
,
is_test_crate
,
};
visit
::
walk_crate
(
&
mut
collect
,
&
krate
);
if
has_proc_macro_decls
||
is_proc_macro_crate
{
visit
::
walk_crate
(
&
mut
collect
,
&
krate
);
}
(
collect
.derives
,
collect
.attr_macros
,
collect
.bang_macros
)
};
...
...
@@ -85,7 +88,7 @@ pub fn modify(sess: &ParseSess,
krate
}
fn
is_proc_macro_attr
(
attr
:
&
ast
::
Attribute
)
->
bool
{
pub
fn
is_proc_macro_attr
(
attr
:
&
ast
::
Attribute
)
->
bool
{
PROC_MACRO_KINDS
.iter
()
.any
(|
kind
|
attr
.check_name
(
kind
))
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录