Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
09398378
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,发现更多精彩内容 >>
提交
09398378
编写于
3月 09, 2015
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename the cryptic cres and ures types.
上级
b3317d68
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
138 addition
and
165 deletion
+138
-165
src/librustc/middle/infer/bivariate.rs
src/librustc/middle/infer/bivariate.rs
+7
-7
src/librustc/middle/infer/combine.rs
src/librustc/middle/infer/combine.rs
+54
-34
src/librustc/middle/infer/equate.rs
src/librustc/middle/infer/equate.rs
+6
-6
src/librustc/middle/infer/glb.rs
src/librustc/middle/infer/glb.rs
+6
-6
src/librustc/middle/infer/higher_ranked/mod.rs
src/librustc/middle/infer/higher_ranked/mod.rs
+7
-7
src/librustc/middle/infer/lattice.rs
src/librustc/middle/infer/lattice.rs
+4
-4
src/librustc/middle/infer/lub.rs
src/librustc/middle/infer/lub.rs
+6
-6
src/librustc/middle/infer/mod.rs
src/librustc/middle/infer/mod.rs
+21
-72
src/librustc/middle/infer/region_inference/mod.rs
src/librustc/middle/infer/region_inference/mod.rs
+10
-6
src/librustc/middle/infer/sub.rs
src/librustc/middle/infer/sub.rs
+6
-6
src/librustc/middle/infer/unify.rs
src/librustc/middle/infer/unify.rs
+7
-7
src/librustc_typeck/check/coercion.rs
src/librustc_typeck/check/coercion.rs
+3
-3
src/librustc_typeck/check/method/probe.rs
src/librustc_typeck/check/method/probe.rs
+1
-1
未找到文件。
src/librustc/middle/infer/bivariate.rs
浏览文件 @
09398378
...
...
@@ -29,7 +29,7 @@
use
middle
::
ty
::{
self
,
Ty
};
use
middle
::
ty
::
TyVar
;
use
middle
::
infer
::
combine
::
*
;
use
middle
::
infer
::
cres
;
use
middle
::
infer
::
CombineResult
;
use
middle
::
infer
::
type_variable
::
BiTo
;
use
util
::
ppaux
::
Repr
;
...
...
@@ -47,7 +47,7 @@ fn tag(&self) -> String { "Bivariate".to_string() }
fn
fields
<
'a
>
(
&
'a
self
)
->
&
'a
CombineFields
<
'a
,
'tcx
>
{
&
self
.fields
}
fn
tys_with_variance
(
&
self
,
v
:
ty
::
Variance
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
{
match
v
{
ty
::
Invariant
=>
self
.equate
()
.tys
(
a
,
b
),
...
...
@@ -58,7 +58,7 @@ fn tys_with_variance(&self, v: ty::Variance, a: Ty<'tcx>, b: Ty<'tcx>)
}
fn
regions_with_variance
(
&
self
,
v
:
ty
::
Variance
,
a
:
ty
::
Region
,
b
:
ty
::
Region
)
->
cres
<
'tcx
,
ty
::
Region
>
->
CombineResult
<
'tcx
,
ty
::
Region
>
{
match
v
{
ty
::
Invariant
=>
self
.equate
()
.regions
(
a
,
b
),
...
...
@@ -68,14 +68,14 @@ fn regions_with_variance(&self, v: ty::Variance, a: ty::Region, b: ty::Region)
}
}
fn
regions
(
&
self
,
a
:
ty
::
Region
,
_
:
ty
::
Region
)
->
cres
<
'tcx
,
ty
::
Region
>
{
fn
regions
(
&
self
,
a
:
ty
::
Region
,
_
:
ty
::
Region
)
->
CombineResult
<
'tcx
,
ty
::
Region
>
{
Ok
(
a
)
}
fn
builtin_bounds
(
&
self
,
a
:
BuiltinBounds
,
b
:
BuiltinBounds
)
->
cres
<
'tcx
,
BuiltinBounds
>
->
CombineResult
<
'tcx
,
BuiltinBounds
>
{
if
a
!=
b
{
Err
(
ty
::
terr_builtin_bounds
(
expected_found
(
self
,
a
,
b
)))
...
...
@@ -84,7 +84,7 @@ fn builtin_bounds(&self,
}
}
fn
tys
(
&
self
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
{
fn
tys
(
&
self
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
{
debug!
(
"{}.tys({}, {})"
,
self
.tag
(),
a
.repr
(
self
.fields.infcx.tcx
),
b
.repr
(
self
.fields.infcx.tcx
));
if
a
==
b
{
return
Ok
(
a
);
}
...
...
@@ -114,7 +114,7 @@ fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> {
}
}
fn
binders
<
T
>
(
&
self
,
a
:
&
ty
::
Binder
<
T
>
,
b
:
&
ty
::
Binder
<
T
>
)
->
cres
<
'tcx
,
ty
::
Binder
<
T
>>
fn
binders
<
T
>
(
&
self
,
a
:
&
ty
::
Binder
<
T
>
,
b
:
&
ty
::
Binder
<
T
>
)
->
CombineResult
<
'tcx
,
ty
::
Binder
<
T
>>
where
T
:
Combineable
<
'tcx
>
{
let
a1
=
ty
::
erase_late_bound_regions
(
self
.tcx
(),
a
);
...
...
src/librustc/middle/infer/combine.rs
浏览文件 @
09398378
...
...
@@ -38,7 +38,7 @@
use
super
::
lub
::
Lub
;
use
super
::
sub
::
Sub
;
use
super
::
unify
::
InferCtxtMethodsForSimplyUnifiableTypes
;
use
super
::{
InferCtxt
,
cres
};
use
super
::{
InferCtxt
,
CombineResult
};
use
super
::{
MiscVariable
,
TypeTrace
};
use
super
::
type_variable
::{
RelationDir
,
BiTo
,
EqTo
,
SubtypeOf
,
SupertypeOf
};
...
...
@@ -74,7 +74,7 @@ fn sub<'a>(&'a self) -> Sub<'a, 'tcx> { self.fields().sub() }
fn
lub
<
'a
>
(
&
'a
self
)
->
Lub
<
'a
,
'tcx
>
{
Lub
(
self
.fields
()
.clone
())
}
fn
glb
<
'a
>
(
&
'a
self
)
->
Glb
<
'a
,
'tcx
>
{
Glb
(
self
.fields
()
.clone
())
}
fn
mts
(
&
self
,
a
:
&
ty
::
mt
<
'tcx
>
,
b
:
&
ty
::
mt
<
'tcx
>
)
->
cres
<
'tcx
,
ty
::
mt
<
'tcx
>>
{
fn
mts
(
&
self
,
a
:
&
ty
::
mt
<
'tcx
>
,
b
:
&
ty
::
mt
<
'tcx
>
)
->
CombineResult
<
'tcx
,
ty
::
mt
<
'tcx
>>
{
debug!
(
"{}.mts({}, {})"
,
self
.tag
(),
a
.repr
(
self
.tcx
()),
...
...
@@ -94,20 +94,20 @@ fn mts(&self, a: &ty::mt<'tcx>, b: &ty::mt<'tcx>) -> cres<'tcx, ty::mt<'tcx>> {
}
fn
tys_with_variance
(
&
self
,
variance
:
ty
::
Variance
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
;
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
;
fn
tys
(
&
self
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
;
fn
tys
(
&
self
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
;
fn
regions_with_variance
(
&
self
,
variance
:
ty
::
Variance
,
a
:
ty
::
Region
,
b
:
ty
::
Region
)
->
cres
<
'tcx
,
ty
::
Region
>
;
->
CombineResult
<
'tcx
,
ty
::
Region
>
;
fn
regions
(
&
self
,
a
:
ty
::
Region
,
b
:
ty
::
Region
)
->
cres
<
'tcx
,
ty
::
Region
>
;
fn
regions
(
&
self
,
a
:
ty
::
Region
,
b
:
ty
::
Region
)
->
CombineResult
<
'tcx
,
ty
::
Region
>
;
fn
substs
(
&
self
,
item_def_id
:
ast
::
DefId
,
a_subst
:
&
subst
::
Substs
<
'tcx
>
,
b_subst
:
&
subst
::
Substs
<
'tcx
>
)
->
cres
<
'tcx
,
subst
::
Substs
<
'tcx
>>
->
CombineResult
<
'tcx
,
subst
::
Substs
<
'tcx
>>
{
debug!
(
"substs: item_def_id={} a_subst={} b_subst={}"
,
item_def_id
.repr
(
self
.infcx
()
.tcx
),
...
...
@@ -126,7 +126,7 @@ fn substs_variances(&self,
variances
:
Option
<&
ty
::
ItemVariances
>
,
a_subst
:
&
subst
::
Substs
<
'tcx
>
,
b_subst
:
&
subst
::
Substs
<
'tcx
>
)
->
cres
<
'tcx
,
subst
::
Substs
<
'tcx
>>
->
CombineResult
<
'tcx
,
subst
::
Substs
<
'tcx
>>
{
let
mut
substs
=
subst
::
Substs
::
empty
();
...
...
@@ -163,7 +163,7 @@ fn relate_type_params<'tcx, C: Combine<'tcx>>(this: &C,
variances
:
Option
<&
[
ty
::
Variance
]
>
,
a_tys
:
&
[
Ty
<
'tcx
>
],
b_tys
:
&
[
Ty
<
'tcx
>
])
->
cres
<
'tcx
,
Vec
<
Ty
<
'tcx
>>>
->
CombineResult
<
'tcx
,
Vec
<
Ty
<
'tcx
>>>
{
if
a_tys
.len
()
!=
b_tys
.len
()
{
return
Err
(
ty
::
terr_ty_param_size
(
expected_found
(
this
,
...
...
@@ -183,7 +183,7 @@ fn relate_region_params<'tcx, C: Combine<'tcx>>(this: &C,
variances
:
Option
<&
[
ty
::
Variance
]
>
,
a_rs
:
&
[
ty
::
Region
],
b_rs
:
&
[
ty
::
Region
])
->
cres
<
'tcx
,
Vec
<
ty
::
Region
>>
->
CombineResult
<
'tcx
,
Vec
<
ty
::
Region
>>
{
let
tcx
=
this
.infcx
()
.tcx
;
let
num_region_params
=
a_rs
.len
();
...
...
@@ -212,7 +212,7 @@ fn relate_region_params<'tcx, C: Combine<'tcx>>(this: &C,
}
fn
bare_fn_tys
(
&
self
,
a
:
&
ty
::
BareFnTy
<
'tcx
>
,
b
:
&
ty
::
BareFnTy
<
'tcx
>
)
->
cres
<
'tcx
,
ty
::
BareFnTy
<
'tcx
>>
{
b
:
&
ty
::
BareFnTy
<
'tcx
>
)
->
CombineResult
<
'tcx
,
ty
::
BareFnTy
<
'tcx
>>
{
let
unsafety
=
try!
(
self
.unsafeties
(
a
.unsafety
,
b
.unsafety
));
let
abi
=
try!
(
self
.abi
(
a
.abi
,
b
.abi
));
let
sig
=
try!
(
self
.binders
(
&
a
.sig
,
&
b
.sig
));
...
...
@@ -221,7 +221,7 @@ fn bare_fn_tys(&self, a: &ty::BareFnTy<'tcx>,
sig
:
sig
})
}
fn
fn_sigs
(
&
self
,
a
:
&
ty
::
FnSig
<
'tcx
>
,
b
:
&
ty
::
FnSig
<
'tcx
>
)
->
cres
<
'tcx
,
ty
::
FnSig
<
'tcx
>>
{
fn
fn_sigs
(
&
self
,
a
:
&
ty
::
FnSig
<
'tcx
>
,
b
:
&
ty
::
FnSig
<
'tcx
>
)
->
CombineResult
<
'tcx
,
ty
::
FnSig
<
'tcx
>>
{
if
a
.variadic
!=
b
.variadic
{
return
Err
(
ty
::
terr_variadic_mismatch
(
expected_found
(
self
,
a
.variadic
,
b
.variadic
)));
}
...
...
@@ -248,7 +248,7 @@ fn fn_sigs(&self, a: &ty::FnSig<'tcx>, b: &ty::FnSig<'tcx>) -> cres<'tcx, ty::Fn
fn
argvecs
<
'tcx
,
C
>
(
combiner
:
&
C
,
a_args
:
&
[
Ty
<
'tcx
>
],
b_args
:
&
[
Ty
<
'tcx
>
])
->
cres
<
'tcx
,
Vec
<
Ty
<
'tcx
>>>
->
CombineResult
<
'tcx
,
Vec
<
Ty
<
'tcx
>>>
where
C
:
Combine
<
'tcx
>
{
if
a_args
.len
()
==
b_args
.len
()
{
a_args
.iter
()
.zip
(
b_args
.iter
())
...
...
@@ -259,11 +259,11 @@ fn argvecs<'tcx, C>(combiner: &C,
}
}
fn
args
(
&
self
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
{
fn
args
(
&
self
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
{
self
.tys_with_variance
(
ty
::
Contravariant
,
a
,
b
)
.and_then
(|
t
|
Ok
(
t
))
}
fn
unsafeties
(
&
self
,
a
:
Unsafety
,
b
:
Unsafety
)
->
cres
<
'tcx
,
Unsafety
>
{
fn
unsafeties
(
&
self
,
a
:
Unsafety
,
b
:
Unsafety
)
->
CombineResult
<
'tcx
,
Unsafety
>
{
if
a
!=
b
{
Err
(
ty
::
terr_unsafety_mismatch
(
expected_found
(
self
,
a
,
b
)))
}
else
{
...
...
@@ -271,7 +271,7 @@ fn unsafeties(&self, a: Unsafety, b: Unsafety) -> cres<'tcx, Unsafety> {
}
}
fn
abi
(
&
self
,
a
:
abi
::
Abi
,
b
:
abi
::
Abi
)
->
cres
<
'tcx
,
abi
::
Abi
>
{
fn
abi
(
&
self
,
a
:
abi
::
Abi
,
b
:
abi
::
Abi
)
->
CombineResult
<
'tcx
,
abi
::
Abi
>
{
if
a
==
b
{
Ok
(
a
)
}
else
{
...
...
@@ -282,7 +282,7 @@ fn abi(&self, a: abi::Abi, b: abi::Abi) -> cres<'tcx, abi::Abi> {
fn
projection_tys
(
&
self
,
a
:
&
ty
::
ProjectionTy
<
'tcx
>
,
b
:
&
ty
::
ProjectionTy
<
'tcx
>
)
->
cres
<
'tcx
,
ty
::
ProjectionTy
<
'tcx
>>
->
CombineResult
<
'tcx
,
ty
::
ProjectionTy
<
'tcx
>>
{
if
a
.item_name
!=
b
.item_name
{
Err
(
ty
::
terr_projection_name_mismatched
(
...
...
@@ -296,7 +296,7 @@ fn projection_tys(&self,
fn
projection_predicates
(
&
self
,
a
:
&
ty
::
ProjectionPredicate
<
'tcx
>
,
b
:
&
ty
::
ProjectionPredicate
<
'tcx
>
)
->
cres
<
'tcx
,
ty
::
ProjectionPredicate
<
'tcx
>>
->
CombineResult
<
'tcx
,
ty
::
ProjectionPredicate
<
'tcx
>>
{
let
projection_ty
=
try!
(
self
.projection_tys
(
&
a
.projection_ty
,
&
b
.projection_ty
));
let
ty
=
try!
(
self
.tys
(
a
.ty
,
b
.ty
));
...
...
@@ -306,7 +306,7 @@ fn projection_predicates(&self,
fn
projection_bounds
(
&
self
,
a
:
&
Vec
<
ty
::
PolyProjectionPredicate
<
'tcx
>>
,
b
:
&
Vec
<
ty
::
PolyProjectionPredicate
<
'tcx
>>
)
->
cres
<
'tcx
,
Vec
<
ty
::
PolyProjectionPredicate
<
'tcx
>>>
->
CombineResult
<
'tcx
,
Vec
<
ty
::
PolyProjectionPredicate
<
'tcx
>>>
{
// To be compatible, `a` and `b` must be for precisely the
// same set of traits and item names. We always require that
...
...
@@ -326,7 +326,7 @@ fn projection_bounds(&self,
fn
existential_bounds
(
&
self
,
a
:
&
ty
::
ExistentialBounds
<
'tcx
>
,
b
:
&
ty
::
ExistentialBounds
<
'tcx
>
)
->
cres
<
'tcx
,
ty
::
ExistentialBounds
<
'tcx
>>
->
CombineResult
<
'tcx
,
ty
::
ExistentialBounds
<
'tcx
>>
{
let
r
=
try!
(
self
.regions_with_variance
(
ty
::
Contravariant
,
a
.region_bound
,
b
.region_bound
));
let
nb
=
try!
(
self
.builtin_bounds
(
a
.builtin_bounds
,
b
.builtin_bounds
));
...
...
@@ -339,7 +339,7 @@ fn existential_bounds(&self,
fn
builtin_bounds
(
&
self
,
a
:
BuiltinBounds
,
b
:
BuiltinBounds
)
->
cres
<
'tcx
,
BuiltinBounds
>
->
CombineResult
<
'tcx
,
BuiltinBounds
>
{
// Two sets of builtin bounds are only relatable if they are
// precisely the same (but see the coercion code).
...
...
@@ -353,7 +353,7 @@ fn builtin_bounds(&self,
fn
trait_refs
(
&
self
,
a
:
&
ty
::
TraitRef
<
'tcx
>
,
b
:
&
ty
::
TraitRef
<
'tcx
>
)
->
cres
<
'tcx
,
ty
::
TraitRef
<
'tcx
>>
->
CombineResult
<
'tcx
,
ty
::
TraitRef
<
'tcx
>>
{
// Different traits cannot be related
if
a
.def_id
!=
b
.def_id
{
...
...
@@ -364,14 +364,14 @@ fn trait_refs(&self,
}
}
fn
binders
<
T
>
(
&
self
,
a
:
&
ty
::
Binder
<
T
>
,
b
:
&
ty
::
Binder
<
T
>
)
->
cres
<
'tcx
,
ty
::
Binder
<
T
>>
fn
binders
<
T
>
(
&
self
,
a
:
&
ty
::
Binder
<
T
>
,
b
:
&
ty
::
Binder
<
T
>
)
->
CombineResult
<
'tcx
,
ty
::
Binder
<
T
>>
where
T
:
Combineable
<
'tcx
>
;
// this must be overridden to do correctly, so as to account for higher-ranked
// behavior
}
pub
trait
Combineable
<
'tcx
>
:
Repr
<
'tcx
>
+
TypeFoldable
<
'tcx
>
{
fn
combine
<
C
:
Combine
<
'tcx
>>
(
combiner
:
&
C
,
a
:
&
Self
,
b
:
&
Self
)
->
cres
<
'tcx
,
Self
>
;
fn
combine
<
C
:
Combine
<
'tcx
>>
(
combiner
:
&
C
,
a
:
&
Self
,
b
:
&
Self
)
->
CombineResult
<
'tcx
,
Self
>
;
}
impl
<
'tcx
,
T
>
Combineable
<
'tcx
>
for
Rc
<
T
>
...
...
@@ -380,7 +380,7 @@ impl<'tcx,T> Combineable<'tcx> for Rc<T>
fn
combine
<
C
>
(
combiner
:
&
C
,
a
:
&
Rc
<
T
>
,
b
:
&
Rc
<
T
>
)
->
cres
<
'tcx
,
Rc
<
T
>>
->
CombineResult
<
'tcx
,
Rc
<
T
>>
where
C
:
Combine
<
'tcx
>
{
Ok
(
Rc
::
new
(
try!
(
Combineable
::
combine
(
combiner
,
&**
a
,
&**
b
))))
}
...
...
@@ -390,7 +390,7 @@ impl<'tcx> Combineable<'tcx> for ty::TraitRef<'tcx> {
fn
combine
<
C
>
(
combiner
:
&
C
,
a
:
&
ty
::
TraitRef
<
'tcx
>
,
b
:
&
ty
::
TraitRef
<
'tcx
>
)
->
cres
<
'tcx
,
ty
::
TraitRef
<
'tcx
>>
->
CombineResult
<
'tcx
,
ty
::
TraitRef
<
'tcx
>>
where
C
:
Combine
<
'tcx
>
{
combiner
.trait_refs
(
a
,
b
)
}
...
...
@@ -400,7 +400,7 @@ impl<'tcx> Combineable<'tcx> for Ty<'tcx> {
fn
combine
<
C
>
(
combiner
:
&
C
,
a
:
&
Ty
<
'tcx
>
,
b
:
&
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
where
C
:
Combine
<
'tcx
>
{
combiner
.tys
(
*
a
,
*
b
)
}
...
...
@@ -410,7 +410,7 @@ impl<'tcx> Combineable<'tcx> for ty::ProjectionPredicate<'tcx> {
fn
combine
<
C
>
(
combiner
:
&
C
,
a
:
&
ty
::
ProjectionPredicate
<
'tcx
>
,
b
:
&
ty
::
ProjectionPredicate
<
'tcx
>
)
->
cres
<
'tcx
,
ty
::
ProjectionPredicate
<
'tcx
>>
->
CombineResult
<
'tcx
,
ty
::
ProjectionPredicate
<
'tcx
>>
where
C
:
Combine
<
'tcx
>
{
combiner
.projection_predicates
(
a
,
b
)
}
...
...
@@ -420,7 +420,7 @@ impl<'tcx> Combineable<'tcx> for ty::FnSig<'tcx> {
fn
combine
<
C
>
(
combiner
:
&
C
,
a
:
&
ty
::
FnSig
<
'tcx
>
,
b
:
&
ty
::
FnSig
<
'tcx
>
)
->
cres
<
'tcx
,
ty
::
FnSig
<
'tcx
>>
->
CombineResult
<
'tcx
,
ty
::
FnSig
<
'tcx
>>
where
C
:
Combine
<
'tcx
>
{
combiner
.fn_sigs
(
a
,
b
)
}
...
...
@@ -448,7 +448,7 @@ pub fn expected_found<'tcx, C, T>(this: &C,
pub
fn
super_tys
<
'tcx
,
C
>
(
this
:
&
C
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
where
C
:
Combine
<
'tcx
>
{
let
tcx
=
this
.infcx
()
.tcx
;
let
a_sty
=
&
a
.sty
;
...
...
@@ -616,7 +616,7 @@ fn unify_integral_variable<'tcx, C>(this: &C,
vid_is_expected
:
bool
,
vid
:
ty
::
IntVid
,
val
:
ty
::
IntVarValue
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
where
C
:
Combine
<
'tcx
>
{
try!
(
this
.infcx
()
.simple_var_t
(
vid_is_expected
,
vid
,
val
));
match
val
{
...
...
@@ -629,7 +629,7 @@ fn unify_float_variable<'tcx, C>(this: &C,
vid_is_expected
:
bool
,
vid
:
ty
::
FloatVid
,
val
:
ast
::
FloatTy
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
where
C
:
Combine
<
'tcx
>
{
try!
(
this
.infcx
()
.simple_var_t
(
vid_is_expected
,
vid
,
val
));
Ok
(
ty
::
mk_mach_float
(
this
.tcx
(),
val
))
...
...
@@ -660,7 +660,7 @@ pub fn instantiate(&self,
a_ty
:
Ty
<
'tcx
>
,
dir
:
RelationDir
,
b_vid
:
ty
::
TyVid
)
->
cres
<
'tcx
,
()
>
->
CombineResult
<
'tcx
,
()
>
{
let
tcx
=
self
.infcx.tcx
;
let
mut
stack
=
Vec
::
new
();
...
...
@@ -746,7 +746,7 @@ fn generalize(&self,
ty
:
Ty
<
'tcx
>
,
for_vid
:
ty
::
TyVid
,
make_region_vars
:
bool
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
{
let
mut
generalize
=
Generalizer
{
infcx
:
self
.infcx
,
...
...
@@ -839,3 +839,23 @@ fn fold_region(&mut self, r: ty::Region) -> ty::Region {
self
.infcx
.next_region_var
(
MiscVariable
(
self
.span
))
}
}
pub
trait
CombineResultCompare
<
'tcx
,
T
>
{
fn
compare
<
F
>
(
&
self
,
t
:
T
,
f
:
F
)
->
CombineResult
<
'tcx
,
T
>
where
F
:
FnOnce
()
->
ty
::
type_err
<
'tcx
>
;
}
impl
<
'tcx
,
T
:
Clone
+
PartialEq
>
CombineResultCompare
<
'tcx
,
T
>
for
CombineResult
<
'tcx
,
T
>
{
fn
compare
<
F
>
(
&
self
,
t
:
T
,
f
:
F
)
->
CombineResult
<
'tcx
,
T
>
where
F
:
FnOnce
()
->
ty
::
type_err
<
'tcx
>
,
{
(
*
self
)
.clone
()
.and_then
(|
s
|
{
if
s
==
t
{
(
*
self
)
.clone
()
}
else
{
Err
(
f
())
}
})
}
}
src/librustc/middle/infer/equate.rs
浏览文件 @
09398378
...
...
@@ -11,7 +11,7 @@
use
middle
::
ty
::{
self
,
Ty
};
use
middle
::
ty
::
TyVar
;
use
middle
::
infer
::
combine
::
*
;
use
middle
::
infer
::
cres
;
use
middle
::
infer
::
CombineResult
;
use
middle
::
infer
::
Subtype
;
use
middle
::
infer
::
type_variable
::
EqTo
;
use
util
::
ppaux
::
Repr
;
...
...
@@ -30,20 +30,20 @@ fn tag(&self) -> String { "Equate".to_string() }
fn
fields
<
'a
>
(
&
'a
self
)
->
&
'a
CombineFields
<
'a
,
'tcx
>
{
&
self
.fields
}
fn
tys_with_variance
(
&
self
,
_
:
ty
::
Variance
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
{
// Once we're equating, it doesn't matter what the variance is.
self
.tys
(
a
,
b
)
}
fn
regions_with_variance
(
&
self
,
_
:
ty
::
Variance
,
a
:
ty
::
Region
,
b
:
ty
::
Region
)
->
cres
<
'tcx
,
ty
::
Region
>
->
CombineResult
<
'tcx
,
ty
::
Region
>
{
// Once we're equating, it doesn't matter what the variance is.
self
.regions
(
a
,
b
)
}
fn
regions
(
&
self
,
a
:
ty
::
Region
,
b
:
ty
::
Region
)
->
cres
<
'tcx
,
ty
::
Region
>
{
fn
regions
(
&
self
,
a
:
ty
::
Region
,
b
:
ty
::
Region
)
->
CombineResult
<
'tcx
,
ty
::
Region
>
{
debug!
(
"{}.regions({}, {})"
,
self
.tag
(),
a
.repr
(
self
.fields.infcx.tcx
),
...
...
@@ -52,7 +52,7 @@ fn regions(&self, a: ty::Region, b: ty::Region) -> cres<'tcx, ty::Region> {
Ok
(
a
)
}
fn
tys
(
&
self
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
{
fn
tys
(
&
self
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
{
debug!
(
"{}.tys({}, {})"
,
self
.tag
(),
a
.repr
(
self
.fields.infcx.tcx
),
b
.repr
(
self
.fields.infcx.tcx
));
if
a
==
b
{
return
Ok
(
a
);
}
...
...
@@ -82,7 +82,7 @@ fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> {
}
}
fn
binders
<
T
>
(
&
self
,
a
:
&
ty
::
Binder
<
T
>
,
b
:
&
ty
::
Binder
<
T
>
)
->
cres
<
'tcx
,
ty
::
Binder
<
T
>>
fn
binders
<
T
>
(
&
self
,
a
:
&
ty
::
Binder
<
T
>
,
b
:
&
ty
::
Binder
<
T
>
)
->
CombineResult
<
'tcx
,
ty
::
Binder
<
T
>>
where
T
:
Combineable
<
'tcx
>
{
try!
(
self
.sub
()
.binders
(
a
,
b
));
...
...
src/librustc/middle/infer/glb.rs
浏览文件 @
09398378
...
...
@@ -11,7 +11,7 @@
use
super
::
combine
::
*
;
use
super
::
lattice
::
*
;
use
super
::
higher_ranked
::
HigherRankedRelations
;
use
super
::
cres
;
use
super
::
CombineResult
;
use
super
::
Subtype
;
use
middle
::
ty
::{
self
,
Ty
};
...
...
@@ -32,7 +32,7 @@ fn tag(&self) -> String { "Glb".to_string() }
fn
fields
<
'a
>
(
&
'a
self
)
->
&
'a
CombineFields
<
'a
,
'tcx
>
{
&
self
.fields
}
fn
tys_with_variance
(
&
self
,
v
:
ty
::
Variance
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
{
match
v
{
ty
::
Invariant
=>
self
.equate
()
.tys
(
a
,
b
),
...
...
@@ -43,7 +43,7 @@ fn tys_with_variance(&self, v: ty::Variance, a: Ty<'tcx>, b: Ty<'tcx>)
}
fn
regions_with_variance
(
&
self
,
v
:
ty
::
Variance
,
a
:
ty
::
Region
,
b
:
ty
::
Region
)
->
cres
<
'tcx
,
ty
::
Region
>
->
CombineResult
<
'tcx
,
ty
::
Region
>
{
match
v
{
ty
::
Invariant
=>
self
.equate
()
.regions
(
a
,
b
),
...
...
@@ -53,7 +53,7 @@ fn regions_with_variance(&self, v: ty::Variance, a: ty::Region, b: ty::Region)
}
}
fn
regions
(
&
self
,
a
:
ty
::
Region
,
b
:
ty
::
Region
)
->
cres
<
'tcx
,
ty
::
Region
>
{
fn
regions
(
&
self
,
a
:
ty
::
Region
,
b
:
ty
::
Region
)
->
CombineResult
<
'tcx
,
ty
::
Region
>
{
debug!
(
"{}.regions({}, {})"
,
self
.tag
(),
a
.repr
(
self
.fields.infcx.tcx
),
...
...
@@ -62,11 +62,11 @@ fn regions(&self, a: ty::Region, b: ty::Region) -> cres<'tcx, ty::Region> {
Ok
(
self
.fields.infcx.region_vars
.glb_regions
(
Subtype
(
self
.trace
()),
a
,
b
))
}
fn
tys
(
&
self
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
{
fn
tys
(
&
self
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
{
super_lattice_tys
(
self
,
a
,
b
)
}
fn
binders
<
T
>
(
&
self
,
a
:
&
ty
::
Binder
<
T
>
,
b
:
&
ty
::
Binder
<
T
>
)
->
cres
<
'tcx
,
ty
::
Binder
<
T
>>
fn
binders
<
T
>
(
&
self
,
a
:
&
ty
::
Binder
<
T
>
,
b
:
&
ty
::
Binder
<
T
>
)
->
CombineResult
<
'tcx
,
ty
::
Binder
<
T
>>
where
T
:
Combineable
<
'tcx
>
{
self
.higher_ranked_glb
(
a
,
b
)
...
...
src/librustc/middle/infer/higher_ranked/mod.rs
浏览文件 @
09398378
...
...
@@ -11,7 +11,7 @@
//! Helper routines for higher-ranked things. See the `doc` module at
//! the end of the file for details.
use
super
::{
CombinedSnapshot
,
cres
,
InferCtxt
,
HigherRankedType
,
SkolemizationMap
};
use
super
::{
CombinedSnapshot
,
CombineResult
,
InferCtxt
,
HigherRankedType
,
SkolemizationMap
};
use
super
::
combine
::{
Combine
,
Combineable
};
use
middle
::
subst
;
...
...
@@ -22,13 +22,13 @@
use
util
::
ppaux
::
Repr
;
pub
trait
HigherRankedRelations
<
'tcx
>
{
fn
higher_ranked_sub
<
T
>
(
&
self
,
a
:
&
Binder
<
T
>
,
b
:
&
Binder
<
T
>
)
->
cres
<
'tcx
,
Binder
<
T
>>
fn
higher_ranked_sub
<
T
>
(
&
self
,
a
:
&
Binder
<
T
>
,
b
:
&
Binder
<
T
>
)
->
CombineResult
<
'tcx
,
Binder
<
T
>>
where
T
:
Combineable
<
'tcx
>
;
fn
higher_ranked_lub
<
T
>
(
&
self
,
a
:
&
Binder
<
T
>
,
b
:
&
Binder
<
T
>
)
->
cres
<
'tcx
,
Binder
<
T
>>
fn
higher_ranked_lub
<
T
>
(
&
self
,
a
:
&
Binder
<
T
>
,
b
:
&
Binder
<
T
>
)
->
CombineResult
<
'tcx
,
Binder
<
T
>>
where
T
:
Combineable
<
'tcx
>
;
fn
higher_ranked_glb
<
T
>
(
&
self
,
a
:
&
Binder
<
T
>
,
b
:
&
Binder
<
T
>
)
->
cres
<
'tcx
,
Binder
<
T
>>
fn
higher_ranked_glb
<
T
>
(
&
self
,
a
:
&
Binder
<
T
>
,
b
:
&
Binder
<
T
>
)
->
CombineResult
<
'tcx
,
Binder
<
T
>>
where
T
:
Combineable
<
'tcx
>
;
}
...
...
@@ -44,7 +44,7 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C
where
C
:
Combine
<
'tcx
>
{
fn
higher_ranked_sub
<
T
>
(
&
self
,
a
:
&
Binder
<
T
>
,
b
:
&
Binder
<
T
>
)
->
cres
<
'tcx
,
Binder
<
T
>>
->
CombineResult
<
'tcx
,
Binder
<
T
>>
where
T
:
Combineable
<
'tcx
>
{
debug!
(
"higher_ranked_sub(a={}, b={})"
,
...
...
@@ -104,7 +104,7 @@ fn higher_ranked_sub<T>(&self, a: &Binder<T>, b: &Binder<T>)
});
}
fn
higher_ranked_lub
<
T
>
(
&
self
,
a
:
&
Binder
<
T
>
,
b
:
&
Binder
<
T
>
)
->
cres
<
'tcx
,
Binder
<
T
>>
fn
higher_ranked_lub
<
T
>
(
&
self
,
a
:
&
Binder
<
T
>
,
b
:
&
Binder
<
T
>
)
->
CombineResult
<
'tcx
,
Binder
<
T
>>
where
T
:
Combineable
<
'tcx
>
{
// Start a snapshot so we can examine "all bindings that were
...
...
@@ -194,7 +194,7 @@ fn generalize_region(infcx: &InferCtxt,
}
}
fn
higher_ranked_glb
<
T
>
(
&
self
,
a
:
&
Binder
<
T
>
,
b
:
&
Binder
<
T
>
)
->
cres
<
'tcx
,
Binder
<
T
>>
fn
higher_ranked_glb
<
T
>
(
&
self
,
a
:
&
Binder
<
T
>
,
b
:
&
Binder
<
T
>
)
->
CombineResult
<
'tcx
,
Binder
<
T
>>
where
T
:
Combineable
<
'tcx
>
{
debug!
(
"{}.higher_ranked_glb({}, {})"
,
...
...
src/librustc/middle/infer/lattice.rs
浏览文件 @
09398378
...
...
@@ -41,11 +41,11 @@
pub
trait
LatticeDir
<
'tcx
>
{
// Relates the type `v` to `a` and `b` such that `v` represents
// the LUB/GLB of `a` and `b` as appropriate.
fn
relate_bound
(
&
self
,
v
:
Ty
<
'tcx
>
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
()
>
;
fn
relate_bound
(
&
self
,
v
:
Ty
<
'tcx
>
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
CombineResult
<
'tcx
,
()
>
;
}
impl
<
'a
,
'tcx
>
LatticeDir
<
'tcx
>
for
Lub
<
'a
,
'tcx
>
{
fn
relate_bound
(
&
self
,
v
:
Ty
<
'tcx
>
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
()
>
{
fn
relate_bound
(
&
self
,
v
:
Ty
<
'tcx
>
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
CombineResult
<
'tcx
,
()
>
{
let
sub
=
self
.sub
();
try!
(
sub
.tys
(
a
,
v
));
try!
(
sub
.tys
(
b
,
v
));
...
...
@@ -54,7 +54,7 @@ fn relate_bound(&self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, ()>
}
impl
<
'a
,
'tcx
>
LatticeDir
<
'tcx
>
for
Glb
<
'a
,
'tcx
>
{
fn
relate_bound
(
&
self
,
v
:
Ty
<
'tcx
>
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
()
>
{
fn
relate_bound
(
&
self
,
v
:
Ty
<
'tcx
>
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
CombineResult
<
'tcx
,
()
>
{
let
sub
=
self
.sub
();
try!
(
sub
.tys
(
v
,
a
));
try!
(
sub
.tys
(
v
,
b
));
...
...
@@ -65,7 +65,7 @@ fn relate_bound(&self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, ()>
pub
fn
super_lattice_tys
<
'tcx
,
L
:
LatticeDir
<
'tcx
>+
Combine
<
'tcx
>>
(
this
:
&
L
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
{
debug!
(
"{}.lattice_tys({}, {})"
,
this
.tag
(),
...
...
src/librustc/middle/infer/lub.rs
浏览文件 @
09398378
...
...
@@ -11,7 +11,7 @@
use
super
::
combine
::
*
;
use
super
::
higher_ranked
::
HigherRankedRelations
;
use
super
::
lattice
::
*
;
use
super
::
cres
;
use
super
::
CombineResult
;
use
super
::
Subtype
;
use
middle
::
ty
::{
self
,
Ty
};
...
...
@@ -32,7 +32,7 @@ fn tag(&self) -> String { "Lub".to_string() }
fn
fields
<
'a
>
(
&
'a
self
)
->
&
'a
CombineFields
<
'a
,
'tcx
>
{
&
self
.fields
}
fn
tys_with_variance
(
&
self
,
v
:
ty
::
Variance
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
{
match
v
{
ty
::
Invariant
=>
self
.equate
()
.tys
(
a
,
b
),
...
...
@@ -43,7 +43,7 @@ fn tys_with_variance(&self, v: ty::Variance, a: Ty<'tcx>, b: Ty<'tcx>)
}
fn
regions_with_variance
(
&
self
,
v
:
ty
::
Variance
,
a
:
ty
::
Region
,
b
:
ty
::
Region
)
->
cres
<
'tcx
,
ty
::
Region
>
->
CombineResult
<
'tcx
,
ty
::
Region
>
{
match
v
{
ty
::
Invariant
=>
self
.equate
()
.regions
(
a
,
b
),
...
...
@@ -53,7 +53,7 @@ fn regions_with_variance(&self, v: ty::Variance, a: ty::Region, b: ty::Region)
}
}
fn
regions
(
&
self
,
a
:
ty
::
Region
,
b
:
ty
::
Region
)
->
cres
<
'tcx
,
ty
::
Region
>
{
fn
regions
(
&
self
,
a
:
ty
::
Region
,
b
:
ty
::
Region
)
->
CombineResult
<
'tcx
,
ty
::
Region
>
{
debug!
(
"{}.regions({}, {})"
,
self
.tag
(),
a
.repr
(
self
.tcx
()),
...
...
@@ -62,11 +62,11 @@ fn regions(&self, a: ty::Region, b: ty::Region) -> cres<'tcx, ty::Region> {
Ok
(
self
.infcx
()
.region_vars
.lub_regions
(
Subtype
(
self
.trace
()),
a
,
b
))
}
fn
tys
(
&
self
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
{
fn
tys
(
&
self
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
{
super_lattice_tys
(
self
,
a
,
b
)
}
fn
binders
<
T
>
(
&
self
,
a
:
&
ty
::
Binder
<
T
>
,
b
:
&
ty
::
Binder
<
T
>
)
->
cres
<
'tcx
,
ty
::
Binder
<
T
>>
fn
binders
<
T
>
(
&
self
,
a
:
&
ty
::
Binder
<
T
>
,
b
:
&
ty
::
Binder
<
T
>
)
->
CombineResult
<
'tcx
,
ty
::
Binder
<
T
>>
where
T
:
Combineable
<
'tcx
>
{
self
.higher_ranked_lub
(
a
,
b
)
...
...
src/librustc/middle/infer/mod.rs
浏览文件 @
09398378
...
...
@@ -63,8 +63,8 @@
pub
type
Bound
<
T
>
=
Option
<
T
>
;
pub
type
cres
<
'tcx
,
T
>
=
Result
<
T
,
ty
::
type_err
<
'tcx
>>
;
// "combine result"
pub
type
ures
<
'tcx
>
=
cres
<
'tcx
,
()
>
;
// "unify result"
pub
type
CombineResult
<
'tcx
,
T
>
=
Result
<
T
,
ty
::
type_err
<
'tcx
>>
;
// "combine result"
pub
type
UnitResult
<
'tcx
>
=
CombineResult
<
'tcx
,
()
>
;
// "unify result"
pub
type
fres
<
T
>
=
Result
<
T
,
fixup_err
>
;
// "fixup result"
pub
struct
InferCtxt
<
'a
,
'tcx
:
'a
>
{
...
...
@@ -359,7 +359,7 @@ pub fn mk_subty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
origin
:
TypeOrigin
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
ures
<
'tcx
>
->
UnitResult
<
'tcx
>
{
debug!
(
"mk_subty({} <: {})"
,
a
.repr
(
cx
.tcx
),
b
.repr
(
cx
.tcx
));
cx
.commit_if_ok
(||
{
...
...
@@ -370,18 +370,18 @@ pub fn mk_subty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
pub
fn
can_mk_subty
<
'a
,
'tcx
>
(
cx
:
&
InferCtxt
<
'a
,
'tcx
>
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
ures
<
'tcx
>
{
->
UnitResult
<
'tcx
>
{
debug!
(
"can_mk_subty({} <: {})"
,
a
.repr
(
cx
.tcx
),
b
.repr
(
cx
.tcx
));
cx
.probe
(|
_
|
{
let
trace
=
TypeTrace
{
origin
:
Misc
(
codemap
::
DUMMY_SP
),
values
:
Types
(
expected_found
(
true
,
a
,
b
))
};
cx
.sub
(
true
,
trace
)
.tys
(
a
,
b
)
.
to_ures
(
)
cx
.sub
(
true
,
trace
)
.tys
(
a
,
b
)
.
map
(|
_
|
()
)
})
}
pub
fn
can_mk_eqty
<
'a
,
'tcx
>
(
cx
:
&
InferCtxt
<
'a
,
'tcx
>
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
ures
<
'tcx
>
pub
fn
can_mk_eqty
<
'a
,
'tcx
>
(
cx
:
&
InferCtxt
<
'a
,
'tcx
>
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
UnitResult
<
'tcx
>
{
cx
.can_equate
(
&
a
,
&
b
)
}
...
...
@@ -401,7 +401,7 @@ pub fn mk_eqty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
origin
:
TypeOrigin
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
ures
<
'tcx
>
->
UnitResult
<
'tcx
>
{
debug!
(
"mk_eqty({} <: {})"
,
a
.repr
(
cx
.tcx
),
b
.repr
(
cx
.tcx
));
cx
.commit_if_ok
(
...
...
@@ -413,7 +413,7 @@ pub fn mk_sub_poly_trait_refs<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
origin
:
TypeOrigin
,
a
:
ty
::
PolyTraitRef
<
'tcx
>
,
b
:
ty
::
PolyTraitRef
<
'tcx
>
)
->
ures
<
'tcx
>
->
UnitResult
<
'tcx
>
{
debug!
(
"mk_sub_trait_refs({} <: {})"
,
a
.repr
(
cx
.tcx
),
b
.repr
(
cx
.tcx
));
...
...
@@ -433,57 +433,6 @@ fn expected_found<T>(a_is_expected: bool,
}
}
trait
then
<
'tcx
>
{
fn
then
<
T
,
F
>
(
&
self
,
f
:
F
)
->
Result
<
T
,
ty
::
type_err
<
'tcx
>>
where
T
:
Clone
,
F
:
FnOnce
()
->
Result
<
T
,
ty
::
type_err
<
'tcx
>>
;
}
impl
<
'tcx
>
then
<
'tcx
>
for
ures
<
'tcx
>
{
fn
then
<
T
,
F
>
(
&
self
,
f
:
F
)
->
Result
<
T
,
ty
::
type_err
<
'tcx
>>
where
T
:
Clone
,
F
:
FnOnce
()
->
Result
<
T
,
ty
::
type_err
<
'tcx
>>
,
{
self
.and_then
(
move
|
_
|
f
())
}
}
trait
ToUres
<
'tcx
>
{
fn
to_ures
(
&
self
)
->
ures
<
'tcx
>
;
}
impl
<
'tcx
,
T
>
ToUres
<
'tcx
>
for
cres
<
'tcx
,
T
>
{
fn
to_ures
(
&
self
)
->
ures
<
'tcx
>
{
match
*
self
{
Ok
(
ref
_
v
)
=>
Ok
(()),
Err
(
ref
e
)
=>
Err
((
*
e
))
}
}
}
trait
CresCompare
<
'tcx
,
T
>
{
fn
compare
<
F
>
(
&
self
,
t
:
T
,
f
:
F
)
->
cres
<
'tcx
,
T
>
where
F
:
FnOnce
()
->
ty
::
type_err
<
'tcx
>
;
}
impl
<
'tcx
,
T
:
Clone
+
PartialEq
>
CresCompare
<
'tcx
,
T
>
for
cres
<
'tcx
,
T
>
{
fn
compare
<
F
>
(
&
self
,
t
:
T
,
f
:
F
)
->
cres
<
'tcx
,
T
>
where
F
:
FnOnce
()
->
ty
::
type_err
<
'tcx
>
,
{
(
*
self
)
.clone
()
.and_then
(
move
|
s
|
{
if
s
==
t
{
(
*
self
)
.clone
()
}
else
{
Err
(
f
())
}
})
}
}
pub
fn
uok
<
'tcx
>
()
->
ures
<
'tcx
>
{
Ok
(())
}
#[must_use
=
"once you start a snapshot, you should always consume it"
]
pub
struct
CombinedSnapshot
{
type_snapshot
:
type_variable
::
Snapshot
,
...
...
@@ -691,12 +640,12 @@ pub fn sub_types(&self,
origin
:
TypeOrigin
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
ures
<
'tcx
>
->
UnitResult
<
'tcx
>
{
debug!
(
"sub_types({} <: {})"
,
a
.repr
(
self
.tcx
),
b
.repr
(
self
.tcx
));
self
.commit_if_ok
(||
{
let
trace
=
TypeTrace
::
types
(
origin
,
a_is_expected
,
a
,
b
);
self
.sub
(
a_is_expected
,
trace
)
.tys
(
a
,
b
)
.
to_ures
(
)
self
.sub
(
a_is_expected
,
trace
)
.tys
(
a
,
b
)
.
map
(|
_
|
()
)
})
}
...
...
@@ -705,11 +654,11 @@ pub fn eq_types(&self,
origin
:
TypeOrigin
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
ures
<
'tcx
>
->
UnitResult
<
'tcx
>
{
self
.commit_if_ok
(||
{
let
trace
=
TypeTrace
::
types
(
origin
,
a_is_expected
,
a
,
b
);
self
.equate
(
a_is_expected
,
trace
)
.tys
(
a
,
b
)
.
to_ures
(
)
self
.equate
(
a_is_expected
,
trace
)
.tys
(
a
,
b
)
.
map
(|
_
|
()
)
})
}
...
...
@@ -718,7 +667,7 @@ pub fn sub_trait_refs(&self,
origin
:
TypeOrigin
,
a
:
Rc
<
ty
::
TraitRef
<
'tcx
>>
,
b
:
Rc
<
ty
::
TraitRef
<
'tcx
>>
)
->
ures
<
'tcx
>
->
UnitResult
<
'tcx
>
{
debug!
(
"sub_trait_refs({} <: {})"
,
a
.repr
(
self
.tcx
),
...
...
@@ -728,7 +677,7 @@ pub fn sub_trait_refs(&self,
origin
:
origin
,
values
:
TraitRefs
(
expected_found
(
a_is_expected
,
a
.clone
(),
b
.clone
()))
};
self
.sub
(
a_is_expected
,
trace
)
.trait_refs
(
&*
a
,
&*
b
)
.
to_ures
(
)
self
.sub
(
a_is_expected
,
trace
)
.trait_refs
(
&*
a
,
&*
b
)
.
map
(|
_
|
()
)
})
}
...
...
@@ -737,7 +686,7 @@ pub fn sub_poly_trait_refs(&self,
origin
:
TypeOrigin
,
a
:
ty
::
PolyTraitRef
<
'tcx
>
,
b
:
ty
::
PolyTraitRef
<
'tcx
>
)
->
ures
<
'tcx
>
->
UnitResult
<
'tcx
>
{
debug!
(
"sub_poly_trait_refs({} <: {})"
,
a
.repr
(
self
.tcx
),
...
...
@@ -747,7 +696,7 @@ pub fn sub_poly_trait_refs(&self,
origin
:
origin
,
values
:
PolyTraitRefs
(
expected_found
(
a_is_expected
,
a
.clone
(),
b
.clone
()))
};
self
.sub
(
a_is_expected
,
trace
)
.binders
(
&
a
,
&
b
)
.
to_ures
(
)
self
.sub
(
a_is_expected
,
trace
)
.binders
(
&
a
,
&
b
)
.
map
(|
_
|
()
)
})
}
...
...
@@ -774,7 +723,7 @@ pub fn skolemize_late_bound_regions<T>(&self,
pub
fn
leak_check
(
&
self
,
skol_map
:
&
SkolemizationMap
,
snapshot
:
&
CombinedSnapshot
)
->
ures
<
'tcx
>
->
UnitResult
<
'tcx
>
{
/*! See `higher_ranked::leak_check` */
...
...
@@ -799,7 +748,7 @@ pub fn plug_leaks<T>(&self,
pub
fn
equality_predicate
(
&
self
,
span
:
Span
,
predicate
:
&
ty
::
PolyEquatePredicate
<
'tcx
>
)
->
ures
<
'tcx
>
{
->
UnitResult
<
'tcx
>
{
self
.try
(|
snapshot
|
{
let
(
ty
::
EquatePredicate
(
a
,
b
),
skol_map
)
=
self
.skolemize_late_bound_regions
(
predicate
,
snapshot
);
...
...
@@ -812,7 +761,7 @@ pub fn equality_predicate(&self,
pub
fn
region_outlives_predicate
(
&
self
,
span
:
Span
,
predicate
:
&
ty
::
PolyRegionOutlivesPredicate
)
->
ures
<
'tcx
>
{
->
UnitResult
<
'tcx
>
{
self
.try
(|
snapshot
|
{
let
(
ty
::
OutlivesPredicate
(
r_a
,
r_b
),
skol_map
)
=
self
.skolemize_late_bound_regions
(
predicate
,
snapshot
);
...
...
@@ -1104,7 +1053,7 @@ pub fn verify_generic_bound(&self,
self
.region_vars
.verify_generic_bound
(
origin
,
kind
,
a
,
bs
);
}
pub
fn
can_equate
<
T
>
(
&
self
,
a
:
&
T
,
b
:
&
T
)
->
ures
<
'tcx
>
pub
fn
can_equate
<
T
>
(
&
self
,
a
:
&
T
,
b
:
&
T
)
->
UnitResult
<
'tcx
>
where
T
:
Combineable
<
'tcx
>
+
Repr
<
'tcx
>
{
debug!
(
"can_equate({}, {})"
,
a
.repr
(
self
.tcx
),
b
.repr
(
self
.tcx
));
...
...
@@ -1118,7 +1067,7 @@ pub fn can_equate<T>(&self, a: &T, b: &T) -> ures<'tcx>
values
:
Types
(
expected_found
(
true
,
e
,
e
))
};
let
eq
=
self
.equate
(
true
,
trace
);
Combineable
::
combine
(
&
eq
,
a
,
b
)
})
.
to_ures
(
)
})
.
map
(|
_
|
()
)
}
}
...
...
src/librustc/middle/infer/region_inference/mod.rs
浏览文件 @
09398378
...
...
@@ -18,7 +18,7 @@
pub
use
self
::
VarValue
::
*
;
use
self
::
Classification
::
*
;
use
super
::
cres
;
use
super
::
CombineResult
;
use
super
::{
RegionVariableOrigin
,
SubregionOrigin
,
TypeTrace
,
MiscVariable
};
use
middle
::
region
;
...
...
@@ -799,7 +799,8 @@ fn lub_concrete_regions(&self, a: Region, b: Region) -> Region {
/// regions are given as argument, in any order, a consistent result is returned.
fn
lub_free_regions
(
&
self
,
a
:
&
FreeRegion
,
b
:
&
FreeRegion
)
->
ty
::
Region
b
:
&
FreeRegion
)
->
ty
::
Region
{
return
match
a
.cmp
(
b
)
{
Less
=>
helper
(
self
,
a
,
b
),
...
...
@@ -824,7 +825,8 @@ fn helper(this: &RegionVarBindings,
fn
glb_concrete_regions
(
&
self
,
a
:
Region
,
b
:
Region
)
->
cres
<
'tcx
,
Region
>
{
->
CombineResult
<
'tcx
,
Region
>
{
debug!
(
"glb_concrete_regions({:?}, {:?})"
,
a
,
b
);
match
(
a
,
b
)
{
(
ReLateBound
(
..
),
_
)
|
...
...
@@ -898,7 +900,8 @@ fn glb_concrete_regions(&self,
/// returned.
fn
glb_free_regions
(
&
self
,
a
:
&
FreeRegion
,
b
:
&
FreeRegion
)
->
cres
<
'tcx
,
ty
::
Region
>
b
:
&
FreeRegion
)
->
CombineResult
<
'tcx
,
ty
::
Region
>
{
return
match
a
.cmp
(
b
)
{
Less
=>
helper
(
self
,
a
,
b
),
...
...
@@ -908,7 +911,7 @@ fn glb_free_regions(&self,
fn
helper
<
'a
,
'tcx
>
(
this
:
&
RegionVarBindings
<
'a
,
'tcx
>
,
a
:
&
FreeRegion
,
b
:
&
FreeRegion
)
->
cres
<
'tcx
,
ty
::
Region
>
b
:
&
FreeRegion
)
->
CombineResult
<
'tcx
,
ty
::
Region
>
{
if
this
.tcx.region_maps
.sub_free_region
(
*
a
,
*
b
)
{
Ok
(
ty
::
ReFree
(
*
a
))
...
...
@@ -926,7 +929,8 @@ fn intersect_scopes(&self,
region_a
:
ty
::
Region
,
region_b
:
ty
::
Region
,
scope_a
:
region
::
CodeExtent
,
scope_b
:
region
::
CodeExtent
)
->
cres
<
'tcx
,
Region
>
scope_b
:
region
::
CodeExtent
)
->
CombineResult
<
'tcx
,
Region
>
{
// We want to generate the intersection of two
// scopes or two free regions. So, if one of
...
...
src/librustc/middle/infer/sub.rs
浏览文件 @
09398378
...
...
@@ -9,7 +9,7 @@
// except according to those terms.
use
super
::
combine
::
*
;
use
super
::
cres
;
use
super
::
CombineResult
;
use
super
::
higher_ranked
::
HigherRankedRelations
;
use
super
::
Subtype
;
use
super
::
type_variable
::{
SubtypeOf
,
SupertypeOf
};
...
...
@@ -33,7 +33,7 @@ fn tag(&self) -> String { "Sub".to_string() }
fn
fields
<
'a
>
(
&
'a
self
)
->
&
'a
CombineFields
<
'a
,
'tcx
>
{
&
self
.fields
}
fn
tys_with_variance
(
&
self
,
v
:
ty
::
Variance
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
{
match
v
{
ty
::
Invariant
=>
self
.equate
()
.tys
(
a
,
b
),
...
...
@@ -44,7 +44,7 @@ fn tys_with_variance(&self, v: ty::Variance, a: Ty<'tcx>, b: Ty<'tcx>)
}
fn
regions_with_variance
(
&
self
,
v
:
ty
::
Variance
,
a
:
ty
::
Region
,
b
:
ty
::
Region
)
->
cres
<
'tcx
,
ty
::
Region
>
->
CombineResult
<
'tcx
,
ty
::
Region
>
{
match
v
{
ty
::
Invariant
=>
self
.equate
()
.regions
(
a
,
b
),
...
...
@@ -54,7 +54,7 @@ fn regions_with_variance(&self, v: ty::Variance, a: ty::Region, b: ty::Region)
}
}
fn
regions
(
&
self
,
a
:
ty
::
Region
,
b
:
ty
::
Region
)
->
cres
<
'tcx
,
ty
::
Region
>
{
fn
regions
(
&
self
,
a
:
ty
::
Region
,
b
:
ty
::
Region
)
->
CombineResult
<
'tcx
,
ty
::
Region
>
{
debug!
(
"{}.regions({}, {})"
,
self
.tag
(),
a
.repr
(
self
.tcx
()),
...
...
@@ -63,7 +63,7 @@ fn regions(&self, a: ty::Region, b: ty::Region) -> cres<'tcx, ty::Region> {
Ok
(
a
)
}
fn
tys
(
&
self
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
Ty
<
'tcx
>>
{
fn
tys
(
&
self
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
CombineResult
<
'tcx
,
Ty
<
'tcx
>>
{
debug!
(
"{}.tys({}, {})"
,
self
.tag
(),
a
.repr
(
self
.tcx
()),
b
.repr
(
self
.tcx
()));
if
a
==
b
{
return
Ok
(
a
);
}
...
...
@@ -99,7 +99,7 @@ fn tys(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> cres<'tcx, Ty<'tcx>> {
}
}
fn
binders
<
T
>
(
&
self
,
a
:
&
ty
::
Binder
<
T
>
,
b
:
&
ty
::
Binder
<
T
>
)
->
cres
<
'tcx
,
ty
::
Binder
<
T
>>
fn
binders
<
T
>
(
&
self
,
a
:
&
ty
::
Binder
<
T
>
,
b
:
&
ty
::
Binder
<
T
>
)
->
CombineResult
<
'tcx
,
ty
::
Binder
<
T
>>
where
T
:
Combineable
<
'tcx
>
{
self
.higher_ranked_sub
(
a
,
b
)
...
...
src/librustc/middle/infer/unify.rs
浏览文件 @
09398378
...
...
@@ -14,7 +14,7 @@
use
middle
::
ty
::{
expected_found
,
IntVarValue
};
use
middle
::
ty
::{
self
,
Ty
};
use
middle
::
infer
::
{
uok
,
ures
}
;
use
middle
::
infer
::
UnitResult
;
use
middle
::
infer
::
InferCtxt
;
use
std
::
cell
::
RefCell
;
use
std
::
fmt
::
Debug
;
...
...
@@ -236,7 +236,7 @@ pub trait SimplyUnifiable<'tcx> : Clone + PartialEq + Debug {
pub
fn
err
<
'tcx
,
V
:
SimplyUnifiable
<
'tcx
>>
(
a_is_expected
:
bool
,
a_t
:
V
,
b_t
:
V
)
->
ures
<
'tcx
>
{
->
UnitResult
<
'tcx
>
{
if
a_is_expected
{
Err
(
SimplyUnifiable
::
to_type_err
(
ty
::
expected_found
{
expected
:
a_t
,
found
:
b_t
}))
...
...
@@ -255,12 +255,12 @@ fn simple_vars(&self,
a_is_expected
:
bool
,
a_id
:
K
,
b_id
:
K
)
->
ures
<
'tcx
>
;
->
UnitResult
<
'tcx
>
;
fn
simple_var_t
(
&
self
,
a_is_expected
:
bool
,
a_id
:
K
,
b
:
V
)
->
ures
<
'tcx
>
;
->
UnitResult
<
'tcx
>
;
fn
probe_var
(
&
self
,
a_id
:
K
)
->
Option
<
Ty
<
'tcx
>>
;
}
...
...
@@ -276,7 +276,7 @@ fn simple_vars(&self,
a_is_expected
:
bool
,
a_id
:
K
,
b_id
:
K
)
->
ures
<
'tcx
>
->
UnitResult
<
'tcx
>
{
let
tcx
=
self
.tcx
;
let
table
=
UnifyKey
::
unification_table
(
self
);
...
...
@@ -285,7 +285,7 @@ fn simple_vars(&self,
let
a_id
=
node_a
.key
.clone
();
let
b_id
=
node_b
.key
.clone
();
if
a_id
==
b_id
{
return
uok
(
);
}
if
a_id
==
b_id
{
return
Ok
(()
);
}
let
combined
=
{
match
(
&
node_a
.value
,
&
node_b
.value
)
{
...
...
@@ -317,7 +317,7 @@ fn simple_var_t(&self,
a_is_expected
:
bool
,
a_id
:
K
,
b
:
V
)
->
ures
<
'tcx
>
->
UnitResult
<
'tcx
>
{
let
tcx
=
self
.tcx
;
let
table
=
UnifyKey
::
unification_table
(
self
);
...
...
src/librustc_typeck/check/coercion.rs
浏览文件 @
09398378
...
...
@@ -62,7 +62,7 @@
use
check
::{
autoderef
,
FnCtxt
,
NoPreference
,
PreferMutLvalue
,
UnresolvedTypeAction
};
use
middle
::
infer
::{
self
,
cres
,
Coercion
,
TypeTrace
};
use
middle
::
infer
::{
self
,
CombineResult
,
Coercion
,
TypeTrace
};
use
middle
::
infer
::
combine
::
Combine
;
use
middle
::
infer
::
sub
::
Sub
;
use
middle
::
subst
;
...
...
@@ -79,7 +79,7 @@ struct Coerce<'a, 'tcx: 'a> {
trace
:
TypeTrace
<
'tcx
>
}
type
CoerceResult
<
'tcx
>
=
cres
<
'tcx
,
Option
<
ty
::
AutoAdjustment
<
'tcx
>>>
;
type
CoerceResult
<
'tcx
>
=
CombineResult
<
'tcx
,
Option
<
ty
::
AutoAdjustment
<
'tcx
>>>
;
impl
<
'f
,
'tcx
>
Coerce
<
'f
,
'tcx
>
{
fn
tcx
(
&
self
)
->
&
ty
::
ctxt
<
'tcx
>
{
...
...
@@ -534,7 +534,7 @@ pub fn mk_assignty<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
expr
:
&
ast
::
Expr
,
a
:
Ty
<
'tcx
>
,
b
:
Ty
<
'tcx
>
)
->
cres
<
'tcx
,
()
>
{
->
CombineResult
<
'tcx
,
()
>
{
debug!
(
"mk_assignty({} -> {})"
,
a
.repr
(
fcx
.tcx
()),
b
.repr
(
fcx
.tcx
()));
let
adjustment
=
try!
(
indent
(||
{
fcx
.infcx
()
.commit_if_ok
(||
{
...
...
src/librustc_typeck/check/method/probe.rs
浏览文件 @
09398378
...
...
@@ -1130,7 +1130,7 @@ fn collapse_candidates_to_trait_pick(&self,
///////////////////////////////////////////////////////////////////////////
// MISCELLANY
fn
make_sub_ty
(
&
self
,
sub
:
Ty
<
'tcx
>
,
sup
:
Ty
<
'tcx
>
)
->
infer
::
ures
<
'tcx
>
{
fn
make_sub_ty
(
&
self
,
sub
:
Ty
<
'tcx
>
,
sup
:
Ty
<
'tcx
>
)
->
infer
::
UnitResult
<
'tcx
>
{
self
.infcx
()
.sub_types
(
false
,
infer
::
Misc
(
DUMMY_SP
),
sub
,
sup
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录