Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e152554e
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,发现更多精彩内容 >>
提交
e152554e
编写于
6月 18, 2019
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resolve/expand: Move expansion info setting to a single earlier point
上级
1ff3bce5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
30 addition
and
35 deletion
+30
-35
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+26
-5
src/libsyntax/ext/base.rs
src/libsyntax/ext/base.rs
+1
-1
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+3
-29
未找到文件。
src/librustc_resolve/macros.rs
浏览文件 @
e152554e
...
...
@@ -114,6 +114,22 @@ enum SubNS { Bang, AttrLike }
candidate
.is_none
()
||
requirement
.is_none
()
||
candidate
==
requirement
}
// We don't want to format a path using pretty-printing,
// `format!("{}", path)`, because that tries to insert
// line-breaks and is slow.
fn
fast_print_path
(
path
:
&
ast
::
Path
)
->
String
{
let
mut
path_str
=
String
::
with_capacity
(
64
);
for
(
i
,
segment
)
in
path
.segments
.iter
()
.enumerate
()
{
if
i
!=
0
{
path_str
.push_str
(
"::"
);
}
if
segment
.ident.name
!=
kw
::
PathRoot
{
path_str
.push_str
(
&
segment
.ident
.as_str
())
}
}
path_str
}
impl
<
'a
>
base
::
Resolver
for
Resolver
<
'a
>
{
fn
next_node_id
(
&
mut
self
)
->
ast
::
NodeId
{
self
.session
.next_node_id
()
...
...
@@ -209,14 +225,19 @@ fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: Mark, force
let
parent_scope
=
self
.invoc_parent_scope
(
invoc_id
,
derives_in_scope
);
let
(
res
,
ext
)
=
match
self
.resolve_macro_to_res
(
path
,
kind
,
&
parent_scope
,
true
,
force
)
{
Ok
((
res
,
ext
))
=>
(
res
,
ext
),
Err
(
Determinacy
::
Determined
)
if
kind
==
MacroKind
::
Attr
=>
{
// Replace unresolved attributes with used inert attributes for better recovery.
return
Ok
(
Some
(
self
.non_macro_attr
(
true
)));
}
// Replace unresolved attributes with used inert attributes for better recovery.
Err
(
Determinacy
::
Determined
)
if
kind
==
MacroKind
::
Attr
=>
(
Res
::
Err
,
self
.non_macro_attr
(
true
)),
Err
(
determinacy
)
=>
return
Err
(
determinacy
),
};
if
let
Res
::
Def
(
DefKind
::
Macro
(
_
),
def_id
)
=
res
{
let
format
=
match
kind
{
MacroKind
::
Derive
=>
format!
(
"derive({})"
,
fast_print_path
(
path
)),
_
=>
fast_print_path
(
path
),
};
invoc
.expansion_data.mark
.set_expn_info
(
ext
.expn_info
(
invoc
.span
(),
&
format
));
if
let
Res
::
Def
(
_
,
def_id
)
=
res
{
if
after_derive
{
self
.session
.span_err
(
invoc
.span
(),
"macro attributes must be placed before `#[derive]`"
);
...
...
src/libsyntax/ext/base.rs
浏览文件 @
e152554e
...
...
@@ -677,7 +677,7 @@ fn expn_format(&self, symbol: Symbol) -> ExpnFormat {
}
}
crate
fn
expn_info
(
&
self
,
call_site
:
Span
,
format
:
&
str
)
->
ExpnInfo
{
pub
fn
expn_info
(
&
self
,
call_site
:
Span
,
format
:
&
str
)
->
ExpnInfo
{
ExpnInfo
{
call_site
,
format
:
self
.expn_format
(
Symbol
::
intern
(
format
)),
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
e152554e
...
...
@@ -188,22 +188,6 @@ fn expect_from_annotatables<I: IntoIterator<Item = Annotatable>>(self, items: I)
}
}
// We don't want to format a path using pretty-printing,
// `format!("{}", path)`, because that tries to insert
// line-breaks and is slow.
fn
fast_print_path
(
path
:
&
ast
::
Path
)
->
String
{
let
mut
path_str
=
String
::
with_capacity
(
64
);
for
(
i
,
segment
)
in
path
.segments
.iter
()
.enumerate
()
{
if
i
!=
0
{
path_str
.push_str
(
"::"
);
}
if
segment
.ident.name
!=
kw
::
PathRoot
{
path_str
.push_str
(
&
segment
.ident
.as_str
())
}
}
path_str
}
pub
struct
Invocation
{
pub
kind
:
InvocationKind
,
fragment_kind
:
AstFragmentKind
,
...
...
@@ -546,9 +530,6 @@ fn expand_attr_invoc(&mut self,
_
=>
unreachable!
(),
};
let
expn_info
=
ext
.expn_info
(
attr
.span
,
&
fast_print_path
(
&
attr
.path
));
invoc
.expansion_data.mark
.set_expn_info
(
expn_info
);
match
&
ext
.kind
{
SyntaxExtensionKind
::
NonMacroAttr
{
mark_used
}
=>
{
attr
::
mark_known
(
&
attr
);
...
...
@@ -682,7 +663,7 @@ fn expand_bang_invoc(&mut self,
invoc
:
Invocation
,
ext
:
&
SyntaxExtension
)
->
Option
<
AstFragment
>
{
let
(
mark
,
kind
)
=
(
invoc
.expansion_data.mark
,
invoc
.fragment_kind
)
;
let
kind
=
invoc
.fragment_kind
;
let
(
mac
,
ident
,
span
)
=
match
invoc
.kind
{
InvocationKind
::
Bang
{
mac
,
ident
,
span
}
=>
(
mac
,
ident
,
span
),
_
=>
unreachable!
(),
...
...
@@ -690,7 +671,7 @@ fn expand_bang_invoc(&mut self,
let
path
=
&
mac
.node.path
;
let
ident
=
ident
.unwrap_or_else
(||
Ident
::
invalid
());
let
validate
_and_set_expn_info
=
|
this
:
&
mut
Self
|
{
let
validate
=
|
this
:
&
mut
Self
|
{
// feature-gate the macro invocation
if
let
Some
((
feature
,
issue
))
=
ext
.unstable_feature
{
let
crate_span
=
this
.cx.current_expansion.crate_span
.unwrap
();
...
...
@@ -715,13 +696,12 @@ fn expand_bang_invoc(&mut self,
this
.cx
.trace_macros_diag
();
return
Err
(
kind
.dummy
(
span
));
}
mark
.set_expn_info
(
ext
.expn_info
(
span
,
&
fast_print_path
(
path
)));
Ok
(())
};
let
opt_expanded
=
match
&
ext
.kind
{
SyntaxExtensionKind
::
LegacyBang
(
expander
)
=>
{
if
let
Err
(
dummy_span
)
=
validate
_and_set_expn_info
(
self
)
{
if
let
Err
(
dummy_span
)
=
validate
(
self
)
{
dummy_span
}
else
{
kind
.make_from
(
expander
.expand
(
...
...
@@ -757,8 +737,6 @@ fn expand_bang_invoc(&mut self,
kind
.dummy
(
span
)
}
else
{
self
.gate_proc_macro_expansion_kind
(
span
,
kind
);
let
expn_info
=
ext
.expn_info
(
span
,
&
fast_print_path
(
path
));
invoc
.expansion_data.mark
.set_expn_info
(
expn_info
);
let
tok_result
=
expander
.expand
(
self
.cx
,
span
,
mac
.node
.stream
());
let
result
=
self
.parse_ast_fragment
(
tok_result
,
kind
,
path
,
span
);
self
.gate_proc_macro_expansion
(
span
,
&
result
);
...
...
@@ -818,10 +796,6 @@ fn expand_derive_invoc(&mut self,
match
&
ext
.kind
{
SyntaxExtensionKind
::
Derive
(
expander
)
|
SyntaxExtensionKind
::
LegacyDerive
(
expander
)
=>
{
let
expn_info
=
ext
.expn_info
(
path
.span
,
&
format!
(
"derive({})"
,
fast_print_path
(
&
path
)));
invoc
.expansion_data.mark
.set_expn_info
(
expn_info
);
let
meta
=
ast
::
MetaItem
{
node
:
ast
::
MetaItemKind
::
Word
,
span
:
path
.span
,
path
};
let
span
=
meta
.span
.with_ctxt
(
self
.cx
.backtrace
());
let
items
=
expander
.expand
(
self
.cx
,
span
,
&
meta
,
item
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录