From 9e281cc6a57417714335ae6e4e476315f6064b39 Mon Sep 17 00:00:00 2001 From: Liigo Zhuang Date: Fri, 1 Dec 2017 13:32:56 +0800 Subject: [PATCH 1/7] doc: macro `cfg!` evaluating at compile-time --- src/libcore/macros.rs | 2 +- src/libstd/macros.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 122baec8e58dc..770651b61a548 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -728,7 +728,7 @@ mod builtin { #[cfg(dox)] macro_rules! module_path { () => ({ /* compiler built-in */ }) } - /// Boolean evaluation of configuration flags. + /// Boolean evaluation of configuration flags, at compile-time. /// /// For more information, see the documentation for [`std::cfg!`]. /// diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 9d0373404aaa7..25d59d912e019 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -598,7 +598,7 @@ pub mod builtin { #[macro_export] macro_rules! module_path { () => ({ /* compiler built-in */ }) } - /// Boolean evaluation of configuration flags. + /// Boolean evaluation of configuration flags, at compile-time. /// /// In addition to the `#[cfg]` attribute, this macro is provided to allow /// boolean expression evaluation of configuration flags. This frequently From dddf1833335ecdbec5f7e0f9a2362a8b3bdf3907 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 2 Dec 2017 13:19:29 +0100 Subject: [PATCH 2/7] Move colors to main.css --- src/librustdoc/html/static/rustdoc.css | 44 +++-------- src/librustdoc/html/static/styles/main.css | 89 ++++++++++++++++++++++ 2 files changed, 100 insertions(+), 33 deletions(-) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 7efe7e1ae3eb3..d2b7bfd962570 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -208,7 +208,7 @@ nav.sub { .sidebar .version { font-size: 15px; text-align: center; - border-bottom: #DDDDDD 1px solid; + border-bottom: 1px solid; overflow-wrap: break-word; word-wrap: break-word; /* deprecated */ word-break: break-word; /* Chrome, non-standard */ @@ -247,8 +247,8 @@ nav.sub { } .sidebar-title { - border-top: 1px solid #777; - border-bottom: 1px solid #777; + border-top: 1px solid; + border-bottom: 1px solid; text-align: center; font-size: 17px; margin-bottom: 5px; @@ -354,7 +354,6 @@ h4 > code, h3 > code, .invisible > code { } .invisible { - background: rgba(0, 0, 0, 0); width: 100%; display: inline-block; } @@ -434,7 +433,6 @@ h4 > code, h3 > code, .invisible > code { .content .fn .where, .content .where.fmt-newline { display: block; - color: #4E4C4C; font-size: 0.8em; } @@ -528,7 +526,6 @@ a { } .search-input:focus { - border-color: #66afe9; border-radius: 2px; border: 0; outline: 0; @@ -550,7 +547,8 @@ a { .content .search-results td:first-child a { padding-right: 10px; } tr.result span.primitive::after { - content: ' (primitive type)'; font-style: italic; color: black; + content: ' (primitive type)'; + font-style: italic; } body.blur > :not(#help) { @@ -687,7 +685,6 @@ a.test-arrow:hover{ font-weight: 300; position: absolute; left: -23px; - color: #999; top: 0; } @@ -894,8 +891,6 @@ span.since { .tooltip .tooltiptext { width: 120px; display: none; - background-color: black; - color: #fff; text-align: center; padding: 5px 3px; border-radius: 6px; @@ -917,13 +912,10 @@ span.since { margin-top: -5px; border-width: 5px; border-style: solid; - border-color: transparent black transparent transparent; } .important-traits .tooltip .tooltiptext { - background-color: white; - color: black; - border: 1px solid #000; + border: 1px solid; } pre.rust { @@ -943,22 +935,21 @@ pre.rust { float: left; width: 33.3%; text-align: center; - border-bottom: 1px solid #ccc; + border-bottom: 1px solid; font-size: 18px; cursor: pointer; } #titles > div.selected { - border-bottom: 3px solid #0078ee; + border-bottom: 3px solid; } #titles > div:hover { - border-bottom: 3px solid #0089ff; + border-bottom: 3px solid; } #titles > div > div.count { display: inline-block; - color: #888; font-size: 16px; } @@ -977,7 +968,6 @@ h4 > .important-traits { position: fixed; width: 100vw; height: 100vh; - background-color: rgba(0,0,0,0.3); z-index: 10000; top: 0; left: 0; @@ -987,13 +977,12 @@ h4 > .important-traits { display: block; max-width: 60%; min-width: 200px; - background-color: #eee; padding: 8px; top: 40%; position: absolute; left: 50%; transform: translate(-50%, -40%); - border: 1px solid #999; + border: 1px solid; border-radius: 4px; border-top-right-radius: 0; } @@ -1020,35 +1009,24 @@ h3.important { right: -25px; top: -1px; font-size: 18px; - background-color: #eee; width: 25px; padding-right: 2px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; text-align: center; - border: 1px solid #999; + border: 1px solid; border-right: 0; cursor: pointer; } -.modal-content > .close:hover { - background-color: #ff1f1f; - color: white; -} - .modal-content > .whiter { height: 25px; position: absolute; width: 3px; - background-color: #eee; right: -2px; top: 0px; } -.modal-content > .close:hover + .whiter { - background-color: #ff1f1f; -} - #main > div.important-traits { position: absolute; left: -24px; diff --git a/src/librustdoc/html/static/styles/main.css b/src/librustdoc/html/static/styles/main.css index cb19034bf0612..5cace837a5557 100644 --- a/src/librustdoc/html/static/styles/main.css +++ b/src/librustdoc/html/static/styles/main.css @@ -31,6 +31,10 @@ h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.t background-color: white; } +.invisible { + background: rgba(0, 0, 0, 0); +} + .docblock code, .docblock-short code { background-color: #F5F5F5; } @@ -56,6 +60,15 @@ pre { color: #333; } +.sidebar .version { + border-bottom-color: #DDD; +} + +.sidebar-title { + border-top-color: #777; + border-bottom-color: #777; +} + .block a:hover { background: #F5F5F5; } @@ -89,6 +102,12 @@ pre { background: #FDFFD3; } +.content .method .where, +.content .fn .where, +.content .where.fmt-newline { + color: #4E4C4C; +} + .content .highlighted { color: #000 !important; background-color: #ccc; @@ -152,12 +171,20 @@ a.test-arrow { color: #f5f5f5; } +.collapse-toggle { + color: #999; +} + .search-input { color: #555; box-shadow: 0 0 0 1px #e0e0e0, 0 0 0 2px transparent; background-color: white; } +.search-input:focus { + border-color: #66afe9; +} + .stab.unstable { background: #FFF5D6; border-color: #FFC600; } .stab.deprecated { background: #F3DFFF; border-color: #7F0087; } .stab.portability { background: #C4ECFF; border-color: #7BA5DB; } @@ -176,6 +203,10 @@ a.test-arrow { color: grey; } +tr.result span.primitive::after { + color: black; +} + .line-numbers :target { background-color: transparent; } /* Code highlighting */ @@ -241,3 +272,61 @@ pre.ignore:hover, .information:hover + pre.ignore { .search-failed > a { color: #0089ff; } + +.tooltip .tooltiptext { + background-color: black; + color: #fff; +} + +.tooltip .tooltiptext::after { + border-color: transparent black transparent transparent; +} + +.important-traits .tooltip .tooltiptext { + background-color: white; + color: black; + border-color: black; +} + +#titles > div { + border-bottom-color: #ccc; +} + +#titles > div.selected { + border-bottom-color: #0078ee; +} + +#titles > div:hover { + border-bottom-color: #0089ff; +} + +#titles > div > div.count { + color: #888; +} + +.modal { + background-color: rgba(0,0,0,0.3); +} + +.modal-content { + background-color: #eee; + border-color: #999; +} + +.modal-content > .close { + background-color: #eee; + border-color: #999; +} + +.modal-content > .close:hover { + background-color: #ff1f1f; + color: white; +} + +.modal-content > .whiter { + background-color: #eee; +} + +.modal-content > .close:hover + .whiter { + background-color: #ff1f1f; +} From 77faf79c0e2b8cf52a4ce9d3aaece794674ac2ae Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 6 Dec 2017 15:41:03 +0100 Subject: [PATCH 3/7] Do not automatically merge Cargo.lock --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index e737c7946ef61..2b4f3d472632a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,3 +7,4 @@ src/etc/installer/gfx/* binary *.woff binary src/vendor/** -text +Cargo.lock -merge From 9307917d6abc115faf7d2cb625c550cb509b5c4d Mon Sep 17 00:00:00 2001 From: Jonathan Strong Date: Wed, 6 Dec 2017 20:30:57 -0500 Subject: [PATCH 4/7] Adds language to the documentation for `Option` and `Result` suggesting the use of lazily evaluated alternatives when appropriate. These comments are intended to echo a clippy lint on the same topic (see https://rust-lang-nursery.github.io/rust-clippy/master/index.html#or_fun_call) --- src/libcore/option.rs | 12 ++++++++++++ src/libcore/result.rs | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 980ea551f0806..e354c7e16a13c 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -338,6 +338,10 @@ impl Option { /// Returns the contained value or a default. /// + /// Arguments passed to `unwrap_or` are eagerly evaluated; if you are passing + /// the result of a function call, it is recommended to use `unwrap_or_else`, + /// which is lazily evaluated. + /// /// # Examples /// /// ``` @@ -451,6 +455,10 @@ impl Option { /// Transforms the `Option` into a [`Result`], mapping [`Some(v)`] to /// [`Ok(v)`] and [`None`] to [`Err(err)`]. /// + /// Arguments passed to `ok_or` are eagerly evaluated; if you are passing the + /// result of a function call, it is recommended to use `ok_or_else`, which is + /// lazily evaluated. + /// /// [`Result`]: ../../std/result/enum.Result.html /// [`Ok(v)`]: ../../std/result/enum.Result.html#variant.Ok /// [`Err(err)`]: ../../std/result/enum.Result.html#variant.Err @@ -609,6 +617,10 @@ impl Option { /// Returns the option if it contains a value, otherwise returns `optb`. /// + /// Arguments passed to `or` are eagerly evaluated; if you are passing the + /// result of a function call, it is recommended to use `or_else`, which is + /// lazily evaluated. + /// /// # Examples /// /// ``` diff --git a/src/libcore/result.rs b/src/libcore/result.rs index db5bffced10cc..438b3ed46a145 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -625,6 +625,10 @@ impl Result { /// Returns `res` if the result is [`Err`], otherwise returns the [`Ok`] value of `self`. /// + /// Arguments passed to `or` are eagerly evaluated; if you are passing the + /// result of a function call, it is recommended to use `or_else`, which is + /// lazily evaluated. + /// /// [`Ok`]: enum.Result.html#variant.Ok /// [`Err`]: enum.Result.html#variant.Err /// @@ -690,6 +694,10 @@ impl Result { /// Unwraps a result, yielding the content of an [`Ok`]. /// Else, it returns `optb`. /// + /// Arguments passed to `unwrap_or` are eagerly evaluated; if you are passing + /// the result of a function call, it is recommended to use `unwrap_or_else`, + /// which is lazily evaluated. + /// /// [`Ok`]: enum.Result.html#variant.Ok /// [`Err`]: enum.Result.html#variant.Err /// From 5847d0babdb4bc4545d9aeb9ef89862589ae1504 Mon Sep 17 00:00:00 2001 From: Jonathan Strong Date: Thu, 7 Dec 2017 12:19:24 -0500 Subject: [PATCH 5/7] adds links to methods, removes trailing whitespace --- src/libcore/option.rs | 15 ++++++++++----- src/libcore/result.rs | 10 ++++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index e354c7e16a13c..0d7ec6071fbad 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -338,9 +338,11 @@ impl Option { /// Returns the contained value or a default. /// - /// Arguments passed to `unwrap_or` are eagerly evaluated; if you are passing - /// the result of a function call, it is recommended to use `unwrap_or_else`, - /// which is lazily evaluated. + /// Arguments passed to `unwrap_or` are eagerly evaluated; if you are passing + /// the result of a function call, it is recommended to use [`unwrap_or_else`], + /// which is lazily evaluated. + /// + /// [`unwrap_or_else`]: #method.unwrap_or_else /// /// # Examples /// @@ -456,7 +458,7 @@ impl Option { /// [`Ok(v)`] and [`None`] to [`Err(err)`]. /// /// Arguments passed to `ok_or` are eagerly evaluated; if you are passing the - /// result of a function call, it is recommended to use `ok_or_else`, which is + /// result of a function call, it is recommended to use [`ok_or_else`], which is /// lazily evaluated. /// /// [`Result`]: ../../std/result/enum.Result.html @@ -464,6 +466,7 @@ impl Option { /// [`Err(err)`]: ../../std/result/enum.Result.html#variant.Err /// [`None`]: #variant.None /// [`Some(v)`]: #variant.Some + /// [`ok_or_else`]: #method.ok_or_else /// /// # Examples /// @@ -618,9 +621,11 @@ impl Option { /// Returns the option if it contains a value, otherwise returns `optb`. /// /// Arguments passed to `or` are eagerly evaluated; if you are passing the - /// result of a function call, it is recommended to use `or_else`, which is + /// result of a function call, it is recommended to use [`or_else`], which is /// lazily evaluated. /// + /// [`or_else`]: #method.or_else + /// /// # Examples /// /// ``` diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 438b3ed46a145..97cfc2b4dbc53 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -626,11 +626,12 @@ impl Result { /// Returns `res` if the result is [`Err`], otherwise returns the [`Ok`] value of `self`. /// /// Arguments passed to `or` are eagerly evaluated; if you are passing the - /// result of a function call, it is recommended to use `or_else`, which is + /// result of a function call, it is recommended to use [`or_else`], which is /// lazily evaluated. /// /// [`Ok`]: enum.Result.html#variant.Ok /// [`Err`]: enum.Result.html#variant.Err + /// [`or_else`]: #method.or_else /// /// # Examples /// @@ -694,12 +695,13 @@ impl Result { /// Unwraps a result, yielding the content of an [`Ok`]. /// Else, it returns `optb`. /// - /// Arguments passed to `unwrap_or` are eagerly evaluated; if you are passing - /// the result of a function call, it is recommended to use `unwrap_or_else`, - /// which is lazily evaluated. + /// Arguments passed to `unwrap_or` are eagerly evaluated; if you are passing + /// the result of a function call, it is recommended to use [`unwrap_or_else`], + /// which is lazily evaluated. /// /// [`Ok`]: enum.Result.html#variant.Ok /// [`Err`]: enum.Result.html#variant.Err + /// [`unwrap_or_else`]: #method.unwrap_or_else /// /// # Examples /// From 71b70feb1ffaf98f4183fd94231ac3cc442651f0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 6 Dec 2017 00:42:33 +0100 Subject: [PATCH 6/7] Greatly improve sidebar when width < 700px --- src/librustdoc/html/layout.rs | 1 + src/librustdoc/html/render.rs | 7 +++++ src/librustdoc/html/static/main.js | 38 +++++++++++++++++++++++++- src/librustdoc/html/static/rustdoc.css | 29 +++++++++++++++++--- 4 files changed, 70 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 8c14d1bbe8f8a..61de5f4bc4c45 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -65,6 +65,7 @@ r##" {before_content} diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 9dc01bb0916f5..d42faebd39e57 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -3542,6 +3542,7 @@ impl<'a> fmt::Display for Sidebar<'a> { let cx = self.cx; let it = self.item; let parentlen = cx.current.len() - if it.is_mod() {1} else {0}; + let mut should_close = false; if it.is_struct() || it.is_trait() || it.is_primitive() || it.is_union() || it.is_enum() || it.is_mod() || it.is_typedef() @@ -3575,6 +3576,8 @@ impl<'a> fmt::Display for Sidebar<'a> { } } + write!(fmt, "
")?; + should_close = true; match it.inner { clean::StructItem(ref s) => sidebar_struct(fmt, it, s)?, clean::TraitItem(ref t) => sidebar_trait(fmt, it, t)?, @@ -3625,6 +3628,10 @@ impl<'a> fmt::Display for Sidebar<'a> { write!(fmt, "", path = relpath)?; } + if should_close { + // Closes sidebar-elems div. + write!(fmt, "
")?; + } Ok(()) } diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index bdd7b7dd0b76a..0db739fe0616c 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -106,6 +106,24 @@ return (elem.offsetParent === null) } + function showSidebar() { + document.getElementsByClassName("sidebar-elems")[0].style.display = "block"; + var sidebar = document.getElementsByClassName('sidebar')[0]; + sidebar.style.position = 'fixed'; + sidebar.style.width = '100%'; + sidebar.style.marginLeft = '0'; + document.getElementsByTagName("body")[0].style.marginTop = '45px'; + } + + function hideSidebar() { + document.getElementsByClassName("sidebar-elems")[0].style.display = ""; + var sidebar = document.getElementsByClassName('sidebar')[0]; + sidebar.style.position = ''; + sidebar.style.width = ''; + sidebar.style.marginLeft = ''; + document.getElementsByTagName("body")[0].style.marginTop = ''; + } + // used for special search precedence var TY_PRIMITIVE = itemTypes.indexOf("primitive"); @@ -130,6 +148,8 @@ } function highlightSourceLines(ev) { + // If we're in mobile mode, we should add the sidebar in any case. + hideSidebar(); var search = document.getElementById("search"); var i, from, to, match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/); if (match) { @@ -1459,7 +1479,7 @@ // delayed sidebar rendering. function initSidebarItems(items) { - var sidebar = document.getElementsByClassName('sidebar')[0]; + var sidebar = document.getElementsByClassName('sidebar-elems')[0]; var current = window.sidebarCurrent; function block(shortty, longty) { @@ -1829,6 +1849,22 @@ removeClass(search, "hidden"); search.innerHTML = '

Loading search results...

'; } + + var sidebar_menu = document.getElementsByClassName("sidebar-menu")[0]; + if (sidebar_menu) { + sidebar_menu.onclick = function() { + var sidebar = document.getElementsByClassName('sidebar')[0]; + if (sidebar.style.position === "fixed") { + hideSidebar(); + } else { + showSidebar(); + } + }; + } + + window.onresize = function() { + hideSidebar(); + }; }()); // Sets the focus on the search bar at the top of the page diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index f32252b726c8f..af7374eb68b0b 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -263,6 +263,10 @@ nav.sub { width: 100%; } +.sidebar-menu { + display: none; +} + .content { padding: 15px 0; } @@ -823,7 +827,7 @@ span.since { position: static; } - .sidebar .location { + .sidebar > .location { float: right; margin: 0px; margin-top: 2px; @@ -843,16 +847,33 @@ span.since { margin-top: 5px; margin-bottom: 5px; float: left; + margin-left: 50px; } - nav.sub { - margin: 0 auto; + .sidebar-menu { + position: absolute; + font-size: 2rem; + cursor: pointer; + margin-top: 2px; + display: block; } - .sidebar .block { + .sidebar-elems { + background-color: #F1F1F1; + position: fixed; + z-index: 1; + left: 0; + top: 45px; + bottom: 0; + overflow-y: auto; + border-right: 1px solid #000; display: none; } + nav.sub { + margin: 0 auto; + } + .content { margin-left: 0px; } From 423e5ac6f3ca61cd050277293dcae9faf9bd08f5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 7 Dec 2017 22:55:14 +0100 Subject: [PATCH 7/7] Fix JS errors --- src/librustdoc/html/static/main.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 0db739fe0616c..06e9cbbdf9a71 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -107,7 +107,10 @@ } function showSidebar() { - document.getElementsByClassName("sidebar-elems")[0].style.display = "block"; + var elems = document.getElementsByClassName("sidebar-elems")[0]; + if (elems) { + elems.style.display = "block"; + } var sidebar = document.getElementsByClassName('sidebar')[0]; sidebar.style.position = 'fixed'; sidebar.style.width = '100%'; @@ -116,7 +119,10 @@ } function hideSidebar() { - document.getElementsByClassName("sidebar-elems")[0].style.display = ""; + var elems = document.getElementsByClassName("sidebar-elems")[0]; + if (elems) { + elems.style.display = ""; + } var sidebar = document.getElementsByClassName('sidebar')[0]; sidebar.style.position = ''; sidebar.style.width = '';