Skip to content

Commit

Permalink
Auto merge of rust-lang#84279 - Dylan-DPC:rollup-k7otd7e, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

Successful merges:

 - rust-lang#83237 (rustdoc: use more precise relative URLs)
 - rust-lang#84150 (rustdoc: move some search code into search.js)
 - rust-lang#84203 (rustdoc: Give a more accurate span for anchor failures)
 - rust-lang#84257 (Add documentation to help people find `Ipv4Addr::UNSPECIFIED`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Apr 17, 2021
2 parents bd9949b + a3277e2 commit 392ba2b
Show file tree
Hide file tree
Showing 55 changed files with 2,295 additions and 2,254 deletions.
3 changes: 3 additions & 0 deletions library/std/src/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ impl Ipv4Addr {

/// An IPv4 address representing an unspecified address: 0.0.0.0
///
/// This corresponds to the constant `INADDR_ANY` in other languages.
///
/// # Examples
///
/// ```
Expand All @@ -342,6 +344,7 @@ impl Ipv4Addr {
/// let addr = Ipv4Addr::UNSPECIFIED;
/// assert_eq!(addr, Ipv4Addr::new(0, 0, 0, 0));
/// ```
#[doc(alias = "INADDR_ANY")]
#[stable(feature = "ip_constructors", since = "1.30.0")]
pub const UNSPECIFIED: Self = Ipv4Addr::new(0, 0, 0, 0);

Expand Down
33 changes: 21 additions & 12 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use crate::core::DocContext;
use crate::formats::cache::Cache;
use crate::formats::item_type::ItemType;
use crate::html::render::cache::ExternalLocation;
use crate::html::render::Context;

use self::FnRetTy::*;
use self::ItemKind::*;
Expand Down Expand Up @@ -193,19 +194,18 @@ impl Item {
self.attrs.collapsed_doc_value()
}

crate fn links(&self, cache: &Cache) -> Vec<RenderedLink> {
crate fn links(&self, cx: &Context<'_>) -> Vec<RenderedLink> {
use crate::html::format::href;
use crate::html::render::CURRENT_DEPTH;

cache
cx.cache()
.intra_doc_links
.get(&self.def_id)
.map_or(&[][..], |v| v.as_slice())
.iter()
.filter_map(|ItemLink { link: s, link_text, did, fragment }| {
.filter_map(|ItemLink { link: s, link_text, did, ref fragment }| {
match *did {
Some(did) => {
if let Some((mut href, ..)) = href(did, cache) {
if let Some((mut href, ..)) = href(did, cx) {
if let Some(ref fragment) = *fragment {
href.push('#');
href.push_str(fragment);
Expand All @@ -219,16 +219,26 @@ impl Item {
None
}
}
// FIXME(83083): using fragments as a side-channel for
// primitive names is very unfortunate
None => {
let relative_to = &cx.current;
if let Some(ref fragment) = *fragment {
let url = match cache.extern_locations.get(&self.def_id.krate) {
let url = match cx.cache().extern_locations.get(&self.def_id.krate) {
Some(&(_, _, ExternalLocation::Local)) => {
let depth = CURRENT_DEPTH.with(|l| l.get());
"../".repeat(depth)
if relative_to[0] == "std" {
let depth = relative_to.len() - 1;
"../".repeat(depth)
} else {
let depth = relative_to.len();
format!("{}std/", "../".repeat(depth))
}
}
Some(&(_, _, ExternalLocation::Remote(ref s))) => {
format!("{}/std/", s.trim_end_matches('/'))
}
Some(&(_, _, ExternalLocation::Remote(ref s))) => s.to_string(),
Some(&(_, _, ExternalLocation::Unknown)) | None => format!(
"https://doc.rust-lang.org/{}",
"https://doc.rust-lang.org/{}/std/",
crate::doc_rust_lang_org_channel(),
),
};
Expand All @@ -238,9 +248,8 @@ impl Item {
original_text: s.clone(),
new_text: link_text.clone(),
href: format!(
"{}{}std/primitive.{}.html{}",
"{}primitive.{}.html{}",
url,
if !url.ends_with('/') { "/" } else { "" },
&fragment[..tail],
&fragment[tail..]
),
Expand Down
Loading

0 comments on commit 392ba2b

Please sign in to comment.