@@ -20,7 +20,6 @@ use rustc_span::BytePos;
20
20
use smallvec:: { smallvec, SmallVec } ;
21
21
22
22
use std:: borrow:: Cow ;
23
- use std:: fmt:: Write ;
24
23
use std:: mem;
25
24
use std:: ops:: Range ;
26
25
@@ -226,34 +225,37 @@ pub(crate) enum UrlFragment {
226
225
227
226
impl UrlFragment {
228
227
/// Render the fragment, including the leading `#`.
229
- pub ( crate ) fn render ( & self , s : & mut String , tcx : TyCtxt < ' _ > ) -> std :: fmt :: Result {
228
+ pub ( crate ) fn render ( & self , s : & mut String , tcx : TyCtxt < ' _ > ) {
230
229
s. push ( '#' ) ;
231
230
match self {
232
231
& UrlFragment :: Item ( def_id) => {
233
- let name = tcx. item_name ( def_id) ;
234
- match tcx. def_kind ( def_id) {
232
+ let kind = match tcx. def_kind ( def_id) {
235
233
DefKind :: AssocFn => {
236
234
if tcx. associated_item ( def_id) . defaultness . has_value ( ) {
237
- write ! ( s , "method.{}" , name )
235
+ "method."
238
236
} else {
239
- write ! ( s , "tymethod.{}" , name )
237
+ "tymethod."
240
238
}
241
239
}
242
- DefKind :: AssocConst => write ! ( s , "associatedconstant.{}" , name ) ,
243
- DefKind :: AssocTy => write ! ( s , "associatedtype.{}" , name ) ,
244
- DefKind :: Variant => write ! ( s , "variant.{}" , name ) ,
240
+ DefKind :: AssocConst => "associatedconstant." ,
241
+ DefKind :: AssocTy => "associatedtype." ,
242
+ DefKind :: Variant => "variant." ,
245
243
DefKind :: Field => {
246
244
let parent_id = tcx. parent ( def_id) ;
247
245
if tcx. def_kind ( parent_id) == DefKind :: Variant {
248
- write ! ( s, "variant.{}.field.{}" , tcx. item_name( parent_id) , name)
246
+ s. push_str ( "variant." ) ;
247
+ s. push_str ( tcx. item_name ( parent_id) . as_str ( ) ) ;
248
+ ".field."
249
249
} else {
250
- write ! ( s , "structfield.{}" , name )
250
+ "structfield."
251
251
}
252
252
}
253
253
kind => bug ! ( "unexpected associated item kind: {:?}" , kind) ,
254
- }
254
+ } ;
255
+ s. push_str ( kind) ;
256
+ s. push_str ( tcx. item_name ( def_id) . as_str ( ) ) ;
255
257
}
256
- UrlFragment :: UserWritten ( raw) => Ok ( s. push_str ( & raw ) ) ,
258
+ UrlFragment :: UserWritten ( raw) => s. push_str ( & raw ) ,
257
259
}
258
260
}
259
261
}
0 commit comments