Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
124e1e18
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,发现更多精彩内容 >>
提交
124e1e18
编写于
12月 11, 2014
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve comments and address nits.
上级
5f43899d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
54 addition
and
38 deletion
+54
-38
src/librustc/middle/traits/fulfill.rs
src/librustc/middle/traits/fulfill.rs
+25
-23
src/librustc/middle/traits/mod.rs
src/librustc/middle/traits/mod.rs
+6
-1
src/librustc/middle/traits/util.rs
src/librustc/middle/traits/util.rs
+14
-1
src/librustc/middle/ty.rs
src/librustc/middle/ty.rs
+9
-12
src/librustc_typeck/check/wf.rs
src/librustc_typeck/check/wf.rs
+0
-1
未找到文件。
src/librustc/middle/traits/fulfill.rs
浏览文件 @
124e1e18
...
...
@@ -250,13 +250,15 @@ fn select<'a>(&mut self,
self
.predicates
.retain
(|
predicate
|
{
// Hack: Retain does not pass in the index, but we want
// to avoid processing the first `start_count` entries.
if
skip
==
0
{
retain_predicate
(
selcx
,
predicate
,
&
mut
selections
,
&
mut
errors
,
region_obligations
)
}
else
{
skip
-=
1
;
true
}
let
processed
=
if
skip
==
0
{
process_predicate
(
selcx
,
predicate
,
&
mut
selections
,
&
mut
errors
,
region_obligations
)
}
else
{
skip
-=
1
;
false
};
!
processed
});
}
...
...
@@ -286,17 +288,17 @@ fn select<'a>(&mut self,
}
}
fn
retain
_predicate
<
'a
,
'tcx
>
(
selcx
:
&
mut
SelectionContext
<
'a
,
'tcx
>
,
predicate
:
&
PredicateObligation
<
'tcx
>
,
selections
:
&
mut
Vec
<
Selection
<
'tcx
>>
,
errors
:
&
mut
Vec
<
FulfillmentError
<
'tcx
>>
,
region_obligations
:
&
mut
NodeMap
<
Vec
<
RegionObligation
<
'tcx
>>>
)
->
bool
fn
process
_predicate
<
'a
,
'tcx
>
(
selcx
:
&
mut
SelectionContext
<
'a
,
'tcx
>
,
predicate
:
&
PredicateObligation
<
'tcx
>
,
selections
:
&
mut
Vec
<
Selection
<
'tcx
>>
,
errors
:
&
mut
Vec
<
FulfillmentError
<
'tcx
>>
,
region_obligations
:
&
mut
NodeMap
<
Vec
<
RegionObligation
<
'tcx
>>>
)
->
bool
{
/*!
*
Evaluat
es a predicate obligation and modifies the appropriate
* output array
. Returns `true` if the predicate must be retained
*
because it could not be fully evaluated yet
due to insufficient
*
Process
es a predicate obligation and modifies the appropriate
* output array
with the successful/error result. Returns `false`
*
if the predicate could not be processed
due to insufficient
* type inference.
*/
...
...
@@ -308,11 +310,11 @@ fn retain_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
trait_ref
:
trait_ref
.clone
()
};
match
selcx
.select
(
&
trait_obligation
)
{
Ok
(
None
)
=>
{
tru
e
fals
e
}
Ok
(
Some
(
s
))
=>
{
selections
.push
(
s
);
fals
e
tru
e
}
Err
(
selection_err
)
=>
{
debug!
(
"predicate: {} error: {}"
,
...
...
@@ -322,7 +324,7 @@ fn retain_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
FulfillmentError
::
new
(
predicate
.clone
(),
CodeSelectionError
(
selection_err
)));
fals
e
tru
e
}
}
}
...
...
@@ -331,14 +333,14 @@ fn retain_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
let
origin
=
infer
::
EquatePredicate
(
predicate
.cause.span
);
match
infer
::
mk_eqty
(
selcx
.infcx
(),
false
,
origin
,
a
,
b
)
{
Ok
(())
=>
{
fals
e
tru
e
}
Err
(
_
)
=>
{
errors
.push
(
FulfillmentError
::
new
(
predicate
.clone
(),
CodeSelectionError
(
Unimplemented
)));
fals
e
tru
e
}
}
}
...
...
@@ -346,12 +348,12 @@ fn retain_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
ty
::
Predicate
::
RegionOutlives
(
r_a
,
r_b
)
=>
{
let
origin
=
infer
::
RelateRegionParamBound
(
predicate
.cause.span
);
let
()
=
infer
::
mk_subr
(
selcx
.infcx
(),
origin
,
r_b
,
r_a
);
// `b : a` ==> `a <= b`
fals
e
tru
e
}
ty
::
Predicate
::
TypeOutlives
(
t_a
,
r_b
)
=>
{
register_region_obligation
(
tcx
,
t_a
,
r_b
,
predicate
.cause
,
region_obligations
);
fals
e
tru
e
}
}
}
...
...
src/librustc/middle/traits/mod.rs
浏览文件 @
124e1e18
...
...
@@ -61,7 +61,12 @@ pub struct Obligation<'tcx, T> {
pub
struct
ObligationCause
<
'tcx
>
{
pub
span
:
Span
,
// the id of XXX
// The id of the fn body that triggered this obligation. This is
// used for region obligations to determine the precise
// environment in which the region obligation should be evaluated
// (in particular, closures can add new assumptions). See the
// field `region_obligations` of the `FulfillmentContext` for more
// information.
pub
body_id
:
ast
::
NodeId
,
pub
code
:
ObligationCauseCode
<
'tcx
>
...
...
src/librustc/middle/traits/util.rs
浏览文件 @
124e1e18
...
...
@@ -24,8 +24,16 @@
VtableImpl
,
VtableParam
,
VtableParamData
,
VtableImplData
};
///////////////////////////////////////////////////////////////////////////
// Elaboration iterator
// `Elaboration` iterator
///////////////////////////////////////////////////////////////////////////
/// "Elaboration" is the process of identifying all the predicates that
/// are implied by a source predicate. Currently this basically means
/// walking the "supertraits" and other similar assumptions. For
/// example, if we know that `T : Ord`, the elaborator would deduce
/// that `T : PartialOrd` holds as well. Similarly, if we have `trait
/// Foo : 'static`, and we know that `T : Foo`, then we know that `T :
/// 'static`.
pub
struct
Elaborator
<
'cx
,
'tcx
:
'cx
>
{
tcx
:
&
'cx
ty
::
ctxt
<
'tcx
>
,
stack
:
Vec
<
StackEntry
<
'tcx
>>
,
...
...
@@ -157,7 +165,10 @@ fn next(&mut self) -> Option<ty::Predicate<'tcx>> {
///////////////////////////////////////////////////////////////////////////
// Supertrait iterator
///////////////////////////////////////////////////////////////////////////
/// A filter around the `Elaborator` that just yields up supertrait references,
/// not other kinds of predicates.
pub
struct
Supertraits
<
'cx
,
'tcx
:
'cx
>
{
elaborator
:
Elaborator
<
'cx
,
'tcx
>
,
}
...
...
@@ -197,6 +208,8 @@ fn next(&mut self) -> Option<Rc<ty::TraitRef<'tcx>>> {
}
}
///////////////////////////////////////////////////////////////////////////
// Other
///////////////////////////////////////////////////////////////////////////
// determine the `self` type, using fresh variables for all variables
...
...
src/librustc/middle/ty.rs
浏览文件 @
124e1e18
...
...
@@ -1656,14 +1656,16 @@ pub fn to_bounds(&self, tcx: &ty::ctxt<'tcx>, substs: &Substs<'tcx>)
#[deriving(Clone,
PartialEq,
Eq,
Hash,
Show)]
pub
enum
Predicate
<
'tcx
>
{
/// where Foo : Bar
/// Corresponds to `where Foo : Bar<A,B,C>`. `Foo` here would be
/// the `Self` type of the trait reference and `A`, `B`, and `C`
/// would be the parameters in the `TypeSpace`.
Trait
(
Rc
<
TraitRef
<
'tcx
>>
),
/// where
Foo == Bar
Equate
(
Ty
<
'tcx
>
,
Ty
<
'tcx
>
),
/// where
`T1 == T2`.
Equate
(
/* T1 */
Ty
<
'tcx
>
,
/* T2 */
Ty
<
'tcx
>
),
/// where 'a : 'b
RegionOutlives
(
Region
,
Region
),
RegionOutlives
(
/* 'a */
Region
,
/* 'b */
Region
),
/// where T : 'a
TypeOutlives
(
Ty
<
'tcx
>
,
Region
),
...
...
@@ -1807,7 +1809,6 @@ pub fn for_item(cx: &ctxt<'tcx>, id: NodeId) -> ParameterEnvironment<'tcx> {
let
method_generics
=
&
method_ty
.generics
;
construct_parameter_environment
(
cx
,
method
.span
,
method_generics
,
method
.pe_body
()
.id
)
}
...
...
@@ -1842,7 +1843,6 @@ pub fn for_item(cx: &ctxt<'tcx>, id: NodeId) -> ParameterEnvironment<'tcx> {
let
method_generics
=
&
method_ty
.generics
;
construct_parameter_environment
(
cx
,
method
.span
,
method_generics
,
method
.pe_body
()
.id
)
}
...
...
@@ -1869,7 +1869,6 @@ pub fn for_item(cx: &ctxt<'tcx>, id: NodeId) -> ParameterEnvironment<'tcx> {
let
fn_pty
=
ty
::
lookup_item_type
(
cx
,
fn_def_id
);
construct_parameter_environment
(
cx
,
item
.span
,
&
fn_pty
.generics
,
body
.id
)
}
...
...
@@ -1880,8 +1879,7 @@ pub fn for_item(cx: &ctxt<'tcx>, id: NodeId) -> ParameterEnvironment<'tcx> {
ast
::
ItemStatic
(
..
)
=>
{
let
def_id
=
ast_util
::
local_def
(
id
);
let
pty
=
ty
::
lookup_item_type
(
cx
,
def_id
);
construct_parameter_environment
(
cx
,
item
.span
,
&
pty
.generics
,
id
)
construct_parameter_environment
(
cx
,
&
pty
.generics
,
id
)
}
_
=>
{
cx
.sess
.span_bug
(
item
.span
,
...
...
@@ -5031,8 +5029,8 @@ pub fn lookup_trait_def<'tcx>(cx: &ctxt<'tcx>, did: ast::DefId)
})
}
/// Given a reference to a trait, returns the
bounds declared on the
/// trait, with appropriate substitutions applied.
/// Given a reference to a trait, returns the
"superbounds" declared
///
on the
trait, with appropriate substitutions applied.
pub
fn
predicates_for_trait_ref
<
'tcx
>
(
tcx
:
&
ctxt
<
'tcx
>
,
trait_ref
:
&
TraitRef
<
'tcx
>
)
->
Vec
<
ty
::
Predicate
<
'tcx
>>
...
...
@@ -5929,7 +5927,6 @@ pub fn empty_parameter_environment<'tcx>() -> ParameterEnvironment<'tcx> {
/// See `ParameterEnvironment` struct def'n for details
pub
fn
construct_parameter_environment
<
'tcx
>
(
tcx
:
&
ctxt
<
'tcx
>
,
_
span
:
Span
,
generics
:
&
ty
::
Generics
<
'tcx
>
,
free_id
:
ast
::
NodeId
)
->
ParameterEnvironment
<
'tcx
>
...
...
src/librustc_typeck/check/wf.rs
浏览文件 @
124e1e18
...
...
@@ -91,7 +91,6 @@ fn with_fcx(&mut self,
let
polytype
=
ty
::
lookup_item_type
(
ccx
.tcx
,
item_def_id
);
let
param_env
=
ty
::
construct_parameter_environment
(
ccx
.tcx
,
item
.span
,
&
polytype
.generics
,
item
.id
);
let
inh
=
Inherited
::
new
(
ccx
.tcx
,
param_env
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录