Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
99191c2e
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,发现更多精彩内容 >>
提交
99191c2e
编写于
12月 05, 2019
作者:
M
Mazdak Farrokhzad
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
parse_meta: ditch parse_in_attr
上级
cbc9f683
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
99 addition
and
48 deletion
+99
-48
src/librustc_parse/config.rs
src/librustc_parse/config.rs
+4
-21
src/librustc_parse/lib.rs
src/librustc_parse/lib.rs
+0
-11
src/librustc_parse/parser/attr.rs
src/librustc_parse/parser/attr.rs
+17
-2
src/librustc_parse/validate_attr.rs
src/librustc_parse/validate_attr.rs
+35
-3
src/libsyntax_expand/proc_macro.rs
src/libsyntax_expand/proc_macro.rs
+5
-5
src/test/ui/malformed/malformed-meta-delim.rs
src/test/ui/malformed/malformed-meta-delim.rs
+11
-0
src/test/ui/malformed/malformed-meta-delim.stderr
src/test/ui/malformed/malformed-meta-delim.stderr
+24
-0
src/test/ui/on-unimplemented/expected-comma-found-token.rs
src/test/ui/on-unimplemented/expected-comma-found-token.rs
+1
-1
src/test/ui/on-unimplemented/expected-comma-found-token.stderr
...est/ui/on-unimplemented/expected-comma-found-token.stderr
+2
-5
未找到文件。
src/librustc_parse/config.rs
浏览文件 @
99191c2e
...
...
@@ -18,7 +18,6 @@
use
syntax
::
edition
::
Edition
;
use
syntax
::
mut_visit
::
*
;
use
syntax
::
ptr
::
P
;
use
syntax
::
tokenstream
::
DelimSpan
;
use
syntax
::
sess
::
ParseSess
;
use
syntax
::
util
::
map_in_place
::
MapInPlace
;
use
syntax_pos
::
Span
;
...
...
@@ -139,11 +138,10 @@ fn process_cfg_attr(&mut self, attr: Attribute) -> Vec<Attribute> {
}
fn
parse_cfg_attr
(
&
self
,
attr
:
&
Attribute
)
->
Option
<
(
MetaItem
,
Vec
<
(
AttrItem
,
Span
)
>
)
>
{
match
&
attr
.get_normal_item
()
.args
{
ast
::
MacArgs
::
Delimited
(
dspan
,
delim
,
tts
)
if
!
tts
.is_empty
()
=>
{
if
let
ast
::
MacDelimiter
::
Brace
|
ast
::
MacDelimiter
::
Bracket
=
delim
{
self
.error_malformed_cfg_attr_wrong_delim
(
*
dspan
);
}
match
attr
.get_normal_item
()
.args
{
ast
::
MacArgs
::
Delimited
(
dspan
,
delim
,
ref
tts
)
if
!
tts
.is_empty
()
=>
{
let
msg
=
"wrong `cfg_attr` delimiters"
;
validate_attr
::
check_meta_bad_delim
(
self
.sess
,
dspan
,
delim
,
msg
);
match
parse_in
(
self
.sess
,
tts
.clone
(),
"`cfg_attr` input"
,
|
p
|
p
.parse_cfg_attr
())
{
Ok
(
r
)
=>
return
Some
(
r
),
Err
(
mut
e
)
=>
e
...
...
@@ -157,21 +155,6 @@ fn parse_cfg_attr(&self, attr: &Attribute) -> Option<(MetaItem, Vec<(AttrItem, S
None
}
fn
error_malformed_cfg_attr_wrong_delim
(
&
self
,
dspan
:
DelimSpan
)
{
self
.sess
.span_diagnostic
.struct_span_err
(
dspan
.entire
(),
"wrong `cfg_attr` delimiters"
)
.multipart_suggestion
(
"the delimiters should be `(` and `)`"
,
vec!
[
(
dspan
.open
,
"("
.to_string
()),
(
dspan
.close
,
")"
.to_string
()),
],
Applicability
::
MachineApplicable
,
)
.emit
();
}
fn
error_malformed_cfg_attr_missing
(
&
self
,
span
:
Span
)
{
self
.sess
.span_diagnostic
...
...
src/librustc_parse/lib.rs
浏览文件 @
99191c2e
...
...
@@ -284,17 +284,6 @@ pub fn parse_in<'a, T>(
Ok
(
result
)
}
/// Runs the given subparser `f` on the tokens of the given `attr`'s item.
fn
parse_in_attr
<
'a
,
T
>
(
sess
:
&
'a
ParseSess
,
attr
:
&
ast
::
Attribute
,
f
:
impl
FnMut
(
&
mut
Parser
<
'a
>
)
->
PResult
<
'a
,
T
>
,
)
->
PResult
<
'a
,
T
>
{
// FIXME(#66940, Centril | petrochenkov): refactor this function so it doesn't
// require reconstructing and immediately re-parsing delimiters.
parse_in
(
sess
,
attr
.get_normal_item
()
.args
.outer_tokens
(),
"attribute"
,
f
)
}
// NOTE(Centril): The following probably shouldn't be here but it acknowledges the
// fact that architecturally, we are using parsing (read on below to understand why).
...
...
src/librustc_parse/parser/attr.rs
浏览文件 @
99191c2e
...
...
@@ -220,7 +220,7 @@ pub fn parse_attr_item(&mut self) -> PResult<'a, ast::AttrItem> {
Ok
(
attrs
)
}
pub
(
super
)
fn
parse_unsuffixed_lit
(
&
mut
self
)
->
PResult
<
'a
,
ast
::
Lit
>
{
crate
fn
parse_unsuffixed_lit
(
&
mut
self
)
->
PResult
<
'a
,
ast
::
Lit
>
{
let
lit
=
self
.parse_lit
()
?
;
debug!
(
"checking if {:?} is unusuffixed"
,
lit
);
...
...
@@ -247,12 +247,27 @@ pub fn parse_cfg_attr(&mut self) -> PResult<'a, (ast::MetaItem, Vec<(ast::AttrIt
let
lo
=
self
.token.span
;
let
item
=
self
.parse_attr_item
()
?
;
expanded_attrs
.push
((
item
,
lo
.to
(
self
.prev_span
)));
self
.eat
(
&
token
::
Comma
);
if
!
self
.eat
(
&
token
::
Comma
)
{
break
;
}
}
Ok
((
cfg_predicate
,
expanded_attrs
))
}
/// Matches `COMMASEP(meta_item_inner)`.
crate
fn
parse_meta_seq_top
(
&
mut
self
)
->
PResult
<
'a
,
Vec
<
ast
::
NestedMetaItem
>>
{
// Presumably, the majority of the time there will only be one attr.
let
mut
nmis
=
Vec
::
with_capacity
(
1
);
while
self
.token.kind
!=
token
::
Eof
{
nmis
.push
(
self
.parse_meta_item_inner
()
?
);
if
!
self
.eat
(
&
token
::
Comma
)
{
break
;
}
}
Ok
(
nmis
)
}
/// Matches the following grammar (per RFC 1559).
///
/// meta_item : PATH ( '=' UNSUFFIXED_LIT | '(' meta_item_inner? ')' )? ;
...
...
src/librustc_parse/validate_attr.rs
浏览文件 @
99191c2e
//! Meta-syntax validation logic of attributes for post-expansion.
use
crate
::
parse_in
;
use
rustc_errors
::{
PResult
,
Applicability
};
use
rustc_feature
::{
AttributeTemplate
,
BUILTIN_ATTRIBUTE_MAP
};
use
syntax
::
ast
::{
self
,
Attribute
,
AttrKind
,
Ident
,
MacArgs
,
MetaItem
,
MetaItemKind
};
use
syntax
::
ast
::{
self
,
Attribute
,
AttrKind
,
Ident
,
MacArgs
,
M
acDelimiter
,
M
etaItem
,
MetaItemKind
};
use
syntax
::
attr
::
mk_name_value_item_str
;
use
syntax
::
early_buffered_lints
::
ILL_FORMED_ATTRIBUTE_INPUT
;
use
syntax
::
tokenstream
::
DelimSpan
;
use
syntax
::
sess
::
ParseSess
;
use
syntax_pos
::{
Symbol
,
sym
};
...
...
@@ -27,9 +30,20 @@ pub fn check_meta(sess: &ParseSess, attr: &Attribute) {
pub
fn
parse_meta
<
'a
>
(
sess
:
&
'a
ParseSess
,
attr
:
&
Attribute
)
->
PResult
<
'a
,
MetaItem
>
{
Ok
(
match
attr
.kind
{
AttrKind
::
Normal
(
ref
item
)
=>
MetaItem
{
path
:
item
.path
.clone
(),
kind
:
super
::
parse_in_attr
(
sess
,
attr
,
|
p
|
p
.parse_meta_item_kind
())
?
,
span
:
attr
.span
,
path
:
item
.path
.clone
(),
kind
:
match
&
attr
.get_normal_item
()
.args
{
MacArgs
::
Empty
=>
MetaItemKind
::
Word
,
MacArgs
::
Eq
(
_
,
t
)
=>
{
let
v
=
parse_in
(
sess
,
t
.clone
(),
"name value"
,
|
p
|
p
.parse_unsuffixed_lit
())
?
;
MetaItemKind
::
NameValue
(
v
)
}
MacArgs
::
Delimited
(
dspan
,
delim
,
t
)
=>
{
check_meta_bad_delim
(
sess
,
*
dspan
,
*
delim
,
"wrong meta list delimiters"
);
let
nmis
=
parse_in
(
sess
,
t
.clone
(),
"meta list"
,
|
p
|
p
.parse_meta_seq_top
())
?
;
MetaItemKind
::
List
(
nmis
)
}
}
},
AttrKind
::
DocComment
(
comment
)
=>
{
mk_name_value_item_str
(
Ident
::
new
(
sym
::
doc
,
attr
.span
),
comment
,
attr
.span
)
...
...
@@ -37,6 +51,24 @@ pub fn parse_meta<'a>(sess: &'a ParseSess, attr: &Attribute) -> PResult<'a, Meta
})
}
crate
fn
check_meta_bad_delim
(
sess
:
&
ParseSess
,
span
:
DelimSpan
,
delim
:
MacDelimiter
,
msg
:
&
str
)
{
if
let
ast
::
MacDelimiter
::
Parenthesis
=
delim
{
return
;
}
sess
.span_diagnostic
.struct_span_err
(
span
.entire
(),
msg
)
.multipart_suggestion
(
"the delimiters should be `(` and `)`"
,
vec!
[
(
span
.open
,
"("
.to_string
()),
(
span
.close
,
")"
.to_string
()),
],
Applicability
::
MachineApplicable
,
)
.emit
();
}
/// Checks that the given meta-item is compatible with this `AttributeTemplate`.
fn
is_attr_template_compatible
(
template
:
&
AttributeTemplate
,
meta
:
&
ast
::
MetaItemKind
)
->
bool
{
match
meta
{
...
...
src/libsyntax_expand/proc_macro.rs
浏览文件 @
99191c2e
...
...
@@ -188,14 +188,14 @@ fn expand(&self,
Some
(
x
)
=>
x
,
};
let
mut
retain_in_fm
=
tru
e
;
let
mut
retain_in_map
=
tru
e
;
let
mut
error_reported_filter_map
=
fals
e
;
let
mut
error_reported_map
=
fals
e
;
let
traits
=
nmis
.into_iter
()
// 2) Moreover, let's ensure we have a path and not `#[derive("foo")]`.
.filter_map
(|
nmi
|
match
nmi
{
NestedMetaItem
::
Literal
(
lit
)
=>
{
retain_in_fm
=
fals
e
;
error_reported_filter_map
=
tru
e
;
cx
.struct_span_err
(
lit
.span
,
"expected path to a trait, found literal"
)
.help
(
"for example, write `#[derive(Debug)]` for `Debug`"
)
.emit
();
...
...
@@ -209,7 +209,7 @@ fn expand(&self,
// wanted this trait to be derived, so let's keep it.
.map
(|
mi
|
{
let
mut
traits_dont_accept
=
|
title
,
action
|
{
retain_in_map
=
fals
e
;
error_reported_map
=
tru
e
;
let
sp
=
mi
.span
.with_lo
(
mi
.path.span
.hi
());
cx
.struct_span_err
(
sp
,
title
)
.span_suggestion
(
...
...
@@ -235,7 +235,7 @@ fn expand(&self,
});
result
.extend
(
traits
);
retain_in_fm
&&
retain_in
_map
!
error_reported_filter_map
&&
!
error_reported
_map
});
result
}
src/test/ui/malformed/malformed-meta-delim.rs
0 → 100644
浏览文件 @
99191c2e
fn
main
()
{}
#[allow
{
foo_lint
}
]
//~^ ERROR wrong meta list delimiters
//~| HELP the delimiters should be `(` and `)`
fn
delim_brace
()
{}
#[allow
[
foo_lint
]
]
//~^ ERROR wrong meta list delimiters
//~| HELP the delimiters should be `(` and `)`
fn
delim_bracket
()
{}
src/test/ui/malformed/malformed-meta-delim.stderr
0 → 100644
浏览文件 @
99191c2e
error: wrong meta list delimiters
--> $DIR/malformed-meta-delim.rs:3:9
|
LL | #[allow { foo_lint } ]
| ^^^^^^^^^^^^
|
help: the delimiters should be `(` and `)`
|
LL | #[allow ( foo_lint ) ]
| ^ ^
error: wrong meta list delimiters
--> $DIR/malformed-meta-delim.rs:8:9
|
LL | #[allow [ foo_lint ] ]
| ^^^^^^^^^^^^
|
help: the delimiters should be `(` and `)`
|
LL | #[allow ( foo_lint ) ]
| ^ ^
error: aborting due to 2 previous errors
src/test/ui/on-unimplemented/expected-comma-found-token.rs
浏览文件 @
99191c2e
...
...
@@ -6,7 +6,7 @@
#[rustc_on_unimplemented(
message=
"the message"
label=
"the label"
//~ ERROR expected
one of `)` or
`,`, found `label`
label=
"the label"
//~ ERROR expected `,`, found `label`
)]
trait
T
{}
...
...
src/test/ui/on-unimplemented/expected-comma-found-token.stderr
浏览文件 @
99191c2e
error: expected
one of `)` or
`,`, found `label`
error: expected `,`, found `label`
--> $DIR/expected-comma-found-token.rs:9:5
|
LL | message="the message"
| -
| |
| expected one of `)` or `,`
| help: missing `,`
| - expected `,`
LL | label="the label"
| ^^^^^ unexpected token
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录