Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
43a0268f
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,发现更多精彩内容 >>
提交
43a0268f
编写于
8月 26, 2022
作者:
N
Nicholas Nethercote
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use boxed slices in `PatKind`.
To shrink it a little more.
上级
a40124e0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
36 addition
and
25 deletion
+36
-25
compiler/rustc_middle/src/thir.rs
compiler/rustc_middle/src/thir.rs
+10
-10
compiler/rustc_middle/src/thir/visit.rs
compiler/rustc_middle/src/thir/visit.rs
+3
-3
compiler/rustc_mir_build/src/build/matches/mod.rs
compiler/rustc_mir_build/src/build/matches/mod.rs
+3
-3
compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
+3
-3
compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
+10
-5
compiler/rustc_mir_build/src/thir/pattern/mod.rs
compiler/rustc_mir_build/src/thir/pattern/mod.rs
+7
-1
未找到文件。
compiler/rustc_middle/src/thir.rs
浏览文件 @
43a0268f
...
...
@@ -634,22 +634,22 @@ pub enum PatKind<'tcx> {
/// irrefutable when there is a slice pattern and both `prefix` and `suffix` are empty.
/// e.g., `&[ref xs @ ..]`.
Slice
{
prefix
:
Vec
<
Box
<
Pat
<
'tcx
>>
>
,
prefix
:
Box
<
[
Box
<
Pat
<
'tcx
>>
]
>
,
slice
:
Option
<
Box
<
Pat
<
'tcx
>>>
,
suffix
:
Vec
<
Box
<
Pat
<
'tcx
>>
>
,
suffix
:
Box
<
[
Box
<
Pat
<
'tcx
>>
]
>
,
},
/// Fixed match against an array; irrefutable.
Array
{
prefix
:
Vec
<
Box
<
Pat
<
'tcx
>>
>
,
prefix
:
Box
<
[
Box
<
Pat
<
'tcx
>>
]
>
,
slice
:
Option
<
Box
<
Pat
<
'tcx
>>>
,
suffix
:
Vec
<
Box
<
Pat
<
'tcx
>>
>
,
suffix
:
Box
<
[
Box
<
Pat
<
'tcx
>>
]
>
,
},
/// An or-pattern, e.g. `p | q`.
/// Invariant: `pats.len() >= 2`.
Or
{
pats
:
Vec
<
Box
<
Pat
<
'tcx
>>
>
,
pats
:
Box
<
[
Box
<
Pat
<
'tcx
>>
]
>
,
},
}
...
...
@@ -775,7 +775,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
PatKind
::
Slice
{
ref
prefix
,
ref
slice
,
ref
suffix
}
|
PatKind
::
Array
{
ref
prefix
,
ref
slice
,
ref
suffix
}
=>
{
write!
(
f
,
"["
)
?
;
for
p
in
prefix
{
for
p
in
prefix
.iter
()
{
write!
(
f
,
"{}{}"
,
start_or_comma
(),
p
)
?
;
}
if
let
Some
(
ref
slice
)
=
*
slice
{
...
...
@@ -786,13 +786,13 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
}
write!
(
f
,
".."
)
?
;
}
for
p
in
suffix
{
for
p
in
suffix
.iter
()
{
write!
(
f
,
"{}{}"
,
start_or_comma
(),
p
)
?
;
}
write!
(
f
,
"]"
)
}
PatKind
::
Or
{
ref
pats
}
=>
{
for
pat
in
pats
{
for
pat
in
pats
.iter
()
{
write!
(
f
,
"{}{}"
,
start_or_continue
(
" | "
),
pat
)
?
;
}
Ok
(())
...
...
@@ -809,8 +809,8 @@ mod size_asserts {
static_assert_size!
(
Block
,
56
);
static_assert_size!
(
Expr
<
'_
>
,
64
);
static_assert_size!
(
ExprKind
<
'_
>
,
40
);
static_assert_size!
(
Pat
<
'_
>
,
80
);
static_assert_size!
(
PatKind
<
'_
>
,
64
);
static_assert_size!
(
Pat
<
'_
>
,
72
);
static_assert_size!
(
PatKind
<
'_
>
,
56
);
static_assert_size!
(
Stmt
<
'_
>
,
56
);
static_assert_size!
(
StmtKind
<
'_
>
,
48
);
}
compiler/rustc_middle/src/thir/visit.rs
浏览文件 @
43a0268f
...
...
@@ -232,18 +232,18 @@ pub fn walk_pat<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, pat: &Pat<'
Constant
{
value
:
_
}
=>
{}
Range
(
_
)
=>
{}
Slice
{
prefix
,
slice
,
suffix
}
|
Array
{
prefix
,
slice
,
suffix
}
=>
{
for
subpattern
in
prefix
{
for
subpattern
in
prefix
.iter
()
{
visitor
.visit_pat
(
&
subpattern
);
}
if
let
Some
(
pat
)
=
slice
{
visitor
.visit_pat
(
&
pat
);
}
for
subpattern
in
suffix
{
for
subpattern
in
suffix
.iter
()
{
visitor
.visit_pat
(
&
subpattern
);
}
}
Or
{
pats
}
=>
{
for
pat
in
pats
{
for
pat
in
pats
.iter
()
{
visitor
.visit_pat
(
&
pat
);
}
}
...
...
compiler/rustc_mir_build/src/build/matches/mod.rs
浏览文件 @
43a0268f
...
...
@@ -764,7 +764,7 @@ pub(super) fn visit_primary_bindings(
|
PatKind
::
Slice
{
ref
prefix
,
ref
slice
,
ref
suffix
}
=>
{
let
from
=
u64
::
try_from
(
prefix
.len
())
.unwrap
();
let
to
=
u64
::
try_from
(
suffix
.len
())
.unwrap
();
for
subpattern
in
prefix
{
for
subpattern
in
prefix
.iter
()
{
self
.visit_primary_bindings
(
subpattern
,
pattern_user_ty
.clone
()
.index
(),
f
);
}
for
subpattern
in
slice
{
...
...
@@ -774,7 +774,7 @@ pub(super) fn visit_primary_bindings(
f
,
);
}
for
subpattern
in
suffix
{
for
subpattern
in
suffix
.iter
()
{
self
.visit_primary_bindings
(
subpattern
,
pattern_user_ty
.clone
()
.index
(),
f
);
}
}
...
...
@@ -827,7 +827,7 @@ pub(super) fn visit_primary_bindings(
// may not all be in the leftmost subpattern. For example in
// `let (x | y) = ...`, the primary binding of `y` occurs in
// the right subpattern
for
subpattern
in
pats
{
for
subpattern
in
pats
.iter
()
{
self
.visit_primary_bindings
(
subpattern
,
pattern_user_ty
.clone
(),
f
);
}
}
...
...
compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
浏览文件 @
43a0268f
...
...
@@ -400,7 +400,7 @@ fn recur(
.map
(|
val
|
self
.recur
(
*
val
,
false
))
.collect
::
<
Result
<
_
,
_
>>
()
?
,
slice
:
None
,
suffix
:
Vec
::
new
(
),
suffix
:
Box
::
new
([]
),
},
ty
::
Ref
(
_
,
pointee_ty
,
..
)
=>
match
*
pointee_ty
.kind
()
{
// These are not allowed and will error elsewhere anyway.
...
...
@@ -436,7 +436,7 @@ fn recur(
.map
(|
val
|
self
.recur
(
*
val
,
false
))
.collect
::
<
Result
<
_
,
_
>>
()
?
,
slice
:
None
,
suffix
:
vec!
[]
,
suffix
:
Box
::
new
([])
,
},
span
,
ty
:
*
pointee_ty
,
...
...
@@ -462,7 +462,7 @@ fn recur(
.map
(|
val
|
self
.recur
(
*
val
,
false
))
.collect
::
<
Result
<
_
,
_
>>
()
?
,
slice
:
None
,
suffix
:
vec!
[]
,
suffix
:
Box
::
new
([])
,
},
span
,
ty
:
tcx
.mk_slice
(
elem_ty
),
...
...
compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
浏览文件 @
43a0268f
...
...
@@ -72,7 +72,7 @@
fn
expand_or_pat
<
'p
,
'tcx
>
(
pat
:
&
'p
Pat
<
'tcx
>
)
->
Vec
<&
'p
Pat
<
'tcx
>>
{
fn
expand
<
'p
,
'tcx
>
(
pat
:
&
'p
Pat
<
'tcx
>
,
vec
:
&
mut
Vec
<&
'p
Pat
<
'tcx
>>
)
{
if
let
PatKind
::
Or
{
pats
}
=
&
pat
.kind
{
for
pat
in
pats
{
for
pat
in
pats
.iter
()
{
expand
(
&
pat
,
vec
);
}
}
else
{
...
...
@@ -1433,7 +1433,8 @@ pub(crate) fn from_pat(cx: &MatchCheckCtxt<'p, 'tcx>, pat: &Pat<'tcx>) -> Self {
FixedLen
(
prefix
.len
()
+
suffix
.len
())
};
ctor
=
Slice
(
Slice
::
new
(
array_len
,
kind
));
fields
=
Fields
::
from_iter
(
cx
,
prefix
.iter
()
.chain
(
suffix
)
.map
(|
p
|
mkpat
(
&*
p
)));
fields
=
Fields
::
from_iter
(
cx
,
prefix
.iter
()
.chain
(
suffix
.iter
())
.map
(|
p
|
mkpat
(
&*
p
)));
}
PatKind
::
Or
{
..
}
=>
{
ctor
=
Or
;
...
...
@@ -1489,7 +1490,7 @@ pub(crate) fn to_pat(&self, cx: &MatchCheckCtxt<'p, 'tcx>) -> Pat<'tcx> {
FixedLen
(
_
)
=>
PatKind
::
Slice
{
prefix
:
subpatterns
.collect
(),
slice
:
None
,
suffix
:
vec!
[]
,
suffix
:
Box
::
new
([])
,
},
VarLen
(
prefix
,
_
)
=>
{
let
mut
subpatterns
=
subpatterns
.peekable
();
...
...
@@ -1508,9 +1509,13 @@ pub(crate) fn to_pat(&self, cx: &MatchCheckCtxt<'p, 'tcx>) -> Pat<'tcx> {
subpatterns
.next
();
}
}
let
suffix
:
Vec
<
_
>
=
subpatterns
.collect
();
let
suffix
:
Box
<
[
_
]
>
=
subpatterns
.collect
();
let
wild
=
Pat
::
wildcard_from_ty
(
self
.ty
);
PatKind
::
Slice
{
prefix
,
slice
:
Some
(
Box
::
new
(
wild
)),
suffix
}
PatKind
::
Slice
{
prefix
:
prefix
.into_boxed_slice
(),
slice
:
Some
(
Box
::
new
(
wild
)),
suffix
,
}
}
}
}
...
...
compiler/rustc_mir_build/src/thir/pattern/mod.rs
浏览文件 @
43a0268f
...
...
@@ -344,7 +344,7 @@ fn lower_tuple_subpats(
.collect
()
}
fn
lower_patterns
(
&
mut
self
,
pats
:
&
'tcx
[
hir
::
Pat
<
'tcx
>
])
->
Vec
<
Box
<
Pat
<
'tcx
>>
>
{
fn
lower_patterns
(
&
mut
self
,
pats
:
&
'tcx
[
hir
::
Pat
<
'tcx
>
])
->
Box
<
[
Box
<
Pat
<
'tcx
>>
]
>
{
pats
.iter
()
.map
(|
p
|
self
.lower_pattern
(
p
))
.collect
()
}
...
...
@@ -653,6 +653,12 @@ fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
}
}
impl
<
'tcx
,
T
:
PatternFoldable
<
'tcx
>>
PatternFoldable
<
'tcx
>
for
Box
<
[
T
]
>
{
fn
super_fold_with
<
F
:
PatternFolder
<
'tcx
>>
(
&
self
,
folder
:
&
mut
F
)
->
Self
{
self
.iter
()
.map
(|
t
|
t
.fold_with
(
folder
))
.collect
()
}
}
impl
<
'tcx
,
T
:
PatternFoldable
<
'tcx
>>
PatternFoldable
<
'tcx
>
for
Option
<
T
>
{
fn
super_fold_with
<
F
:
PatternFolder
<
'tcx
>>
(
&
self
,
folder
:
&
mut
F
)
->
Self
{
self
.as_ref
()
.map
(|
t
|
t
.fold_with
(
folder
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录