Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
93d369bc
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,发现更多精彩内容 >>
提交
93d369bc
编写于
8月 20, 2019
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resolve/expand: Rename some things for clarity and add comments
上级
a83c3569
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
29 addition
and
18 deletion
+29
-18
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+22
-14
src/libsyntax/ext/base.rs
src/libsyntax/ext/base.rs
+3
-2
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+4
-2
未找到文件。
src/librustc_resolve/macros.rs
浏览文件 @
93d369bc
...
...
@@ -140,11 +140,23 @@ fn resolve_imports(&mut self) {
ImportResolver
{
r
:
self
}
.resolve_imports
()
}
fn
resolve_macro_invocation
(
&
mut
self
,
invoc
:
&
Invocation
,
invoc_id
:
ExpnId
,
force
:
bool
)
->
Result
<
Option
<
Lrc
<
SyntaxExtension
>>
,
Indeterminate
>
{
let
inherited_parent_scope
=
self
.invocation_parent_scopes
[
&
invoc_id
];
let
parent_scope
=
*
self
.invocation_parent_scopes
.entry
(
invoc
.expansion_data.id
)
.or_insert
(
inherited_parent_scope
);
fn
resolve_macro_invocation
(
&
mut
self
,
invoc
:
&
Invocation
,
eager_expansion_root
:
ExpnId
,
force
:
bool
)
->
Result
<
Option
<
Lrc
<
SyntaxExtension
>>
,
Indeterminate
>
{
let
invoc_id
=
invoc
.expansion_data.id
;
let
parent_scope
=
match
self
.invocation_parent_scopes
.get
(
&
invoc_id
)
{
Some
(
parent_scope
)
=>
*
parent_scope
,
None
=>
{
// If there's no entry in the table, then we are resolving an eagerly expanded
// macro, which should inherit its parent scope from its eager expansion root -
// the macro that requested this eager expansion.
let
parent_scope
=
*
self
.invocation_parent_scopes
.get
(
&
eager_expansion_root
)
.expect
(
"non-eager expansion without a parent scope"
);
self
.invocation_parent_scopes
.insert
(
invoc_id
,
parent_scope
);
parent_scope
}
};
let
(
path
,
kind
,
derives
,
after_derive
)
=
match
invoc
.kind
{
InvocationKind
::
Attr
{
ref
attr
,
ref
derives
,
after_derive
,
..
}
=>
(
&
attr
.path
,
MacroKind
::
Attr
,
self
.arenas
.alloc_ast_paths
(
derives
),
after_derive
),
...
...
@@ -163,7 +175,7 @@ fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: ExpnId, for
match
self
.resolve_macro_path
(
path
,
Some
(
MacroKind
::
Derive
),
&
parent_scope
,
true
,
force
)
{
Ok
((
Some
(
ref
ext
),
_
))
if
ext
.is_derive_copy
=>
{
self
.add_derives
(
invoc
.expansion_data.
id
,
SpecialDerives
::
COPY
);
self
.add_derives
(
invoc
_
id
,
SpecialDerives
::
COPY
);
return
Ok
(
None
);
}
Err
(
Determinacy
::
Undetermined
)
=>
result
=
Err
(
Indeterminate
),
...
...
@@ -180,19 +192,15 @@ fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: ExpnId, for
let
(
ext
,
res
)
=
self
.smart_resolve_macro_path
(
path
,
kind
,
parent_scope
,
force
)
?
;
let
span
=
invoc
.span
();
invoc
.expansion_data.id
.set_expn_data
(
ext
.expn_data
(
parent_scope
.expansion
,
span
,
fast_print_path
(
path
))
);
invoc_id
.set_expn_data
(
ext
.expn_data
(
parent_scope
.expansion
,
span
,
fast_print_path
(
path
)));
if
let
Res
::
Def
(
_
,
def_id
)
=
res
{
if
after_derive
{
self
.session
.span_err
(
span
,
"macro attributes must be placed before `#[derive]`"
);
}
self
.macro_defs
.insert
(
invoc
.expansion_data.id
,
def_id
);
let
normal_module_def_id
=
self
.macro_def_scope
(
invoc
.expansion_data.id
)
.normal_ancestor_id
;
self
.definitions
.add_parent_module_of_macro_def
(
invoc
.expansion_data.id
,
normal_module_def_id
);
self
.macro_defs
.insert
(
invoc_id
,
def_id
);
let
normal_module_def_id
=
self
.macro_def_scope
(
invoc_id
)
.normal_ancestor_id
;
self
.definitions
.add_parent_module_of_macro_def
(
invoc_id
,
normal_module_def_id
);
}
Ok
(
Some
(
ext
))
...
...
src/libsyntax/ext/base.rs
浏览文件 @
93d369bc
...
...
@@ -682,8 +682,9 @@ fn visit_ast_fragment_with_placeholders(&mut self, expn_id: ExpnId, fragment: &A
fn
resolve_imports
(
&
mut
self
);
fn
resolve_macro_invocation
(
&
mut
self
,
invoc
:
&
Invocation
,
invoc_id
:
ExpnId
,
force
:
bool
)
->
Result
<
Option
<
Lrc
<
SyntaxExtension
>>
,
Indeterminate
>
;
fn
resolve_macro_invocation
(
&
mut
self
,
invoc
:
&
Invocation
,
eager_expansion_root
:
ExpnId
,
force
:
bool
)
->
Result
<
Option
<
Lrc
<
SyntaxExtension
>>
,
Indeterminate
>
;
fn
check_unused_macros
(
&
self
);
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
93d369bc
...
...
@@ -305,9 +305,11 @@ pub fn fully_expand_fragment(&mut self, input_fragment: AstFragment) -> AstFragm
continue
};
let
scope
=
let
eager_expansion_root
=
if
self
.monotonic
{
invoc
.expansion_data.id
}
else
{
orig_expansion_data
.id
};
let
ext
=
match
self
.cx.resolver
.resolve_macro_invocation
(
&
invoc
,
scope
,
force
)
{
let
ext
=
match
self
.cx.resolver
.resolve_macro_invocation
(
&
invoc
,
eager_expansion_root
,
force
)
{
Ok
(
ext
)
=>
ext
,
Err
(
Indeterminate
)
=>
{
undetermined_invocations
.push
(
invoc
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录