Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2624c14a
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,发现更多精彩内容 >>
提交
2624c14a
编写于
6月 08, 2018
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
extract the handling of region constraints from queries
上级
bebd3ff6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
50 addition
and
40 deletion
+50
-40
src/librustc/infer/canonical/query_result.rs
src/librustc/infer/canonical/query_result.rs
+50
-40
未找到文件。
src/librustc/infer/canonical/query_result.rs
浏览文件 @
2624c14a
...
@@ -22,15 +22,16 @@
...
@@ -22,15 +22,16 @@
Canonical
,
CanonicalVarValues
,
Canonicalize
,
Certainty
,
QueryRegionConstraint
,
QueryResult
,
Canonical
,
CanonicalVarValues
,
Canonicalize
,
Certainty
,
QueryRegionConstraint
,
QueryResult
,
};
};
use
infer
::
region_constraints
::{
Constraint
,
RegionConstraintData
};
use
infer
::
region_constraints
::{
Constraint
,
RegionConstraintData
};
use
infer
::{
InferCtxt
,
InferOk
,
InferResult
};
use
infer
::{
InferCtxt
,
InferOk
,
InferResult
,
RegionObligation
};
use
rustc_data_structures
::
indexed_vec
::
Idx
;
use
rustc_data_structures
::
indexed_vec
::
Idx
;
use
std
::
fmt
::
Debug
;
use
std
::
fmt
::
Debug
;
use
syntax
::
ast
;
use
traits
::
query
::
NoSolution
;
use
traits
::
query
::
NoSolution
;
use
traits
::{
FulfillmentContext
,
TraitEngine
};
use
traits
::{
FulfillmentContext
,
TraitEngine
};
use
traits
::{
Obligation
,
ObligationCause
,
PredicateObligation
};
use
traits
::{
Obligation
,
ObligationCause
,
PredicateObligation
};
use
ty
::
fold
::
TypeFoldable
;
use
ty
::
fold
::
TypeFoldable
;
use
ty
::
subst
::{
Kind
,
UnpackedKind
};
use
ty
::
subst
::{
Kind
,
UnpackedKind
};
use
ty
::{
self
,
CanonicalVar
};
use
ty
::{
self
,
CanonicalVar
,
TyCtxt
};
use
rustc_data_structures
::
indexed_vec
::
IndexVec
;
use
rustc_data_structures
::
indexed_vec
::
IndexVec
;
...
@@ -120,45 +121,8 @@ fn make_query_result<T>(
...
@@ -120,45 +121,8 @@ fn make_query_result<T>(
debug!
(
"ambig_errors = {:#?}"
,
ambig_errors
);
debug!
(
"ambig_errors = {:#?}"
,
ambig_errors
);
let
region_obligations
=
self
.take_registered_region_obligations
();
let
region_obligations
=
self
.take_registered_region_obligations
();
let
region_constraints
=
self
.with_region_constraints
(|
region_constraints
|
{
let
region_constraints
=
self
.with_region_constraints
(|
region_constraints
|
{
let
RegionConstraintData
{
make_query_outlives
(
tcx
,
region_obligations
,
region_constraints
)
constraints
,
verifys
,
givens
,
}
=
region_constraints
;
assert
!
(
verifys
.is_empty
());
assert
!
(
givens
.is_empty
());
let
mut
outlives
:
Vec
<
_
>
=
constraints
.into_iter
()
.map
(|(
k
,
_
)|
match
*
k
{
// Swap regions because we are going from sub (<=) to outlives
// (>=).
Constraint
::
VarSubVar
(
v1
,
v2
)
=>
ty
::
OutlivesPredicate
(
tcx
.mk_region
(
ty
::
ReVar
(
v2
))
.into
(),
tcx
.mk_region
(
ty
::
ReVar
(
v1
)),
),
Constraint
::
VarSubReg
(
v1
,
r2
)
=>
{
ty
::
OutlivesPredicate
(
r2
.into
(),
tcx
.mk_region
(
ty
::
ReVar
(
v1
)))
}
Constraint
::
RegSubVar
(
r1
,
v2
)
=>
{
ty
::
OutlivesPredicate
(
tcx
.mk_region
(
ty
::
ReVar
(
v2
))
.into
(),
r1
)
}
Constraint
::
RegSubReg
(
r1
,
r2
)
=>
ty
::
OutlivesPredicate
(
r2
.into
(),
r1
),
})
.map
(
ty
::
Binder
::
dummy
)
// no bound regions in the code above
.collect
();
outlives
.extend
(
region_obligations
.into_iter
()
.map
(|(
_
,
r_o
)|
ty
::
OutlivesPredicate
(
r_o
.sup_type
.into
(),
r_o
.sub_region
))
.map
(
ty
::
Binder
::
dummy
),
// no bound regions in the code above
);
outlives
});
});
let
certainty
=
if
ambig_errors
.is_empty
()
{
let
certainty
=
if
ambig_errors
.is_empty
()
{
...
@@ -358,3 +322,49 @@ fn unify_canonical_vars(
...
@@ -358,3 +322,49 @@ fn unify_canonical_vars(
})
})
}
}
}
}
/// Given the region obligations and constraints scraped from the infcx,
/// creates query region constraints.
fn
make_query_outlives
<
'tcx
>
(
tcx
:
TyCtxt
<
'_
,
'_
,
'tcx
>
,
region_obligations
:
Vec
<
(
ast
::
NodeId
,
RegionObligation
<
'tcx
>
)
>
,
region_constraints
:
&
RegionConstraintData
<
'tcx
>
,
)
->
Vec
<
QueryRegionConstraint
<
'tcx
>>
{
let
RegionConstraintData
{
constraints
,
verifys
,
givens
,
}
=
region_constraints
;
assert
!
(
verifys
.is_empty
());
assert
!
(
givens
.is_empty
());
let
mut
outlives
:
Vec
<
_
>
=
constraints
.into_iter
()
.map
(|(
k
,
_
)|
match
*
k
{
// Swap regions because we are going from sub (<=) to outlives
// (>=).
Constraint
::
VarSubVar
(
v1
,
v2
)
=>
ty
::
OutlivesPredicate
(
tcx
.mk_region
(
ty
::
ReVar
(
v2
))
.into
(),
tcx
.mk_region
(
ty
::
ReVar
(
v1
)),
),
Constraint
::
VarSubReg
(
v1
,
r2
)
=>
{
ty
::
OutlivesPredicate
(
r2
.into
(),
tcx
.mk_region
(
ty
::
ReVar
(
v1
)))
}
Constraint
::
RegSubVar
(
r1
,
v2
)
=>
{
ty
::
OutlivesPredicate
(
tcx
.mk_region
(
ty
::
ReVar
(
v2
))
.into
(),
r1
)
}
Constraint
::
RegSubReg
(
r1
,
r2
)
=>
ty
::
OutlivesPredicate
(
r2
.into
(),
r1
),
})
.map
(
ty
::
Binder
::
dummy
)
// no bound regions in the code above
.collect
();
outlives
.extend
(
region_obligations
.into_iter
()
.map
(|(
_
,
r_o
)|
ty
::
OutlivesPredicate
(
r_o
.sup_type
.into
(),
r_o
.sub_region
))
.map
(
ty
::
Binder
::
dummy
),
// no bound regions in the code above
);
outlives
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录