diff options
| author | bors <bors@rust-lang.org> | 2021-04-20 11:19:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-04-20 11:19:31 +0000 |
| commit | 7d0132ae90757af425a26a3d69c4d579b9b110a6 (patch) | |
| tree | 12ba1095f48caae00d76645b5f1da1dd5b8a84dc | |
| parent | 6af1e632a974b78b62895e8cb918b889cf613882 (diff) | |
| parent | 868de80ac2455b983cb90f2f9970b5992f177770 (diff) | |
| download | rust-7d0132ae90757af425a26a3d69c4d579b9b110a6.tar.gz rust-7d0132ae90757af425a26a3d69c4d579b9b110a6.zip | |
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
| -rw-r--r-- | library/core/src/option.rs | 64 | ||||
| -rw-r--r-- | src/bootstrap/doc.rs | 9 | ||||
| -rw-r--r-- | src/librustdoc/html/layout.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 56 | ||||
| -rw-r--r-- | src/librustdoc/html/static/main.js | 2 |
5 files changed, 48 insertions, 85 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 1e1e9613696..1c68abaf79d 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -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 ///////////////////////////////////////////////////////////////////////// @@ -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 /// /// ``` diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index dc96fd819d5..87f8cf160e0 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -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); diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index c50ebf1e6dc..dc29add9333 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -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.\ diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 7cb6466817c..d773f37ad90 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -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 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); } } } diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index f017fd846b1..be8d0a5996f 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -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; |
