File tree Expand file tree Collapse file tree 1 file changed +18
-18
lines changed Expand file tree Collapse file tree 1 file changed +18
-18
lines changed Original file line number Diff line number Diff line change @@ -406,8 +406,20 @@ example:
406
406
```
407
407
408
408
The `Self` keyword represents the current type, which explains why it
409
- can only be used inside an impl or a trait. For example, it is used
410
- to solve conflicts like this one:
409
+ can only be used inside an impl or a trait. It gives access to
410
+ associated items of a type:
411
+
412
+ ```
413
+ trait Foo {
414
+ type Bar;
415
+ }
416
+
417
+ trait Baz : Foo {
418
+ fn bar() -> Self::Bar; // like this
419
+ }
420
+ ```
421
+
422
+ However, be careful when two types has a common associated type:
411
423
412
424
```
413
425
trait Foo {
@@ -424,26 +436,14 @@ trait Baz : Foo + Foo2 {
424
436
}
425
437
```
426
438
427
- Which can be solved by specifying from which trait we want to use
428
- the `Bar` type:
439
+ It can be solved by specifying from which trait we want to use the
440
+ `Bar` type:
429
441
430
442
```
431
443
trait Baz : Foo + Foo2 {
432
444
fn bar() -> <Self as Foo>::Bar; // ok!
433
445
}
434
446
```
435
-
436
- A more simple example gives:
437
-
438
- ```
439
- trait Foo {
440
- type Bar;
441
- }
442
-
443
- trait Baz : Foo {
444
- fn bar() -> <Self as Foo>::Bar; // ok!
445
- }
446
- ```
447
447
"## ,
448
448
449
449
E0412 : r##"
@@ -872,8 +872,8 @@ impl Foo for i32 {}
872
872
}
873
873
874
874
register_diagnostics ! {
875
- E0153 , // called no where
876
- E0157 , // called from no where
875
+ // E0153,
876
+ // E0157,
877
877
E0254 , // import conflicts with imported crate in this module
878
878
E0257 ,
879
879
E0258 ,
You can’t perform that action at this time.
0 commit comments