3
3
use std:: fmt:: { self , Write } ;
4
4
5
5
use itertools:: Itertools ;
6
+ use span:: Edition ;
6
7
7
8
use crate :: {
8
9
hir:: {
@@ -15,20 +16,26 @@ use crate::{
15
16
16
17
use super :: * ;
17
18
18
- pub ( super ) fn print_body_hir ( db : & dyn DefDatabase , body : & Body , owner : DefWithBodyId ) -> String {
19
+ pub ( super ) fn print_body_hir (
20
+ db : & dyn DefDatabase ,
21
+ body : & Body ,
22
+ owner : DefWithBodyId ,
23
+ edition : Edition ,
24
+ ) -> String {
19
25
let header = match owner {
20
- DefWithBodyId :: FunctionId ( it) => {
21
- it. lookup ( db) . id . resolved ( db, |it| format ! ( "fn {}" , it. name. display( db. upcast( ) ) ) )
22
- }
26
+ DefWithBodyId :: FunctionId ( it) => it
27
+ . lookup ( db)
28
+ . id
29
+ . resolved ( db, |it| format ! ( "fn {}" , it. name. display( db. upcast( ) , edition) ) ) ,
23
30
DefWithBodyId :: StaticId ( it) => it
24
31
. lookup ( db)
25
32
. id
26
- . resolved ( db, |it| format ! ( "static {} = " , it. name. display( db. upcast( ) ) ) ) ,
33
+ . resolved ( db, |it| format ! ( "static {} = " , it. name. display( db. upcast( ) , edition ) ) ) ,
27
34
DefWithBodyId :: ConstId ( it) => it. lookup ( db) . id . resolved ( db, |it| {
28
35
format ! (
29
36
"const {} = " ,
30
37
match & it. name {
31
- Some ( name) => name. display( db. upcast( ) ) . to_string( ) ,
38
+ Some ( name) => name. display( db. upcast( ) , edition ) . to_string( ) ,
32
39
None => "_" . to_owned( ) ,
33
40
}
34
41
)
@@ -39,13 +46,13 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
39
46
let enum_loc = loc. parent . lookup ( db) ;
40
47
format ! (
41
48
"enum {}::{}" ,
42
- enum_loc. id. item_tree( db) [ enum_loc. id. value] . name. display( db. upcast( ) ) ,
43
- loc. id. item_tree( db) [ loc. id. value] . name. display( db. upcast( ) ) ,
49
+ enum_loc. id. item_tree( db) [ enum_loc. id. value] . name. display( db. upcast( ) , edition ) ,
50
+ loc. id. item_tree( db) [ loc. id. value] . name. display( db. upcast( ) , edition ) ,
44
51
)
45
52
}
46
53
} ;
47
54
48
- let mut p = Printer { db, body, buf : header, indent_level : 0 , needs_indent : false } ;
55
+ let mut p = Printer { db, body, buf : header, indent_level : 0 , needs_indent : false , edition } ;
49
56
if let DefWithBodyId :: FunctionId ( it) = owner {
50
57
p. buf . push ( '(' ) ;
51
58
let function_data = & db. function_data ( it) ;
@@ -86,8 +93,10 @@ pub(super) fn print_expr_hir(
86
93
body : & Body ,
87
94
_owner : DefWithBodyId ,
88
95
expr : ExprId ,
96
+ edition : Edition ,
89
97
) -> String {
90
- let mut p = Printer { db, body, buf : String :: new ( ) , indent_level : 0 , needs_indent : false } ;
98
+ let mut p =
99
+ Printer { db, body, buf : String :: new ( ) , indent_level : 0 , needs_indent : false , edition } ;
91
100
p. print_expr ( expr) ;
92
101
p. buf
93
102
}
@@ -113,6 +122,7 @@ struct Printer<'a> {
113
122
buf : String ,
114
123
indent_level : usize ,
115
124
needs_indent : bool ,
125
+ edition : Edition ,
116
126
}
117
127
118
128
impl Write for Printer < ' _ > {
@@ -173,13 +183,14 @@ impl Printer<'_> {
173
183
Expr :: OffsetOf ( offset_of) => {
174
184
w ! ( self , "builtin#offset_of(" ) ;
175
185
self . print_type_ref ( & offset_of. container ) ;
186
+ let edition = self . edition ;
176
187
w ! (
177
188
self ,
178
189
", {})" ,
179
190
offset_of
180
191
. fields
181
192
. iter( )
182
- . format_with( "." , |field, f| f( & field. display( self . db. upcast( ) ) ) )
193
+ . format_with( "." , |field, f| f( & field. display( self . db. upcast( ) , edition ) ) )
183
194
) ;
184
195
}
185
196
Expr :: Path ( path) => self . print_path ( path) ,
@@ -201,7 +212,7 @@ impl Printer<'_> {
201
212
}
202
213
Expr :: Loop { body, label } => {
203
214
if let Some ( lbl) = label {
204
- w ! ( self , "{}: " , self . body[ * lbl] . name. display( self . db. upcast( ) ) ) ;
215
+ w ! ( self , "{}: " , self . body[ * lbl] . name. display( self . db. upcast( ) , self . edition ) ) ;
205
216
}
206
217
w ! ( self , "loop " ) ;
207
218
self . print_expr ( * body) ;
@@ -221,10 +232,11 @@ impl Printer<'_> {
221
232
}
222
233
Expr :: MethodCall { receiver, method_name, args, generic_args } => {
223
234
self . print_expr ( * receiver) ;
224
- w ! ( self , ".{}" , method_name. display( self . db. upcast( ) ) ) ;
235
+ w ! ( self , ".{}" , method_name. display( self . db. upcast( ) , self . edition ) ) ;
225
236
if let Some ( args) = generic_args {
226
237
w ! ( self , "::<" ) ;
227
- print_generic_args ( self . db , args, self ) . unwrap ( ) ;
238
+ let edition = self . edition ;
239
+ print_generic_args ( self . db , args, self , edition) . unwrap ( ) ;
228
240
w ! ( self , ">" ) ;
229
241
}
230
242
w ! ( self , "(" ) ;
@@ -259,13 +271,13 @@ impl Printer<'_> {
259
271
Expr :: Continue { label } => {
260
272
w ! ( self , "continue" ) ;
261
273
if let Some ( lbl) = label {
262
- w ! ( self , " {}" , self . body[ * lbl] . name. display( self . db. upcast( ) ) ) ;
274
+ w ! ( self , " {}" , self . body[ * lbl] . name. display( self . db. upcast( ) , self . edition ) ) ;
263
275
}
264
276
}
265
277
Expr :: Break { expr, label } => {
266
278
w ! ( self , "break" ) ;
267
279
if let Some ( lbl) = label {
268
- w ! ( self , " {}" , self . body[ * lbl] . name. display( self . db. upcast( ) ) ) ;
280
+ w ! ( self , " {}" , self . body[ * lbl] . name. display( self . db. upcast( ) , self . edition ) ) ;
269
281
}
270
282
if let Some ( expr) = expr {
271
283
self . whitespace ( ) ;
@@ -307,9 +319,10 @@ impl Printer<'_> {
307
319
}
308
320
309
321
w ! ( self , "{{" ) ;
322
+ let edition = self . edition ;
310
323
self . indented ( |p| {
311
324
for field in & * * fields {
312
- w ! ( p, "{}: " , field. name. display( self . db. upcast( ) ) ) ;
325
+ w ! ( p, "{}: " , field. name. display( self . db. upcast( ) , edition ) ) ;
313
326
p. print_expr ( field. expr ) ;
314
327
wln ! ( p, "," ) ;
315
328
}
@@ -326,7 +339,7 @@ impl Printer<'_> {
326
339
}
327
340
Expr :: Field { expr, name } => {
328
341
self . print_expr ( * expr) ;
329
- w ! ( self , ".{}" , name. display( self . db. upcast( ) ) ) ;
342
+ w ! ( self , ".{}" , name. display( self . db. upcast( ) , self . edition ) ) ;
330
343
}
331
344
Expr :: Await { expr } => {
332
345
self . print_expr ( * expr) ;
@@ -464,8 +477,9 @@ impl Printer<'_> {
464
477
}
465
478
Expr :: Literal ( lit) => self . print_literal ( lit) ,
466
479
Expr :: Block { id : _, statements, tail, label } => {
467
- let label =
468
- label. map ( |lbl| format ! ( "{}: " , self . body[ lbl] . name. display( self . db. upcast( ) ) ) ) ;
480
+ let label = label. map ( |lbl| {
481
+ format ! ( "{}: " , self . body[ lbl] . name. display( self . db. upcast( ) , self . edition) )
482
+ } ) ;
469
483
self . print_block ( label. as_deref ( ) , statements, tail) ;
470
484
}
471
485
Expr :: Unsafe { id : _, statements, tail } => {
@@ -539,9 +553,10 @@ impl Printer<'_> {
539
553
}
540
554
541
555
w ! ( self , " {{" ) ;
556
+ let edition = self . edition ;
542
557
self . indented ( |p| {
543
558
for arg in args. iter ( ) {
544
- w ! ( p, "{}: " , arg. name. display( self . db. upcast( ) ) ) ;
559
+ w ! ( p, "{}: " , arg. name. display( self . db. upcast( ) , edition ) ) ;
545
560
p. print_pat ( arg. pat ) ;
546
561
wln ! ( p, "," ) ;
547
562
}
@@ -686,11 +701,13 @@ impl Printer<'_> {
686
701
}
687
702
688
703
fn print_type_ref ( & mut self , ty : & TypeRef ) {
689
- print_type_ref ( self . db , ty, self ) . unwrap ( ) ;
704
+ let edition = self . edition ;
705
+ print_type_ref ( self . db , ty, self , edition) . unwrap ( ) ;
690
706
}
691
707
692
708
fn print_path ( & mut self , path : & Path ) {
693
- print_path ( self . db , path, self ) . unwrap ( ) ;
709
+ let edition = self . edition ;
710
+ print_path ( self . db , path, self , edition) . unwrap ( ) ;
694
711
}
695
712
696
713
fn print_binding ( & mut self , id : BindingId ) {
@@ -701,6 +718,6 @@ impl Printer<'_> {
701
718
BindingAnnotation :: Ref => "ref " ,
702
719
BindingAnnotation :: RefMut => "ref mut " ,
703
720
} ;
704
- w ! ( self , "{}{}" , mode, name. display( self . db. upcast( ) ) ) ;
721
+ w ! ( self , "{}{}" , mode, name. display( self . db. upcast( ) , self . edition ) ) ;
705
722
}
706
723
}
0 commit comments