Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 4 pull requests #84363

Merged
merged 9 commits into from
Apr 20, 2021
64 changes: 35 additions & 29 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,34 +594,6 @@ impl<T> Option<T> {
}
}

/// 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
/////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -849,12 +821,46 @@ impl<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
///
/// ```
Expand Down
9 changes: 0 additions & 9 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,6 @@ impl Step for Std {
// 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);
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ crate fn render<T: Print, S: Print>(
</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.\
Expand Down
56 changes: 11 additions & 45 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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;
}
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -1547,30 +1522,21 @@ fn render_impl(
// 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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down