Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b20bfb1f
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,发现更多精彩内容 >>
提交
b20bfb1f
编写于
11月 21, 2017
作者:
G
Gianni Ciccarelli
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support `default impl` for specialization
not skipping any wfchecks on default impls
上级
13e80af1
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
64 addition
and
31 deletion
+64
-31
src/librustc/infer/mod.rs
src/librustc/infer/mod.rs
+4
-0
src/librustc/traits/select.rs
src/librustc/traits/select.rs
+20
-11
src/librustc/ty/trait_def.rs
src/librustc/ty/trait_def.rs
+3
-9
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/mod.rs
+18
-0
src/librustc_typeck/check/wfcheck.rs
src/librustc_typeck/check/wfcheck.rs
+1
-11
src/test/compile-fail/specialization/defaultimpl/specialization-wfcheck.rs
...fail/specialization/defaultimpl/specialization-wfcheck.rs
+18
-0
未找到文件。
src/librustc/infer/mod.rs
浏览文件 @
b20bfb1f
...
...
@@ -181,6 +181,9 @@ 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
...
...
@@ -452,6 +455,7 @@ 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
浏览文件 @
b20bfb1f
...
...
@@ -1296,6 +1296,12 @@ 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
}
...
...
@@ -1714,18 +1720,21 @@ fn assemble_candidates_from_impls(&mut self,
obligation
.predicate
.def_id
(),
obligation
.predicate
.0
.trait_ref
.self_ty
(),
|
impl_def_id
|
{
self
.probe
(|
this
,
snapshot
|
{
/* [1] */
match
this
.match_impl
(
impl_def_id
,
obligation
,
snapshot
)
{
Ok
(
skol_map
)
=>
{
candidates
.vec
.push
(
ImplCandidate
(
impl_def_id
));
// NB: we can safely drop the skol map
// since we are in a probe [1]
mem
::
drop
(
skol_map
);
if
self
.infcx
()
.emit_defaul_impl_candidates
.get
()
||
!
self
.tcx
()
.impl_is_default
(
impl_def_id
)
{
self
.probe
(|
this
,
snapshot
|
{
/* [1] */
match
this
.match_impl
(
impl_def_id
,
obligation
,
snapshot
)
{
Ok
(
skol_map
)
=>
{
candidates
.vec
.push
(
ImplCandidate
(
impl_def_id
));
// NB: we can safely drop the skol map
// since we are in a probe [1]
mem
::
drop
(
skol_map
);
}
Err
(
_
)
=>
{
}
}
Err
(
_
)
=>
{
}
}
});
});
}
}
);
...
...
src/librustc/ty/trait_def.rs
浏览文件 @
b20bfb1f
...
...
@@ -92,16 +92,10 @@ pub fn for_each_relevant_impl<F: FnMut(DefId)>(self,
self_ty
:
Ty
<
'tcx
>
,
mut
f
:
F
)
{
let
mut
emit_impl
=
|
impl_def_id
:
DefId
|
{
if
!
self
.impl_is_default
(
impl_def_id
)
{
f
(
impl_def_id
);
}
};
let
impls
=
self
.trait_impls_of
(
def_id
);
for
&
impl_def_id
in
impls
.blanket_impls
.iter
()
{
emit_impl
(
impl_def_id
);
f
(
impl_def_id
);
}
// simplify_type(.., false) basically replaces type parameters and
...
...
@@ -132,13 +126,13 @@ pub fn for_each_relevant_impl<F: FnMut(DefId)>(self,
if
let
Some
(
simp
)
=
fast_reject
::
simplify_type
(
self
,
self_ty
,
true
)
{
if
let
Some
(
impls
)
=
impls
.non_blanket_impls
.get
(
&
simp
)
{
for
&
impl_def_id
in
impls
{
emit_impl
(
impl_def_id
);
f
(
impl_def_id
);
}
}
}
else
{
for
v
in
impls
.non_blanket_impls
.values
()
{
for
&
impl_def_id
in
v
{
emit_impl
(
impl_def_id
);
f
(
impl_def_id
);
}
}
}
...
...
src/librustc_typeck/check/mod.rs
浏览文件 @
b20bfb1f
...
...
@@ -1745,6 +1745,8 @@ 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
,
...
...
@@ -1763,6 +1765,22 @@ 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/librustc_typeck/check/wfcheck.rs
浏览文件 @
b20bfb1f
...
...
@@ -343,18 +343,8 @@ fn check_impl(&mut self,
fcx
.body_id
,
&
trait_ref
,
ast_trait_ref
.path.span
);
// not registering predicates associcated with a `default impl`
let
impl_is_default
=
fcx
.tcx
.impl_is_default
(
item_def_id
);
for
obligation
in
obligations
{
let
register
=
match
obligation
.predicate
{
ty
::
Predicate
::
Trait
(
..
)
=>
!
impl_is_default
,
_
=>
true
};
if
register
{
fcx
.register_predicate
(
obligation
);
}
fcx
.register_predicate
(
obligation
);
}
}
None
=>
{
...
...
src/test/compile-fail/specialization/defaultimpl/specialization-wfcheck.rs
0 → 100644
浏览文件 @
b20bfb1f
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(specialization)]
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
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录