@@ -141,18 +141,40 @@ 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
- match self {
145
- Self :: Tuple ( tys) => DisplayTree :: sep_by ( a, ", " , tys. iter ( ) )
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 ( ) )
146
158
. surrounded ( a, "[" , "]" )
147
159
. tag ( "ty_list" ) ,
148
- Self :: Ref ( mutable, ty) => format ! ( "&{mutable}" )
149
- . to_display_tree ( a)
150
- . then ( a, ty)
151
- . tag ( "ty_ref" ) ,
152
- Self :: OtherNonRef ( name) | Self :: AbstractNonRef ( name) | Self :: Abstract ( name) => {
160
+ Type :: OtherNonRef ( name) | Type :: AbstractNonRef ( name) | Type :: Abstract ( name) => {
153
161
name. to_display_tree ( a)
154
162
}
155
- }
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" )
156
178
}
157
179
}
158
180
0 commit comments