Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
cf73e36a
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,发现更多精彩内容 >>
提交
cf73e36a
编写于
2月 18, 2015
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rework trait-bound-conversion so be based on the AST and rework collect
to pass in the appropriate ast::generics etc
上级
36d04711
变更
9
展开全部
隐藏空白更改
内联
并排
Showing
9 changed file
with
552 addition
and
266 deletion
+552
-266
src/librustc/metadata/tydecode.rs
src/librustc/metadata/tydecode.rs
+16
-0
src/librustc_typeck/collect.rs
src/librustc_typeck/collect.rs
+334
-256
src/test/compile-fail/associated-type-projection-ambig-between-bound-and-where-clause.rs
...d-type-projection-ambig-between-bound-and-where-clause.rs
+52
-0
src/test/compile-fail/cycle-projection-based-on-where-clause.rs
...st/compile-fail/cycle-projection-based-on-where-clause.rs
+34
-0
src/test/compile-fail/cycle-trait-supertrait-direct.rs
src/test/compile-fail/cycle-trait-supertrait-direct.rs
+1
-1
src/test/compile-fail/cycle-trait-supertrait-indirect.rs
src/test/compile-fail/cycle-trait-supertrait-indirect.rs
+1
-1
src/test/run-pass/associated-types-project-from-type-param-via-bound-in-where-clause.rs
...ypes-project-from-type-param-via-bound-in-where-clause.rs
+107
-0
src/test/run-pass/cycle-generic-bound.rs
src/test/run-pass/cycle-generic-bound.rs
+4
-5
src/test/run-pass/cycle-trait-type-trait.rs
src/test/run-pass/cycle-trait-type-trait.rs
+3
-3
未找到文件。
src/librustc/metadata/tydecode.rs
浏览文件 @
cf73e36a
...
...
@@ -835,6 +835,22 @@ fn parse_type_param_def_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F)
}
}
fn
parse_object_lifetime_default
<
'a
,
'tcx
,
F
>
(
st
:
&
mut
PState
<
'a
,
'tcx
>
,
conv
:
&
mut
F
)
->
Option
<
ty
::
ObjectLifetimeDefault
>
where
F
:
FnMut
(
DefIdSource
,
ast
::
DefId
)
->
ast
::
DefId
,
{
match
next
(
st
)
{
'n'
=>
None
,
'a'
=>
Some
(
ty
::
ObjectLifetimeDefault
::
Ambiguous
),
's'
=>
{
let
region
=
parse_region_
(
st
,
conv
);
Some
(
ty
::
ObjectLifetimeDefault
::
Specific
(
region
))
}
_
=>
panic!
(
"parse_object_lifetime_default: bad input"
)
}
}
fn
parse_existential_bounds
<
'a
,
'tcx
,
F
>
(
st
:
&
mut
PState
<
'a
,
'tcx
>
,
mut
conv
:
F
)
->
ty
::
ExistentialBounds
<
'tcx
>
where
...
...
src/librustc_typeck/collect.rs
浏览文件 @
cf73e36a
此差异已折叠。
点击以展开。
src/test/compile-fail/associated-type-projection-ambig-between-bound-and-where-clause.rs
0 → 100644
浏览文件 @
cf73e36a
// Copyright 2014 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.
// Test equality constraints in a where clause where the type being
// equated appears in a supertrait.
pub
trait
Vehicle
{
type
Color
;
fn
go
(
&
self
)
{
}
}
pub
trait
Box
{
type
Color
;
fn
mail
(
&
self
)
{
}
}
fn
a
<
C
:
Vehicle
+
Box
>
(
_
:
C
::
Color
)
{
//~^ ERROR ambiguous associated type `Color` in bounds of `C`
}
fn
b
<
C
>
(
_
:
C
::
Color
)
where
C
:
Vehicle
+
Box
{
//~^ ERROR ambiguous associated type `Color` in bounds of `C`
}
fn
c
<
C
>
(
_
:
C
::
Color
)
where
C
:
Vehicle
,
C
:
Box
{
//~^ ERROR ambiguous associated type `Color` in bounds of `C`
}
struct
D
<
X
>
;
impl
<
X
>
D
<
X
>
where
X
:
Vehicle
{
fn
d
(
&
self
,
_
:
X
::
Color
)
where
X
:
Box
{
}
//~^ ERROR ambiguous associated type `Color` in bounds of `X`
}
trait
E
<
X
:
Vehicle
>
{
fn
e
(
&
self
,
_
:
X
::
Color
)
where
X
:
Box
;
//~^ ERROR ambiguous associated type `Color` in bounds of `X`
fn
f
(
&
self
,
_
:
X
::
Color
)
where
X
:
Box
{
}
//~^ ERROR ambiguous associated type `Color` in bounds of `X`
}
pub
fn
main
()
{
}
src/test/compile-fail/cycle-projection-based-on-where-clause.rs
0 → 100644
浏览文件 @
cf73e36a
// 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.
// Example cycle where a bound on `T` uses a shorthand for `T`. This
// creates a cycle because we have to know the bounds on `T` to figure
// out what trait defines `Item`, but we can't know the bounds on `T`
// without knowing how to handle `T::Item`.
//
// Note that in the future cases like this could perhaps become legal,
// if we got more fine-grained about our cycle detection or changed
// how we handle `T::Item` resolution.
use
std
::
ops
::
Add
;
// Preamble.
trait
Trait
{
type
Item
;
}
struct
A
<
T
>
where
T
:
Trait
,
T
:
Add
<
T
::
Item
>
//~^ ERROR illegal recursive type
{
data
:
T
}
fn
main
()
{
}
src/test/compile-fail/cycle-trait-supertrait-direct.rs
浏览文件 @
cf73e36a
...
...
@@ -11,7 +11,7 @@
// Test a supertrait cycle where a trait extends itself.
trait
Chromosome
:
Chromosome
{
//~^ ERROR
cyclic reference detected
//~^ ERROR
unsupported cyclic reference
}
fn
main
()
{
}
src/test/compile-fail/cycle-trait-supertrait-indirect.rs
浏览文件 @
cf73e36a
...
...
@@ -15,8 +15,8 @@ trait A: B {
}
trait
B
:
C
{
}
//~^ ERROR cyclic reference detected
trait
C
:
B
{
}
//~^ ERROR unsupported cyclic reference
fn
main
()
{
}
src/test/run-pass/associated-types-project-from-type-param-via-bound-in-where-clause.rs
0 → 100644
浏览文件 @
cf73e36a
// 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.
// Various uses of `T::Item` syntax where the bound that supplies
// `Item` originates in a where-clause, not the declaration of
// `T`. Issue #20300.
use
std
::
marker
::{
MarkerTrait
,
PhantomData
};
use
std
::
sync
::
atomic
::{
AtomicUsize
,
ATOMIC_USIZE_INIT
};
use
std
::
sync
::
atomic
::
Ordering
::
SeqCst
;
static
COUNTER
:
AtomicUsize
=
ATOMIC_USIZE_INIT
;
// Preamble.
trait
Trait
:
MarkerTrait
{
type
Item
;
}
struct
Struct
;
impl
Trait
for
Struct
{
type
Item
=
u32
;
}
// Where-clause attached on the method which declares `T`.
struct
A
;
impl
A
{
fn
foo
<
T
>
(
_
x
:
T
::
Item
)
where
T
:
Trait
{
COUNTER
.fetch_add
(
1
,
SeqCst
);
}
}
// Where-clause attached on the method to a parameter from the struct.
struct
B
<
T
>
(
PhantomData
<
T
>
);
impl
<
T
>
B
<
T
>
{
fn
foo
(
_
x
:
T
::
Item
)
where
T
:
Trait
{
COUNTER
.fetch_add
(
10
,
SeqCst
);
}
}
// Where-clause attached to free fn.
fn
c
<
T
>
(
_
:
T
::
Item
)
where
T
:
Trait
{
COUNTER
.fetch_add
(
100
,
SeqCst
);
}
// Where-clause attached to defaulted and non-defaulted trait method.
trait
AnotherTrait
{
fn
method
<
T
>
(
&
self
,
_
:
T
::
Item
)
where
T
:
Trait
;
fn
default_method
<
T
>
(
&
self
,
_
:
T
::
Item
)
where
T
:
Trait
{
COUNTER
.fetch_add
(
1000
,
SeqCst
);
}
}
struct
D
;
impl
AnotherTrait
for
D
{
fn
method
<
T
>
(
&
self
,
_
:
T
::
Item
)
where
T
:
Trait
{
COUNTER
.fetch_add
(
10000
,
SeqCst
);
}
}
// Where-clause attached to trait and impl containing the method.
trait
YetAnotherTrait
<
T
>
where
T
:
Trait
{
fn
method
(
&
self
,
_
:
T
::
Item
);
fn
default_method
(
&
self
,
_
:
T
::
Item
)
{
COUNTER
.fetch_add
(
100000
,
SeqCst
);
}
}
struct
E
<
T
>
(
PhantomData
<
T
>
);
impl
<
T
>
YetAnotherTrait
<
T
>
for
E
<
T
>
where
T
:
Trait
{
fn
method
(
&
self
,
_
:
T
::
Item
)
{
COUNTER
.fetch_add
(
1000000
,
SeqCst
);
}
}
// Where-clause attached to inherent impl containing the method.
struct
F
<
T
>
(
PhantomData
<
T
>
);
impl
<
T
>
F
<
T
>
where
T
:
Trait
{
fn
method
(
&
self
,
_
:
T
::
Item
)
{
COUNTER
.fetch_add
(
10000000
,
SeqCst
);
}
}
// Where-clause attached to struct.
#[allow(dead_code)]
struct
G
<
T
>
where
T
:
Trait
{
data
:
T
::
Item
,
phantom
:
PhantomData
<
T
>
,
}
fn
main
()
{
A
::
foo
::
<
Struct
>
(
22
);
B
::
<
Struct
>
::
foo
(
22
);
c
::
<
Struct
>
(
22
);
D
.method
::
<
Struct
>
(
22
);
D
.default_method
::
<
Struct
>
(
22
);
E
(
PhantomData
::
<
Struct
>
)
.method
(
22
);
E
(
PhantomData
::
<
Struct
>
)
.default_method
(
22
);
F
(
PhantomData
::
<
Struct
>
)
.method
(
22
);
G
::
<
Struct
>
{
data
:
22
,
phantom
:
PhantomData
};
assert_eq!
(
COUNTER
.load
(
SeqCst
),
11111111
);
}
src/test/
compile-fail
/cycle-generic-bound.rs
→
src/test/
run-pass
/cycle-generic-bound.rs
浏览文件 @
cf73e36a
...
...
@@ -8,12 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Regression test for #15477. This test should pass, vs reporting an
// error as it does now, but at least this test shows it doesn't
// segfault.
// Regression test for #15477. This test just needs to compile.
trait
Chromosome
<
X
:
Chromosome
>
{
//~^ ERROR cyclic reference detected
use
std
::
marker
::
PhantomFn
;
trait
Chromosome
<
X
:
Chromosome
<
i32
>>
:
PhantomFn
<
(
Self
,
X
)
>
{
}
fn
main
()
{
}
src/test/
compile-fail
/cycle-trait-type-trait.rs
→
src/test/
run-pass
/cycle-trait-type-trait.rs
浏览文件 @
cf73e36a
...
...
@@ -8,10 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test a supertrait cycle where a trait extends itself.
// Test a case where a supertrait references a type that references
// the original trait. This poses no problem at the moment.
trait
Chromosome
:
Get
<
Struct
>
{
//~^ ERROR cyclic reference detected
trait
Chromosome
:
Get
<
Struct
<
i32
>>
{
}
trait
Get
<
A
>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录