Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e5dc4ba2
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,发现更多精彩内容 >>
提交
e5dc4ba2
编写于
11月 22, 2017
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
renumber types in `ty::Const` and relate them to `mir::Constant`
上级
7b637b77
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
61 addition
and
1 deletion
+61
-1
src/librustc_mir/borrow_check/nll/mod.rs
src/librustc_mir/borrow_check/nll/mod.rs
+5
-0
src/librustc_mir/borrow_check/nll/renumber.rs
src/librustc_mir/borrow_check/nll/renumber.rs
+5
-0
src/librustc_mir/borrow_check/nll/subtype_constraint_generation.rs
...stc_mir/borrow_check/nll/subtype_constraint_generation.rs
+4
-1
src/librustc_mir/transform/type_check.rs
src/librustc_mir/transform/type_check.rs
+47
-0
未找到文件。
src/librustc_mir/borrow_check/nll/mod.rs
浏览文件 @
e5dc4ba2
...
...
@@ -43,12 +43,17 @@ pub(in borrow_check) fn replace_regions_in_mir<'cx, 'gcx, 'tcx>(
def_id
:
DefId
,
mir
:
&
mut
Mir
<
'tcx
>
,
)
->
UniversalRegions
<
'tcx
>
{
debug!
(
"replace_regions_in_mir(def_id={:?})"
,
def_id
);
// Compute named region information.
let
universal_regions
=
universal_regions
::
universal_regions
(
infcx
,
def_id
);
// Replace all regions with fresh inference variables.
renumber
::
renumber_mir
(
infcx
,
&
universal_regions
,
mir
);
let
source
=
MirSource
::
item
(
def_id
);
mir_util
::
dump_mir
(
infcx
.tcx
,
None
,
"renumber"
,
&
0
,
source
,
mir
,
|
_
,
_
|
Ok
(()));
universal_regions
}
...
...
src/librustc_mir/borrow_check/nll/renumber.rs
浏览文件 @
e5dc4ba2
...
...
@@ -138,6 +138,11 @@ fn visit_region(&mut self, region: &mut ty::Region<'tcx>, location: Location) {
debug!
(
"visit_region: region={:?}"
,
region
);
}
fn
visit_const
(
&
mut
self
,
constant
:
&
mut
&
'tcx
ty
::
Const
<
'tcx
>
,
location
:
Location
)
{
let
ty_context
=
TyContext
::
Location
(
location
);
*
constant
=
self
.renumber_regions
(
ty_context
,
&*
constant
);
}
fn
visit_closure_substs
(
&
mut
self
,
substs
:
&
mut
ClosureSubsts
<
'tcx
>
,
location
:
Location
)
{
debug!
(
"visit_closure_substs(substs={:?}, location={:?})"
,
...
...
src/librustc_mir/borrow_check/nll/subtype_constraint_generation.rs
浏览文件 @
e5dc4ba2
...
...
@@ -106,7 +106,10 @@ fn to_region_vid(&self, r: ty::Region<'tcx>) -> ty::RegionVid {
if
let
ty
::
ReVar
(
vid
)
=
r
{
*
vid
}
else
{
self
.universal_regions.indices
[
&
r
]
*
self
.universal_regions
.indices
.get
(
&
r
)
.unwrap_or_else
(||
bug!
(
"to_region_vid: bad region {:?}"
,
r
))
}
}
}
src/librustc_mir/transform/type_check.rs
浏览文件 @
e5dc4ba2
...
...
@@ -110,6 +110,7 @@ fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location:
fn
visit_constant
(
&
mut
self
,
constant
:
&
Constant
<
'tcx
>
,
location
:
Location
)
{
self
.super_constant
(
constant
,
location
);
self
.sanitize_constant
(
constant
,
location
);
self
.sanitize_type
(
constant
,
constant
.ty
);
}
...
...
@@ -159,6 +160,52 @@ fn sanitize_type(&mut self, parent: &fmt::Debug, ty: Ty<'tcx>) -> Ty<'tcx> {
}
}
/// Checks that the constant's `ty` field matches up with what
/// would be expected from its literal.
fn
sanitize_constant
(
&
mut
self
,
constant
:
&
Constant
<
'tcx
>
,
location
:
Location
)
{
debug!
(
"sanitize_constant(constant={:?}, location={:?})"
,
constant
,
location
);
let
expected_ty
=
match
constant
.literal
{
Literal
::
Value
{
value
}
=>
value
.ty
,
Literal
::
Promoted
{
..
}
=>
{
// FIXME -- promoted MIR return types reference
// various "free regions" (e.g., scopes and things)
// that they ought not to do. We have to figure out
// how best to handle that -- probably we want treat
// promoted MIR much like closures, renumbering all
// their free regions and propagating constraints
// upwards. We have the same acyclic guarantees, so
// that should be possible. But for now, ignore them.
//
// let promoted_mir = &self.mir.promoted[index];
// promoted_mir.return_ty()
return
;
}
};
debug!
(
"sanitize_constant: expected_ty={:?}"
,
expected_ty
);
if
let
Err
(
terr
)
=
self
.cx
.eq_types
(
expected_ty
,
constant
.ty
,
location
.at_self
())
{
span_mirbug!
(
self
,
constant
,
"constant {:?} should have type {:?} but has {:?} ({:?})"
,
constant
,
expected_ty
,
constant
.ty
,
terr
,
);
}
}
/// Checks that the types internal to the `place` match up with
/// what would be expected.
fn
sanitize_place
(
&
mut
self
,
place
:
&
Place
<
'tcx
>
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录