@@ -21,18 +21,16 @@ pub trait Print<'tcx, P> {
21
21
fn print ( & self , p : & mut P ) -> Result < ( ) , PrintError > ;
22
22
}
23
23
24
- /// Interface for outputting user-facing "type-system entities"
25
- /// (paths, types, lifetimes, constants, etc.) as a side-effect
26
- /// (e.g. formatting, like `PrettyPrinter` implementors do) or by
27
- /// constructing some alternative representation (e.g. an AST),
28
- /// which the associated types allow passing through the methods.
29
- ///
30
- /// For pretty-printing/formatting in particular, see `PrettyPrinter`.
31
- //
32
- // FIXME(eddyb) find a better name; this is more general than "printing".
24
+ /// A trait that "prints" user-facing type system entities: paths, types, lifetimes, constants,
25
+ /// etc. "Printing" here means building up a representation of the entity's path, usually as a
26
+ /// `String` (e.g. "std::io::Read") or a `Vec<Symbol>` (e.g. `[sym::std, sym::io, sym::Read]`). The
27
+ /// representation is built up by appending one or more pieces. The specific details included in
28
+ /// the built-up representation depend on the purpose of the printer. The more advanced printers
29
+ /// also rely on the `PrettyPrinter` sub-trait.
33
30
pub trait Printer < ' tcx > : Sized {
34
31
fn tcx < ' a > ( & ' a self ) -> TyCtxt < ' tcx > ;
35
32
33
+ /// Appends a representation of an entity with a normal path, e.g. "std::io::Read".
36
34
fn print_def_path (
37
35
& mut self ,
38
36
def_id : DefId ,
@@ -41,6 +39,7 @@ pub trait Printer<'tcx>: Sized {
41
39
self . default_print_def_path ( def_id, args)
42
40
}
43
41
42
+ /// Like `print_def_path`, but for `DefPathData::Impl`.
44
43
fn print_impl_path (
45
44
& mut self ,
46
45
impl_def_id : DefId ,
@@ -66,42 +65,65 @@ pub trait Printer<'tcx>: Sized {
66
65
self . default_print_impl_path ( impl_def_id, self_ty, impl_trait_ref)
67
66
}
68
67
68
+ /// Appends a representation of a region.
69
69
fn print_region ( & mut self , region : ty:: Region < ' tcx > ) -> Result < ( ) , PrintError > ;
70
70
71
+ /// Appends a representation of a type.
71
72
fn print_type ( & mut self , ty : Ty < ' tcx > ) -> Result < ( ) , PrintError > ;
72
73
74
+ /// Appends a representation of a list of `PolyExistentialPredicate`s.
73
75
fn print_dyn_existential (
74
76
& mut self ,
75
77
predicates : & ' tcx ty:: List < ty:: PolyExistentialPredicate < ' tcx > > ,
76
78
) -> Result < ( ) , PrintError > ;
77
79
80
+ /// Appends a representation of a const.
78
81
fn print_const ( & mut self , ct : ty:: Const < ' tcx > ) -> Result < ( ) , PrintError > ;
79
82
83
+ /// Appends a representation of a crate name, e.g. "std", or even "".
80
84
fn path_crate ( & mut self , cnum : CrateNum ) -> Result < ( ) , PrintError > ;
81
85
82
- fn path_qualified (
86
+ /// Appends a representation of a (full or partial) simple path, in two parts. `print_prefix`,
87
+ /// when called, appends the representation of the leading segments. The rest of the method
88
+ /// appends the representation of the final segment, the details of which are in
89
+ /// `disambiguated_data`.
90
+ ///
91
+ /// E.g. "std::io" + "Read" -> "std::io::Read".
92
+ fn path_append (
83
93
& mut self ,
84
- self_ty : Ty < ' tcx > ,
85
- trait_ref : Option < ty :: TraitRef < ' tcx > > ,
94
+ print_prefix : impl FnOnce ( & mut Self ) -> Result < ( ) , PrintError > ,
95
+ disambiguated_data : & DisambiguatedDefPathData ,
86
96
) -> Result < ( ) , PrintError > ;
87
97
98
+ /// Similar to `path_append`, but the final segment is an `impl` segment.
99
+ ///
100
+ /// E.g. "slice" + "<impl [T]>" -> "slice::<impl [T]>", which may then be further appended to,
101
+ /// giving a longer path representation such as "slice::<impl [T]>::to_vec_in::ConvertVec".
88
102
fn path_append_impl (
89
103
& mut self ,
90
104
print_prefix : impl FnOnce ( & mut Self ) -> Result < ( ) , PrintError > ,
91
105
self_ty : Ty < ' tcx > ,
92
106
trait_ref : Option < ty:: TraitRef < ' tcx > > ,
93
107
) -> Result < ( ) , PrintError > ;
94
108
95
- fn path_append (
109
+ /// Appends a representation of a path ending in generic args, in two parts. `print_prefix`,
110
+ /// when called, appends the leading segments. The rest of the method appends the
111
+ /// representation of the generic args. (Some printers choose to skip appending the generic
112
+ /// args.)
113
+ ///
114
+ /// E.g. "ImplementsTraitForUsize" + "<usize>" -> "ImplementsTraitForUsize<usize>".
115
+ fn path_generic_args (
96
116
& mut self ,
97
117
print_prefix : impl FnOnce ( & mut Self ) -> Result < ( ) , PrintError > ,
98
- disambiguated_data : & DisambiguatedDefPathData ,
118
+ args : & [ GenericArg < ' tcx > ] ,
99
119
) -> Result < ( ) , PrintError > ;
100
120
101
- fn path_generic_args (
121
+ /// Appends a representation of a qualified path segment, e.g. "<OsString as From<&T>>".
122
+ /// If `trait_ref` is `None`, it may fall back to simpler forms, e.g. "<Vec<T>>" or just "Foo".
123
+ fn path_qualified (
102
124
& mut self ,
103
- print_prefix : impl FnOnce ( & mut Self ) -> Result < ( ) , PrintError > ,
104
- args : & [ GenericArg < ' tcx > ] ,
125
+ self_ty : Ty < ' tcx > ,
126
+ trait_ref : Option < ty :: TraitRef < ' tcx > > ,
105
127
) -> Result < ( ) , PrintError > ;
106
128
107
129
fn should_truncate ( & mut self ) -> bool {
0 commit comments