@@ -141,68 +141,35 @@ impl<'d> ToDisplayTree<'d> for Pattern<'_> {
141
141
142
142
impl < ' d > ToDisplayTree < ' d > for Type < ' _ > {
143
143
fn to_display_tree ( & self , a : & ' d Arenas < ' d > ) -> DisplayTree < ' d > {
144
- /// Remove the refs in front of this type.
145
- fn strip_refs < ' a > ( ty : & ' a Type < ' a > , mutabilities : & mut Vec < Mutability > ) -> & ' a Type < ' a > {
146
- match ty {
147
- Type :: Ref ( mtbl, ty) => {
148
- mutabilities. push ( * mtbl) ;
149
- strip_refs ( ty, mutabilities)
150
- }
151
- _ => & ty,
152
- }
153
- }
154
- let mut mutabilities = Vec :: new ( ) ;
155
- let ty = strip_refs ( self , & mut mutabilities) ;
156
- let leaf = match ty {
157
- Type :: Tuple ( tys) => DisplayTree :: sep_by ( a, ", " , tys. iter ( ) )
144
+ match self {
145
+ Self :: Tuple ( tys) => DisplayTree :: sep_by ( a, ", " , tys. iter ( ) )
158
146
. surrounded ( a, "[" , "]" )
159
147
. tag ( "ty_list" ) ,
160
- Type :: OtherNonRef ( name) | Type :: AbstractNonRef ( name) | Type :: Abstract ( name) => {
148
+ Self :: Ref ( mutable, ty) => format ! ( "&{mutable}" )
149
+ . to_display_tree ( a)
150
+ . prepend_to_tagged_list ( a, "ty_refs" , "" , CompareMode :: Suffix , ty) ,
151
+ Self :: OtherNonRef ( name) | Self :: AbstractNonRef ( name) | Self :: Abstract ( name) => {
161
152
name. to_display_tree ( a)
162
153
}
163
- Type :: Ref ( ..) => unreachable ! ( ) ,
164
- } ;
165
- // Types tend be the same on the inside; so we want to show that the innermost types are
166
- // the same and the surrounding refs differ. To do this, we extract the list of refs and
167
- // add them to the same list, with `Suffix` compare mode.
168
- DisplayTree :: sep_by_compare_mode (
169
- a,
170
- "" ,
171
- mutabilities
172
- . iter ( )
173
- . map ( |mutable| format ! ( "&{mutable}" ) . to_display_tree ( a) )
174
- . chain ( [ leaf] ) ,
175
- CompareMode :: Suffix ,
176
- )
177
- . tag ( "ty_refs" )
154
+ }
178
155
}
179
156
}
180
157
181
158
impl < ' d > ToDisplayTree < ' d > for ExprKind < ' _ > {
182
159
fn to_display_tree ( & self , a : & ' d Arenas < ' d > ) -> DisplayTree < ' d > {
183
- enum Symbol {
184
- Deref ,
185
- Ref ( Mutability ) ,
186
- }
187
- /// Remove the refs and derefs in front of this expression.
188
- fn strip_symbols < ' a > ( e : & ' a ExprKind < ' a > , symbols : & mut Vec < Symbol > ) -> & ' a ExprKind < ' a > {
189
- match e {
190
- ExprKind :: Ref ( mtbl, e) => {
191
- symbols. push ( Symbol :: Ref ( * mtbl) ) ;
192
- strip_symbols ( & e. kind , symbols)
193
- }
194
- ExprKind :: Deref ( e) => {
195
- symbols. push ( Symbol :: Deref ) ;
196
- strip_symbols ( & e. kind , symbols)
197
- }
198
- _ => & e,
199
- }
200
- }
201
- let mut symbols = Vec :: new ( ) ;
202
- let e = strip_symbols ( self , & mut symbols) ;
203
- let leaf = match e {
160
+ match self {
204
161
ExprKind :: Scrutinee => "s" . to_display_tree ( a) ,
205
162
ExprKind :: Abstract { .. } => "e" . to_display_tree ( a) ,
163
+ ExprKind :: Ref ( mutable, e) => format ! ( "&{mutable}" )
164
+ . to_display_tree ( a)
165
+ . prepend_to_tagged_list ( a, "expr_symbols" , "" , CompareMode :: Suffix , e) ,
166
+ ExprKind :: Deref ( e) => "*" . to_display_tree ( a) . prepend_to_tagged_list (
167
+ a,
168
+ "expr_symbols" ,
169
+ "" ,
170
+ CompareMode :: Suffix ,
171
+ e,
172
+ ) ,
206
173
ExprKind :: Field ( e, n) => {
207
174
let needs_parens = matches ! ( e. kind, ExprKind :: Deref ( ..) ) ;
208
175
let ( before, after) = if needs_parens { ( "(" , ")" ) } else { ( "" , "" ) } ;
@@ -218,24 +185,7 @@ impl<'d> ToDisplayTree<'d> for ExprKind<'_> {
218
185
] ,
219
186
)
220
187
}
221
- ExprKind :: Ref ( ..) | ExprKind :: Deref ( ..) => unreachable ! ( ) ,
222
- } ;
223
- // We cleverly diff expressions: expressions tend to start the same then diverge; so we
224
- // want to show that the innermost expressions are the same and the surrounding `&`/`*`
225
- // differ. To do this, we extract the list of `&`/`*` and add them to the same list, with
226
- // `Suffix` compare mode.
227
- DisplayTree :: sep_by_compare_mode (
228
- a,
229
- "" ,
230
- symbols
231
- . iter ( )
232
- . map ( |s| match s {
233
- Symbol :: Deref => "*" . to_display_tree ( a) ,
234
- Symbol :: Ref ( mutable) => format ! ( "&{mutable}" ) . to_display_tree ( a) ,
235
- } )
236
- . chain ( [ leaf] ) ,
237
- CompareMode :: Suffix ,
238
- )
188
+ }
239
189
}
240
190
}
241
191
0 commit comments