Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
79efed84
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,发现更多精彩内容 >>
提交
79efed84
编写于
10月 15, 2018
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove wrapper functions that had no purpose
上级
5f0fe8f0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
37 addition
and
56 deletion
+37
-56
src/librustc/traits/select.rs
src/librustc/traits/select.rs
+37
-56
未找到文件。
src/librustc/traits/select.rs
浏览文件 @
79efed84
...
...
@@ -29,8 +29,7 @@
use
dep_graph
::{
DepKind
,
DepNodeIndex
};
use
hir
::
def_id
::
DefId
;
use
infer
;
use
infer
::{
InferCtxt
,
InferOk
,
TypeFreshener
};
use
infer
::{
self
,
InferCtxt
,
InferOk
,
TypeFreshener
};
use
middle
::
lang_items
;
use
mir
::
interpret
::
GlobalId
;
use
ty
::
fast_reject
;
...
...
@@ -531,24 +530,6 @@ pub fn closure_typer(&self) -> &'cx InferCtxt<'cx, 'gcx, 'tcx> {
self
.infcx
}
/// Wraps the inference context's in_snapshot s.t. snapshot handling is only from the selection
/// context's self.
fn
in_snapshot
<
R
,
F
>
(
&
mut
self
,
f
:
F
)
->
R
where
F
:
FnOnce
(
&
mut
Self
,
&
infer
::
CombinedSnapshot
<
'cx
,
'tcx
>
)
->
R
,
{
self
.infcx
.in_snapshot
(|
snapshot
|
f
(
self
,
snapshot
))
}
/// Wraps a probe s.t. obligations collected during it are ignored and old obligations are
/// retained.
fn
probe
<
R
,
F
>
(
&
mut
self
,
f
:
F
)
->
R
where
F
:
FnOnce
(
&
mut
Self
,
&
infer
::
CombinedSnapshot
<
'cx
,
'tcx
>
)
->
R
,
{
self
.infcx
.probe
(|
snapshot
|
f
(
self
,
snapshot
))
}
///////////////////////////////////////////////////////////////////////////
// Selection
//
...
...
@@ -630,8 +611,8 @@ pub fn evaluate_obligation_recursively(
&
mut
self
,
obligation
:
&
PredicateObligation
<
'tcx
>
,
)
->
Result
<
EvaluationResult
,
OverflowError
>
{
self
.
probe
(|
this
,
_
|
{
this
.evaluate_predicate_recursively
(
TraitObligationStackList
::
empty
(),
obligation
)
self
.
infcx
.probe
(|
_
|
{
self
.evaluate_predicate_recursively
(
TraitObligationStackList
::
empty
(),
obligation
)
})
}
...
...
@@ -1066,10 +1047,10 @@ fn evaluate_candidate<'o>(
"evaluate_candidate: depth={} candidate={:?}"
,
stack
.obligation.recursion_depth
,
candidate
);
let
result
=
self
.
probe
(|
this
,
_
|
{
let
result
=
self
.
infcx
.probe
(|
_
|
{
let
candidate
=
(
*
candidate
)
.clone
();
match
this
.confirm_candidate
(
stack
.obligation
,
candidate
)
{
Ok
(
selection
)
=>
this
.evaluate_predicates_recursively
(
match
self
.confirm_candidate
(
stack
.obligation
,
candidate
)
{
Ok
(
selection
)
=>
self
.evaluate_predicates_recursively
(
stack
.list
(),
selection
.nested_obligations
()
.iter
(),
),
...
...
@@ -1697,8 +1678,8 @@ fn assemble_candidates_from_projected_tys(
_
=>
return
,
}
let
result
=
self
.
probe
(|
this
,
snapshot
|
{
this
.match_projection_obligation_against_definition_bounds
(
obligation
,
snapshot
)
let
result
=
self
.
infcx
.probe
(|
snapshot
|
{
self
.match_projection_obligation_against_definition_bounds
(
obligation
,
snapshot
)
});
if
result
{
...
...
@@ -1750,8 +1731,8 @@ fn match_projection_obligation_against_definition_bounds(
let
matching_bound
=
util
::
elaborate_predicates
(
self
.tcx
(),
bounds
.predicates
)
.filter_to_traits
()
.find
(|
bound
|
{
self
.
probe
(|
this
,
_
|
{
this
.match_projection
(
self
.
infcx
.probe
(|
_
|
{
self
.match_projection
(
obligation
,
bound
.clone
(),
skol_trait_predicate
.trait_ref
.clone
(),
...
...
@@ -1853,10 +1834,10 @@ fn evaluate_where_clause<'o>(
stack
:
&
TraitObligationStack
<
'o
,
'tcx
>
,
where_clause_trait_ref
:
ty
::
PolyTraitRef
<
'tcx
>
,
)
->
Result
<
EvaluationResult
,
OverflowError
>
{
self
.
probe
(
move
|
this
,
_
|
{
match
this
.match_where_clause_trait_ref
(
stack
.obligation
,
where_clause_trait_ref
)
{
self
.
infcx
.probe
(|
_
|
{
match
self
.match_where_clause_trait_ref
(
stack
.obligation
,
where_clause_trait_ref
)
{
Ok
(
obligations
)
=>
{
this
.evaluate_predicates_recursively
(
stack
.list
(),
obligations
.iter
())
self
.evaluate_predicates_recursively
(
stack
.list
(),
obligations
.iter
())
}
Err
(())
=>
Ok
(
EvaluatedToErr
),
}
...
...
@@ -2006,8 +1987,8 @@ fn assemble_candidates_from_impls(
obligation
.predicate
.def_id
(),
obligation
.predicate
.skip_binder
()
.trait_ref
.self_ty
(),
|
impl_def_id
|
{
self
.
probe
(|
this
,
snapshot
|
{
if
let
Ok
(
placeholder_map
)
=
this
.match_impl
(
impl_def_id
,
obligation
,
snapshot
)
self
.
infcx
.probe
(|
snapshot
|
{
if
let
Ok
(
placeholder_map
)
=
self
.match_impl
(
impl_def_id
,
obligation
,
snapshot
)
{
candidates
.vec
.push
(
ImplCandidate
(
impl_def_id
));
...
...
@@ -2084,11 +2065,11 @@ fn assemble_candidates_from_object_ty(
obligation
.self_ty
()
.skip_binder
()
);
self
.
probe
(|
this
,
_
snapshot
|
{
self
.
infcx
.probe
(|
_
snapshot
|
{
// The code below doesn't care about regions, and the
// self-ty here doesn't escape this probe, so just erase
// any LBR.
let
self_ty
=
this
.tcx
()
.erase_late_bound_regions
(
&
obligation
.self_ty
());
let
self_ty
=
self
.tcx
()
.erase_late_bound_regions
(
&
obligation
.self_ty
());
let
poly_trait_ref
=
match
self_ty
.sty
{
ty
::
Dynamic
(
ref
data
,
..
)
=>
{
if
data
.auto_traits
()
...
...
@@ -2102,7 +2083,7 @@ fn assemble_candidates_from_object_ty(
return
;
}
data
.principal
()
.with_self_ty
(
this
.tcx
(),
self_ty
)
data
.principal
()
.with_self_ty
(
self
.tcx
(),
self_ty
)
}
ty
::
Infer
(
ty
::
TyVar
(
_
))
=>
{
debug!
(
"assemble_candidates_from_object_ty: ambiguous"
);
...
...
@@ -2122,11 +2103,11 @@ fn assemble_candidates_from_object_ty(
// correct trait, but also the correct type parameters.
// For example, we may be trying to upcast `Foo` to `Bar<i32>`,
// but `Foo` is declared as `trait Foo : Bar<u32>`.
let
upcast_trait_refs
=
util
::
supertraits
(
this
.tcx
(),
poly_trait_ref
)
let
upcast_trait_refs
=
util
::
supertraits
(
self
.tcx
(),
poly_trait_ref
)
.filter
(|
upcast_trait_ref
|
{
this
.probe
(|
this
,
_
|
{
self
.infcx
.probe
(|
_
|
{
let
upcast_trait_ref
=
upcast_trait_ref
.clone
();
this
.match_poly_trait_ref
(
obligation
,
upcast_trait_ref
)
self
.match_poly_trait_ref
(
obligation
,
upcast_trait_ref
)
.is_ok
()
})
})
...
...
@@ -2671,20 +2652,20 @@ fn collect_predicates_for_types(
// binder moved -\
let
ty
:
ty
::
Binder
<
Ty
<
'tcx
>>
=
ty
::
Binder
::
bind
(
ty
);
// <----/
self
.in
_snapshot
(|
this
,
snapshot
|
{
let
(
skol_ty
,
placeholder_map
)
=
this
.infcx
()
self
.in
fcx
.in_snapshot
(|
snapshot
|
{
let
(
skol_ty
,
placeholder_map
)
=
self
.infcx
.replace_bound_vars_with_placeholders
(
&
ty
);
let
Normalized
{
value
:
normalized_ty
,
mut
obligations
,
}
=
project
::
normalize_with_depth
(
this
,
self
,
param_env
,
cause
.clone
(),
recursion_depth
,
&
skol_ty
,
);
let
skol_obligation
=
this
.tcx
()
.predicate_for_trait_def
(
let
skol_obligation
=
self
.tcx
()
.predicate_for_trait_def
(
param_env
,
cause
.clone
(),
trait_def_id
,
...
...
@@ -2693,7 +2674,7 @@ fn collect_predicates_for_types(
&
[],
);
obligations
.push
(
skol_obligation
);
this
.infcx
()
self
.infcx
.plug_leaks
(
placeholder_map
,
snapshot
,
obligations
)
})
})
...
...
@@ -2785,9 +2766,9 @@ fn confirm_candidate(
}
fn
confirm_projection_candidate
(
&
mut
self
,
obligation
:
&
TraitObligation
<
'tcx
>
)
{
self
.in
_snapshot
(|
this
,
snapshot
|
{
self
.in
fcx
.in_snapshot
(|
snapshot
|
{
let
result
=
this
.match_projection_obligation_against_definition_bounds
(
obligation
,
snapshot
);
self
.match_projection_obligation_against_definition_bounds
(
obligation
,
snapshot
);
assert
!
(
result
);
})
}
...
...
@@ -2904,12 +2885,12 @@ fn vtable_auto_impl(
nested
,
);
let
trait_obligations
:
Vec
<
PredicateObligation
<
'_
>>
=
self
.in
_snapshot
(|
this
,
snapshot
|
{
let
trait_obligations
:
Vec
<
PredicateObligation
<
'_
>>
=
self
.in
fcx
.in_snapshot
(|
snapshot
|
{
let
poly_trait_ref
=
obligation
.predicate
.to_poly_trait_ref
();
let
(
trait_ref
,
placeholder_map
)
=
this
.infcx
()
let
(
trait_ref
,
placeholder_map
)
=
self
.infcx
.replace_bound_vars_with_placeholders
(
&
poly_trait_ref
);
let
cause
=
obligation
.derived_cause
(
ImplDerivedObligation
);
this
.impl_or_trait_obligations
(
self
.impl_or_trait_obligations
(
cause
,
obligation
.recursion_depth
+
1
,
obligation
.param_env
,
...
...
@@ -2941,11 +2922,11 @@ fn confirm_impl_candidate(
// First, create the substitutions by matching the impl again,
// this time not in a probe.
self
.in
_snapshot
(|
this
,
snapshot
|
{
let
(
substs
,
placeholder_map
)
=
this
.rematch_impl
(
impl_def_id
,
obligation
,
snapshot
);
self
.in
fcx
.in_snapshot
(|
snapshot
|
{
let
(
substs
,
placeholder_map
)
=
self
.rematch_impl
(
impl_def_id
,
obligation
,
snapshot
);
debug!
(
"confirm_impl_candidate: substs={:?}"
,
substs
);
let
cause
=
obligation
.derived_cause
(
ImplDerivedObligation
);
this
.vtable_impl
(
self
.vtable_impl
(
impl_def_id
,
substs
,
cause
,
...
...
@@ -3108,14 +3089,14 @@ fn confirm_trait_alias_candidate(
obligation
,
alias_def_id
);
self
.in
_snapshot
(|
this
,
snapshot
|
{
let
(
predicate
,
placeholder_map
)
=
this
.infcx
()
self
.in
fcx
.in_snapshot
(|
snapshot
|
{
let
(
predicate
,
placeholder_map
)
=
self
.infcx
.replace_bound_vars_with_placeholders
(
&
obligation
.predicate
);
let
trait_ref
=
predicate
.trait_ref
;
let
trait_def_id
=
trait_ref
.def_id
;
let
substs
=
trait_ref
.substs
;
let
trait_obligations
=
this
.impl_or_trait_obligations
(
let
trait_obligations
=
self
.impl_or_trait_obligations
(
obligation
.cause
.clone
(),
obligation
.recursion_depth
,
obligation
.param_env
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录