Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
45f60271
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
45f60271
编写于
11月 17, 2017
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
break type-checking of aggregate-kind out into helper function
上级
31d61f1f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
52 addition
and
45 deletion
+52
-45
src/librustc_mir/transform/type_check.rs
src/librustc_mir/transform/type_check.rs
+52
-45
未找到文件。
src/librustc_mir/transform/type_check.rs
浏览文件 @
45f60271
...
...
@@ -1031,13 +1031,13 @@ fn check_local(&mut self, mir: &Mir<'tcx>, local: Local, local_decl: &LocalDecl<
fn
aggregate_field_ty
(
&
mut
self
,
ak
:
&
Box
<
AggregateKind
<
'tcx
>
>
,
ak
:
&
AggregateKind
<
'tcx
>
,
field_index
:
usize
,
location
:
Location
,
)
->
Result
<
Ty
<
'tcx
>
,
FieldAccessError
>
{
let
tcx
=
self
.tcx
();
match
*
*
ak
{
match
*
ak
{
AggregateKind
::
Adt
(
def
,
variant_index
,
substs
,
active_field_index
)
=>
{
let
variant
=
&
def
.variants
[
variant_index
];
let
adj_field_index
=
active_field_index
.unwrap_or
(
field_index
);
...
...
@@ -1069,56 +1069,17 @@ fn aggregate_field_ty(
}
}
}
AggregateKind
::
Array
(
ty
)
=>
{
Ok
(
ty
)
}
AggregateKind
::
Array
(
ty
)
=>
Ok
(
ty
),
AggregateKind
::
Tuple
=>
{
unreachable!
(
"This should have been covered in check_rvalues"
);
}
}
}
fn
check_rvalue
(
&
mut
self
,
mir
:
&
Mir
<
'tcx
>
,
rv
:
&
Rvalue
<
'tcx
>
,
location
:
Location
)
{
let
tcx
=
self
.tcx
();
match
rv
{
fn
check_rvalue
(
&
mut
self
,
mir
:
&
Mir
<
'tcx
>
,
rvalue
:
&
Rvalue
<
'tcx
>
,
location
:
Location
)
{
match
rvalue
{
Rvalue
::
Aggregate
(
ak
,
ops
)
=>
{
match
**
ak
{
// tuple rvalue field type is always the type of the op. Nothing to check here.
AggregateKind
::
Tuple
=>
{}
_
=>
{
for
(
i
,
op
)
in
ops
.iter
()
.enumerate
()
{
let
field_ty
=
match
self
.aggregate_field_ty
(
ak
,
i
,
location
)
{
Ok
(
field_ty
)
=>
field_ty
,
Err
(
FieldAccessError
::
OutOfRange
{
field_count
})
=>
{
span_mirbug!
(
self
,
rv
,
"accessed field #{} but variant only has {}"
,
i
,
field_count
);
continue
;
}
};
let
op_ty
=
op
.ty
(
mir
,
tcx
);
if
let
Err
(
terr
)
=
self
.sub_types
(
op_ty
,
field_ty
,
location
.at_successor_within_block
(),
)
{
span_mirbug!
(
self
,
rv
,
"{:?} is not a subtype of {:?}: {:?}"
,
op_ty
,
field_ty
,
terr
);
}
}
}
}
self
.check_aggregate_rvalue
(
mir
,
rvalue
,
ak
,
ops
,
location
)
}
// FIXME: These other cases have to be implemented in future PRs
Rvalue
::
Use
(
..
)
|
...
...
@@ -1134,6 +1095,52 @@ fn check_rvalue(&mut self, mir: &Mir<'tcx>, rv: &Rvalue<'tcx>, location: Locatio
}
}
fn
check_aggregate_rvalue
(
&
mut
self
,
mir
:
&
Mir
<
'tcx
>
,
rvalue
:
&
Rvalue
<
'tcx
>
,
aggregate_kind
:
&
AggregateKind
<
'tcx
>
,
operands
:
&
[
Operand
<
'tcx
>
],
location
:
Location
,
)
{
match
aggregate_kind
{
// tuple rvalue field type is always the type of the op. Nothing to check here.
AggregateKind
::
Tuple
=>
return
,
_
=>
{}
}
let
tcx
=
self
.tcx
();
for
(
i
,
operand
)
in
operands
.iter
()
.enumerate
()
{
let
field_ty
=
match
self
.aggregate_field_ty
(
aggregate_kind
,
i
,
location
)
{
Ok
(
field_ty
)
=>
field_ty
,
Err
(
FieldAccessError
::
OutOfRange
{
field_count
})
=>
{
span_mirbug!
(
self
,
rvalue
,
"accessed field #{} but variant only has {}"
,
i
,
field_count
);
continue
;
}
};
let
operand_ty
=
operand
.ty
(
mir
,
tcx
);
if
let
Err
(
terr
)
=
self
.sub_types
(
operand_ty
,
field_ty
,
location
.at_successor_within_block
())
{
span_mirbug!
(
self
,
rvalue
,
"{:?} is not a subtype of {:?}: {:?}"
,
operand_ty
,
field_ty
,
terr
);
}
}
}
fn
typeck_mir
(
&
mut
self
,
mir
:
&
Mir
<
'tcx
>
)
{
self
.last_span
=
mir
.span
;
debug!
(
"run_on_mir: {:?}"
,
mir
.span
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录