Skip to content

Commit 7d0132a

Browse files
committed
Auto merge of #84363 - Dylan-DPC:rollup-ink2wyq, r=Dylan-DPC
Rollup of 4 pull requests Successful merges: - #84337 (Clarify the difference between insert and get_or_insert) - #84340 (rustdoc: Show nag box on IE11) - #84345 (Remove comment about doc hack.) - #84347 (rustdoc: Simplify some document functions) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6af1e63 + 868de80 commit 7d0132a

File tree

5 files changed

+48
-85
lines changed

5 files changed

+48
-85
lines changed

library/core/src/option.rs

+35-29
Original file line numberDiff line numberDiff line change
@@ -594,34 +594,6 @@ impl<T> Option<T> {
594594
}
595595
}
596596

597-
/// Inserts `value` into the option then returns a mutable reference to it.
598-
///
599-
/// If the option already contains a value, the old value is dropped.
600-
///
601-
/// # Example
602-
///
603-
/// ```
604-
/// let mut opt = None;
605-
/// let val = opt.insert(1);
606-
/// assert_eq!(*val, 1);
607-
/// assert_eq!(opt.unwrap(), 1);
608-
/// let val = opt.insert(2);
609-
/// assert_eq!(*val, 2);
610-
/// *val = 3;
611-
/// assert_eq!(opt.unwrap(), 3);
612-
/// ```
613-
#[inline]
614-
#[stable(feature = "option_insert", since = "1.53.0")]
615-
pub fn insert(&mut self, value: T) -> &mut T {
616-
*self = Some(value);
617-
618-
match self {
619-
Some(v) => v,
620-
// SAFETY: the code above just filled the option
621-
None => unsafe { hint::unreachable_unchecked() },
622-
}
623-
}
624-
625597
/////////////////////////////////////////////////////////////////////////
626598
// Iterator constructors
627599
/////////////////////////////////////////////////////////////////////////
@@ -849,12 +821,46 @@ impl<T> Option<T> {
849821
}
850822

851823
/////////////////////////////////////////////////////////////////////////
852-
// Entry-like operations to insert if None and return a reference
824+
// Entry-like operations to insert a value and return a reference
853825
/////////////////////////////////////////////////////////////////////////
854826

827+
/// Inserts `value` into the option then returns a mutable reference to it.
828+
///
829+
/// If the option already contains a value, the old value is dropped.
830+
///
831+
/// See also [`Option::get_or_insert`], which doesn't update the value if
832+
/// the option already contains [`Some`].
833+
///
834+
/// # Example
835+
///
836+
/// ```
837+
/// let mut opt = None;
838+
/// let val = opt.insert(1);
839+
/// assert_eq!(*val, 1);
840+
/// assert_eq!(opt.unwrap(), 1);
841+
/// let val = opt.insert(2);
842+
/// assert_eq!(*val, 2);
843+
/// *val = 3;
844+
/// assert_eq!(opt.unwrap(), 3);
845+
/// ```
846+
#[inline]
847+
#[stable(feature = "option_insert", since = "1.53.0")]
848+
pub fn insert(&mut self, value: T) -> &mut T {
849+
*self = Some(value);
850+
851+
match self {
852+
Some(v) => v,
853+
// SAFETY: the code above just filled the option
854+
None => unsafe { hint::unreachable_unchecked() },
855+
}
856+
}
857+
855858
/// Inserts `value` into the option if it is [`None`], then
856859
/// returns a mutable reference to the contained value.
857860
///
861+
/// See also [`Option::insert`], which updates the value even if
862+
/// the option already contains [`Some`].
863+
///
858864
/// # Examples
859865
///
860866
/// ```

src/bootstrap/doc.rs

-9
Original file line numberDiff line numberDiff line change
@@ -461,15 +461,6 @@ impl Step for Std {
461461
// create correct links between crates because rustdoc depends on the
462462
// existence of the output directories to know if it should be a local
463463
// or remote link.
464-
//
465-
// There's also a mild hack here where we build the first crate in this
466-
// list, core, twice. This is currently necessary to make sure that
467-
// cargo's cached rustc/rustdoc versions are up to date which means
468-
// cargo won't delete the out_dir we create for the stampfile.
469-
// Essentially any crate could go into the first slot here as it's
470-
// output directory will be deleted by us (as cargo will purge the stamp
471-
// file during the first slot's run), and core is relatively fast to
472-
// build so works OK to fill this 'dummy' slot.
473464
let krates = ["core", "alloc", "std", "proc_macro", "test"];
474465
for krate in &krates {
475466
run_cargo_rustdoc_for(krate);

src/librustdoc/html/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ crate fn render<T: Print, S: Print>(
6868
</style>\
6969
</head>\
7070
<body class=\"rustdoc {css_class}\">\
71-
<!--[if lte IE 8]>\
71+
<!--[if lte IE 11]>\
7272
<div class=\"warning\">\
7373
This old browser is unsupported and will most likely display funky \
7474
things.\

src/librustdoc/html/render/mod.rs

+11-45
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ fn document(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, parent: Option
509509
info!("Documenting {}", name);
510510
}
511511
document_item_info(w, cx, item, false, parent);
512-
document_full(w, item, cx, "", false);
512+
document_full(w, item, cx, false);
513513
}
514514

515515
/// Render md_text as markdown.
@@ -518,15 +518,13 @@ fn render_markdown(
518518
cx: &Context<'_>,
519519
md_text: &str,
520520
links: Vec<RenderedLink>,
521-
prefix: &str,
522521
is_hidden: bool,
523522
) {
524523
let mut ids = cx.id_map.borrow_mut();
525524
write!(
526525
w,
527-
"<div class=\"docblock{}\">{}{}</div>",
526+
"<div class=\"docblock{}\">{}</div>",
528527
if is_hidden { " hidden" } else { "" },
529-
prefix,
530528
Markdown(
531529
md_text,
532530
&links,
@@ -546,12 +544,11 @@ fn document_short(
546544
item: &clean::Item,
547545
cx: &Context<'_>,
548546
link: AssocItemLink<'_>,
549-
prefix: &str,
550547
is_hidden: bool,
551-
parent: Option<&clean::Item>,
548+
parent: &clean::Item,
552549
show_def_docs: bool,
553550
) {
554-
document_item_info(w, cx, item, is_hidden, parent);
551+
document_item_info(w, cx, item, is_hidden, Some(parent));
555552
if !show_def_docs {
556553
return;
557554
}
@@ -570,39 +567,17 @@ fn document_short(
570567

571568
write!(
572569
w,
573-
"<div class='docblock{}'>{}{}</div>",
570+
"<div class='docblock{}'>{}</div>",
574571
if is_hidden { " hidden" } else { "" },
575-
prefix,
576572
summary_html,
577573
);
578-
} else if !prefix.is_empty() {
579-
write!(
580-
w,
581-
"<div class=\"docblock{}\">{}</div>",
582-
if is_hidden { " hidden" } else { "" },
583-
prefix
584-
);
585574
}
586575
}
587576

588-
fn document_full(
589-
w: &mut Buffer,
590-
item: &clean::Item,
591-
cx: &Context<'_>,
592-
prefix: &str,
593-
is_hidden: bool,
594-
) {
577+
fn document_full(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>, is_hidden: bool) {
595578
if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) {
596579
debug!("Doc block: =====\n{}\n=====", s);
597-
render_markdown(w, cx, &*s, item.links(cx), prefix, is_hidden);
598-
} else if !prefix.is_empty() {
599-
if is_hidden {
600-
w.write_str("<div class=\"docblock hidden\">");
601-
} else {
602-
w.write_str("<div class=\"docblock\">");
603-
}
604-
w.write_str(prefix);
605-
w.write_str("</div>");
580+
render_markdown(w, cx, &s, item.links(cx), is_hidden);
606581
}
607582
}
608583

@@ -1547,30 +1522,21 @@ fn render_impl(
15471522
// because impls can't have a stability.
15481523
if item.doc_value().is_some() {
15491524
document_item_info(w, cx, it, is_hidden, Some(parent));
1550-
document_full(w, item, cx, "", is_hidden);
1525+
document_full(w, item, cx, is_hidden);
15511526
} else {
15521527
// In case the item isn't documented,
15531528
// provide short documentation from the trait.
1554-
document_short(
1555-
w,
1556-
it,
1557-
cx,
1558-
link,
1559-
"",
1560-
is_hidden,
1561-
Some(parent),
1562-
show_def_docs,
1563-
);
1529+
document_short(w, it, cx, link, is_hidden, parent, show_def_docs);
15641530
}
15651531
}
15661532
} else {
15671533
document_item_info(w, cx, item, is_hidden, Some(parent));
15681534
if show_def_docs {
1569-
document_full(w, item, cx, "", is_hidden);
1535+
document_full(w, item, cx, is_hidden);
15701536
}
15711537
}
15721538
} else {
1573-
document_short(w, item, cx, link, "", is_hidden, Some(parent), show_def_docs);
1539+
document_short(w, item, cx, link, is_hidden, parent, show_def_docs);
15741540
}
15751541
}
15761542
}

src/librustdoc/html/static/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ function hideThemeButtonState() {
12811281
if (currentType) {
12821282
currentType = currentType.getElementsByClassName("rust")[0];
12831283
if (currentType) {
1284-
currentType.classList.forEach(function(item) {
1284+
onEachLazy(currentType.classList, function(item) {
12851285
if (item !== "main") {
12861286
className = item;
12871287
return true;

0 commit comments

Comments
 (0)