From 9cf2516251c5379d3e8429342e8a392df81b9aaa Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Thu, 10 Dec 2020 17:47:28 -0500 Subject: [PATCH 1/5] doc(array,vec): add notes about side effects when empty-initializing --- library/alloc/src/macros.rs | 3 +++ library/std/src/primitive_docs.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index a992d768d6314..bbff1d3dc4d2e 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -29,6 +29,9 @@ /// to the same boxed integer value, not five references pointing to independently /// boxed integers. /// +/// Also, note that `[T; 0]` is a valid initializer. This will initialize (or call) +/// `T` but not populate the vector with it, so be mindful of side effects. +/// /// [`Vec`]: crate::vec::Vec #[cfg(not(test))] #[macro_export] diff --git a/library/std/src/primitive_docs.rs b/library/std/src/primitive_docs.rs index 55171ef2292d7..b22adbbe3d356 100644 --- a/library/std/src/primitive_docs.rs +++ b/library/std/src/primitive_docs.rs @@ -489,6 +489,9 @@ mod prim_pointer {} /// * A repeat expression `[x; N]`, which produces an array with `N` copies of `x`. /// The type of `x` must be [`Copy`]. /// +/// Note that `[x; 0]` is a valid repeat expression. This will produce an empty array +/// but will also initialize (or call) `x`, which may produce side effects. +/// /// Arrays of *any* size implement the following traits if the element type allows it: /// /// - [`Copy`] From d986924eb13a103fc79c474eded47a663c91bb7f Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Fri, 11 Dec 2020 10:09:40 -0500 Subject: [PATCH 2/5] doc: apply suggestions --- library/alloc/src/macros.rs | 5 +++-- library/std/src/primitive_docs.rs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index bbff1d3dc4d2e..7d4eff6185dbe 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -29,8 +29,9 @@ /// to the same boxed integer value, not five references pointing to independently /// boxed integers. /// -/// Also, note that `[T; 0]` is a valid initializer. This will initialize (or call) -/// `T` but not populate the vector with it, so be mindful of side effects. +/// Also, note that `vec![expr; 0]` is allowed, and produces an empty vector. +/// This will still evaluate `expr`, however, and immediately drop the resulting value, so +/// be mindful of side effects. /// /// [`Vec`]: crate::vec::Vec #[cfg(not(test))] diff --git a/library/std/src/primitive_docs.rs b/library/std/src/primitive_docs.rs index b22adbbe3d356..7aca5451ebc20 100644 --- a/library/std/src/primitive_docs.rs +++ b/library/std/src/primitive_docs.rs @@ -489,8 +489,9 @@ mod prim_pointer {} /// * A repeat expression `[x; N]`, which produces an array with `N` copies of `x`. /// The type of `x` must be [`Copy`]. /// -/// Note that `[x; 0]` is a valid repeat expression. This will produce an empty array -/// but will also initialize (or call) `x`, which may produce side effects. +/// Note that `[expr; 0]` is allowed, and produces an empty array. +/// This will still evaluate `expr`, however, and immediately drop the resulting value, so +/// be mindful of side effects. /// /// Arrays of *any* size implement the following traits if the element type allows it: /// From ebfea6224bc3b72f3159cd8240a0f3e98366a604 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 11 Dec 2020 18:02:23 +0100 Subject: [PATCH 3/5] Fix item name display on mobile --- src/librustdoc/html/static/rustdoc.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 8eef65a231d0b..f208281d3b661 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -1571,7 +1571,7 @@ h4 > .notable-traits { #main > table:not(.table-display) td { word-break: break-word; - min-width: 10%; + width: 50%; } .search-container > div { From 9c36491538476dd3ff5ec834944aacdaceb12f30 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 11 Dec 2020 20:07:24 +0100 Subject: [PATCH 4/5] Fix main section position so that the search input remains clickable --- src/librustdoc/html/static/rustdoc.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index f208281d3b661..ebb8f98756d6e 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -1569,6 +1569,10 @@ h4 > .notable-traits { height: 73px; } + #main { + margin-top: 100px; + } + #main > table:not(.table-display) td { word-break: break-word; width: 50%; From ec0f1d70c955643a77e89d67eb2469ff5d7d6eba Mon Sep 17 00:00:00 2001 From: Alexis Bourget Date: Sun, 13 Dec 2020 17:47:46 +0100 Subject: [PATCH 5/5] Refactor test_lang_string_parse to make it clearer --- src/librustdoc/html/markdown/tests.rs | 143 +++++++++++++------------- 1 file changed, 69 insertions(+), 74 deletions(-) diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index 9807d8632c75d..75ff3c5af2fd2 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -51,82 +51,77 @@ fn test_unique_id() { #[test] fn test_lang_string_parse() { - fn t( - s: &str, - should_panic: bool, - no_run: bool, - ignore: Ignore, - rust: bool, - test_harness: bool, - compile_fail: bool, - allow_fail: bool, - error_codes: Vec, - edition: Option, - ) { - assert_eq!( - LangString::parse(s, ErrorCodes::Yes, true, None), - LangString { - should_panic, - no_run, - ignore, - rust, - test_harness, - compile_fail, - error_codes, - original: s.to_owned(), - allow_fail, - edition, - } - ) + fn t(lg: LangString) { + let s = &lg.original; + assert_eq!(LangString::parse(s, ErrorCodes::Yes, true, None), lg) } - let ignore_foo = Ignore::Some(vec!["foo".to_string()]); - fn v() -> Vec { - Vec::new() - } - - // marker | should_panic | no_run | ignore | rust | test_harness - // | compile_fail | allow_fail | error_codes | edition - t("", false, false, Ignore::None, true, false, false, false, v(), None); - t("rust", false, false, Ignore::None, true, false, false, false, v(), None); - t("sh", false, false, Ignore::None, false, false, false, false, v(), None); - t("ignore", false, false, Ignore::All, true, false, false, false, v(), None); - t("ignore-foo", false, false, ignore_foo, true, false, false, false, v(), None); - t("should_panic", true, false, Ignore::None, true, false, false, false, v(), None); - t("no_run", false, true, Ignore::None, true, false, false, false, v(), None); - t("test_harness", false, false, Ignore::None, true, true, false, false, v(), None); - t("compile_fail", false, true, Ignore::None, true, false, true, false, v(), None); - t("allow_fail", false, false, Ignore::None, true, false, false, true, v(), None); - t("{.no_run .example}", false, true, Ignore::None, true, false, false, false, v(), None); - t("{.sh .should_panic}", true, false, Ignore::None, false, false, false, false, v(), None); - t("{.example .rust}", false, false, Ignore::None, true, false, false, false, v(), None); - t("{.test_harness .rust}", false, false, Ignore::None, true, true, false, false, v(), None); - t("text, no_run", false, true, Ignore::None, false, false, false, false, v(), None); - t("text,no_run", false, true, Ignore::None, false, false, false, false, v(), None); - t( - "edition2015", - false, - false, - Ignore::None, - true, - false, - false, - false, - v(), - Some(Edition::Edition2015), - ); - t( - "edition2018", - false, - false, - Ignore::None, - true, - false, - false, - false, - v(), - Some(Edition::Edition2018), - ); + t(LangString::all_false()); + t(LangString { original: "rust".into(), ..LangString::all_false() }); + t(LangString { original: "sh".into(), rust: false, ..LangString::all_false() }); + t(LangString { original: "ignore".into(), ignore: Ignore::All, ..LangString::all_false() }); + t(LangString { + original: "ignore-foo".into(), + ignore: Ignore::Some(vec!["foo".to_string()]), + ..LangString::all_false() + }); + t(LangString { + original: "should_panic".into(), + should_panic: true, + ..LangString::all_false() + }); + t(LangString { original: "no_run".into(), no_run: true, ..LangString::all_false() }); + t(LangString { + original: "test_harness".into(), + test_harness: true, + ..LangString::all_false() + }); + t(LangString { + original: "compile_fail".into(), + no_run: true, + compile_fail: true, + ..LangString::all_false() + }); + t(LangString { original: "allow_fail".into(), allow_fail: true, ..LangString::all_false() }); + t(LangString { + original: "{.no_run .example}".into(), + no_run: true, + ..LangString::all_false() + }); + t(LangString { + original: "{.sh .should_panic}".into(), + should_panic: true, + rust: false, + ..LangString::all_false() + }); + t(LangString { original: "{.example .rust}".into(), ..LangString::all_false() }); + t(LangString { + original: "{.test_harness .rust}".into(), + test_harness: true, + ..LangString::all_false() + }); + t(LangString { + original: "text, no_run".into(), + no_run: true, + rust: false, + ..LangString::all_false() + }); + t(LangString { + original: "text,no_run".into(), + no_run: true, + rust: false, + ..LangString::all_false() + }); + t(LangString { + original: "edition2015".into(), + edition: Some(Edition::Edition2015), + ..LangString::all_false() + }); + t(LangString { + original: "edition2018".into(), + edition: Some(Edition::Edition2018), + ..LangString::all_false() + }); } #[test]