Skip to content

Commit c5449f5

Browse files
committed
rustdoc: Stop using write! in UrlFragment::render
1 parent f7521db commit c5449f5

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl Item {
525525
if let Ok((mut href, ..)) = href(*did, cx) {
526526
debug!(?href);
527527
if let Some(ref fragment) = *fragment {
528-
fragment.render(&mut href, cx.tcx()).unwrap()
528+
fragment.render(&mut href, cx.tcx())
529529
}
530530
Some(RenderedLink {
531531
original_text: s.clone(),

src/librustdoc/passes/collect_intra_doc_links.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use rustc_span::BytePos;
2020
use smallvec::{smallvec, SmallVec};
2121

2222
use std::borrow::Cow;
23-
use std::fmt::Write;
2423
use std::mem;
2524
use std::ops::Range;
2625

@@ -226,34 +225,37 @@ pub(crate) enum UrlFragment {
226225

227226
impl 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

Comments
 (0)