@@ -20,7 +20,6 @@ use rustc_span::BytePos;
2020use smallvec:: { smallvec, SmallVec } ;
2121
2222use std:: borrow:: Cow ;
23- use std:: fmt:: Write ;
2423use std:: mem;
2524use std:: ops:: Range ;
2625
@@ -226,34 +225,37 @@ pub(crate) enum UrlFragment {
226225
227226impl UrlFragment {
228227 /// 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 < ' _ > ) {
230229 s. push ( '#' ) ;
231230 match self {
232231 & 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) {
235233 DefKind :: AssocFn => {
236234 if tcx. associated_item ( def_id) . defaultness . has_value ( ) {
237- write ! ( s , "method.{}" , name )
235+ "method."
238236 } else {
239- write ! ( s , "tymethod.{}" , name )
237+ "tymethod."
240238 }
241239 }
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." ,
245243 DefKind :: Field => {
246244 let parent_id = tcx. parent ( def_id) ;
247245 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."
249249 } else {
250- write ! ( s , "structfield.{}" , name )
250+ "structfield."
251251 }
252252 }
253253 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 ( ) ) ;
255257 }
256- UrlFragment :: UserWritten ( raw) => Ok ( s. push_str ( & raw ) ) ,
258+ UrlFragment :: UserWritten ( raw) => s. push_str ( & raw ) ,
257259 }
258260 }
259261}
0 commit comments