Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
d9d1f237
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
d9d1f237
编写于
12月 15, 2019
作者:
M
Mazdak Farrokhzad
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
improve lower_pat_slice docs + while -> for
上级
66bb978a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
26 addition
and
12 deletion
+26
-12
src/librustc/hir/lowering.rs
src/librustc/hir/lowering.rs
+26
-12
未找到文件。
src/librustc/hir/lowering.rs
浏览文件 @
d9d1f237
...
...
@@ -2852,19 +2852,23 @@ fn lower_pat_tuple(
let
mut
rest
=
None
;
let
mut
iter
=
pats
.iter
()
.enumerate
();
while
let
Some
((
idx
,
pat
))
=
iter
.next
()
{
// Interpret the first `..` pattern as a subtuple pattern.
for
(
idx
,
pat
)
in
iter
.by_ref
()
{
// Interpret the first `..` pattern as a sub-tuple pattern.
// Note that unlike for slice patterns,
// where `xs @ ..` is a legal sub-slice pattern,
// it is not a legal sub-tuple pattern.
if
pat
.is_rest
()
{
rest
=
Some
((
idx
,
pat
.span
));
break
;
}
// It was not a sub
slic
e pattern so lower it normally.
// It was not a sub
-tupl
e pattern so lower it normally.
elems
.push
(
self
.lower_pat
(
pat
));
}
while
let
Some
((
_
,
pat
))
=
iter
.next
()
{
// There was a previous sub
tuple pattern; make sure we don't allow more
.
for
(
_
,
pat
)
in
iter
{
// There was a previous sub
-tuple pattern; make sure we don't allow more..
.
if
pat
.is_rest
()
{
// ...but there was one again, so error.
self
.ban_extra_rest_pat
(
pat
.span
,
rest
.unwrap
()
.1
,
ctx
);
}
else
{
elems
.push
(
self
.lower_pat
(
pat
));
...
...
@@ -2874,6 +2878,12 @@ fn lower_pat_tuple(
(
elems
.into
(),
rest
.map
(|(
ddpos
,
_
)|
ddpos
))
}
/// Lower a slice pattern of form `[pat_0, ..., pat_n]` into
/// `hir::PatKind::Slice(before, slice, after)`.
///
/// When encountering `($binding_mode $ident @)? ..` (`slice`),
/// this is interpreted as a sub-slice pattern semantically.
/// Patterns that follow, which are not like `slice` -- or an error occurs, are in `after`.
fn
lower_pat_slice
(
&
mut
self
,
pats
:
&
[
AstP
<
Pat
>
])
->
hir
::
PatKind
{
let
mut
before
=
Vec
::
new
();
let
mut
after
=
Vec
::
new
();
...
...
@@ -2881,14 +2891,17 @@ fn lower_pat_slice(&mut self, pats: &[AstP<Pat>]) -> hir::PatKind {
let
mut
prev_rest_span
=
None
;
let
mut
iter
=
pats
.iter
();
while
let
Some
(
pat
)
=
iter
.next
()
{
// Interpret the first `((ref mut?)? x @)? ..` pattern as a subslice pattern.
// Lower all the patterns until the first occurence of a sub-slice pattern.
for
pat
in
iter
.by_ref
()
{
match
pat
.kind
{
// Found a sub-slice pattern `..`. Record, lower it to `_`, and stop here.
PatKind
::
Rest
=>
{
prev_rest_span
=
Some
(
pat
.span
);
slice
=
Some
(
self
.pat_wild_with_node_id_of
(
pat
));
break
;
},
// Found a sub-slice pattern `$binding_mode $ident @ ..`.
// Record, lower it to `$binding_mode $ident @ _`, and stop here.
PatKind
::
Ident
(
ref
bm
,
ident
,
Some
(
ref
sub
))
if
sub
.is_rest
()
=>
{
prev_rest_span
=
Some
(
sub
.span
);
let
lower_sub
=
|
this
:
&
mut
Self
|
Some
(
this
.pat_wild_with_node_id_of
(
sub
));
...
...
@@ -2896,14 +2909,13 @@ fn lower_pat_slice(&mut self, pats: &[AstP<Pat>]) -> hir::PatKind {
slice
=
Some
(
self
.pat_with_node_id_of
(
pat
,
node
));
break
;
},
_
=>
{}
// It was not a subslice pattern so lower it normally.
_
=>
before
.push
(
self
.lower_pat
(
pat
)),
}
// It was not a subslice pattern so lower it normally.
before
.push
(
self
.lower_pat
(
pat
));
}
while
let
Some
(
pat
)
=
iter
.next
()
{
// Lower all the patterns after the first sub-slice pattern.
for
pat
in
iter
{
// There was a previous subslice pattern; make sure we don't allow more.
let
rest_span
=
match
pat
.kind
{
PatKind
::
Rest
=>
Some
(
pat
.span
),
...
...
@@ -2915,8 +2927,10 @@ fn lower_pat_slice(&mut self, pats: &[AstP<Pat>]) -> hir::PatKind {
_
=>
None
,
};
if
let
Some
(
rest_span
)
=
rest_span
{
// We have e.g., `[a, .., b, ..]`. That's no good, error!
self
.ban_extra_rest_pat
(
rest_span
,
prev_rest_span
.unwrap
(),
"slice"
);
}
else
{
// Lower the pattern normally.
after
.push
(
self
.lower_pat
(
pat
));
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录