@@ -310,6 +310,7 @@ error[E0072]: recursive type `List` has infinite size
310
310
```
311
311
312
312
## Migration advice
313
+ [ migration advice ] : #migration-advice
313
314
314
315
Since the new introduced syntax is often clearer and shorter, especially when
315
316
dealing with long type names with many generic parameters, tools like ` clippy `
@@ -627,4 +628,37 @@ is preferred.
627
628
# Unresolved questions
628
629
[ unresolved ] : #unresolved-questions
629
630
630
- There are no unresolved questions.
631
+ ## Should the migration advice be to use ` Self ` instead of the concrete type?
632
+
633
+ In the [ migration advice] we suggest that ` clippy ` should encourage users to
634
+ move towards using ` Self ` instead of the concrete type. This RFC currently
635
+ argues that this should be best practice.
636
+
637
+ However, there is some concern that the reading code that pervasively uses
638
+ ` Self ` across the board adds a level of indirection since readers are often
639
+ interested in the concrete type instead of just knowing that it is the ` Self `
640
+ type. To mitigate this indirection, it is possible to improve ` rustdoc ` such
641
+ that you can hover ` Self ` and its associated types (if there are any) to see
642
+ what the concrete type is. Hovering can reduce the degree to which you have
643
+ to jump to see what the concrete type is.
644
+
645
+ Furthermore, the level of indirection introduced by using ` Self ` is not much.
646
+ Only one level of indirection is introduced.
647
+
648
+ With respect to type definitions specifically, there usually are few enough
649
+ variants that you can keep the header ` enum Foo { ` in visual scope in your editor.
650
+ Therefore, you can quickly see what the concrete type is.
651
+
652
+ When you are dealing with complex types, ` Self ` can also be easier to read
653
+ as you can syntax-highlight for it easily and provide a distinct color for it.
654
+
655
+ Using ` Self ` or an associated type of ` Self ` such as in ` -> Option<Self::Item> `
656
+ also provides information about the context we are dealing with in the case of
657
+ traits. Writing out the concrete type can therefore make patterns harder to see.
658
+
659
+ However, the standard library currently writes out the associated type. This
660
+ can be seen in the case of ` Iterator ` , where instead of writing
661
+ ` fn next(&mut self) -> Option<Self::Item> ` the standard library will use
662
+ ` fn next(&mut self) -> Option<SomeConcreteType> ` .
663
+
664
+ There are no other unresolved questions.
0 commit comments