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
This commit is contained in:
bors 2021-04-20 11:19:31 +00:00
commit 7d0132ae90
5 changed files with 48 additions and 85 deletions

View File

@ -594,34 +594,6 @@ pub fn ok_or_else<E, F: FnOnce() -> E>(self, err: F) -> Result<T, E> {
}
}
/// Inserts `value` into the option then returns a mutable reference to it.
///
/// If the option already contains a value, the old value is dropped.
///
/// # Example
///
/// ```
/// let mut opt = None;
/// let val = opt.insert(1);
/// assert_eq!(*val, 1);
/// assert_eq!(opt.unwrap(), 1);
/// let val = opt.insert(2);
/// assert_eq!(*val, 2);
/// *val = 3;
/// assert_eq!(opt.unwrap(), 3);
/// ```
#[inline]
#[stable(feature = "option_insert", since = "1.53.0")]
pub fn insert(&mut self, value: T) -> &mut T {
*self = Some(value);
match self {
Some(v) => v,
// SAFETY: the code above just filled the option
None => unsafe { hint::unreachable_unchecked() },
}
}
/////////////////////////////////////////////////////////////////////////
// Iterator constructors
/////////////////////////////////////////////////////////////////////////
@ -849,12 +821,46 @@ pub fn xor(self, optb: Option<T>) -> Option<T> {
}
/////////////////////////////////////////////////////////////////////////
// Entry-like operations to insert if None and return a reference
// Entry-like operations to insert a value and return a reference
/////////////////////////////////////////////////////////////////////////
/// Inserts `value` into the option then returns a mutable reference to it.
///
/// If the option already contains a value, the old value is dropped.
///
/// See also [`Option::get_or_insert`], which doesn't update the value if
/// the option already contains [`Some`].
///
/// # Example
///
/// ```
/// let mut opt = None;
/// let val = opt.insert(1);
/// assert_eq!(*val, 1);
/// assert_eq!(opt.unwrap(), 1);
/// let val = opt.insert(2);
/// assert_eq!(*val, 2);
/// *val = 3;
/// assert_eq!(opt.unwrap(), 3);
/// ```
#[inline]
#[stable(feature = "option_insert", since = "1.53.0")]
pub fn insert(&mut self, value: T) -> &mut T {
*self = Some(value);
match self {
Some(v) => v,
// SAFETY: the code above just filled the option
None => unsafe { hint::unreachable_unchecked() },
}
}
/// Inserts `value` into the option if it is [`None`], then
/// returns a mutable reference to the contained value.
///
/// See also [`Option::insert`], which updates the value even if
/// the option already contains [`Some`].
///
/// # Examples
///
/// ```

View File

@ -461,15 +461,6 @@ fn run(self, builder: &Builder<'_>) {
// create correct links between crates because rustdoc depends on the
// existence of the output directories to know if it should be a local
// or remote link.
//
// There's also a mild hack here where we build the first crate in this
// list, core, twice. This is currently necessary to make sure that
// cargo's cached rustc/rustdoc versions are up to date which means
// cargo won't delete the out_dir we create for the stampfile.
// Essentially any crate could go into the first slot here as it's
// output directory will be deleted by us (as cargo will purge the stamp
// file during the first slot's run), and core is relatively fast to
// build so works OK to fill this 'dummy' slot.
let krates = ["core", "alloc", "std", "proc_macro", "test"];
for krate in &krates {
run_cargo_rustdoc_for(krate);

View File

@ -68,7 +68,7 @@
</style>\
</head>\
<body class=\"rustdoc {css_class}\">\
<!--[if lte IE 8]>\
<!--[if lte IE 11]>\
<div class=\"warning\">\
This old browser is unsupported and will most likely display funky \
things.\

View File

@ -509,7 +509,7 @@ fn document(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, parent: Option
info!("Documenting {}", name);
}
document_item_info(w, cx, item, false, parent);
document_full(w, item, cx, "", false);
document_full(w, item, cx, false);
}
/// Render md_text as markdown.
@ -518,15 +518,13 @@ fn render_markdown(
cx: &Context<'_>,
md_text: &str,
links: Vec<RenderedLink>,
prefix: &str,
is_hidden: bool,
) {
let mut ids = cx.id_map.borrow_mut();
write!(
w,
"<div class=\"docblock{}\">{}{}</div>",
"<div class=\"docblock{}\">{}</div>",
if is_hidden { " hidden" } else { "" },
prefix,
Markdown(
md_text,
&links,
@ -546,12 +544,11 @@ fn document_short(
item: &clean::Item,
cx: &Context<'_>,
link: AssocItemLink<'_>,
prefix: &str,
is_hidden: bool,
parent: Option<&clean::Item>,
parent: &clean::Item,
show_def_docs: bool,
) {
document_item_info(w, cx, item, is_hidden, parent);
document_item_info(w, cx, item, is_hidden, Some(parent));
if !show_def_docs {
return;
}
@ -570,39 +567,17 @@ fn document_short(
write!(
w,
"<div class='docblock{}'>{}{}</div>",
"<div class='docblock{}'>{}</div>",
if is_hidden { " hidden" } else { "" },
prefix,
summary_html,
);
} else if !prefix.is_empty() {
write!(
w,
"<div class=\"docblock{}\">{}</div>",
if is_hidden { " hidden" } else { "" },
prefix
);
}
}
fn document_full(
w: &mut Buffer,
item: &clean::Item,
cx: &Context<'_>,
prefix: &str,
is_hidden: bool,
) {
fn document_full(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>, is_hidden: bool) {
if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) {
debug!("Doc block: =====\n{}\n=====", s);
render_markdown(w, cx, &*s, item.links(cx), prefix, is_hidden);
} else if !prefix.is_empty() {
if is_hidden {
w.write_str("<div class=\"docblock hidden\">");
} else {
w.write_str("<div class=\"docblock\">");
}
w.write_str(prefix);
w.write_str("</div>");
render_markdown(w, cx, &s, item.links(cx), is_hidden);
}
}
@ -1547,30 +1522,21 @@ fn doc_impl_item(
// because impls can't have a stability.
if item.doc_value().is_some() {
document_item_info(w, cx, it, is_hidden, Some(parent));
document_full(w, item, cx, "", is_hidden);
document_full(w, item, cx, is_hidden);
} else {
// In case the item isn't documented,
// provide short documentation from the trait.
document_short(
w,
it,
cx,
link,
"",
is_hidden,
Some(parent),
show_def_docs,
);
document_short(w, it, cx, link, is_hidden, parent, show_def_docs);
}
}
} else {
document_item_info(w, cx, item, is_hidden, Some(parent));
if show_def_docs {
document_full(w, item, cx, "", is_hidden);
document_full(w, item, cx, is_hidden);
}
}
} else {
document_short(w, item, cx, link, "", is_hidden, Some(parent), show_def_docs);
document_short(w, item, cx, link, is_hidden, parent, show_def_docs);
}
}
}

View File

@ -1281,7 +1281,7 @@ function hideThemeButtonState() {
if (currentType) {
currentType = currentType.getElementsByClassName("rust")[0];
if (currentType) {
currentType.classList.forEach(function(item) {
onEachLazy(currentType.classList, function(item) {
if (item !== "main") {
className = item;
return true;