Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
869fa27d
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,发现更多精彩内容 >>
提交
869fa27d
编写于
6月 20, 2018
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
hygiene: Rename `MarkKind` to `Transparency`
Move `is_builtin` for `Mark` to a separate flag
上级
b15785b6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
58 addition
and
26 deletion
+58
-26
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+2
-2
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+3
-3
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+2
-2
src/libsyntax_pos/hygiene.rs
src/libsyntax_pos/hygiene.rs
+51
-19
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
869fa27d
...
...
@@ -45,7 +45,7 @@
use
rustc
::
util
::
nodemap
::{
NodeMap
,
NodeSet
,
FxHashMap
,
FxHashSet
,
DefIdMap
};
use
syntax
::
codemap
::
CodeMap
;
use
syntax
::
ext
::
hygiene
::{
Mark
,
MarkKind
,
SyntaxContext
};
use
syntax
::
ext
::
hygiene
::{
Mark
,
Transparency
,
SyntaxContext
};
use
syntax
::
ast
::{
self
,
Name
,
NodeId
,
Ident
,
FloatTy
,
IntTy
,
UintTy
};
use
syntax
::
ext
::
base
::
SyntaxExtension
;
use
syntax
::
ext
::
base
::
Determinacy
::{
self
,
Determined
,
Undetermined
};
...
...
@@ -1988,7 +1988,7 @@ fn resolve_crate_root(&mut self, mut ctxt: SyntaxContext, legacy: bool) -> Modul
// When resolving `$crate` from a `macro_rules!` invoked in a `macro`,
// we don't want to pretend that the `macro_rules!` definition is in the `macro`
// as described in `SyntaxContext::apply_mark`, so we ignore prepended modern marks.
ctxt
.marks
()
.into_iter
()
.find
(|
&
mark
|
mark
.
kind
()
!=
MarkKind
::
Modern
)
ctxt
.marks
()
.into_iter
()
.find
(|
&
mark
|
mark
.
transparency
()
!=
Transparency
::
Opaque
)
}
else
{
ctxt
=
ctxt
.modern
();
ctxt
.adjust
(
Mark
::
root
())
...
...
src/librustc_resolve/macros.rs
浏览文件 @
869fa27d
...
...
@@ -24,7 +24,7 @@
use
syntax
::
ext
::
base
::{
self
,
Annotatable
,
Determinacy
,
MultiModifier
,
MultiDecorator
};
use
syntax
::
ext
::
base
::{
MacroKind
,
SyntaxExtension
,
Resolver
as
SyntaxResolver
};
use
syntax
::
ext
::
expand
::{
Expansion
,
ExpansionKind
,
Invocation
,
InvocationKind
,
find_attr_invoc
};
use
syntax
::
ext
::
hygiene
::{
self
,
Mark
,
MarkKind
};
use
syntax
::
ext
::
hygiene
::{
self
,
Mark
,
Transparency
};
use
syntax
::
ext
::
placeholders
::
placeholder
;
use
syntax
::
ext
::
tt
::
macro_rules
;
use
syntax
::
feature_gate
::{
self
,
emit_feature_err
,
GateIssue
};
...
...
@@ -331,9 +331,9 @@ fn resolve_invoc(&mut self, invoc: &mut Invocation, scope: Mark, force: bool)
self
.unused_macros
.remove
(
&
def_id
);
let
ext
=
self
.get_macro
(
def
);
if
ext
.is_modern
()
{
invoc
.expansion_data.mark
.set_
kind
(
MarkKind
::
Modern
);
invoc
.expansion_data.mark
.set_
transparency
(
Transparency
::
Opaque
);
}
else
if
def_id
.krate
==
BUILTIN_MACROS_CRATE
{
invoc
.expansion_data.mark
.set_
kind
(
MarkKind
::
Builtin
);
invoc
.expansion_data.mark
.set_
is_builtin
(
true
);
}
Ok
(
Some
(
ext
))
}
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
869fa27d
...
...
@@ -18,7 +18,7 @@
use
attr
;
use
codemap
::{
self
,
CodeMap
};
use
syntax_pos
::{
self
,
BytePos
};
use
syntax_pos
::
hygiene
::{
Mark
,
MarkKind
,
SyntaxContext
};
use
syntax_pos
::
hygiene
::{
Mark
,
SyntaxContext
};
use
parse
::
token
::{
self
,
BinOpToken
,
Token
};
use
parse
::
lexer
::
comments
;
use
parse
::{
self
,
ParseSess
};
...
...
@@ -842,7 +842,7 @@ fn nbsp(&mut self) -> io::Result<()> { self.writer().word(" ") }
fn
print_dollar_crate
(
&
mut
self
,
mut
ctxt
:
SyntaxContext
)
->
io
::
Result
<
()
>
{
if
let
Some
(
mark
)
=
ctxt
.adjust
(
Mark
::
root
())
{
// Make a best effort to print something that complies
if
mark
.
kind
()
==
MarkKind
::
Builtin
{
if
mark
.
is_builtin
()
{
if
let
Some
(
name
)
=
std_inject
::
injected_crate_name
()
{
self
.writer
()
.word
(
"::"
)
?
;
self
.writer
()
.word
(
name
)
?
;
...
...
src/libsyntax_pos/hygiene.rs
浏览文件 @
869fa27d
...
...
@@ -43,21 +43,41 @@ pub struct SyntaxContextData {
#[derive(Debug)]
struct
MarkData
{
parent
:
Mark
,
kind
:
MarkKind
,
transparency
:
Transparency
,
is_builtin
:
bool
,
expn_info
:
Option
<
ExpnInfo
>
,
}
/// A property of a macro expansion that determines how identifiers
/// produced by that expansion are resolved.
#[derive(Copy,
Clone,
PartialEq,
Eq,
Debug)]
pub
enum
MarkKind
{
Modern
,
Builtin
,
Legacy
,
pub
enum
Transparency
{
/// Identifier produced by a transparent expansion is always resolved at call-site.
/// Call-site spans in procedural macros, hygiene opt-out in `macro` should use this.
/// (Not used yet.)
Transparent
,
/// Identifier produced by a semi-transparent expansion may be resolved
/// either at call-site or at definition-site.
/// If it's a local variable, label or `$crate` then it's resolved at def-site.
/// Otherwise it's resolved at call-site.
/// `macro_rules` macros behave like this, built-in macros currently behave like this too,
/// but that's an implementation detail.
SemiTransparent
,
/// Identifier produced by an opaque expansion is always resolved at definition-site.
/// Def-site spans in procedural macros, identifiers from `macro` by default use this.
Opaque
,
}
impl
Mark
{
pub
fn
fresh
(
parent
:
Mark
)
->
Self
{
HygieneData
::
with
(|
data
|
{
data
.marks
.push
(
MarkData
{
parent
:
parent
,
kind
:
MarkKind
::
Legacy
,
expn_info
:
None
});
data
.marks
.push
(
MarkData
{
parent
,
// By default expansions behave like `macro_rules`.
transparency
:
Transparency
::
SemiTransparent
,
is_builtin
:
false
,
expn_info
:
None
,
});
Mark
(
data
.marks
.len
()
as
u32
-
1
)
})
}
...
...
@@ -97,23 +117,31 @@ pub fn set_expn_info(self, info: ExpnInfo) {
pub
fn
modern
(
mut
self
)
->
Mark
{
HygieneData
::
with
(|
data
|
{
loop
{
if
self
==
Mark
::
root
()
||
data
.marks
[
self
.0
as
usize
]
.kind
==
MarkKind
::
Modern
{
return
self
;
}
while
data
.marks
[
self
.0
as
usize
]
.transparency
!=
Transparency
::
Opaque
{
self
=
data
.marks
[
self
.0
as
usize
]
.parent
;
}
self
})
}
#[inline]
pub
fn
kind
(
self
)
->
MarkKind
{
HygieneData
::
with
(|
data
|
data
.marks
[
self
.0
as
usize
]
.kind
)
pub
fn
transparency
(
self
)
->
Transparency
{
HygieneData
::
with
(|
data
|
data
.marks
[
self
.0
as
usize
]
.transparency
)
}
#[inline]
pub
fn
set_transparency
(
self
,
transparency
:
Transparency
)
{
HygieneData
::
with
(|
data
|
data
.marks
[
self
.0
as
usize
]
.transparency
=
transparency
)
}
#[inline]
pub
fn
is_builtin
(
self
)
->
bool
{
HygieneData
::
with
(|
data
|
data
.marks
[
self
.0
as
usize
]
.is_builtin
)
}
#[inline]
pub
fn
set_
kind
(
self
,
kind
:
MarkKind
)
{
HygieneData
::
with
(|
data
|
data
.marks
[
self
.0
as
usize
]
.
kind
=
kind
)
pub
fn
set_
is_builtin
(
self
,
is_builtin
:
bool
)
{
HygieneData
::
with
(|
data
|
data
.marks
[
self
.0
as
usize
]
.
is_builtin
=
is_builtin
)
}
pub
fn
is_descendant_of
(
mut
self
,
ancestor
:
Mark
)
->
bool
{
...
...
@@ -169,7 +197,10 @@ pub fn new() -> Self {
HygieneData
{
marks
:
vec!
[
MarkData
{
parent
:
Mark
::
root
(),
kind
:
MarkKind
::
Builtin
,
// If the root is opaque, then loops searching for an opaque mark
// will automatically stop after reaching it.
transparency
:
Transparency
::
Opaque
,
is_builtin
:
true
,
expn_info
:
None
,
}],
syntax_contexts
:
vec!
[
SyntaxContextData
{
...
...
@@ -215,8 +246,9 @@ pub fn allocate_directly(expansion_info: ExpnInfo) -> Self {
HygieneData
::
with
(|
data
|
{
data
.marks
.push
(
MarkData
{
parent
:
Mark
::
root
(),
kind
:
MarkKind
::
Legacy
,
expn_info
:
Some
(
expansion_info
)
transparency
:
Transparency
::
SemiTransparent
,
is_builtin
:
false
,
expn_info
:
Some
(
expansion_info
),
});
let
mark
=
Mark
(
data
.marks
.len
()
as
u32
-
1
);
...
...
@@ -232,7 +264,7 @@ pub fn allocate_directly(expansion_info: ExpnInfo) -> Self {
/// Extend a syntax context with a given mark
pub
fn
apply_mark
(
self
,
mark
:
Mark
)
->
SyntaxContext
{
if
mark
.
kind
()
==
MarkKind
::
Modern
{
if
mark
.
transparency
()
==
Transparency
::
Opaque
{
return
self
.apply_mark_internal
(
mark
);
}
...
...
@@ -262,7 +294,7 @@ fn apply_mark_internal(self, mark: Mark) -> SyntaxContext {
HygieneData
::
with
(|
data
|
{
let
syntax_contexts
=
&
mut
data
.syntax_contexts
;
let
mut
modern
=
syntax_contexts
[
self
.0
as
usize
]
.modern
;
if
data
.marks
[
mark
.0
as
usize
]
.
kind
==
MarkKind
::
Modern
{
if
data
.marks
[
mark
.0
as
usize
]
.
transparency
==
Transparency
::
Opaque
{
modern
=
*
data
.markings
.entry
((
modern
,
mark
))
.or_insert_with
(||
{
let
len
=
syntax_contexts
.len
()
as
u32
;
syntax_contexts
.push
(
SyntaxContextData
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录