Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b13eb61a
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,发现更多精彩内容 >>
提交
b13eb61a
编写于
6月 07, 2022
作者:
M
Michael Goulet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Recover missing comma after match arm
上级
9f7e997c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
44 addition
and
23 deletion
+44
-23
compiler/rustc_parse/src/parser/expr.rs
compiler/rustc_parse/src/parser/expr.rs
+38
-13
src/test/ui/parser/match-arm-without-braces.rs
src/test/ui/parser/match-arm-without-braces.rs
+3
-3
src/test/ui/parser/match-arm-without-braces.stderr
src/test/ui/parser/match-arm-without-braces.stderr
+3
-7
未找到文件。
compiler/rustc_parse/src/parser/expr.rs
浏览文件 @
b13eb61a
...
...
@@ -2718,13 +2718,12 @@ fn check_let_expr(expr: &Expr) -> (bool, bool) {
));
}
this
.expect_one_of
(
&
[
token
::
Comma
],
&
[
token
::
CloseDelim
(
Delimiter
::
Brace
)])
.map_err
(|
mut
err
|
{
match
(
sm
.span_to_lines
(
expr
.span
),
sm
.span_to_lines
(
arm_start_span
))
{
(
Ok
(
ref
expr_lines
),
Ok
(
ref
arm_start_lines
))
if
arm_start_lines
.lines
[
0
]
.end_col
==
expr_lines
.lines
[
0
]
.end_col
&&
expr_lines
.lines
.len
()
==
2
&&
this
.token
==
token
::
FatArrow
=>
.or_else
(|
mut
err
|
{
if
this
.token
==
token
::
FatArrow
{
if
let
Ok
(
expr_lines
)
=
sm
.span_to_lines
(
expr
.span
)
&&
let
Ok
(
arm_start_lines
)
=
sm
.span_to_lines
(
arm_start_span
)
&&
arm_start_lines
.lines
[
0
]
.end_col
==
expr_lines
.lines
[
0
]
.end_col
&&
expr_lines
.lines
.len
()
==
2
{
// We check whether there's any trailing code in the parse span,
// if there isn't, we very likely have the following:
...
...
@@ -2743,15 +2742,41 @@ fn check_let_expr(expr: &Expr) -> (bool, bool) {
","
.to_owned
(),
Applicability
::
MachineApplicable
,
);
return
Err
(
err
);
}
_
=>
{
err
.span_label
(
arrow_span
,
"while parsing the `match` arm starting here"
,
);
}
else
{
// FIXME(compiler-errors): We could also recover `; PAT =>` here
// Try to parse a following `PAT =>`, if successful
// then we should recover.
let
mut
snapshot
=
this
.create_snapshot_for_diagnostic
();
let
pattern_follows
=
snapshot
.parse_pat_allow_top_alt
(
None
,
RecoverComma
::
Yes
,
RecoverColon
::
Yes
,
CommaRecoveryMode
::
EitherTupleOrPipe
,
)
.map_err
(|
err
|
err
.cancel
())
.is_ok
();
if
pattern_follows
&&
snapshot
.check
(
&
TokenKind
::
FatArrow
)
{
err
.cancel
();
this
.struct_span_err
(
hi
.shrink_to_hi
(),
"expected `,` following `match` arm"
,
)
.span_suggestion
(
hi
.shrink_to_hi
(),
"missing a comma here to end this `match` arm"
,
","
.to_owned
(),
Applicability
::
MachineApplicable
,
)
.emit
();
return
Ok
(
true
);
}
}
err
err
.span_label
(
arrow_span
,
"while parsing the `match` arm starting here"
);
Err
(
err
)
})
?
;
}
else
{
this
.eat
(
&
token
::
Comma
);
...
...
src/test/ui/parser/match-arm-without-braces.rs
浏览文件 @
b13eb61a
...
...
@@ -45,9 +45,9 @@ fn main() {
15
;
}
match
S
::
get
(
16
)
{
Some
(
Val
::
Foo
)
=>
17
_
=>
18
,
//~ ERROR expected one of
}
Some
(
Val
::
Foo
)
=>
17
//~ ERROR expected `,` following `match` arm
_
=>
18
,
}
;
match
S
::
get
(
19
)
{
Some
(
Val
::
Foo
)
=>
20
;
//~ ERROR `match` arm body without braces
...
...
src/test/ui/parser/match-arm-without-braces.stderr
浏览文件 @
b13eb61a
...
...
@@ -52,15 +52,11 @@ LL ~ { 14;
LL ~ 15; }
|
error: expected
one of `,`, `.`, `?`, `}`, or an operator, found reserved identifier `_`
--> $DIR/match-arm-without-braces.rs:4
9:
9
error: expected
`,` following `match` arm
--> $DIR/match-arm-without-braces.rs:4
8:2
9
|
LL | Some(Val::Foo) => 17
| -- - expected one of `,`, `.`, `?`, `}`, or an operator
| |
| while parsing the `match` arm starting here
LL | _ => 18,
| ^ unexpected token
| ^ help: missing a comma here to end this `match` arm: `,`
error: `match` arm body without braces
--> $DIR/match-arm-without-braces.rs:53:11
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录