@@ -27,16 +27,16 @@ impl HirDisplay for Function {
27
27
let data = f. db . function_data ( self . id ) ;
28
28
write_visibility ( self . module ( f. db ) . id , self . visibility ( f. db ) , f) ?;
29
29
if data. is_default ( ) {
30
- write ! ( f , "default " ) ?;
30
+ f . write_str ( "default " ) ?;
31
31
}
32
32
if data. is_const ( ) {
33
- write ! ( f , "const " ) ?;
33
+ f . write_str ( "const " ) ?;
34
34
}
35
35
if data. is_async ( ) {
36
- write ! ( f , "async " ) ?;
36
+ f . write_str ( "async " ) ?;
37
37
}
38
38
if data. is_unsafe ( ) {
39
- write ! ( f , "unsafe " ) ?;
39
+ f . write_str ( "unsafe " ) ?;
40
40
}
41
41
if let Some ( abi) = & data. abi {
42
42
// FIXME: String escape?
@@ -46,31 +46,31 @@ impl HirDisplay for Function {
46
46
47
47
write_generic_params ( GenericDefId :: FunctionId ( self . id ) , f) ?;
48
48
49
- write ! ( f , "(" ) ?;
49
+ f . write_char ( '(' ) ?;
50
50
51
51
let write_self_param = |ty : & TypeRef , f : & mut HirFormatter | match ty {
52
- TypeRef :: Path ( p) if p. is_self_type ( ) => write ! ( f , "self" ) ,
52
+ TypeRef :: Path ( p) if p. is_self_type ( ) => f . write_str ( "self" ) ,
53
53
TypeRef :: Reference ( inner, lifetime, mut_) if matches ! ( & * * inner, TypeRef :: Path ( p) if p. is_self_type( ) ) =>
54
54
{
55
- write ! ( f , "&" ) ?;
55
+ f . write_char ( '&' ) ?;
56
56
if let Some ( lifetime) = lifetime {
57
57
write ! ( f, "{} " , lifetime. name) ?;
58
58
}
59
59
if let hir_def:: type_ref:: Mutability :: Mut = mut_ {
60
- write ! ( f , "mut " ) ?;
60
+ f . write_str ( "mut " ) ?;
61
61
}
62
- write ! ( f , "self" )
62
+ f . write_str ( "self" )
63
63
}
64
64
_ => {
65
- write ! ( f , "self: " ) ?;
65
+ f . write_str ( "self: " ) ?;
66
66
ty. hir_fmt ( f)
67
67
}
68
68
} ;
69
69
70
70
let mut first = true ;
71
71
for ( name, type_ref) in & data. params {
72
72
if !first {
73
- write ! ( f , ", " ) ?;
73
+ f . write_str ( ", " ) ?;
74
74
} else {
75
75
first = false ;
76
76
if data. has_self_param ( ) {
@@ -80,18 +80,18 @@ impl HirDisplay for Function {
80
80
}
81
81
match name {
82
82
Some ( name) => write ! ( f, "{}: " , name) ?,
83
- None => write ! ( f , "_: " ) ?,
83
+ None => f . write_str ( "_: " ) ?,
84
84
}
85
85
// FIXME: Use resolved `param.ty` or raw `type_ref`?
86
86
// The former will ignore lifetime arguments currently.
87
87
type_ref. hir_fmt ( f) ?;
88
88
}
89
89
90
90
if data. is_varargs ( ) {
91
- write ! ( f , ", ..." ) ?;
91
+ f . write_str ( ", ..." ) ?;
92
92
}
93
93
94
- write ! ( f , ")" ) ?;
94
+ f . write_char ( ')' ) ?;
95
95
96
96
// `FunctionData::ret_type` will be `::core::future::Future<Output = ...>` for async fns.
97
97
// Use ugly pattern match to strip the Future trait.
@@ -117,7 +117,7 @@ impl HirDisplay for Function {
117
117
match ret_type {
118
118
TypeRef :: Tuple ( tup) if tup. is_empty ( ) => { }
119
119
ty => {
120
- write ! ( f , " -> " ) ?;
120
+ f . write_str ( " -> " ) ?;
121
121
ty. hir_fmt ( f) ?;
122
122
}
123
123
}
@@ -141,7 +141,7 @@ impl HirDisplay for Adt {
141
141
impl HirDisplay for Struct {
142
142
fn hir_fmt ( & self , f : & mut HirFormatter ) -> Result < ( ) , HirDisplayError > {
143
143
write_visibility ( self . module ( f. db ) . id , self . visibility ( f. db ) , f) ?;
144
- write ! ( f , "struct " ) ?;
144
+ f . write_str ( "struct " ) ?;
145
145
write ! ( f, "{}" , self . name( f. db) ) ?;
146
146
let def_id = GenericDefId :: AdtId ( AdtId :: StructId ( self . id ) ) ;
147
147
write_generic_params ( def_id, f) ?;
@@ -153,7 +153,7 @@ impl HirDisplay for Struct {
153
153
impl HirDisplay for Enum {
154
154
fn hir_fmt ( & self , f : & mut HirFormatter ) -> Result < ( ) , HirDisplayError > {
155
155
write_visibility ( self . module ( f. db ) . id , self . visibility ( f. db ) , f) ?;
156
- write ! ( f , "enum " ) ?;
156
+ f . write_str ( "enum " ) ?;
157
157
write ! ( f, "{}" , self . name( f. db) ) ?;
158
158
let def_id = GenericDefId :: AdtId ( AdtId :: EnumId ( self . id ) ) ;
159
159
write_generic_params ( def_id, f) ?;
@@ -165,7 +165,7 @@ impl HirDisplay for Enum {
165
165
impl HirDisplay for Union {
166
166
fn hir_fmt ( & self , f : & mut HirFormatter ) -> Result < ( ) , HirDisplayError > {
167
167
write_visibility ( self . module ( f. db ) . id , self . visibility ( f. db ) , f) ?;
168
- write ! ( f , "union " ) ?;
168
+ f . write_str ( "union " ) ?;
169
169
write ! ( f, "{}" , self . name( f. db) ) ?;
170
170
let def_id = GenericDefId :: AdtId ( AdtId :: UnionId ( self . id ) ) ;
171
171
write_generic_params ( def_id, f) ?;
@@ -189,34 +189,34 @@ impl HirDisplay for Variant {
189
189
match & * data {
190
190
VariantData :: Unit => { }
191
191
VariantData :: Tuple ( fields) => {
192
- write ! ( f , "(" ) ?;
192
+ f . write_char ( '(' ) ?;
193
193
let mut first = true ;
194
194
for ( _, field) in fields. iter ( ) {
195
195
if first {
196
196
first = false ;
197
197
} else {
198
- write ! ( f , ", " ) ?;
198
+ f . write_str ( ", " ) ?;
199
199
}
200
200
// Enum variant fields must be pub.
201
201
field. type_ref . hir_fmt ( f) ?;
202
202
}
203
- write ! ( f , ")" ) ?;
203
+ f . write_char ( ')' ) ?;
204
204
}
205
205
VariantData :: Record ( fields) => {
206
- write ! ( f , " {{" ) ?;
206
+ f . write_str ( " {{" ) ?;
207
207
let mut first = true ;
208
208
for ( _, field) in fields. iter ( ) {
209
209
if first {
210
210
first = false ;
211
- write ! ( f , " " ) ?;
211
+ f . write_char ( ' ' ) ?;
212
212
} else {
213
- write ! ( f , ", " ) ?;
213
+ f . write_str ( ", " ) ?;
214
214
}
215
215
// Enum variant fields must be pub.
216
216
write ! ( f, "{}: " , field. name) ?;
217
217
field. type_ref . hir_fmt ( f) ?;
218
218
}
219
- write ! ( f , " }}" ) ?;
219
+ f . write_str ( " }}" ) ?;
220
220
}
221
221
}
222
222
Ok ( ( ) )
@@ -301,15 +301,15 @@ fn write_generic_params(def: GenericDefId, f: &mut HirFormatter) -> Result<(), H
301
301
{
302
302
return Ok ( ( ) ) ;
303
303
}
304
- write ! ( f , "<" ) ?;
304
+ f . write_char ( '<' ) ?;
305
305
306
306
let mut first = true ;
307
307
let mut delim = |f : & mut HirFormatter | {
308
308
if first {
309
309
first = false ;
310
310
Ok ( ( ) )
311
311
} else {
312
- write ! ( f , ", " )
312
+ f . write_str ( ", " )
313
313
}
314
314
} ;
315
315
for ( _, lifetime) in params. lifetimes . iter ( ) {
@@ -326,7 +326,7 @@ fn write_generic_params(def: GenericDefId, f: &mut HirFormatter) -> Result<(), H
326
326
delim ( f) ?;
327
327
write ! ( f, "{}" , name) ?;
328
328
if let Some ( default) = & ty. default {
329
- write ! ( f , " = " ) ?;
329
+ f . write_str ( " = " ) ?;
330
330
default. hir_fmt ( f) ?;
331
331
}
332
332
}
@@ -339,7 +339,7 @@ fn write_generic_params(def: GenericDefId, f: &mut HirFormatter) -> Result<(), H
339
339
}
340
340
}
341
341
342
- write ! ( f , ">" ) ?;
342
+ f . write_char ( '>' ) ?;
343
343
Ok ( ( ) )
344
344
}
345
345
@@ -370,31 +370,30 @@ fn write_where_clause(def: GenericDefId, f: &mut HirFormatter) -> Result<(), Hir
370
370
WherePredicateTypeTarget :: TypeOrConstParam ( id) => {
371
371
match & params. type_or_consts [ * id] . name ( ) {
372
372
Some ( name) => write ! ( f, "{}" , name) ,
373
- None => write ! ( f , "{{unnamed}}" ) ,
373
+ None => f . write_str ( "{{unnamed}}" ) ,
374
374
}
375
375
}
376
376
} ;
377
377
378
- write ! ( f , "\n where" ) ?;
378
+ f . write_str ( "\n where" ) ?;
379
379
380
380
for ( pred_idx, pred) in params. where_predicates . iter ( ) . enumerate ( ) {
381
381
let prev_pred =
382
382
if pred_idx == 0 { None } else { Some ( & params. where_predicates [ pred_idx - 1 ] ) } ;
383
383
384
- let new_predicate = |f : & mut HirFormatter | {
385
- write ! ( f, "{}" , if pred_idx == 0 { "\n " } else { ",\n " } )
386
- } ;
384
+ let new_predicate =
385
+ |f : & mut HirFormatter | f. write_str ( if pred_idx == 0 { "\n " } else { ",\n " } ) ;
387
386
388
387
match pred {
389
388
WherePredicate :: TypeBound { target, .. } if is_unnamed_type_target ( target) => { }
390
389
WherePredicate :: TypeBound { target, bound } => {
391
390
if matches ! ( prev_pred, Some ( WherePredicate :: TypeBound { target: target_, .. } ) if target_ == target)
392
391
{
393
- write ! ( f , " + " ) ?;
392
+ f . write_str ( " + " ) ?;
394
393
} else {
395
394
new_predicate ( f) ?;
396
395
write_target ( target, f) ?;
397
- write ! ( f , ": " ) ?;
396
+ f . write_str ( ": " ) ?;
398
397
}
399
398
bound. hir_fmt ( f) ?;
400
399
}
@@ -413,27 +412,27 @@ fn write_where_clause(def: GenericDefId, f: &mut HirFormatter) -> Result<(), Hir
413
412
Some ( WherePredicate :: ForLifetime { lifetimes: lifetimes_, target: target_, .. } )
414
413
if lifetimes_ == lifetimes && target_ == target,
415
414
) {
416
- write ! ( f , " + " ) ?;
415
+ f . write_str ( " + " ) ?;
417
416
} else {
418
417
new_predicate ( f) ?;
419
- write ! ( f , "for<" ) ?;
418
+ f . write_str ( "for<" ) ?;
420
419
for ( idx, lifetime) in lifetimes. iter ( ) . enumerate ( ) {
421
420
if idx != 0 {
422
- write ! ( f , ", " ) ?;
421
+ f . write_str ( ", " ) ?;
423
422
}
424
423
write ! ( f, "{}" , lifetime) ?;
425
424
}
426
- write ! ( f , "> " ) ?;
425
+ f . write_str ( "> " ) ?;
427
426
write_target ( target, f) ?;
428
- write ! ( f , ": " ) ?;
427
+ f . write_str ( ": " ) ?;
429
428
}
430
429
bound. hir_fmt ( f) ?;
431
430
}
432
431
}
433
432
}
434
433
435
434
// End of final predicate. There must be at least one predicate here.
436
- write ! ( f , "," ) ?;
435
+ f . write_char ( ',' ) ?;
437
436
438
437
Ok ( ( ) )
439
438
}
@@ -442,10 +441,10 @@ impl HirDisplay for Const {
442
441
fn hir_fmt ( & self , f : & mut HirFormatter ) -> Result < ( ) , HirDisplayError > {
443
442
write_visibility ( self . module ( f. db ) . id , self . visibility ( f. db ) , f) ?;
444
443
let data = f. db . const_data ( self . id ) ;
445
- write ! ( f , "const " ) ?;
444
+ f . write_str ( "const " ) ?;
446
445
match & data. name {
447
446
Some ( name) => write ! ( f, "{}: " , name) ?,
448
- None => write ! ( f , "_: " ) ?,
447
+ None => f . write_str ( "_: " ) ?,
449
448
}
450
449
data. type_ref . hir_fmt ( f) ?;
451
450
Ok ( ( ) )
@@ -456,9 +455,9 @@ impl HirDisplay for Static {
456
455
fn hir_fmt ( & self , f : & mut HirFormatter ) -> Result < ( ) , HirDisplayError > {
457
456
write_visibility ( self . module ( f. db ) . id , self . visibility ( f. db ) , f) ?;
458
457
let data = f. db . static_data ( self . id ) ;
459
- write ! ( f , "static " ) ?;
458
+ f . write_str ( "static " ) ?;
460
459
if data. mutable {
461
- write ! ( f , "mut " ) ?;
460
+ f . write_str ( "mut " ) ?;
462
461
}
463
462
write ! ( f, "{}: " , & data. name) ?;
464
463
data. type_ref . hir_fmt ( f) ?;
@@ -471,10 +470,10 @@ impl HirDisplay for Trait {
471
470
write_visibility ( self . module ( f. db ) . id , self . visibility ( f. db ) , f) ?;
472
471
let data = f. db . trait_data ( self . id ) ;
473
472
if data. is_unsafe {
474
- write ! ( f , "unsafe " ) ?;
473
+ f . write_str ( "unsafe " ) ?;
475
474
}
476
475
if data. is_auto {
477
- write ! ( f , "auto " ) ?;
476
+ f . write_str ( "auto " ) ?;
478
477
}
479
478
write ! ( f, "trait {}" , data. name) ?;
480
479
let def_id = GenericDefId :: TraitId ( self . id ) ;
@@ -490,11 +489,11 @@ impl HirDisplay for TypeAlias {
490
489
let data = f. db . type_alias_data ( self . id ) ;
491
490
write ! ( f, "type {}" , data. name) ?;
492
491
if !data. bounds . is_empty ( ) {
493
- write ! ( f , ": " ) ?;
492
+ f . write_str ( ": " ) ?;
494
493
f. write_joined ( & data. bounds , " + " ) ?;
495
494
}
496
495
if let Some ( ty) = & data. type_ref {
497
- write ! ( f , " = " ) ?;
496
+ f . write_str ( " = " ) ?;
498
497
ty. hir_fmt ( f) ?;
499
498
}
500
499
Ok ( ( ) )
@@ -508,19 +507,19 @@ impl HirDisplay for Module {
508
507
Some ( name) => write ! ( f, "mod {}" , name) ,
509
508
None if self . is_crate_root ( f. db ) => match self . krate ( ) . display_name ( f. db ) {
510
509
Some ( name) => write ! ( f, "extern crate {}" , name) ,
511
- None => write ! ( f , "extern crate {{unknown}}" ) ,
510
+ None => f . write_str ( "extern crate {{unknown}}" ) ,
512
511
} ,
513
- None => write ! ( f , "mod {{unnamed}}" ) ,
512
+ None => f . write_str ( "mod {{unnamed}}" ) ,
514
513
}
515
514
}
516
515
}
517
516
518
517
impl HirDisplay for Macro {
519
518
fn hir_fmt ( & self , f : & mut HirFormatter ) -> Result < ( ) , HirDisplayError > {
520
519
match self . id {
521
- hir_def:: MacroId :: Macro2Id ( _) => write ! ( f , "macro" ) ,
522
- hir_def:: MacroId :: MacroRulesId ( _) => write ! ( f , "macro_rules!" ) ,
523
- hir_def:: MacroId :: ProcMacroId ( _) => write ! ( f , "proc_macro" ) ,
520
+ hir_def:: MacroId :: Macro2Id ( _) => f . write_str ( "macro" ) ,
521
+ hir_def:: MacroId :: MacroRulesId ( _) => f . write_str ( "macro_rules!" ) ,
522
+ hir_def:: MacroId :: ProcMacroId ( _) => f . write_str ( "proc_macro" ) ,
524
523
} ?;
525
524
write ! ( f, " {}" , self . name( f. db) )
526
525
}
0 commit comments