Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
4082cd95
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,发现更多精彩内容 >>
提交
4082cd95
编写于
8月 25, 2019
作者:
M
Matthew Jasper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow ast passes to create hygienic spans
上级
0133941f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
72 addition
and
4 deletion
+72
-4
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+2
-1
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+22
-0
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+38
-1
src/libsyntax/ext/base.rs
src/libsyntax/ext/base.rs
+9
-1
src/libsyntax_pos/hygiene.rs
src/libsyntax_pos/hygiene.rs
+1
-1
未找到文件。
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
4082cd95
...
...
@@ -126,7 +126,8 @@ impl<'a> Resolver<'a> {
crate
fn
macro_def_scope
(
&
mut
self
,
expn_id
:
ExpnId
)
->
Module
<
'a
>
{
let
def_id
=
match
self
.macro_defs
.get
(
&
expn_id
)
{
Some
(
def_id
)
=>
*
def_id
,
None
=>
return
self
.graph_root
,
None
=>
return
self
.ast_transform_scopes
.get
(
&
expn_id
)
.unwrap_or
(
&
self
.graph_root
),
};
if
let
Some
(
id
)
=
self
.definitions
.as_local_node_id
(
def_id
)
{
self
.local_macro_def_scopes
[
&
id
]
...
...
src/librustc_resolve/lib.rs
浏览文件 @
4082cd95
...
...
@@ -879,6 +879,10 @@ pub struct Resolver<'a> {
/// There will be an anonymous module created around `g` with the ID of the
/// entry block for `f`.
block_map
:
NodeMap
<
Module
<
'a
>>
,
/// A fake module that contains no definition and no prelude. Used so that
/// some AST passes can generate identifiers that only resolve to local or
/// language items.
empty_module
:
Module
<
'a
>
,
module_map
:
FxHashMap
<
DefId
,
Module
<
'a
>>
,
extern_module_map
:
FxHashMap
<
(
DefId
,
bool
/* MacrosOnly? */
),
Module
<
'a
>>
,
binding_parent_modules
:
FxHashMap
<
PtrKey
<
'a
,
NameBinding
<
'a
>>
,
Module
<
'a
>>
,
...
...
@@ -913,6 +917,7 @@ pub struct Resolver<'a> {
non_macro_attrs
:
[
Lrc
<
SyntaxExtension
>
;
2
],
macro_defs
:
FxHashMap
<
ExpnId
,
DefId
>
,
local_macro_def_scopes
:
FxHashMap
<
NodeId
,
Module
<
'a
>>
,
ast_transform_scopes
:
FxHashMap
<
ExpnId
,
Module
<
'a
>>
,
unused_macros
:
NodeMap
<
Span
>
,
proc_macro_stubs
:
NodeSet
,
/// Traces collected during macro resolution and validated when it's complete.
...
...
@@ -1080,6 +1085,21 @@ pub fn new(session: &'a Session,
no_implicit_prelude
:
attr
::
contains_name
(
&
krate
.attrs
,
sym
::
no_implicit_prelude
),
..
ModuleData
::
new
(
None
,
root_module_kind
,
root_def_id
,
ExpnId
::
root
(),
krate
.span
)
});
let
empty_module_kind
=
ModuleKind
::
Def
(
DefKind
::
Mod
,
root_def_id
,
kw
::
Invalid
,
);
let
empty_module
=
arenas
.alloc_module
(
ModuleData
{
no_implicit_prelude
:
true
,
..
ModuleData
::
new
(
Some
(
graph_root
),
empty_module_kind
,
root_def_id
,
ExpnId
::
root
(),
DUMMY_SP
,
)
});
let
mut
module_map
=
FxHashMap
::
default
();
module_map
.insert
(
DefId
::
local
(
CRATE_DEF_INDEX
),
graph_root
);
...
...
@@ -1139,10 +1159,12 @@ pub fn new(session: &'a Session,
label_res_map
:
Default
::
default
(),
export_map
:
FxHashMap
::
default
(),
trait_map
:
Default
::
default
(),
empty_module
,
module_map
,
block_map
:
Default
::
default
(),
extern_module_map
:
FxHashMap
::
default
(),
binding_parent_modules
:
FxHashMap
::
default
(),
ast_transform_scopes
:
FxHashMap
::
default
(),
glob_map
:
Default
::
default
(),
...
...
src/librustc_resolve/macros.rs
浏览文件 @
4082cd95
...
...
@@ -8,6 +8,7 @@
use
crate
::
Namespace
::
*
;
use
crate
::
resolve_imports
::
ImportResolver
;
use
rustc
::
hir
::
def
::{
self
,
DefKind
,
NonMacroAttrKind
};
use
rustc
::
hir
::
def_id
;
use
rustc
::
middle
::
stability
;
use
rustc
::{
ty
,
lint
,
span_bug
};
use
syntax
::
ast
::{
self
,
NodeId
,
Ident
};
...
...
@@ -16,7 +17,7 @@
use
syntax
::
ext
::
base
::{
self
,
Indeterminate
,
SpecialDerives
};
use
syntax
::
ext
::
base
::{
MacroKind
,
SyntaxExtension
};
use
syntax
::
ext
::
expand
::{
AstFragment
,
Invocation
,
InvocationKind
};
use
syntax
::
ext
::
hygiene
::{
self
,
ExpnId
,
ExpnData
,
ExpnKind
};
use
syntax
::
ext
::
hygiene
::{
self
,
ExpnId
,
ExpnData
,
ExpnKind
,
Transparency
};
use
syntax
::
ext
::
tt
::
macro_rules
;
use
syntax
::
feature_gate
::{
emit_feature_err
,
is_builtin_attr_name
};
use
syntax
::
feature_gate
::
GateIssue
;
...
...
@@ -25,6 +26,7 @@
use
std
::{
mem
,
ptr
};
use
rustc_data_structures
::
sync
::
Lrc
;
use
syntax_pos
::
hygiene
::
AstPass
;
type
Res
=
def
::
Res
<
NodeId
>
;
...
...
@@ -136,6 +138,41 @@ fn register_builtin_macro(&mut self, ident: ast::Ident, ext: SyntaxExtension) {
}
}
// Create a Span with modern hygiene with a definition site of the provided
// module, or a fake empty `#[no_implicit_prelude]` module if no module is
// provided.
fn
span_for_ast_pass
(
&
mut
self
,
base_span
:
Span
,
pass
:
AstPass
,
features
:
&
[
Symbol
],
parent_module_id
:
Option
<
NodeId
>
,
)
->
Span
{
let
span
=
base_span
.fresh_expansion_with_transparency
(
ExpnData
::
allow_unstable
(
ExpnKind
::
AstPass
(
pass
),
base_span
,
self
.session
.edition
(),
features
.into
(),
),
Transparency
::
Opaque
,
);
let
expn_id
=
span
.ctxt
()
.outer_expn
();
let
parent_scope
=
if
let
Some
(
module_id
)
=
parent_module_id
{
let
parent_def_id
=
self
.definitions
.local_def_id
(
module_id
);
self
.definitions
.add_parent_module_of_macro_def
(
expn_id
,
parent_def_id
);
self
.module_map
[
&
parent_def_id
]
}
else
{
self
.definitions
.add_parent_module_of_macro_def
(
expn_id
,
def_id
::
DefId
::
local
(
def_id
::
CRATE_DEF_INDEX
),
);
self
.empty_module
};
self
.ast_transform_scopes
.insert
(
expn_id
,
parent_scope
);
span
}
fn
resolve_imports
(
&
mut
self
)
{
ImportResolver
{
r
:
self
}
.resolve_imports
()
}
...
...
src/libsyntax/ext/base.rs
浏览文件 @
4082cd95
...
...
@@ -15,7 +15,7 @@
use
errors
::{
DiagnosticBuilder
,
DiagnosticId
};
use
smallvec
::{
smallvec
,
SmallVec
};
use
syntax_pos
::{
FileName
,
Span
,
MultiSpan
,
DUMMY_SP
};
use
syntax_pos
::
hygiene
::{
ExpnData
,
ExpnKind
};
use
syntax_pos
::
hygiene
::{
AstPass
,
ExpnData
,
ExpnKind
};
use
rustc_data_structures
::
fx
::
FxHashMap
;
use
rustc_data_structures
::
sync
::{
self
,
Lrc
};
...
...
@@ -660,6 +660,14 @@ fn visit_ast_fragment_with_placeholders(&mut self, expn_id: ExpnId, fragment: &A
extra_placeholders
:
&
[
NodeId
]);
fn
register_builtin_macro
(
&
mut
self
,
ident
:
ast
::
Ident
,
ext
:
SyntaxExtension
);
fn
span_for_ast_pass
(
&
mut
self
,
span
:
Span
,
pass
:
AstPass
,
features
:
&
[
Symbol
],
parent_module_id
:
Option
<
NodeId
>
,
)
->
Span
;
fn
resolve_imports
(
&
mut
self
);
fn
resolve_macro_invocation
(
...
...
src/libsyntax_pos/hygiene.rs
浏览文件 @
4082cd95
...
...
@@ -550,7 +550,7 @@ impl Span {
/// The returned span belongs to the created expansion and has the new properties,
/// but its location is inherited from the current span.
pub
fn
fresh_expansion
(
self
,
expn_data
:
ExpnData
)
->
Span
{
self
.fresh_expansion_with_transparency
(
expn_data
,
Transparency
::
Semi
Transparent
)
self
.fresh_expansion_with_transparency
(
expn_data
,
Transparency
::
Transparent
)
}
pub
fn
fresh_expansion_with_transparency
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录