Skip to content

Commit

Permalink
review - better error names/doc
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Jul 6, 2021
1 parent fc97fbe commit afb5b21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/librustdoc/html/format.rs
Expand Up @@ -474,11 +474,12 @@ impl clean::GenericArgs {

// Possible errors when computing href link source for a `DefId`
crate enum HrefError {
// `DefId` is in an unknown location. This seems to happen when building without dependencies
// but a trait from a dependency is still visible
UnknownLocation,
// Unavailable because private
Unavailable,
/// This item is known to rustdoc, but from a crate that does not have documentation generated.
///
/// This can only happen for non-local items.
DocumentationNotBuilt,
/// This can only happen for non-local items when `--document-private-items` is not passed.
Private,
// Not in external cache, href link should be in same page
NotInExternalCache,
}
Expand All @@ -491,7 +492,7 @@ crate fn href(did: DefId, cx: &Context<'_>) -> Result<(String, ItemType, Vec<Str
}

if !did.is_local() && !cache.access_levels.is_public(did) && !cache.document_private {
return Err(HrefError::Unavailable);
return Err(HrefError::Private);
}

let (fqp, shortty, mut url_parts) = match cache.paths.get(&did) {
Expand All @@ -513,7 +514,7 @@ crate fn href(did: DefId, cx: &Context<'_>) -> Result<(String, ItemType, Vec<Str
s
}
ExternalLocation::Local => href_relative_parts(module_fqp, relative_to),
ExternalLocation::Unknown => return Err(HrefError::UnknownLocation),
ExternalLocation::Unknown => return Err(HrefError::DocumentationNotBuilt),
},
)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/mod.rs
Expand Up @@ -869,7 +869,7 @@ fn render_assoc_item(

match href(did.expect_def_id(), cx) {
Ok(p) => Some(format!("{}#{}.{}", p.0, ty, name)),
Err(HrefError::UnknownLocation) => None,
Err(HrefError::DocumentationNotBuilt) => None,
Err(_) => Some(format!("#{}.{}", ty, name)),
}
}
Expand Down

0 comments on commit afb5b21

Please sign in to comment.