Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
af366b0e
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,发现更多精彩内容 >>
提交
af366b0e
编写于
6月 22, 2018
作者:
V
varkor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor condition
上级
25ba9118
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
27 addition
and
31 deletion
+27
-31
src/librustc_mir/hair/pattern/_match.rs
src/librustc_mir/hair/pattern/_match.rs
+27
-31
未找到文件。
src/librustc_mir/hair/pattern/_match.rs
浏览文件 @
af366b0e
...
...
@@ -35,6 +35,7 @@
use
std
::
cmp
::{
self
,
Ordering
};
use
std
::
fmt
;
use
std
::
iter
::{
FromIterator
,
IntoIterator
};
use
std
::
ops
::
RangeInclusive
;
pub
fn
expand_pattern
<
'a
,
'tcx
>
(
cx
:
&
MatchCheckCtxt
<
'a
,
'tcx
>
,
pat
:
Pattern
<
'tcx
>
)
->
&
'a
Pattern
<
'tcx
>
...
...
@@ -274,7 +275,7 @@ fn variant_index_for_adt(&self, adt: &'tcx ty::AdtDef) -> usize {
}
}
#[derive(Clone)]
#[derive(Clone
,
Debug
)]
pub
enum
Usefulness
<
'tcx
>
{
Useful
,
UsefulWithWitness
(
Vec
<
Witness
<
'tcx
>>
),
...
...
@@ -290,7 +291,7 @@ fn is_useful(&self) -> bool {
}
}
#[derive(Copy,
Clone)]
#[derive(Copy,
Clone
,
Debug
)]
pub
enum
WitnessPreference
{
ConstructWitness
,
LeaveOutWitness
...
...
@@ -303,7 +304,7 @@ struct PatternContext<'tcx> {
}
/// A stack of patterns in reverse order of construction
#[derive(Clone)]
#[derive(Clone
,
Debug
)]
pub
struct
Witness
<
'tcx
>
(
Vec
<
Pattern
<
'tcx
>>
);
impl
<
'tcx
>
Witness
<
'tcx
>
{
...
...
@@ -418,10 +419,6 @@ fn apply_constructor<'a>(
/// but is instead bounded by the maximum fixed length of slice patterns in
/// the column of patterns being analyzed.
///
/// This intentionally does not list ConstantValue specializations for
/// non-booleans, because we currently assume that there is always a
/// "non-standard constant" that matches. See issue #12483.
///
/// We make sure to omit constructors that are statically impossible. eg for
/// Option<!> we do not include Some(_) in the returned list of constructors.
fn
all_constructors
<
'a
,
'tcx
:
'a
>
(
cx
:
&
mut
MatchCheckCtxt
<
'a
,
'tcx
>
,
...
...
@@ -530,7 +527,7 @@ fn max_slice_length<'p, 'a: 'p, 'tcx: 'a, I>(
// `[true, ..]`
// `[.., false]`
// Then any slice of length ≥1 that matches one of these two
// patterns can be
be
trivially turned to a slice of any
// patterns can be trivially turned to a slice of any
// other length ≥1 that matches them and vice-versa - for
// but the slice from length 2 `[false, true]` that matches neither
// of these patterns can't be turned to a slice from length 1 that
...
...
@@ -823,33 +820,32 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
// as patterns in the `match` expression, but did not.
let
mut
missing_ctors
=
vec!
[];
for
req_ctor
in
&
all_ctors
{
if
consider_value_constructors
{
let
mut
refined_ctors
=
vec!
[
req_ctor
.clone
()];
for
used_ctor
in
&
used_ctors
{
// Refine the required constructors for the type by subtracting
// the range defined by the current constructor pattern.
refined_ctors
=
match
IntRange
::
from_ctor
(
cx
.tcx
,
used_ctor
)
{
Some
(
interval
)
=>
interval
.subtract_from
(
cx
.tcx
,
refined_ctors
),
None
=>
refined_ctors
,
};
// If the constructor patterns that have been considered so far
// already cover the entire range of values, then we the
// constructor is not missing, and we can move on to the next one.
if
refined_ctors
.is_empty
()
{
break
;
let
mut
refined_ctors
=
vec!
[
req_ctor
.clone
()];
for
used_ctor
in
&
used_ctors
{
if
used_ctor
==
req_ctor
{
// If a constructor appears in a `match` arm, we can
// eliminate it straight away.
refined_ctors
=
vec!
[]
}
else
if
exhaustive_integer_patterns
{
if
let
Some
(
interval
)
=
IntRange
::
from_ctor
(
cx
.tcx
,
used_ctor
)
{
// Refine the required constructors for the type by subtracting
// the range defined by the current constructor pattern.
refined_ctors
=
interval
.subtract_from
(
cx
.tcx
,
refined_ctors
);
}
}
// If a constructor has not been matched, then it is missing.
// We add `refined_ctors` instead of `req_ctor`, because then we can
// provide more detailed error information about precisely which
// ranges have been omitted.
missing_ctors
.extend
(
refined_ctors
);
}
else
{
// A constructor is missing if it never appears in a `match` arm.
if
!
used_ctors
.iter
()
.any
(|
used_ctor
|
used_ctor
==
req_ctor
)
{
missing_ctors
.push
(
req_ctor
.clone
());
// If the constructor patterns that have been considered so far
// already cover the entire range of values, then we the
// constructor is not missing, and we can move on to the next one.
if
refined_ctors
.is_empty
()
{
break
;
}
}
// If a constructor has not been matched, then it is missing.
// We add `refined_ctors` instead of `req_ctor`, because then we can
// provide more detailed error information about precisely which
// ranges have been omitted.
missing_ctors
.extend
(
refined_ctors
);
}
// `missing_ctors` is the set of constructors from the same type as the
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录