Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ba3c419a
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,发现更多精彩内容 >>
提交
ba3c419a
编写于
11月 21, 2020
作者:
N
Nadrieril
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move the definitions of the two `Ctxt`s to the top
上级
2184a144
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
46 addition
and
47 deletion
+46
-47
compiler/rustc_mir_build/src/thir/pattern/_match.rs
compiler/rustc_mir_build/src/thir/pattern/_match.rs
+46
-47
未找到文件。
compiler/rustc_mir_build/src/thir/pattern/_match.rs
浏览文件 @
ba3c419a
...
...
@@ -324,6 +324,52 @@
use
std
::
fmt
;
use
std
::
iter
::{
FromIterator
,
IntoIterator
};
crate
struct
MatchCheckCtxt
<
'a
,
'tcx
>
{
crate
tcx
:
TyCtxt
<
'tcx
>
,
/// The module in which the match occurs. This is necessary for
/// checking inhabited-ness of types because whether a type is (visibly)
/// inhabited can depend on whether it was defined in the current module or
/// not. E.g., `struct Foo { _private: ! }` cannot be seen to be empty
/// outside its module and should not be matchable with an empty match statement.
crate
module
:
DefId
,
crate
param_env
:
ty
::
ParamEnv
<
'tcx
>
,
crate
pattern_arena
:
&
'a
TypedArena
<
Pat
<
'tcx
>>
,
}
impl
<
'a
,
'tcx
>
MatchCheckCtxt
<
'a
,
'tcx
>
{
pub
(
super
)
fn
is_uninhabited
(
&
self
,
ty
:
Ty
<
'tcx
>
)
->
bool
{
if
self
.tcx
.features
()
.exhaustive_patterns
{
self
.tcx
.is_ty_uninhabited_from
(
self
.module
,
ty
,
self
.param_env
)
}
else
{
false
}
}
/// Returns whether the given type is an enum from another crate declared `#[non_exhaustive]`.
pub
(
super
)
fn
is_foreign_non_exhaustive_enum
(
&
self
,
ty
:
Ty
<
'tcx
>
)
->
bool
{
match
ty
.kind
()
{
ty
::
Adt
(
def
,
..
)
=>
{
def
.is_enum
()
&&
def
.is_variant_list_non_exhaustive
()
&&
!
def
.did
.is_local
()
}
_
=>
false
,
}
}
}
#[derive(Copy,
Clone)]
pub
(
super
)
struct
PatCtxt
<
'a
,
'p
,
'tcx
>
{
pub
(
super
)
cx
:
&
'a
MatchCheckCtxt
<
'p
,
'tcx
>
,
/// Current state of the matrix.
pub
(
super
)
matrix
:
&
'a
Matrix
<
'p
,
'tcx
>
,
/// Type of the current column under investigation.
pub
(
super
)
ty
:
Ty
<
'tcx
>
,
/// Span of the current pattern under investigation.
pub
(
super
)
span
:
Span
,
/// Whether the current pattern is the whole pattern as found in a match arm, or if it's a
/// subpattern.
pub
(
super
)
is_top_level
:
bool
,
}
crate
fn
expand_pattern
<
'tcx
>
(
pat
:
Pat
<
'tcx
>
)
->
Pat
<
'tcx
>
{
LiteralExpander
.fold_pattern
(
&
pat
)
}
...
...
@@ -572,39 +618,6 @@ fn from_iter<T>(iter: T) -> Self
}
}
crate
struct
MatchCheckCtxt
<
'a
,
'tcx
>
{
crate
tcx
:
TyCtxt
<
'tcx
>
,
/// The module in which the match occurs. This is necessary for
/// checking inhabited-ness of types because whether a type is (visibly)
/// inhabited can depend on whether it was defined in the current module or
/// not. E.g., `struct Foo { _private: ! }` cannot be seen to be empty
/// outside it's module and should not be matchable with an empty match
/// statement.
crate
module
:
DefId
,
crate
param_env
:
ty
::
ParamEnv
<
'tcx
>
,
crate
pattern_arena
:
&
'a
TypedArena
<
Pat
<
'tcx
>>
,
}
impl
<
'a
,
'tcx
>
MatchCheckCtxt
<
'a
,
'tcx
>
{
pub
(
super
)
fn
is_uninhabited
(
&
self
,
ty
:
Ty
<
'tcx
>
)
->
bool
{
if
self
.tcx
.features
()
.exhaustive_patterns
{
self
.tcx
.is_ty_uninhabited_from
(
self
.module
,
ty
,
self
.param_env
)
}
else
{
false
}
}
/// Returns whether the given type is an enum from another crate declared `#[non_exhaustive]`.
pub
(
super
)
fn
is_foreign_non_exhaustive_enum
(
&
self
,
ty
:
Ty
<
'tcx
>
)
->
bool
{
match
ty
.kind
()
{
ty
::
Adt
(
def
,
..
)
=>
{
def
.is_enum
()
&&
def
.is_variant_list_non_exhaustive
()
&&
!
def
.did
.is_local
()
}
_
=>
false
,
}
}
}
#[derive(Clone,
Debug)]
crate
enum
Usefulness
<
'tcx
>
{
/// Carries, for each column in the matrix, a set of sub-branches that have been found to be
...
...
@@ -684,20 +697,6 @@ enum WitnessPreference {
LeaveOutWitness
,
}
#[derive(Copy,
Clone)]
pub
(
super
)
struct
PatCtxt
<
'a
,
'p
,
'tcx
>
{
pub
(
super
)
cx
:
&
'a
MatchCheckCtxt
<
'p
,
'tcx
>
,
/// Current state of the matrix.
pub
(
super
)
matrix
:
&
'a
Matrix
<
'p
,
'tcx
>
,
/// Type of the current column under investigation.
pub
(
super
)
ty
:
Ty
<
'tcx
>
,
/// Span of the current pattern under investigation.
pub
(
super
)
span
:
Span
,
/// Whether the current pattern is the whole pattern as found in a match arm, or if it's a
/// subpattern.
pub
(
super
)
is_top_level
:
bool
,
}
/// A witness of non-exhaustiveness for error reporting, represented
/// as a list of patterns (in reverse order of construction) with
/// wildcards inside to represent elements that can take any inhabitant
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录