Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2f22a929
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,发现更多精彩内容 >>
提交
2f22a929
编写于
2月 07, 2018
作者:
G
Gianni Ciccarelli
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add Self: Trait<..> inside the param_env of a default impl
上级
b20bfb1f
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
49 addition
and
35 deletion
+49
-35
src/librustc/infer/mod.rs
src/librustc/infer/mod.rs
+0
-4
src/librustc/traits/select.rs
src/librustc/traits/select.rs
+20
-7
src/librustc/ty/instance.rs
src/librustc/ty/instance.rs
+1
-1
src/librustc/ty/mod.rs
src/librustc/ty/mod.rs
+24
-1
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/mod.rs
+0
-18
src/test/compile-fail/specialization/defaultimpl/specialization-trait-item-not-implemented.rs
.../defaultimpl/specialization-trait-item-not-implemented.rs
+1
-1
src/test/compile-fail/specialization/defaultimpl/specialization-trait-not-implemented.rs
...ation/defaultimpl/specialization-trait-not-implemented.rs
+1
-1
src/test/compile-fail/specialization/defaultimpl/specialization-wfcheck.rs
...fail/specialization/defaultimpl/specialization-wfcheck.rs
+1
-1
src/test/run-pass/specialization/defaultimpl/specialization-trait-item-not-implemented.rs
.../defaultimpl/specialization-trait-item-not-implemented.rs
+1
-1
未找到文件。
src/librustc/infer/mod.rs
浏览文件 @
2f22a929
...
...
@@ -181,9 +181,6 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
// obligations within. This is expected to be done 'late enough'
// that all type inference variables have been bound and so forth.
region_obligations
:
RefCell
<
Vec
<
(
ast
::
NodeId
,
RegionObligation
<
'tcx
>
)
>>
,
// true if trait selection in this context should emit `default impl` candiates
pub
emit_defaul_impl_candidates
:
Cell
<
bool
>
,
}
/// A map returned by `skolemize_late_bound_regions()` indicating the skolemized
...
...
@@ -455,7 +452,6 @@ pub fn enter<F, R>(&'tcx mut self, f: F) -> R
err_count_on_creation
:
tcx
.sess
.err_count
(),
in_snapshot
:
Cell
::
new
(
false
),
region_obligations
:
RefCell
::
new
(
vec!
[]),
emit_defaul_impl_candidates
:
Cell
::
new
(
false
)
}))
}
}
...
...
src/librustc/traits/select.rs
浏览文件 @
2f22a929
...
...
@@ -1296,12 +1296,6 @@ fn can_use_global_caches(&self, param_env: ty::ParamEnv<'tcx>) -> bool {
return
false
;
}
// Using local cache if the infcx can emit `default impls`
if
self
.infcx.emit_defaul_impl_candidates
.get
()
{
return
false
;
}
// Otherwise, we can use the global cache.
true
}
...
...
@@ -1716,11 +1710,30 @@ fn assemble_candidates_from_impls(&mut self,
{
debug!
(
"assemble_candidates_from_impls(obligation={:?})"
,
obligation
);
// Check if default impls should be emitted.
// default impls are emitted if the param_env is refered to a default impl.
// The param_env should contain a Self: Trait<..> predicate in those cases
let
self_trait_is_present
:
Vec
<&
ty
::
Predicate
<
'tcx
>>
=
obligation
.param_env
.caller_bounds
.iter
()
.filter
(|
predicate
|
{
match
**
predicate
{
ty
::
Predicate
::
Trait
(
ref
trait_predicate
)
=>
{
trait_predicate
.def_id
()
==
obligation
.predicate
.def_id
()
&&
obligation
.predicate
.0
.trait_ref
.self_ty
()
==
trait_predicate
.skip_binder
()
.self_ty
()
}
_
=>
false
}
})
.collect
::
<
Vec
<&
ty
::
Predicate
<
'tcx
>>>
();
self
.tcx
()
.for_each_relevant_impl
(
obligation
.predicate
.def_id
(),
obligation
.predicate
.0
.trait_ref
.self_ty
(),
|
impl_def_id
|
{
if
self
.infcx
()
.emit_defaul_impl_candidates
.get
()
||
if
self
_trait_is_present
.len
()
>
0
||
!
self
.tcx
()
.impl_is_default
(
impl_def_id
)
{
self
.probe
(|
this
,
snapshot
|
{
/* [1] */
match
this
.match_impl
(
impl_def_id
,
obligation
,
snapshot
)
{
...
...
src/librustc/ty/instance.rs
浏览文件 @
2f22a929
...
...
@@ -10,7 +10,7 @@
use
hir
::
def_id
::
DefId
;
use
ty
::{
self
,
Ty
,
TypeFoldable
,
Substs
,
TyCtxt
};
use
ty
::
subst
::
{
Kind
,
Subst
}
;
use
ty
::
subst
::
Kind
;
use
traits
;
use
syntax
::
abi
::
Abi
;
use
util
::
ppaux
;
...
...
src/librustc/ty/mod.rs
浏览文件 @
2f22a929
...
...
@@ -2606,8 +2606,31 @@ fn param_env<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id
:
DefId
)
->
ParamEnv
<
'tcx
>
{
// Compute the bounds on Self and the type parameters.
let
mut
predicates
=
tcx
.predicates_of
(
def_id
);
match
tcx
.hir
.as_local_node_id
(
def_id
)
.and_then
(|
node_id
|
tcx
.hir
.find
(
node_id
))
.and_then
(|
item
|
{
match
item
{
hir
::
map
::
NodeItem
(
..
)
=>
{
if
tcx
.impl_is_default
(
def_id
)
{
tcx
.impl_trait_ref
(
def_id
)
}
else
{
None
}
}
_
=>
None
}
})
{
Some
(
trait_ref
)
=>
predicates
.predicates
.push
(
trait_ref
.to_poly_trait_ref
()
.to_predicate
()
),
None
=>
{}
}
let
bounds
=
tcx
.predicates_of
(
def_id
)
.instantiate_identity
(
tcx
);
let
bounds
=
predicates
.instantiate_identity
(
tcx
);
let
predicates
=
bounds
.predicates
;
// Finally, we have to normalize the bounds in the environment, in
...
...
src/librustc_typeck/check/mod.rs
浏览文件 @
2f22a929
...
...
@@ -1745,8 +1745,6 @@ pub fn new(inh: &'a Inherited<'a, 'gcx, 'tcx>,
param_env
:
ty
::
ParamEnv
<
'tcx
>
,
body_id
:
ast
::
NodeId
)
->
FnCtxt
<
'a
,
'gcx
,
'tcx
>
{
FnCtxt
::
set_emit_default_impl_candidates
(
inh
,
body_id
);
FnCtxt
{
body_id
,
param_env
,
...
...
@@ -1765,22 +1763,6 @@ pub fn new(inh: &'a Inherited<'a, 'gcx, 'tcx>,
}
}
fn
set_emit_default_impl_candidates
(
inh
:
&
'a
Inherited
<
'a
,
'gcx
,
'tcx
>
,
body_id
:
ast
::
NodeId
)
{
inh
.infcx.emit_defaul_impl_candidates
.set
(
match
inh
.tcx.hir
.find
(
body_id
)
{
Some
(
Node
::
NodeItem
(
..
))
=>
{
if
inh
.tcx
.impl_is_default
(
inh
.tcx.hir
.local_def_id
(
body_id
))
{
true
}
else
{
false
}
},
_
=>
false
}
);
}
pub
fn
sess
(
&
self
)
->
&
Session
{
&
self
.tcx.sess
}
...
...
src/test/compile-fail/specialization/defaultimpl/specialization-trait-item-not-implemented.rs
浏览文件 @
2f22a929
...
...
@@ -28,4 +28,4 @@ impl Foo for MyStruct {}
fn
main
()
{
println!
(
"{}"
,
MyStruct
.foo_one
());
}
\ No newline at end of file
}
src/test/compile-fail/specialization/defaultimpl/specialization-trait-not-implemented.rs
浏览文件 @
2f22a929
...
...
@@ -27,4 +27,4 @@ fn foo_one(&self) -> &'static str {
fn
main
()
{
println!
(
"{}"
,
MyStruct
.foo_one
());
//~^ ERROR no method named `foo_one` found for type `MyStruct` in the current scope
}
\ No newline at end of file
}
src/test/compile-fail/specialization/defaultimpl/specialization-wfcheck.rs
浏览文件 @
2f22a929
...
...
@@ -15,4 +15,4 @@ trait Foo<'a, T: Eq + 'a> { }
default
impl
<
U
>
Foo
<
'static
,
U
>
for
()
{}
//~^ ERROR the trait bound `U: std::cmp::Eq` is not satisfied
fn
main
(){}
\ No newline at end of file
fn
main
(){}
src/test/run-pass/specialization/defaultimpl/specialization-trait-item-not-implemented.rs
浏览文件 @
2f22a929
...
...
@@ -31,4 +31,4 @@ fn foo_two(&self) -> &'static str {
fn
main
()
{
assert
!
(
MyStruct
.foo_two
()
==
"generic"
);
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录