Skip to content

Commit 8fcf512

Browse files
committed
Refactor url_parts to return is_absolute instead of out param
1 parent 58745ca commit 8fcf512

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

‎src/librustdoc/html/format.rs‎

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,15 @@ fn generate_item_def_id_path(
459459

460460
let shortty = ItemType::from_def_id(def_id, tcx);
461461
let module_fqp = to_module_fqp(shortty, &fqp);
462-
let mut is_absolute = false;
463462

464-
let url_parts = url_parts(cx.cache(), def_id, module_fqp, &cx.current, &mut is_absolute)?;
465-
let mut url_parts = make_href(root_path, shortty, url_parts, &fqp, is_absolute);
463+
let (parts, is_absolute) = url_parts(cx.cache(), def_id, module_fqp, &cx.current)?;
464+
let mut url = make_href(root_path, shortty, parts, &fqp, is_absolute);
465+
466466
if def_id != original_def_id {
467467
let kind = ItemType::from_def_id(original_def_id, tcx);
468-
url_parts = format!("{url_parts}#{kind}.{}", tcx.item_name(original_def_id))
468+
url = format!("{url}#{kind}.{}", tcx.item_name(original_def_id))
469469
};
470-
Ok(HrefInfo { url: url_parts, kind: shortty, rust_path: fqp })
470+
Ok(HrefInfo { url, kind: shortty, rust_path: fqp })
471471
}
472472

473473
/// Checks if the given defid refers to an item that is unnamable, such as one defined in a const block.
@@ -511,16 +511,14 @@ fn url_parts(
511511
def_id: DefId,
512512
module_fqp: &[Symbol],
513513
relative_to: &[Symbol],
514-
is_absolute: &mut bool,
515-
) -> Result<UrlPartsBuilder, HrefError> {
514+
) -> Result<(UrlPartsBuilder, bool), HrefError> {
516515
match cache.extern_locations[&def_id.krate] {
517-
ExternalLocation::Remote { ref url, is_absolute: abs } => {
518-
*is_absolute = abs;
519-
let mut builder = remote_url_prefix(url, abs, relative_to.len());
516+
ExternalLocation::Remote { ref url, is_absolute } => {
517+
let mut builder = remote_url_prefix(url, is_absolute, relative_to.len());
520518
builder.extend(module_fqp.iter().copied());
521-
Ok(builder)
519+
Ok((builder, is_absolute))
522520
}
523-
ExternalLocation::Local => Ok(href_relative_parts(module_fqp, relative_to)),
521+
ExternalLocation::Local => Ok((href_relative_parts(module_fqp, relative_to), false)),
524522
ExternalLocation::Unknown => Err(HrefError::DocumentationNotBuilt),
525523
}
526524
}
@@ -596,21 +594,26 @@ pub(crate) fn href_with_root_path(
596594
}
597595
}
598596

599-
let mut is_absolute = false;
600-
let (fqp, shortty, url_parts) = match cache.paths.get(&did) {
601-
Some(&(ref fqp, shortty)) => (fqp, shortty, {
602-
let module_fqp = to_module_fqp(shortty, fqp.as_slice());
603-
debug!(?fqp, ?shortty, ?module_fqp);
604-
href_relative_parts(module_fqp, relative_to)
605-
}),
597+
let (fqp, shortty, url_parts, is_absolute) = match cache.paths.get(&did) {
598+
Some(&(ref fqp, shortty)) => (
599+
fqp,
600+
shortty,
601+
{
602+
let module_fqp = to_module_fqp(shortty, fqp.as_slice());
603+
debug!(?fqp, ?shortty, ?module_fqp);
604+
href_relative_parts(module_fqp, relative_to)
605+
},
606+
false,
607+
),
606608
None => {
607609
// Associated items are handled differently with "jump to def". The anchor is generated
608610
// directly here whereas for intra-doc links, we have some extra computation being
609611
// performed there.
610612
let def_id_to_get = if root_path.is_some() { original_did } else { did };
611613
if let Some(&(ref fqp, shortty)) = cache.external_paths.get(&def_id_to_get) {
612614
let module_fqp = to_module_fqp(shortty, fqp);
613-
(fqp, shortty, url_parts(cache, did, module_fqp, relative_to, &mut is_absolute)?)
615+
let (parts, is_absolute) = url_parts(cache, did, module_fqp, relative_to)?;
616+
(fqp, shortty, parts, is_absolute)
614617
} else if matches!(def_kind, DefKind::Macro(_)) {
615618
return generate_macro_def_id_path(did, cx, root_path);
616619
} else if did.is_local() {

0 commit comments

Comments
 (0)