Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
d0ec8ea1
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,发现更多精彩内容 >>
提交
d0ec8ea1
编写于
5月 06, 2018
作者:
M
Matthew Jasper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement RFC 2056 - trivial constraints
上级
0b17da2d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
28 addition
and
46 deletion
+28
-46
src/librustc/traits/mod.rs
src/librustc/traits/mod.rs
+0
-9
src/librustc/traits/select.rs
src/librustc/traits/select.rs
+28
-37
未找到文件。
src/librustc/traits/mod.rs
浏览文件 @
d0ec8ea1
...
...
@@ -641,17 +641,8 @@ pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let
predicates
:
Vec
<
_
>
=
util
::
elaborate_predicates
(
tcx
,
unnormalized_env
.caller_bounds
.to_vec
())
.filter
(|
p
|
!
p
.is_global
())
// (*)
.collect
();
// (*) Any predicate like `i32: Trait<u32>` or whatever doesn't
// need to be in the *environment* to be proven, so screen those
// out. This is important for the soundness of inter-fn
// caching. Note though that we should probably check that these
// predicates hold at the point where the environment is
// constructed, but I am not currently doing so out of laziness.
// -nmatsakis
debug!
(
"normalize_param_env_or_error: elaborated-predicates={:?}"
,
predicates
);
...
...
src/librustc/traits/select.rs
浏览文件 @
d0ec8ea1
...
...
@@ -305,9 +305,6 @@ enum BuiltinImplConditions<'tcx> {
/// There is no built-in impl. There may be some other
/// candidate (a where-clause or user-defined impl).
None
,
/// There is *no* impl for this, builtin or not. Ignore
/// all where-clauses.
Never
,
/// It is unknown whether there is an impl.
Ambiguous
}
...
...
@@ -781,13 +778,13 @@ fn evaluate_trait_predicate_recursively<'o>(&mut self,
mut
obligation
:
TraitObligation
<
'tcx
>
)
->
Result
<
EvaluationResult
,
OverflowError
>
{
debug!
(
"evaluate_trait_predicate_recursively({:?})"
,
obligation
);
debug!
(
"evaluate_trait_predicate_recursively({:?})"
,
obligation
);
if
!
self
.intercrate
.is_some
()
&&
obligation
.is_global
()
{
// If a param env is consistent, global obligations do not depend on its particular
// value in order to work, so we can clear out the param env and get better
// caching. (If the current param env is inconsistent, we don't care what happens).
if
self
.intercrate
.is_none
()
&&
obligation
.is_global
()
&&
obligation
.param_env.caller_bounds
.iter
()
.all
(|
bound
|
bound
.needs_subst
())
{
// If a param env has no global bounds, global obligations do not
// depend on its particular value in order to work, so we can clear
// out the param env and get better caching.
debug!
(
"evaluate_trait_predicate_recursively({:?}) - in global"
,
obligation
);
obligation
.param_env
=
obligation
.param_env
.without_caller_bounds
();
}
...
...
@@ -1451,22 +1448,22 @@ fn assemble_candidates<'o>(&mut self,
let
sized_conditions
=
self
.sized_conditions
(
obligation
);
self
.assemble_builtin_bound_candidates
(
sized_conditions
,
&
mut
candidates
)
?
;
}
else
if
lang_items
.unsize_trait
()
==
Some
(
def_id
)
{
self
.assemble_candidates_for_unsizing
(
obligation
,
&
mut
candidates
);
}
else
{
if
lang_items
.clone_trait
()
==
Some
(
def_id
)
{
// Same builtin conditions as `Copy`, i.e. every type which has builtin support
// for `Copy` also has builtin support for `Clone`, + tuples and arrays of `Clone`
// types have builtin support for `Clone`.
let
clone_conditions
=
self
.copy_clone_conditions
(
obligation
);
self
.assemble_builtin_bound_candidates
(
clone_conditions
,
&
mut
candidates
)
?
;
}
self
.assemble_generator_candidates
(
obligation
,
&
mut
candidates
)
?
;
self
.assemble_closure_candidates
(
obligation
,
&
mut
candidates
)
?
;
self
.assemble_fn_pointer_candidates
(
obligation
,
&
mut
candidates
)
?
;
self
.assemble_candidates_from_impls
(
obligation
,
&
mut
candidates
)
?
;
self
.assemble_candidates_from_object_ty
(
obligation
,
&
mut
candidates
);
}
else
if
lang_items
.unsize_trait
()
==
Some
(
def_id
)
{
self
.assemble_candidates_for_unsizing
(
obligation
,
&
mut
candidates
);
}
else
{
if
lang_items
.clone_trait
()
==
Some
(
def_id
)
{
// Same builtin conditions as `Copy`, i.e. every type which has builtin support
// for `Copy` also has builtin support for `Clone`, + tuples and arrays of `Clone`
// types have builtin support for `Clone`.
let
clone_conditions
=
self
.copy_clone_conditions
(
obligation
);
self
.assemble_builtin_bound_candidates
(
clone_conditions
,
&
mut
candidates
)
?
;
}
self
.assemble_generator_candidates
(
obligation
,
&
mut
candidates
)
?
;
self
.assemble_closure_candidates
(
obligation
,
&
mut
candidates
)
?
;
self
.assemble_fn_pointer_candidates
(
obligation
,
&
mut
candidates
)
?
;
self
.assemble_candidates_from_impls
(
obligation
,
&
mut
candidates
)
?
;
self
.assemble_candidates_from_object_ty
(
obligation
,
&
mut
candidates
);
}
self
.assemble_candidates_from_projected_tys
(
obligation
,
&
mut
candidates
);
...
...
@@ -2081,13 +2078,8 @@ fn candidate_should_be_dropped_in_favor_of<'o>(
// BUILTIN BOUNDS
//
// These cover the traits that are built-in to the language
// itself. This includes `Copy` and `Sized` for sure. For the
// moment, it also includes `Send` / `Sync` and a few others, but
// those will hopefully change to library-defined traits in the
// future.
// itself: `Copy`, `Clone` and `Sized`.
// HACK: if this returns an error, selection exits without considering
// other impls.
fn
assemble_builtin_bound_candidates
<
'o
>
(
&
mut
self
,
conditions
:
BuiltinImplConditions
<
'tcx
>
,
candidates
:
&
mut
SelectionCandidateSet
<
'tcx
>
)
...
...
@@ -2106,14 +2098,13 @@ fn assemble_builtin_bound_candidates<'o>(&mut self,
debug!
(
"assemble_builtin_bound_candidates: ambiguous builtin"
);
Ok
(
candidates
.ambiguous
=
true
)
}
BuiltinImplConditions
::
Never
=>
{
Err
(
Unimplemented
)
}
}
}
fn
sized_conditions
(
&
mut
self
,
obligation
:
&
TraitObligation
<
'tcx
>
)
->
BuiltinImplConditions
<
'tcx
>
{
use
self
::
BuiltinImplConditions
::{
Ambiguous
,
None
,
Never
,
Where
};
use
self
::
BuiltinImplConditions
::{
Ambiguous
,
None
,
Where
};
// NOTE: binder moved to (*)
let
self_ty
=
self
.infcx
.shallow_resolve
(
...
...
@@ -2130,7 +2121,7 @@ fn sized_conditions(&mut self, obligation: &TraitObligation<'tcx>)
Where
(
ty
::
Binder
::
dummy
(
Vec
::
new
()))
}
ty
::
TyStr
|
ty
::
TySlice
(
_
)
|
ty
::
TyDynamic
(
..
)
|
ty
::
TyForeign
(
..
)
=>
N
ever
,
ty
::
TyStr
|
ty
::
TySlice
(
_
)
|
ty
::
TyDynamic
(
..
)
|
ty
::
TyForeign
(
..
)
=>
N
one
,
ty
::
TyTuple
(
tys
)
=>
{
Where
(
ty
::
Binder
::
bind
(
tys
.last
()
.into_iter
()
.cloned
()
.collect
()))
...
...
@@ -2164,7 +2155,7 @@ fn copy_clone_conditions(&mut self, obligation: &TraitObligation<'tcx>)
let
self_ty
=
self
.infcx
.shallow_resolve
(
obligation
.predicate
.skip_binder
()
.self_ty
());
use
self
::
BuiltinImplConditions
::{
Ambiguous
,
None
,
Never
,
Where
};
use
self
::
BuiltinImplConditions
::{
Ambiguous
,
None
,
Where
};
match
self_ty
.sty
{
ty
::
TyInfer
(
ty
::
IntVar
(
_
))
|
ty
::
TyInfer
(
ty
::
FloatVar
(
_
))
|
...
...
@@ -2182,7 +2173,7 @@ fn copy_clone_conditions(&mut self, obligation: &TraitObligation<'tcx>)
ty
::
TyDynamic
(
..
)
|
ty
::
TyStr
|
ty
::
TySlice
(
..
)
|
ty
::
TyGenerator
(
..
)
|
ty
::
TyGeneratorWitness
(
..
)
|
ty
::
TyForeign
(
..
)
|
ty
::
TyRef
(
_
,
_
,
hir
::
MutMutable
)
=>
{
N
ever
N
one
}
ty
::
TyArray
(
element_ty
,
_
)
=>
{
...
...
@@ -2202,7 +2193,7 @@ fn copy_clone_conditions(&mut self, obligation: &TraitObligation<'tcx>)
if
is_copy_trait
||
is_clone_trait
{
Where
(
ty
::
Binder
::
bind
(
substs
.upvar_tys
(
def_id
,
self
.tcx
())
.collect
()))
}
else
{
N
ever
N
one
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录