Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2de04758
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,发现更多精彩内容 >>
提交
2de04758
编写于
11月 21, 2020
作者:
N
Nadrieril
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename `pat_constructor` to `Constructor::from_pat`
上级
ba3c419a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
63 addition
and
63 deletion
+63
-63
compiler/rustc_mir_build/src/thir/pattern/_match.rs
compiler/rustc_mir_build/src/thir/pattern/_match.rs
+2
-2
compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
+61
-61
未找到文件。
compiler/rustc_mir_build/src/thir/pattern/_match.rs
浏览文件 @
2de04758
...
...
@@ -306,7 +306,7 @@
use
self
::
Usefulness
::
*
;
use
self
::
WitnessPreference
::
*
;
use
super
::
deconstruct_pat
::{
pat_constructor
,
Constructor
,
Fields
,
MissingConstructors
};
use
super
::
deconstruct_pat
::{
Constructor
,
Fields
,
MissingConstructors
};
use
super
::{
Pat
,
PatKind
};
use
super
::{
PatternFoldable
,
PatternFolder
};
...
...
@@ -438,7 +438,7 @@ fn head(&self) -> &'p Pat<'tcx> {
}
fn
head_ctor
<
'a
>
(
&
'a
self
,
cx
:
&
MatchCheckCtxt
<
'p
,
'tcx
>
)
->
&
'a
Constructor
<
'tcx
>
{
self
.head_ctor
.get_or_init
(||
pat_constructor
(
cx
,
self
.head
()))
self
.head_ctor
.get_or_init
(||
Constructor
::
from_pat
(
cx
,
self
.head
()))
}
fn
iter
(
&
self
)
->
impl
Iterator
<
Item
=
&
Pat
<
'tcx
>>
{
...
...
compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
浏览文件 @
2de04758
...
...
@@ -606,6 +606,67 @@ fn variant_index_for_adt(&self, adt: &'tcx ty::AdtDef) -> VariantIdx {
}
}
/// Determines the constructor that the given pattern can be specialized to.
pub
(
super
)
fn
from_pat
<
'p
>
(
cx
:
&
MatchCheckCtxt
<
'p
,
'tcx
>
,
pat
:
&
'p
Pat
<
'tcx
>
)
->
Self
{
match
pat
.kind
.as_ref
()
{
PatKind
::
AscribeUserType
{
..
}
=>
bug!
(),
// Handled by `expand_pattern`
PatKind
::
Binding
{
..
}
|
PatKind
::
Wild
=>
Wildcard
,
PatKind
::
Leaf
{
..
}
|
PatKind
::
Deref
{
..
}
=>
Single
,
&
PatKind
::
Variant
{
adt_def
,
variant_index
,
..
}
=>
{
Variant
(
adt_def
.variants
[
variant_index
]
.def_id
)
}
PatKind
::
Constant
{
value
}
=>
{
if
let
Some
(
int_range
)
=
IntRange
::
from_const
(
cx
.tcx
,
cx
.param_env
,
value
,
pat
.span
)
{
IntRange
(
int_range
)
}
else
{
match
pat
.ty
.kind
()
{
ty
::
Float
(
_
)
=>
FloatRange
(
value
,
value
,
RangeEnd
::
Included
),
// In `expand_pattern`, we convert string literals to `&CONST` patterns with
// `CONST` a pattern of type `str`. In truth this contains a constant of type
// `&str`.
ty
::
Str
=>
Str
(
value
),
// All constants that can be structurally matched have already been expanded
// into the corresponding `Pat`s by `const_to_pat`. Constants that remain are
// opaque.
_
=>
Opaque
,
}
}
}
&
PatKind
::
Range
(
PatRange
{
lo
,
hi
,
end
})
=>
{
let
ty
=
lo
.ty
;
if
let
Some
(
int_range
)
=
IntRange
::
from_range
(
cx
.tcx
,
lo
.eval_bits
(
cx
.tcx
,
cx
.param_env
,
lo
.ty
),
hi
.eval_bits
(
cx
.tcx
,
cx
.param_env
,
hi
.ty
),
ty
,
&
end
,
pat
.span
,
)
{
IntRange
(
int_range
)
}
else
{
FloatRange
(
lo
,
hi
,
end
)
}
}
PatKind
::
Array
{
prefix
,
slice
,
suffix
}
|
PatKind
::
Slice
{
prefix
,
slice
,
suffix
}
=>
{
let
array_len
=
match
pat
.ty
.kind
()
{
ty
::
Array
(
_
,
length
)
=>
Some
(
length
.eval_usize
(
cx
.tcx
,
cx
.param_env
)),
ty
::
Slice
(
_
)
=>
None
,
_
=>
span_bug!
(
pat
.span
,
"bad ty {:?} for slice pattern"
,
pat
.ty
),
};
let
prefix
=
prefix
.len
()
as
u64
;
let
suffix
=
suffix
.len
()
as
u64
;
let
kind
=
if
slice
.is_some
()
{
VarLen
(
prefix
,
suffix
)
}
else
{
FixedLen
(
prefix
+
suffix
)
};
Slice
(
Slice
::
new
(
array_len
,
kind
))
}
PatKind
::
Or
{
..
}
=>
bug!
(
"Or-pattern should have been expanded earlier on."
),
}
}
/// Some constructors (namely `Wildcard`, `IntRange` and `Slice`) actually stand for a set of actual
/// constructors (like variants, integers or fixed-sized slices). When specializing for these
/// constructors, we want to be specialising for the actual underlying constructors.
...
...
@@ -756,67 +817,6 @@ fn is_covered_by_any<'p>(
}
}
/// Determines the constructor that the given pattern can be specialized to.
/// Returns `None` in case of a catch-all, which can't be specialized.
pub
(
super
)
fn
pat_constructor
<
'p
,
'tcx
>
(
cx
:
&
MatchCheckCtxt
<
'p
,
'tcx
>
,
pat
:
&
'p
Pat
<
'tcx
>
,
)
->
Constructor
<
'tcx
>
{
match
pat
.kind
.as_ref
()
{
PatKind
::
AscribeUserType
{
..
}
=>
bug!
(),
// Handled by `expand_pattern`
PatKind
::
Binding
{
..
}
|
PatKind
::
Wild
=>
Wildcard
,
PatKind
::
Leaf
{
..
}
|
PatKind
::
Deref
{
..
}
=>
Single
,
&
PatKind
::
Variant
{
adt_def
,
variant_index
,
..
}
=>
{
Variant
(
adt_def
.variants
[
variant_index
]
.def_id
)
}
PatKind
::
Constant
{
value
}
=>
{
if
let
Some
(
int_range
)
=
IntRange
::
from_const
(
cx
.tcx
,
cx
.param_env
,
value
,
pat
.span
)
{
IntRange
(
int_range
)
}
else
{
match
pat
.ty
.kind
()
{
ty
::
Float
(
_
)
=>
FloatRange
(
value
,
value
,
RangeEnd
::
Included
),
// In `expand_pattern`, we convert string literals to `&CONST` patterns with
// `CONST` a pattern of type `str`. In truth this contains a constant of type
// `&str`.
ty
::
Str
=>
Str
(
value
),
// All constants that can be structurally matched have already been expanded
// into the corresponding `Pat`s by `const_to_pat`. Constants that remain are
// opaque.
_
=>
Opaque
,
}
}
}
&
PatKind
::
Range
(
PatRange
{
lo
,
hi
,
end
})
=>
{
let
ty
=
lo
.ty
;
if
let
Some
(
int_range
)
=
IntRange
::
from_range
(
cx
.tcx
,
lo
.eval_bits
(
cx
.tcx
,
cx
.param_env
,
lo
.ty
),
hi
.eval_bits
(
cx
.tcx
,
cx
.param_env
,
hi
.ty
),
ty
,
&
end
,
pat
.span
,
)
{
IntRange
(
int_range
)
}
else
{
FloatRange
(
lo
,
hi
,
end
)
}
}
PatKind
::
Array
{
prefix
,
slice
,
suffix
}
|
PatKind
::
Slice
{
prefix
,
slice
,
suffix
}
=>
{
let
array_len
=
match
pat
.ty
.kind
()
{
ty
::
Array
(
_
,
length
)
=>
Some
(
length
.eval_usize
(
cx
.tcx
,
cx
.param_env
)),
ty
::
Slice
(
_
)
=>
None
,
_
=>
span_bug!
(
pat
.span
,
"bad ty {:?} for slice pattern"
,
pat
.ty
),
};
let
prefix
=
prefix
.len
()
as
u64
;
let
suffix
=
suffix
.len
()
as
u64
;
let
kind
=
if
slice
.is_some
()
{
VarLen
(
prefix
,
suffix
)
}
else
{
FixedLen
(
prefix
+
suffix
)
};
Slice
(
Slice
::
new
(
array_len
,
kind
))
}
PatKind
::
Or
{
..
}
=>
bug!
(
"Or-pattern should have been expanded earlier on."
),
}
}
/// This determines the set of all possible constructors of a pattern matching
/// values of type `left_ty`. For vectors, this would normally be an infinite set
/// but is instead bounded by the maximum fixed length of slice patterns in
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录