Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
3f0729f3
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,发现更多精彩内容 >>
提交
3f0729f3
编写于
6月 20, 2021
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
expand: Move some more derive logic to `rustc_builtin_macros`
上级
75d1500f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
13 addition
and
38 deletion
+13
-38
compiler/rustc_builtin_macros/src/cfg_eval.rs
compiler/rustc_builtin_macros/src/cfg_eval.rs
+5
-6
compiler/rustc_builtin_macros/src/derive.rs
compiler/rustc_builtin_macros/src/derive.rs
+4
-2
compiler/rustc_expand/src/base.rs
compiler/rustc_expand/src/base.rs
+1
-1
compiler/rustc_expand/src/expand.rs
compiler/rustc_expand/src/expand.rs
+2
-28
compiler/rustc_resolve/src/macros.rs
compiler/rustc_resolve/src/macros.rs
+1
-1
未找到文件。
compiler/rustc_builtin_macros/src/cfg_eval.rs
浏览文件 @
3f0729f3
...
...
@@ -24,19 +24,18 @@
annotatable
:
Annotatable
,
)
->
Vec
<
Annotatable
>
{
check_builtin_macro_attribute
(
ecx
,
meta_item
,
sym
::
cfg_eval
);
cfg_eval
(
ecx
,
annotatable
)
vec!
[
cfg_eval
(
ecx
,
annotatable
)]
}
crate
fn
cfg_eval
(
ecx
:
&
ExtCtxt
<
'_
>
,
annotatable
:
Annotatable
)
->
Vec
<
Annotatable
>
{
let
mut
visitor
=
CfgEval
{
crate
fn
cfg_eval
(
ecx
:
&
ExtCtxt
<
'_
>
,
annotatable
:
Annotatable
)
->
Annotatable
{
CfgEval
{
cfg
:
&
mut
StripUnconfigured
{
sess
:
ecx
.sess
,
features
:
ecx
.ecfg.features
,
config_tokens
:
true
,
},
};
let
annotatable
=
visitor
.configure_annotatable
(
annotatable
);
vec!
[
annotatable
]
}
.configure_annotatable
(
annotatable
)
}
struct
CfgEval
<
'a
,
'b
>
{
...
...
compiler/rustc_builtin_macros/src/derive.rs
浏览文件 @
3f0729f3
...
...
@@ -26,6 +26,8 @@ fn expand(
return
ExpandResult
::
Ready
(
vec!
[
item
]);
}
let
item
=
cfg_eval
(
ecx
,
item
);
let
result
=
ecx
.resolver
.resolve_derives
(
ecx
.current_expansion.id
,
ecx
.force_mode
,
&
||
{
let
template
=
...
...
@@ -54,12 +56,12 @@ fn expand(
report_path_args
(
sess
,
&
meta
);
meta
.path
})
.map
(|
path
|
(
path
,
None
))
.map
(|
path
|
(
path
,
item
.clone
(),
None
))
.collect
()
});
match
result
{
Ok
(())
=>
ExpandResult
::
Ready
(
cfg_eval
(
ecx
,
item
)
),
Ok
(())
=>
ExpandResult
::
Ready
(
vec!
[
item
]
),
Err
(
Indeterminate
)
=>
ExpandResult
::
Retry
(
item
),
}
}
...
...
compiler/rustc_expand/src/base.rs
浏览文件 @
3f0729f3
...
...
@@ -835,7 +835,7 @@ pub fn expn_data(
/// Error type that denotes indeterminacy.
pub
struct
Indeterminate
;
pub
type
DeriveResolutions
=
Vec
<
(
ast
::
Path
,
Option
<
Lrc
<
SyntaxExtension
>>
)
>
;
pub
type
DeriveResolutions
=
Vec
<
(
ast
::
Path
,
Annotatable
,
Option
<
Lrc
<
SyntaxExtension
>>
)
>
;
pub
trait
ResolverExpand
{
fn
next_node_id
(
&
mut
self
)
->
NodeId
;
...
...
compiler/rustc_expand/src/expand.rs
浏览文件 @
3f0729f3
...
...
@@ -500,42 +500,16 @@ pub fn fully_expand_fragment(&mut self, input_fragment: AstFragment) -> AstFragm
.resolver
.take_derive_resolutions
(
expn_id
)
.map
(|
derives
|
{
enum
AnnotatableRef
<
'a
>
{
Item
(
&
'a
P
<
ast
::
Item
>
),
Stmt
(
&
'a
ast
::
Stmt
),
}
let
item
=
match
&
fragment
{
AstFragment
::
Items
(
items
)
=>
match
&
items
[
..
]
{
[
item
]
=>
AnnotatableRef
::
Item
(
item
),
_
=>
unreachable!
(),
},
AstFragment
::
Stmts
(
stmts
)
=>
match
&
stmts
[
..
]
{
[
stmt
]
=>
AnnotatableRef
::
Stmt
(
stmt
),
_
=>
unreachable!
(),
},
_
=>
unreachable!
(),
};
derive_invocations
.reserve
(
derives
.len
());
derives
.into_iter
()
.map
(|(
path
,
_
exts
)|
{
.map
(|(
path
,
item
,
_
exts
)|
{
// FIXME: Consider using the derive resolutions (`_exts`)
// instead of enqueuing the derives to be resolved again later.
let
expn_id
=
ExpnId
::
fresh
(
None
);
derive_invocations
.push
((
Invocation
{
kind
:
InvocationKind
::
Derive
{
path
,
item
:
match
item
{
AnnotatableRef
::
Item
(
item
)
=>
{
Annotatable
::
Item
(
item
.clone
())
}
AnnotatableRef
::
Stmt
(
stmt
)
=>
{
Annotatable
::
Stmt
(
P
(
stmt
.clone
()))
}
},
},
kind
:
InvocationKind
::
Derive
{
path
,
item
},
fragment_kind
,
expansion_data
:
ExpansionData
{
id
:
expn_id
,
...
...
compiler/rustc_resolve/src/macros.rs
浏览文件 @
3f0729f3
...
...
@@ -380,7 +380,7 @@ fn resolve_derives(
has_derive_copy
:
false
,
});
let
parent_scope
=
self
.invocation_parent_scopes
[
&
expn_id
];
for
(
i
,
(
path
,
opt_ext
))
in
entry
.resolutions
.iter_mut
()
.enumerate
()
{
for
(
i
,
(
path
,
_
,
opt_ext
))
in
entry
.resolutions
.iter_mut
()
.enumerate
()
{
if
opt_ext
.is_none
()
{
*
opt_ext
=
Some
(
match
self
.resolve_macro_path
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录