Skip to content

Commit 392ba2b

Browse files
committed
Auto merge of #84279 - Dylan-DPC:rollup-k7otd7e, r=Dylan-DPC
Rollup of 4 pull requests Successful merges: - #83237 (rustdoc: use more precise relative URLs) - #84150 (rustdoc: move some search code into search.js) - #84203 (rustdoc: Give a more accurate span for anchor failures) - #84257 (Add documentation to help people find `Ipv4Addr::UNSPECIFIED`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents bd9949b + a3277e2 commit 392ba2b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2295
-2254
lines changed

library/std/src/net/ip.rs

+3
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ impl Ipv4Addr {
334334

335335
/// An IPv4 address representing an unspecified address: 0.0.0.0
336336
///
337+
/// This corresponds to the constant `INADDR_ANY` in other languages.
338+
///
337339
/// # Examples
338340
///
339341
/// ```
@@ -342,6 +344,7 @@ impl Ipv4Addr {
342344
/// let addr = Ipv4Addr::UNSPECIFIED;
343345
/// assert_eq!(addr, Ipv4Addr::new(0, 0, 0, 0));
344346
/// ```
347+
#[doc(alias = "INADDR_ANY")]
345348
#[stable(feature = "ip_constructors", since = "1.30.0")]
346349
pub const UNSPECIFIED: Self = Ipv4Addr::new(0, 0, 0, 0);
347350

src/librustdoc/clean/types.rs

+21-12
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use crate::core::DocContext;
4141
use crate::formats::cache::Cache;
4242
use crate::formats::item_type::ItemType;
4343
use crate::html::render::cache::ExternalLocation;
44+
use crate::html::render::Context;
4445

4546
use self::FnRetTy::*;
4647
use self::ItemKind::*;
@@ -193,19 +194,18 @@ impl Item {
193194
self.attrs.collapsed_doc_value()
194195
}
195196

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

200-
cache
200+
cx.cache()
201201
.intra_doc_links
202202
.get(&self.def_id)
203203
.map_or(&[][..], |v| v.as_slice())
204204
.iter()
205-
.filter_map(|ItemLink { link: s, link_text, did, fragment }| {
205+
.filter_map(|ItemLink { link: s, link_text, did, ref fragment }| {
206206
match *did {
207207
Some(did) => {
208-
if let Some((mut href, ..)) = href(did, cache) {
208+
if let Some((mut href, ..)) = href(did, cx) {
209209
if let Some(ref fragment) = *fragment {
210210
href.push('#');
211211
href.push_str(fragment);
@@ -219,16 +219,26 @@ impl Item {
219219
None
220220
}
221221
}
222+
// FIXME(83083): using fragments as a side-channel for
223+
// primitive names is very unfortunate
222224
None => {
225+
let relative_to = &cx.current;
223226
if let Some(ref fragment) = *fragment {
224-
let url = match cache.extern_locations.get(&self.def_id.krate) {
227+
let url = match cx.cache().extern_locations.get(&self.def_id.krate) {
225228
Some(&(_, _, ExternalLocation::Local)) => {
226-
let depth = CURRENT_DEPTH.with(|l| l.get());
227-
"../".repeat(depth)
229+
if relative_to[0] == "std" {
230+
let depth = relative_to.len() - 1;
231+
"../".repeat(depth)
232+
} else {
233+
let depth = relative_to.len();
234+
format!("{}std/", "../".repeat(depth))
235+
}
236+
}
237+
Some(&(_, _, ExternalLocation::Remote(ref s))) => {
238+
format!("{}/std/", s.trim_end_matches('/'))
228239
}
229-
Some(&(_, _, ExternalLocation::Remote(ref s))) => s.to_string(),
230240
Some(&(_, _, ExternalLocation::Unknown)) | None => format!(
231-
"https://doc.rust-lang.org/{}",
241+
"https://doc.rust-lang.org/{}/std/",
232242
crate::doc_rust_lang_org_channel(),
233243
),
234244
};
@@ -238,9 +248,8 @@ impl Item {
238248
original_text: s.clone(),
239249
new_text: link_text.clone(),
240250
href: format!(
241-
"{}{}std/primitive.{}.html{}",
251+
"{}primitive.{}.html{}",
242252
url,
243-
if !url.ends_with('/') { "/" } else { "" },
244253
&fragment[..tail],
245254
&fragment[tail..]
246255
),

0 commit comments

Comments
 (0)