Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e97686d0
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,发现更多精彩内容 >>
提交
e97686d0
编写于
11月 15, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move `MetaItemKind`'s `Name` to a field of `MetaItem`.
上级
4b9b0d34
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
70 addition
and
71 deletion
+70
-71
src/librustc_driver/lib.rs
src/librustc_driver/lib.rs
+2
-1
src/librustc_incremental/calculate_svh/svh_visitor.rs
src/librustc_incremental/calculate_svh/svh_visitor.rs
+10
-12
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+9
-4
src/libsyntax/attr.rs
src/libsyntax/attr.rs
+21
-20
src/libsyntax/config.rs
src/libsyntax/config.rs
+1
-1
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+3
-3
src/libsyntax/fold.rs
src/libsyntax/fold.rs
+7
-6
src/libsyntax/parse/attr.rs
src/libsyntax/parse/attr.rs
+9
-17
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+6
-6
src/libsyntax/std_inject.rs
src/libsyntax/std_inject.rs
+2
-1
未找到文件。
src/librustc_driver/lib.rs
浏览文件 @
e97686d0
...
...
@@ -615,7 +615,8 @@ fn print_crate_info(sess: &Session,
let
mut
cfgs
=
Vec
::
new
();
for
&
(
name
,
ref
value
)
in
sess
.parse_sess.config
.iter
()
{
let
gated_cfg
=
GatedCfg
::
gate
(
&
ast
::
MetaItem
{
node
:
ast
::
MetaItemKind
::
Word
(
name
),
name
:
name
,
node
:
ast
::
MetaItemKind
::
Word
,
span
:
DUMMY_SP
,
});
if
!
allow_unstable_cfg
&&
gated_cfg
.is_some
()
{
...
...
src/librustc_incremental/calculate_svh/svh_visitor.rs
浏览文件 @
e97686d0
...
...
@@ -874,22 +874,20 @@ fn hash_meta_item(&mut self, meta_item: &ast::MetaItem) {
// ignoring span information, it doesn't matter here
self
.hash_discriminant
(
&
meta_item
.node
);
let
name
=
&*
meta_item
.name
.as_str
();
match
meta_item
.node
{
ast
::
MetaItemKind
::
Word
(
s
)
=>
{
let
s
=
&*
s
.as_str
();
s
.len
()
.hash
(
self
.st
);
s
.hash
(
self
.st
);
ast
::
MetaItemKind
::
Word
=>
{
name
.len
()
.hash
(
self
.st
);
name
.hash
(
self
.st
);
}
ast
::
MetaItemKind
::
NameValue
(
s
,
ref
lit
)
=>
{
let
s
=
&*
s
.as_str
();
s
.len
()
.hash
(
self
.st
);
s
.hash
(
self
.st
);
ast
::
MetaItemKind
::
NameValue
(
ref
lit
)
=>
{
name
.len
()
.hash
(
self
.st
);
name
.hash
(
self
.st
);
lit
.node
.hash
(
self
.st
);
}
ast
::
MetaItemKind
::
List
(
s
,
ref
items
)
=>
{
let
s
=
&*
s
.as_str
();
s
.len
()
.hash
(
self
.st
);
s
.hash
(
self
.st
);
ast
::
MetaItemKind
::
List
(
ref
items
)
=>
{
name
.len
()
.hash
(
self
.st
);
name
.hash
(
self
.st
);
// Sort subitems so the hash does not depend on their order
let
indices
=
self
.indices_sorted_by
(
&
items
,
|
p
|
{
(
p
.name
(),
fnv
::
hash
(
&
p
.literal
()
.map
(|
i
|
&
i
.node
)))
...
...
src/libsyntax/ast.rs
浏览文件 @
e97686d0
...
...
@@ -515,7 +515,12 @@ pub enum NestedMetaItemKind {
/// A spanned compile-time attribute item.
///
/// E.g. `#[test]`, `#[derive(..)]` or `#[feature = "foo"]`
pub
type
MetaItem
=
Spanned
<
MetaItemKind
>
;
#[derive(Clone,
PartialEq,
Eq,
RustcEncodable,
RustcDecodable,
Hash,
Debug)]
pub
struct
MetaItem
{
pub
name
:
Name
,
pub
node
:
MetaItemKind
,
pub
span
:
Span
,
}
/// A compile-time attribute item.
///
...
...
@@ -525,15 +530,15 @@ pub enum MetaItemKind {
/// Word meta item.
///
/// E.g. `test` as in `#[test]`
Word
(
Name
)
,
Word
,
/// List meta item.
///
/// E.g. `derive(..)` as in `#[derive(..)]`
List
(
Name
,
Vec
<
NestedMetaItem
>
),
List
(
Vec
<
NestedMetaItem
>
),
/// Name value meta item.
///
/// E.g. `feature = "foo"` as in `#[feature = "foo"]`
NameValue
(
Name
,
Lit
),
NameValue
(
Lit
)
}
/// A Block (`{ .. }`).
...
...
src/libsyntax/attr.rs
浏览文件 @
e97686d0
...
...
@@ -18,7 +18,7 @@
use
ast
::{
AttrId
,
Attribute
,
Name
};
use
ast
::{
MetaItem
,
MetaItemKind
,
NestedMetaItem
,
NestedMetaItemKind
};
use
ast
::{
Lit
,
Expr
,
Item
,
Local
,
Stmt
,
StmtKind
};
use
codemap
::{
respan
,
spanned
,
dummy_spanned
,
mk_sp
};
use
codemap
::{
spanned
,
dummy_spanned
,
mk_sp
};
use
syntax_pos
::{
Span
,
BytePos
,
DUMMY_SP
};
use
errors
::
Handler
;
use
feature_gate
::{
Features
,
GatedCfg
};
...
...
@@ -219,16 +219,12 @@ pub fn is_value_str(&self) -> bool {
impl
MetaItem
{
pub
fn
name
(
&
self
)
->
Name
{
match
self
.node
{
MetaItemKind
::
Word
(
n
)
=>
n
,
MetaItemKind
::
NameValue
(
n
,
_
)
=>
n
,
MetaItemKind
::
List
(
n
,
_
)
=>
n
,
}
self
.name
}
pub
fn
value_str
(
&
self
)
->
Option
<
InternedString
>
{
match
self
.node
{
MetaItemKind
::
NameValue
(
_
,
ref
v
)
=>
{
MetaItemKind
::
NameValue
(
ref
v
)
=>
{
match
v
.node
{
ast
::
LitKind
::
Str
(
ref
s
,
_
)
=>
Some
((
*
s
)
.clone
()),
_
=>
None
,
...
...
@@ -240,14 +236,14 @@ pub fn value_str(&self) -> Option<InternedString> {
pub
fn
meta_item_list
(
&
self
)
->
Option
<&
[
NestedMetaItem
]
>
{
match
self
.node
{
MetaItemKind
::
List
(
_
,
ref
l
)
=>
Some
(
&
l
[
..
]),
MetaItemKind
::
List
(
ref
l
)
=>
Some
(
&
l
[
..
]),
_
=>
None
}
}
pub
fn
is_word
(
&
self
)
->
bool
{
match
self
.node
{
MetaItemKind
::
Word
(
_
)
=>
true
,
MetaItemKind
::
Word
=>
true
,
_
=>
false
,
}
}
...
...
@@ -320,15 +316,15 @@ pub fn mk_word_item(name: Name) -> P<MetaItem> {
}
pub
fn
mk_spanned_name_value_item
(
sp
:
Span
,
name
:
Name
,
value
:
ast
::
Lit
)
->
P
<
MetaItem
>
{
P
(
respan
(
sp
,
MetaItemKind
::
NameValue
(
name
,
value
))
)
P
(
MetaItem
{
span
:
sp
,
name
:
name
,
node
:
MetaItemKind
::
NameValue
(
value
)
}
)
}
pub
fn
mk_spanned_list_item
(
sp
:
Span
,
name
:
Name
,
items
:
Vec
<
NestedMetaItem
>
)
->
P
<
MetaItem
>
{
P
(
respan
(
sp
,
MetaItemKind
::
List
(
name
,
items
))
)
P
(
MetaItem
{
span
:
sp
,
name
:
name
,
node
:
MetaItemKind
::
List
(
items
)
}
)
}
pub
fn
mk_spanned_word_item
(
sp
:
Span
,
name
:
Name
)
->
P
<
MetaItem
>
{
P
(
respan
(
sp
,
MetaItemKind
::
Word
(
name
))
)
P
(
MetaItem
{
span
:
sp
,
name
:
name
,
node
:
MetaItemKind
::
Word
}
)
}
...
...
@@ -394,7 +390,11 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos, hi: By
Attribute
{
id
:
id
,
style
:
style
,
value
:
P
(
spanned
(
lo
,
hi
,
MetaItemKind
::
NameValue
(
token
::
intern
(
"doc"
),
lit
))),
value
:
P
(
MetaItem
{
span
:
mk_sp
(
lo
,
hi
),
name
:
token
::
intern
(
"doc"
),
node
:
MetaItemKind
::
NameValue
(
lit
),
}),
is_sugared_doc
:
true
,
span
:
mk_sp
(
lo
,
hi
),
}
...
...
@@ -472,13 +472,14 @@ pub enum InlineAttr {
/// Determine what `#[inline]` attribute is present in `attrs`, if any.
pub
fn
find_inline_attr
(
diagnostic
:
Option
<&
Handler
>
,
attrs
:
&
[
Attribute
])
->
InlineAttr
{
attrs
.iter
()
.fold
(
InlineAttr
::
None
,
|
ia
,
attr
|
{
attrs
.iter
()
.fold
(
InlineAttr
::
None
,
|
ia
,
attr
|
{
match
attr
.value.node
{
MetaItemKind
::
Word
(
n
)
if
n
==
"inline"
=>
{
_
if
attr
.value.name
!=
"inline"
=>
ia
,
MetaItemKind
::
Word
=>
{
mark_used
(
attr
);
InlineAttr
::
Hint
}
MetaItemKind
::
List
(
n
,
ref
items
)
if
n
==
"inline"
=>
{
MetaItemKind
::
List
(
ref
items
)
=>
{
mark_used
(
attr
);
if
items
.len
()
!=
1
{
diagnostic
.map
(|
d
|{
span_err!
(
d
,
attr
.span
,
E0534
,
"expected one argument"
);
});
...
...
@@ -511,7 +512,7 @@ pub fn requests_inline(attrs: &[Attribute]) -> bool {
/// Tests if a cfg-pattern matches the cfg set
pub
fn
cfg_matches
(
cfg
:
&
ast
::
MetaItem
,
sess
:
&
ParseSess
,
features
:
Option
<&
Features
>
)
->
bool
{
match
cfg
.node
{
ast
::
MetaItemKind
::
List
(
ref
pred
,
ref
mis
)
=>
{
ast
::
MetaItemKind
::
List
(
ref
mis
)
=>
{
for
mi
in
mis
.iter
()
{
if
!
mi
.is_meta_item
()
{
handle_errors
(
&
sess
.span_diagnostic
,
mi
.span
,
AttrError
::
UnsupportedLiteral
);
...
...
@@ -521,7 +522,7 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
// The unwraps below may look dangerous, but we've already asserted
// that they won't fail with the loop above.
match
&*
pred
.as_str
()
{
match
&*
cfg
.name
.as_str
()
{
"any"
=>
mis
.iter
()
.any
(|
mi
|
{
cfg_matches
(
mi
.meta_item
()
.unwrap
(),
sess
,
features
)
}),
...
...
@@ -542,7 +543,7 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
}
}
},
ast
::
MetaItemKind
::
Word
(
_
)
|
ast
::
MetaItemKind
::
NameValue
(
..
)
=>
{
ast
::
MetaItemKind
::
Word
|
ast
::
MetaItemKind
::
NameValue
(
..
)
=>
{
if
let
(
Some
(
feats
),
Some
(
gated_cfg
))
=
(
features
,
GatedCfg
::
gate
(
cfg
))
{
gated_cfg
.check_and_emit
(
sess
,
feats
);
}
...
...
@@ -880,7 +881,7 @@ pub fn require_unique_names(diagnostic: &Handler, metas: &[P<MetaItem>]) {
pub
fn
find_repr_attrs
(
diagnostic
:
&
Handler
,
attr
:
&
Attribute
)
->
Vec
<
ReprAttr
>
{
let
mut
acc
=
Vec
::
new
();
match
attr
.value.node
{
ast
::
MetaItemKind
::
List
(
s
,
ref
items
)
if
s
==
"repr"
=>
{
ast
::
MetaItemKind
::
List
(
ref
items
)
if
attr
.value.name
==
"repr"
=>
{
mark_used
(
attr
);
for
item
in
items
{
if
!
item
.is_meta_item
()
{
...
...
src/libsyntax/config.rs
浏览文件 @
e97686d0
...
...
@@ -133,7 +133,7 @@ pub fn in_cfg(&mut self, attrs: &[ast::Attribute]) -> bool {
}
let
mis
=
match
attr
.value.node
{
ast
::
MetaItemKind
::
List
(
_
,
ref
mis
)
if
is_cfg
(
&
attr
)
=>
mis
,
ast
::
MetaItemKind
::
List
(
ref
mis
)
if
is_cfg
(
&
attr
)
=>
mis
,
_
=>
return
true
};
...
...
src/libsyntax/feature_gate.rs
浏览文件 @
e97686d0
...
...
@@ -991,9 +991,9 @@ fn contains_novel_literal(item: &ast::MetaItem) -> bool {
use
ast
::
NestedMetaItemKind
::
*
;
match
item
.node
{
Word
(
..
)
=>
false
,
NameValue
(
_
,
ref
lit
)
=>
!
lit
.node
.is_str
(),
List
(
_
,
ref
list
)
=>
list
.iter
()
.any
(|
li
|
{
Word
=>
false
,
NameValue
(
ref
lit
)
=>
!
lit
.node
.is_str
(),
List
(
ref
list
)
=>
list
.iter
()
.any
(|
li
|
{
match
li
.node
{
MetaItem
(
ref
mi
)
=>
contains_novel_literal
(
&**
mi
),
Literal
(
_
)
=>
true
,
...
...
src/libsyntax/fold.rs
浏览文件 @
e97686d0
...
...
@@ -520,13 +520,14 @@ pub fn noop_fold_meta_list_item<T: Folder>(li: NestedMetaItem, fld: &mut T)
}
pub
fn
noop_fold_meta_item
<
T
:
Folder
>
(
mi
:
P
<
MetaItem
>
,
fld
:
&
mut
T
)
->
P
<
MetaItem
>
{
mi
.map
(|
Spanned
{
node
,
span
}|
Spanned
{
mi
.map
(|
MetaItem
{
name
,
node
,
span
}|
MetaItem
{
name
:
name
,
node
:
match
node
{
MetaItemKind
::
Word
(
id
)
=>
MetaItemKind
::
Word
(
id
)
,
MetaItemKind
::
List
(
id
,
mis
)
=>
{
MetaItemKind
::
List
(
id
,
mis
.move_map
(|
e
|
fld
.fold_meta_list_item
(
e
)))
}
MetaItemKind
::
NameValue
(
id
,
s
)
=>
MetaItemKind
::
NameValue
(
id
,
s
)
MetaItemKind
::
Word
=>
MetaItemKind
::
Word
,
MetaItemKind
::
List
(
mis
)
=>
{
MetaItemKind
::
List
(
mis
.move_map
(|
e
|
fld
.fold_meta_list_item
(
e
)))
}
,
MetaItemKind
::
NameValue
(
s
)
=>
MetaItemKind
::
NameValue
(
s
),
},
span
:
fld
.new_span
(
span
)
})
...
...
src/libsyntax/parse/attr.rs
浏览文件 @
e97686d0
...
...
@@ -227,23 +227,15 @@ pub fn parse_meta_item(&mut self) -> PResult<'a, P<ast::MetaItem>> {
let
lo
=
self
.span.lo
;
let
ident
=
self
.parse_ident
()
?
;
match
self
.token
{
token
::
Eq
=>
{
self
.bump
();
let
lit
=
self
.parse_unsuffixed_lit
()
?
;
let
hi
=
self
.prev_span.hi
;
Ok
(
P
(
spanned
(
lo
,
hi
,
ast
::
MetaItemKind
::
NameValue
(
ident
.name
,
lit
))))
}
token
::
OpenDelim
(
token
::
Paren
)
=>
{
let
inner_items
=
self
.parse_meta_seq
()
?
;
let
hi
=
self
.prev_span.hi
;
Ok
(
P
(
spanned
(
lo
,
hi
,
ast
::
MetaItemKind
::
List
(
ident
.name
,
inner_items
))))
}
_
=>
{
let
hi
=
self
.prev_span.hi
;
Ok
(
P
(
spanned
(
lo
,
hi
,
ast
::
MetaItemKind
::
Word
(
ident
.name
))))
}
}
let
node
=
if
self
.eat
(
&
token
::
Eq
)
{
ast
::
MetaItemKind
::
NameValue
(
self
.parse_unsuffixed_lit
()
?
)
}
else
if
self
.token
==
token
::
OpenDelim
(
token
::
Paren
)
{
ast
::
MetaItemKind
::
List
(
self
.parse_meta_seq
()
?
)
}
else
{
ast
::
MetaItemKind
::
Word
};
let
hi
=
self
.prev_span.hi
;
Ok
(
P
(
ast
::
MetaItem
{
name
:
ident
.name
,
node
:
node
,
span
:
mk_sp
(
lo
,
hi
)
}))
}
/// matches meta_item_inner : (meta_item | UNSUFFIXED_LIT) ;
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
e97686d0
...
...
@@ -777,16 +777,16 @@ fn print_meta_list_item(&mut self, item: &ast::NestedMetaItem) -> io::Result<()>
fn
print_meta_item
(
&
mut
self
,
item
:
&
ast
::
MetaItem
)
->
io
::
Result
<
()
>
{
try!
(
self
.ibox
(
INDENT_UNIT
));
match
item
.node
{
ast
::
MetaItemKind
::
Word
(
ref
name
)
=>
{
try!
(
word
(
self
.writer
(),
&
name
.as_str
()));
ast
::
MetaItemKind
::
Word
=>
{
try!
(
word
(
self
.writer
(),
&
item
.
name
.as_str
()));
}
ast
::
MetaItemKind
::
NameValue
(
ref
name
,
ref
value
)
=>
{
try!
(
self
.word_space
(
&
name
.as_str
()));
ast
::
MetaItemKind
::
NameValue
(
ref
value
)
=>
{
try!
(
self
.word_space
(
&
item
.
name
.as_str
()));
try!
(
self
.word_space
(
"="
));
try!
(
self
.print_literal
(
value
));
}
ast
::
MetaItemKind
::
List
(
ref
name
,
ref
items
)
=>
{
try!
(
word
(
self
.writer
(),
&
name
.as_str
()));
ast
::
MetaItemKind
::
List
(
ref
items
)
=>
{
try!
(
word
(
self
.writer
(),
&
item
.
name
.as_str
()));
try!
(
self
.popen
());
try!
(
self
.commasep
(
Consistent
,
&
items
[
..
],
...
...
src/libsyntax/std_inject.rs
浏览文件 @
e97686d0
...
...
@@ -70,7 +70,8 @@ pub fn maybe_inject_crates_ref(sess: &ParseSess,
attrs
:
vec!
[
ast
::
Attribute
{
style
:
ast
::
AttrStyle
::
Outer
,
value
:
P
(
ast
::
MetaItem
{
node
:
ast
::
MetaItemKind
::
Word
(
token
::
intern
(
"prelude_import"
)),
name
:
token
::
intern
(
"prelude_import"
),
node
:
ast
::
MetaItemKind
::
Word
,
span
:
span
,
}),
id
:
attr
::
mk_attr_id
(),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录