Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
462c83e2
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,发现更多精彩内容 >>
提交
462c83e2
编写于
1月 30, 2016
作者:
A
Aaron Turon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Address basic nits from initial review
上级
9734406a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
97 addition
and
19 deletion
+97
-19
src/librustc/middle/traits/specialize.rs
src/librustc/middle/traits/specialize.rs
+9
-8
src/librustc/middle/ty/trait_def.rs
src/librustc/middle/ty/trait_def.rs
+12
-8
src/librustc_typeck/coherence/overlap.rs
src/librustc_typeck/coherence/overlap.rs
+1
-3
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+1
-0
src/test/compile-fail/specialization-negative-impl.rs
src/test/compile-fail/specialization-negative-impl.rs
+2
-0
src/test/compile-fail/specialization-no-default.rs
src/test/compile-fail/specialization-no-default.rs
+49
-0
src/test/run-pass/specialization-default-methods.rs
src/test/run-pass/specialization-default-methods.rs
+23
-0
未找到文件。
src/librustc/middle/traits/specialize.rs
浏览文件 @
462c83e2
...
...
@@ -52,10 +52,9 @@ pub struct SpecializationGraph {
}
/// Information pertinent to an overlapping impl error.
pub
struct
Overlap
<
'tcx
>
{
pub
struct
Overlap
<
'a
,
'tcx
:
'a
>
{
pub
in_context
:
InferCtxt
<
'a
,
'tcx
>
,
pub
with_impl
:
DefId
,
/// NB: this TraitRef can contain inference variables!
pub
on_trait_ref
:
ty
::
TraitRef
<
'tcx
>
,
}
...
...
@@ -70,13 +69,13 @@ pub fn new() -> SpecializationGraph {
/// Insert a local impl into the specialization graph. If an existing impl
/// conflicts with it (has overlap, but neither specializes the other),
/// information about the area of overlap is returned in the `Err`.
pub
fn
insert
<
'tcx
>
(
&
mut
self
,
tcx
:
&
ty
::
ctxt
<
'tcx
>
,
impl_def_id
:
DefId
,
trait_ref
:
ty
::
TraitRef
)
->
Result
<
(),
Overlap
<
'tcx
>>
{
pub
fn
insert
<
'a
,
'tcx
>
(
&
mut
self
,
tcx
:
&
'a
ty
::
ctxt
<
'tcx
>
,
impl_def_id
:
DefId
)
->
Result
<
(),
Overlap
<
'a
,
'tcx
>>
{
assert
!
(
impl_def_id
.is_local
());
let
trait_ref
=
tcx
.impl_trait_ref
(
impl_def_id
)
.unwrap
();
let
mut
parent
=
trait_ref
.def_id
;
let
mut
my_children
=
vec!
[];
...
...
@@ -98,6 +97,7 @@ pub fn insert<'tcx>(&mut self,
return
Err
(
Overlap
{
with_impl
:
possible_sibling
,
on_trait_ref
:
trait_ref
,
in_context
:
infcx
,
});
}
...
...
@@ -118,6 +118,7 @@ pub fn insert<'tcx>(&mut self,
return
Err
(
Overlap
{
with_impl
:
possible_sibling
,
on_trait_ref
:
trait_ref
,
in_context
:
infcx
,
});
}
...
...
src/librustc/middle/ty/trait_def.rs
浏览文件 @
462c83e2
...
...
@@ -125,7 +125,8 @@ fn read_trait_impls(&self, tcx: &TyCtxt<'tcx>) {
fn
record_impl
(
&
self
,
tcx
:
&
TyCtxt
<
'tcx
>
,
impl_def_id
:
DefId
,
impl_trait_ref
:
TraitRef
<
'tcx
>
)
->
bool
{
impl_trait_ref
:
TraitRef
<
'tcx
>
)
->
bool
{
debug!
(
"TraitDef::record_impl for {:?}, from {:?}"
,
self
,
impl_trait_ref
);
...
...
@@ -161,7 +162,9 @@ pub fn record_local_impl(&self,
tcx
:
&
TyCtxt
<
'tcx
>
,
impl_def_id
:
DefId
,
impl_trait_ref
:
TraitRef
<
'tcx
>
)
{
self
.record_impl
(
tcx
,
impl_def_id
,
impl_trait_ref
);
assert
!
(
impl_def_id
.is_local
());
let
was_new
=
self
.record_impl
(
tcx
,
impl_def_id
,
impl_trait_ref
);
assert
!
(
was_new
);
}
/// Records a trait-to-implementation mapping for a non-local impl.
...
...
@@ -174,6 +177,8 @@ pub fn record_remote_impl(&self,
impl_def_id
:
DefId
,
impl_trait_ref
:
TraitRef
<
'tcx
>
,
parent_impl
:
DefId
)
{
assert
!
(
!
impl_def_id
.is_local
());
// if the impl has not previously been recorded
if
self
.record_impl
(
tcx
,
impl_def_id
,
impl_trait_ref
)
{
// if the impl is non-local, it's placed directly into the
...
...
@@ -186,15 +191,14 @@ pub fn record_remote_impl(&self,
/// Adds a local impl into the specialization graph, returning an error with
/// overlap information if the impl overlaps but does not specialize an
/// existing impl.
pub
fn
add_impl_for_specialization
(
&
self
,
tcx
:
&
ctxt
<
'tcx
>
,
impl_def_id
:
DefId
,
impl_trait_ref
:
TraitRef
<
'tcx
>
)
->
Result
<
(),
traits
::
Overlap
<
'tcx
>>
{
pub
fn
add_impl_for_specialization
<
'a
>
(
&
self
,
tcx
:
&
'a
ctxt
<
'tcx
>
,
impl_def_id
:
DefId
)
->
Result
<
(),
traits
::
Overlap
<
'a
,
'tcx
>>
{
assert
!
(
impl_def_id
.is_local
());
self
.specialization_graph
.borrow_mut
()
.insert
(
tcx
,
impl_def_id
,
impl_trait_ref
)
.insert
(
tcx
,
impl_def_id
)
}
/// Returns the immediately less specialized impl, if any.
...
...
src/librustc_typeck/coherence/overlap.rs
浏览文件 @
462c83e2
...
...
@@ -133,9 +133,7 @@ fn visit_item(&mut self, item: &'v hir::Item) {
let
def
=
self
.tcx
.lookup_trait_def
(
trait_def_id
);
// attempt to insert into the specialization graph
let
insert_result
=
def
.add_impl_for_specialization
(
self
.tcx
,
impl_def_id
,
trait_ref
);
let
insert_result
=
def
.add_impl_for_specialization
(
self
.tcx
,
impl_def_id
);
// insertion failed due to overlap
if
let
Err
(
overlap
)
=
insert_result
{
...
...
src/libsyntax/feature_gate.rs
浏览文件 @
462c83e2
...
...
@@ -250,6 +250,7 @@
(
"question_mark"
,
"1.9.0"
,
Some
(
31436
),
Active
)
// impl specialization (RFC 1210)
// TODO: update with issue number (once it exists), before landing
(
"specialization"
,
"1.7.0"
,
None
,
Active
),
];
// (changing above list without updating src/doc/reference.md makes @cmr sad)
...
...
src/test/compile-fail/specialization-negative-impl.rs
浏览文件 @
462c83e2
...
...
@@ -13,6 +13,8 @@
struct
TestType
<
T
>
(
T
);
// TODO: nail down the rules here with @nikomatsakis
unsafe
impl
<
T
>
Send
for
TestType
<
T
>
{}
impl
!
Send
for
TestType
<
u8
>
{}
...
...
src/test/compile-fail/specialization-no-default.rs
浏览文件 @
462c83e2
...
...
@@ -10,6 +10,10 @@
#![feature(specialization)]
////////////////////////////////////////////////////////////////////////////////
// Test 1: one layer of specialization, multiple methods, missing `default`
////////////////////////////////////////////////////////////////////////////////
trait
Foo
{
fn
foo
(
&
self
);
fn
bar
(
&
self
);
...
...
@@ -28,6 +32,10 @@ impl Foo for u32 {
fn
bar
(
&
self
)
{}
//~ ERROR E0520
}
////////////////////////////////////////////////////////////////////////////////
// Test 2: one layer of specialization, missing `default` on associated type
////////////////////////////////////////////////////////////////////////////////
trait
Bar
{
type
T
;
}
...
...
@@ -40,4 +48,45 @@ impl Bar for u8 {
type
T
=
();
//~ ERROR E0520
}
////////////////////////////////////////////////////////////////////////////////
// Test 3a: multiple layers of specialization, missing interior `default`
////////////////////////////////////////////////////////////////////////////////
trait
Baz
{
fn
baz
(
&
self
);
}
impl
<
T
>
Baz
for
T
{
default
fn
baz
(
&
self
)
{}
}
impl
<
T
:
Clone
>
Baz
for
T
{
fn
baz
(
&
self
)
{}
}
impl
Baz
for
i32
{
fn
baz
(
&
self
)
{}
}
////////////////////////////////////////////////////////////////////////////////
// Test 3b: multiple layers of specialization, missing interior `default`,
// redundant `default` in bottom layer.
////////////////////////////////////////////////////////////////////////////////
trait
Redundant
{
fn
redundant
(
&
self
);
}
impl
<
T
>
Redundant
for
T
{
default
fn
redundant
(
&
self
)
{}
}
impl
<
T
:
Clone
>
Redundant
for
T
{
fn
redundant
(
&
self
)
{}
}
impl
Redundant
for
i32
{
default
fn
redundant
(
&
self
)
{}
}
fn
main
()
{}
src/test/run-pass/specialization-default-methods.rs
浏览文件 @
462c83e2
...
...
@@ -16,6 +16,12 @@ trait Foo {
fn
foo
(
&
self
)
->
bool
;
}
// Specialization tree for Foo:
//
// T
// / \
// i32 i64
impl
<
T
>
Foo
for
T
{
default
fn
foo
(
&
self
)
->
bool
{
false
}
}
...
...
@@ -38,6 +44,23 @@ trait Bar {
fn
bar
(
&
self
)
->
i32
{
0
}
}
// Specialization tree for Bar.
// Uses of $ designate that method is provided
//
// $Bar (the trait)
// |
// T
// /|\
// / | \
// / | \
// / | \
// / | \
// / | \
// $i32 &str $Vec<T>
// /\
// / \
// Vec<i32> $Vec<i64>
impl
<
T
>
Bar
for
T
{}
// use the provided method
impl
Bar
for
i32
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录