File tree Expand file tree Collapse file tree 6 files changed +144
-2
lines changed
test/run-pass/rfc1598-generic-associated-types Expand file tree Collapse file tree 6 files changed +144
-2
lines changed Original file line number Diff line number Diff line change @@ -4444,7 +4444,7 @@ impl<'a> Parser<'a> {
4444
4444
}
4445
4445
4446
4446
fn parse_trait_item_assoc_ty ( & mut self , preceding_attrs : Vec < Attribute > )
4447
- -> PResult < ' a , ( Generics , TyParam ) > {
4447
+ -> PResult < ' a , ( ast :: Generics , TyParam ) > {
4448
4448
let span = self . span ;
4449
4449
let ident = self . parse_ident ( ) ?;
4450
4450
let mut generics = self . parse_generics ( ) ?;
@@ -4463,7 +4463,7 @@ impl<'a> Parser<'a> {
4463
4463
} ;
4464
4464
generics. where_clause = self . parse_where_clause ( ) ?;
4465
4465
4466
- Ok ( ( Generics , TyParam {
4466
+ Ok ( ( generics , TyParam {
4467
4467
attrs : preceding_attrs. into ( ) ,
4468
4468
ident,
4469
4469
id : ast:: DUMMY_NODE_ID ,
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 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
+ trait Foo {
12
+ type Bar < ' a , ' b > ;
13
+ }
14
+
15
+ trait Baz {
16
+ type Quux < ' a > ;
17
+ }
18
+
19
+ impl < T > Baz for T where T : Foo {
20
+ type Quux < ' a > = <T as Foo >:: Bar < ' a , ' static > ;
21
+ }
22
+
23
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 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
+ trait Iterable {
12
+ type Item < ' a > ;
13
+ type Iter < ' a > : Iterator < Item = Self :: Item < ' a > > ;
14
+
15
+ fn iter < ' a > ( & ' a self ) -> Self :: Iter < ' a > ;
16
+ }
17
+
18
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 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
+ use std:: rc:: Rc ;
12
+ use std:: sync:: Arc ;
13
+ use std:: ops:: Deref ;
14
+
15
+ trait PointerFamily {
16
+ type Pointer < T > : Deref < Target = T > ;
17
+ fn new < T > ( value : T ) -> Self :: Pointer < T > ;
18
+ }
19
+
20
+ struct ArcFamily ;
21
+
22
+ impl PointerFamily for ArcFamily {
23
+ type Pointer < T > = Arc < T > ;
24
+ fn new < T > ( value : T ) -> Self :: Pointer < T > {
25
+ Arc :: new ( value)
26
+ }
27
+ }
28
+
29
+ struct RcFamily ;
30
+
31
+ impl PointerFamily for RcFamily {
32
+ type Pointer < T > = Rc < T > ;
33
+ fn new < T > ( value : T ) -> Self :: Pointer < T > {
34
+ Rc :: new ( value)
35
+ }
36
+ }
37
+
38
+ struct Foo < P : PointerFamily > {
39
+ bar : P :: Pointer < String > ,
40
+ }
41
+
42
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 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
+ use std:: fmt:: Display ;
12
+
13
+ trait StreamingIterator {
14
+ type Item < ' a > ;
15
+ // Applying the lifetime parameter `'a` to `Self::Item` inside the trait.
16
+ fn next < ' a > ( & ' a self ) -> Option < Self :: Item < ' a > > ;
17
+ }
18
+
19
+ struct Foo < T : StreamingIterator > {
20
+ // Applying a concrete lifetime to the constructor outside the trait.
21
+ bar : <T as StreamingIterator >:: Item < ' static > ,
22
+ }
23
+
24
+ // Users can bound parameters by the type constructed by that trait's associated type constructor
25
+ // of a trait using HRTB. Both type equality bounds and trait bounds of this kind are valid:
26
+ //fn foo<T: for<'a> StreamingIterator<Item<'a>=&'a [i32]>>(iter: T) { ... }
27
+ fn foo < T > ( iter : T ) where T : StreamingIterator , for < ' a > T :: Item < ' a > : Display { /* ... */ }
28
+
29
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 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
+ // Checking the interaction with this other feature
12
+ #![ feature( associated_type_defaults) ]
13
+
14
+ use std:: fmt:: { Display , Debug } ;
15
+
16
+ trait Foo {
17
+ type Assoc where Self : Sized ;
18
+ type Assoc2 < T > where T : Display ;
19
+ type WithDefault < T > = Iterator < Item =T > where T : Debug ;
20
+ }
21
+
22
+ struct Bar ;
23
+
24
+ impl Foo for Bar {
25
+ type Assoc = usize ;
26
+ type Assoc2 < T > = Vec < T > ;
27
+ type WithDefault < ' a , T > = & ' a Iterator < T > ;
28
+ }
29
+
30
+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments