Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
0e505d42
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,发现更多精彩内容 >>
提交
0e505d42
编写于
4月 24, 2019
作者:
E
Esteban Küber
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add guard for missing comma in macro call suggestion
上级
e305df18
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
9 deletion
+27
-9
src/libsyntax/tokenstream.rs
src/libsyntax/tokenstream.rs
+4
-2
src/test/ui/macros/missing-comma.rs
src/test/ui/macros/missing-comma.rs
+7
-0
src/test/ui/macros/missing-comma.stderr
src/test/ui/macros/missing-comma.stderr
+16
-7
未找到文件。
src/libsyntax/tokenstream.rs
浏览文件 @
0e505d42
...
...
@@ -182,8 +182,10 @@ pub(crate) fn add_comma(&self) -> Option<(TokenStream, Span)> {
(
_
,
(
TokenTree
::
Token
(
_
,
token
::
Token
::
Comma
),
_
))
=>
continue
,
((
TokenTree
::
Token
(
sp
,
token_left
),
NonJoint
),
(
TokenTree
::
Token
(
_
,
token_right
),
_
))
if
(
token_left
.is_ident
()
||
token_left
.is_lit
())
&&
(
token_right
.is_ident
()
||
token_right
.is_lit
())
=>
*
sp
,
if
((
token_left
.is_ident
()
&&
!
token_left
.is_reserved_ident
())
||
token_left
.is_lit
())
&&
((
token_right
.is_ident
()
&&
!
token_right
.is_reserved_ident
())
||
token_right
.is_lit
())
=>
*
sp
,
((
TokenTree
::
Delimited
(
sp
,
..
),
NonJoint
),
_
)
=>
sp
.entire
(),
_
=>
continue
,
};
...
...
src/test/ui/macros/missing-comma.rs
浏览文件 @
0e505d42
...
...
@@ -10,6 +10,10 @@
(
$lvl:expr
,
$
(
$arg:tt
)
+
)
=>
{}
}
macro_rules!
check
{
(
$ty:ty
,
$expected:expr
)
=>
{};
(
$ty_of:expr
,
$expected:expr
)
=>
{};
}
fn
main
()
{
println!
(
"{}"
a
);
...
...
@@ -24,4 +28,7 @@ fn main() {
//~^ ERROR no rules expected the token `d`
bar!
(
Level
::
Error
,
);
//~^ ERROR unexpected end of macro invocation
check!
(
<
str
as
Debug
>
::
fmt
,
"fmt"
);
check!
(
<
str
as
Debug
>
::
fmt
,
"fmt"
,);
//~^ ERROR no rules expected the token `,`
}
src/test/ui/macros/missing-comma.stderr
浏览文件 @
0e505d42
error: expected token: `,`
--> $DIR/missing-comma.rs:1
5
:19
--> $DIR/missing-comma.rs:1
9
:19
|
LL | println!("{}" a);
| ^
error: no rules expected the token `b`
--> $DIR/missing-comma.rs:
17
:12
--> $DIR/missing-comma.rs:
21
:12
|
LL | macro_rules! foo {
| ---------------- when calling this macro
...
...
@@ -16,7 +16,7 @@ LL | foo!(a b);
| help: missing comma here
error: no rules expected the token `e`
--> $DIR/missing-comma.rs:
19
:21
--> $DIR/missing-comma.rs:
23
:21
|
LL | macro_rules! foo {
| ---------------- when calling this macro
...
...
@@ -27,7 +27,7 @@ LL | foo!(a, b, c, d e);
| help: missing comma here
error: no rules expected the token `d`
--> $DIR/missing-comma.rs:2
1
:18
--> $DIR/missing-comma.rs:2
5
:18
|
LL | macro_rules! foo {
| ---------------- when calling this macro
...
...
@@ -38,7 +38,7 @@ LL | foo!(a, b, c d, e);
| help: missing comma here
error: no rules expected the token `d`
--> $DIR/missing-comma.rs:2
3
:18
--> $DIR/missing-comma.rs:2
7
:18
|
LL | macro_rules! foo {
| ---------------- when calling this macro
...
...
@@ -47,7 +47,7 @@ LL | foo!(a, b, c d e);
| ^ no rules expected this token in macro call
error: unexpected end of macro invocation
--> $DIR/missing-comma.rs:2
5
:23
--> $DIR/missing-comma.rs:2
9
:23
|
LL | macro_rules! bar {
| ---------------- when calling this macro
...
...
@@ -55,5 +55,14 @@ LL | macro_rules! bar {
LL | bar!(Level::Error, );
| ^ missing tokens in macro arguments
error: aborting due to 6 previous errors
error: no rules expected the token `,`
--> $DIR/missing-comma.rs:32:38
|
LL | macro_rules! check {
| ------------------ when calling this macro
...
LL | check!(<str as Debug>::fmt, "fmt",);
| ^ no rules expected this token in macro call
error: aborting due to 7 previous errors
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录