File tree Expand file tree Collapse file tree 11 files changed +255
-0
lines changed Expand file tree Collapse file tree 11 files changed +255
-0
lines changed Original file line number Diff line number Diff line change 1+ // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
11+ #![ feature( associated_types) ]
12+
13+ pub trait T {
14+ type C ;
15+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
11+ #![ feature( associated_types) ]
12+
13+ trait Foo {
14+ type Item ;
15+ }
16+
17+ struct X ;
18+
19+ impl Foo for X {
20+ type Item = bool ;
21+ }
22+
23+ fn print_x ( _: & Foo , extra : & str ) {
24+ println ! ( "{}" , extra) ;
25+ }
26+
27+ fn main ( ) {
28+ print_x ( X ) ; //~error this function takes 2 parameters but 1 parameter was supplied
29+ }
Original file line number Diff line number Diff line change 1+ // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
11+ #![ feature( associated_types) ]
12+
13+ trait From < Src > {
14+ type Output ;
15+
16+ fn from ( src : Src ) -> <Self as From < Src > >:: Output ;
17+ }
18+
19+ trait To {
20+ // This is a typo, the return type should be `<Dst as From<Self>>::Output`
21+ fn to < Dst : From < Self > > ( self ) -> <Dst as From < Self > >:: Dst {
22+ //~ error: the trait `core::kinds::Sized` is not implemented
23+ From :: from ( self )
24+ }
25+ }
26+
27+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
11+ #![ feature( associated_types) ]
12+
13+ trait From < Src > {
14+ type Result ;
15+
16+ fn from ( src : Src ) -> Self :: Result ;
17+ }
18+
19+ trait To {
20+ fn to < Dst > ( self ) -> <Dst as From < Self > >:: Result where Dst : From < Self > {
21+ From :: from ( self ) //~error: type annotations required
22+ }
23+ }
24+
25+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
11+ #![ feature( associated_types) ]
12+ trait Person {
13+ type string ;
14+ }
15+
16+ struct Someone < P : Person > ;
17+
18+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
11+ #![ feature( associated_types) ]
12+ trait Base { }
13+ trait AssocA {
14+ type X : Base ;
15+ }
16+ trait AssocB {
17+ type Y : Base ;
18+ }
19+ impl < T : AssocA > AssocB for T {
20+ type Y = <T as AssocA >:: X ;
21+ }
22+
23+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
11+ #![ feature( associated_types) ]
12+
13+ trait PoolManager {
14+ type C ;
15+ }
16+
17+ struct InnerPool < M > {
18+ manager : M ,
19+ }
20+
21+ impl < M > InnerPool < M > where M : PoolManager { }
22+
23+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
11+ #![ feature( associated_types) ]
12+
13+ trait PoolManager {
14+ type C ;
15+ }
16+
17+ struct InnerPool < M : PoolManager > {
18+ manager : M ,
19+ }
20+
21+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
11+ // Test that `<Type as Trait>::Output` and `Self::Output` are accepted as type annotations in let
12+ // bindings
13+
14+ #![ feature( associated_types) ]
15+
16+ trait Int {
17+ fn one ( ) -> Self ;
18+ fn leading_zeros ( self ) -> uint ;
19+ }
20+
21+ trait Foo {
22+ type T : Int ;
23+
24+ fn test ( & self ) {
25+ let r: <Self as Foo >:: T = Int :: one ( ) ;
26+ let r: Self :: T = Int :: one ( ) ;
27+ }
28+ }
29+
30+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
11+ // Check that associated types are `Sized`
12+
13+ #![ feature( associated_types) ]
14+
15+ trait Trait {
16+ type Output ;
17+
18+ fn is_sized ( & self ) -> Self :: Output ;
19+ fn wasnt_sized ( & self ) -> Self :: Output { loop { } }
20+ }
21+
22+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments