From 30d49a401ab11402429c8a839f54ff3b952d10a7 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 16 Jul 2021 21:58:23 -0700 Subject: [PATCH 01/18] Rustdoc accessibility: make the sidebar headers actual headers Part of #87059 Preview it at: https://notriddle.com/notriddle-rustdoc-test/rustdoc-sidebar-header/std/index.html --- src/librustdoc/html/render/context.rs | 4 +- src/librustdoc/html/render/mod.rs | 54 +++++++++++----------- src/librustdoc/html/static/css/rustdoc.css | 5 ++ 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 61057ff515b16..b6c3220901f06 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -539,7 +539,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { }; let sidebar = if let Some(ref version) = self.cache.crate_version { format!( - "

Crate {}

\ + "

Crate {}

\
\

Version {}

\
\ @@ -567,7 +567,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { page.root_path = "./"; let mut style_files = self.shared.style_files.clone(); - let sidebar = "

Settings

"; + let sidebar = "

Settings

"; style_files.push(StylePath { path: PathBuf::from("settings.css"), disabled: false }); let v = layout::render( &self.shared.templates, diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 7de023cabeff5..68c59612ccc44 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1654,7 +1654,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { { write!( buffer, - "

{}{}

", + "

{}{}

", match *it.kind { clean::StructItem(..) => "Struct ", clean::TraitItem(..) => "Trait ", @@ -1718,7 +1718,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { // to navigate the documentation (though slightly inefficiently). if !it.is_mod() { - buffer.write_str("

Other items in
"); + buffer.write_str("

Other items in
"); for (i, name) in cx.current.iter().take(parentlen).enumerate() { if i > 0 { buffer.write_str("::"); @@ -1730,7 +1730,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { *name ); } - buffer.write_str("

"); + buffer.write_str("

"); } // Sidebar refers to the enclosing module, not this module. @@ -1841,7 +1841,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) { ret.sort(); out.push_str( - "Methods\ + "

Methods

\
", ); for line in ret { @@ -1906,24 +1906,24 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) { if !concrete_format.is_empty() { out.push_str( - "\ - Trait Implementations", + "

\ + Trait Implementations

", ); write_sidebar_links(out, concrete_format); } if !synthetic_format.is_empty() { out.push_str( - "\ - Auto Trait Implementations", + "

\ + Auto Trait Implementations

", ); write_sidebar_links(out, synthetic_format); } if !blanket_format.is_empty() { out.push_str( - "\ - Blanket Implementations", + "

\ + Blanket Implementations

", ); write_sidebar_links(out, blanket_format); } @@ -1975,7 +1975,7 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V if !ret.is_empty() { write!( out, - "Methods from {}<Target={}>", + "

Methods from {}<Target={}>

", Escape(&format!("{:#}", impl_.inner_impl().trait_.as_ref().unwrap().print(cx))), Escape(&format!("{:#}", real_target.print(cx))), ); @@ -1998,7 +1998,7 @@ fn sidebar_struct(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, s: &clea if !fields.is_empty() { if let CtorKind::Fictive = s.struct_type { sidebar.push_str( - "Fields\ + "

Fields

\
", ); @@ -2075,8 +2075,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean print_sidebar_section( buf, &t.items, - "\ - Associated Types
", + "

\ + Associated Types

", |m| m.is_associated_type(), |out, sym| write!(out, "{0}", sym), "
", @@ -2085,8 +2085,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean print_sidebar_section( buf, &t.items, - "\ - Associated Constants
", + "

\ + Associated Constants

", |m| m.is_associated_const(), |out, sym| write!(out, "{0}", sym), "
", @@ -2095,8 +2095,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean print_sidebar_section( buf, &t.items, - "\ - Required Methods
", + "

\ + Required Methods

", |m| m.is_ty_method(), |out, sym| write!(out, "{0}", sym), "
", @@ -2105,8 +2105,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean print_sidebar_section( buf, &t.items, - "\ - Provided Methods
", + "

\ + Provided Methods

", |m| m.is_method(), |out, sym| write!(out, "{0}", sym), "
", @@ -2128,8 +2128,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean if !res.is_empty() { res.sort(); buf.push_str( - "\ - Implementations on Foreign Types\ + "

\ + Implementations on Foreign Types

\
", ); for (name, id) in res.into_iter() { @@ -2141,11 +2141,11 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean sidebar_assoc_items(cx, buf, it); - buf.push_str("Implementors"); + buf.push_str("

Implementors

"); if t.is_auto { buf.push_str( - "Auto Implementors", + "

Auto Implementors

", ); } @@ -2188,7 +2188,7 @@ fn sidebar_union(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, u: &clean if !fields.is_empty() { sidebar.push_str( - "Fields\ + "

Fields

\
", ); @@ -2220,7 +2220,7 @@ fn sidebar_enum(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, e: &clean: if !variants.is_empty() { variants.sort_unstable(); sidebar.push_str(&format!( - "Variants\ + "

Variants

\
{}
", variants.join(""), )); diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index b86f012c0e168..bb7582e23b4d0 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -339,9 +339,12 @@ nav.sub { .sidebar .location { border: 1px solid; font-size: 17px; + font-weight: inherit; margin: 30px 10px 20px 10px; text-align: center; word-wrap: break-word; + font-weight: inherit; + padding: 0; } .sidebar .version { @@ -394,6 +397,8 @@ nav.sub { text-align: center; font-size: 17px; margin-bottom: 5px; + font-weight: inherit; + padding: 0; } .sidebar-links { From ee97b4a52876a53f18d09571107d0c88d6f74c06 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 16 Jul 2021 22:00:22 -0700 Subject: [PATCH 02/18] Remove redundant CSS --- src/librustdoc/html/static/css/rustdoc.css | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index bb7582e23b4d0..a7ffd8a9aea14 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -339,7 +339,6 @@ nav.sub { .sidebar .location { border: 1px solid; font-size: 17px; - font-weight: inherit; margin: 30px 10px 20px 10px; text-align: center; word-wrap: break-word; From 10bdc42be86c9b83dc6303fa4c8eb8983403e627 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 17 Jul 2021 09:45:07 -0700 Subject: [PATCH 03/18] Fix test cases for header titles in sidebar --- src/test/rustdoc/deref-typedef.rs | 2 +- src/test/rustdoc/negative-impl-sidebar.rs | 2 +- src/test/rustdoc/sidebar-items.rs | 14 +++++++------- src/test/rustdoc/sidebar-links-to-foreign-impl.rs | 2 +- src/test/rustdoc/typedef.rs | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/test/rustdoc/deref-typedef.rs b/src/test/rustdoc/deref-typedef.rs index 3fc48b46d7410..d42ff384b29b8 100644 --- a/src/test/rustdoc/deref-typedef.rs +++ b/src/test/rustdoc/deref-typedef.rs @@ -6,7 +6,7 @@ // @has '-' '//*[@class="impl-items"]//*[@id="method.foo_b"]' 'pub fn foo_b(&self)' // @has '-' '//*[@class="impl-items"]//*[@id="method.foo_c"]' 'pub fn foo_c(&self)' // @has '-' '//*[@class="impl-items"]//*[@id="method.foo_j"]' 'pub fn foo_j(&self)' -// @has '-' '//*[@class="sidebar-title"][@href="#deref-methods"]' 'Methods from Deref' +// @has '-' '//*[@class="sidebar-title"]/a[@href="#deref-methods"]' 'Methods from Deref' // @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_a"]' 'foo_a' // @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_b"]' 'foo_b' // @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_c"]' 'foo_c' diff --git a/src/test/rustdoc/negative-impl-sidebar.rs b/src/test/rustdoc/negative-impl-sidebar.rs index 3414d9540776a..d63ab346045ee 100644 --- a/src/test/rustdoc/negative-impl-sidebar.rs +++ b/src/test/rustdoc/negative-impl-sidebar.rs @@ -4,6 +4,6 @@ pub struct Foo; // @has foo/struct.Foo.html -// @has - '//*[@class="sidebar-title"][@href="#trait-implementations"]' 'Trait Implementations' +// @has - '//*[@class="sidebar-title"]/a[@href="#trait-implementations"]' 'Trait Implementations' // @has - '//*[@class="sidebar-links"]/a' '!Sync' impl !Sync for Foo {} diff --git a/src/test/rustdoc/sidebar-items.rs b/src/test/rustdoc/sidebar-items.rs index 3ba6dbacc8d32..5da660b4df304 100644 --- a/src/test/rustdoc/sidebar-items.rs +++ b/src/test/rustdoc/sidebar-items.rs @@ -1,13 +1,13 @@ #![crate_name = "foo"] // @has foo/trait.Foo.html -// @has - '//*[@class="sidebar-title"][@href="#required-methods"]' 'Required Methods' +// @has - '//*[@class="sidebar-title"]/a[@href="#required-methods"]' 'Required Methods' // @has - '//*[@class="sidebar-links"]/a' 'bar' -// @has - '//*[@class="sidebar-title"][@href="#provided-methods"]' 'Provided Methods' +// @has - '//*[@class="sidebar-title"]/a[@href="#provided-methods"]' 'Provided Methods' // @has - '//*[@class="sidebar-links"]/a' 'foo' -// @has - '//*[@class="sidebar-title"][@href="#associated-const"]' 'Associated Constants' +// @has - '//*[@class="sidebar-title"]/a[@href="#associated-const"]' 'Associated Constants' // @has - '//*[@class="sidebar-links"]/a' 'BAR' -// @has - '//*[@class="sidebar-title"][@href="#associated-types"]' 'Associated Types' +// @has - '//*[@class="sidebar-title"]/a[@href="#associated-types"]' 'Associated Types' // @has - '//*[@class="sidebar-links"]/a' 'Output' pub trait Foo { const BAR: u32 = 0; @@ -18,7 +18,7 @@ pub trait Foo { } // @has foo/struct.Bar.html -// @has - '//*[@class="sidebar-title"][@href="#fields"]' 'Fields' +// @has - '//*[@class="sidebar-title"]/a[@href="#fields"]' 'Fields' // @has - '//*[@class="sidebar-links"]/a[@href="#structfield.f"]' 'f' // @has - '//*[@class="sidebar-links"]/a[@href="#structfield.u"]' 'u' // @!has - '//*[@class="sidebar-links"]/a' 'waza' @@ -29,7 +29,7 @@ pub struct Bar { } // @has foo/enum.En.html -// @has - '//*[@class="sidebar-title"][@href="#variants"]' 'Variants' +// @has - '//*[@class="sidebar-title"]/a[@href="#variants"]' 'Variants' // @has - '//*[@class="sidebar-links"]/a' 'foo' // @has - '//*[@class="sidebar-links"]/a' 'bar' pub enum En { @@ -38,7 +38,7 @@ pub enum En { } // @has foo/union.MyUnion.html -// @has - '//*[@class="sidebar-title"][@href="#fields"]' 'Fields' +// @has - '//*[@class="sidebar-title"]/a[@href="#fields"]' 'Fields' // @has - '//*[@class="sidebar-links"]/a[@href="#structfield.f1"]' 'f1' // @has - '//*[@class="sidebar-links"]/a[@href="#structfield.f2"]' 'f2' // @!has - '//*[@class="sidebar-links"]/a' 'waza' diff --git a/src/test/rustdoc/sidebar-links-to-foreign-impl.rs b/src/test/rustdoc/sidebar-links-to-foreign-impl.rs index d256fbe8de08a..e73c5b4f640cf 100644 --- a/src/test/rustdoc/sidebar-links-to-foreign-impl.rs +++ b/src/test/rustdoc/sidebar-links-to-foreign-impl.rs @@ -3,7 +3,7 @@ #![crate_name = "foo"] // @has foo/trait.Foo.html -// @has - '//*[@class="sidebar-title"][@href="#foreign-impls"]' 'Implementations on Foreign Types' +// @has - '//*[@class="sidebar-title"]/a[@href="#foreign-impls"]' 'Implementations on Foreign Types' // @has - '//h2[@id="foreign-impls"]' 'Implementations on Foreign Types' // @has - '//*[@class="sidebar-links"]/a[@href="#impl-Foo-for-u32"]' 'u32' // @has - '//div[@id="impl-Foo-for-u32"]//code' 'impl Foo for u32' diff --git a/src/test/rustdoc/typedef.rs b/src/test/rustdoc/typedef.rs index 21a7fdda7691d..479cd91a9dc60 100644 --- a/src/test/rustdoc/typedef.rs +++ b/src/test/rustdoc/typedef.rs @@ -12,7 +12,7 @@ impl MyStruct { // @has - '//*[@class="impl has-srclink"]//code' 'impl MyAlias' // @has - '//*[@class="impl has-srclink"]//code' 'impl MyTrait for MyAlias' // @has - 'Alias docstring' -// @has - '//*[@class="sidebar"]//p[@class="location"]' 'Type Definition MyAlias' +// @has - '//*[@class="sidebar"]//*[@class="location"]' 'Type Definition MyAlias' // @has - '//*[@class="sidebar"]//a[@href="#implementations"]' 'Methods' // @has - '//*[@class="sidebar"]//a[@href="#trait-implementations"]' 'Trait Implementations' /// Alias docstring From 1941764607cf1c2f85d1301496d5e49eb3e5356a Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 17 Jul 2021 11:53:59 -0700 Subject: [PATCH 04/18] Fix sidebar-mobile test to focus on an actual focusable element --- src/test/rustdoc-gui/sidebar-mobile.goml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/rustdoc-gui/sidebar-mobile.goml b/src/test/rustdoc-gui/sidebar-mobile.goml index f0c9361d0806b..7138f91667573 100644 --- a/src/test/rustdoc-gui/sidebar-mobile.goml +++ b/src/test/rustdoc-gui/sidebar-mobile.goml @@ -13,7 +13,7 @@ click: ".sidebar-menu" assert-css: (".sidebar-elems", {"display": "block", "left": "-246px"}) // Force the sidebar open by focusing a link inside it. // This makes it easier for keyboard users to get to it. -focus: ".sidebar-title" +focus: ".sidebar-title a" assert-css: (".sidebar-elems", {"display": "block", "left": "0px"}) // When we tab out of the sidebar, close it. focus: ".search-input" From 46010c4618d4602cd6999c613fce7081fad438c2 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sat, 17 Jul 2021 05:47:39 -0700 Subject: [PATCH 05/18] Remove args cleanup code. As of 91c3eee1735ad72b579f99cbb6919c3471747d94, the global ARGC and ARGV no longer reference dynamically-allocated memory, so they don't need to be cleaned up. --- library/std/src/sys/unix/args.rs | 13 ------------- library/std/src/sys/unix/mod.rs | 1 - 2 files changed, 14 deletions(-) diff --git a/library/std/src/sys/unix/args.rs b/library/std/src/sys/unix/args.rs index fc423e393d4a4..d9e3c29f36b1e 100644 --- a/library/std/src/sys/unix/args.rs +++ b/library/std/src/sys/unix/args.rs @@ -14,11 +14,6 @@ pub unsafe fn init(argc: isize, argv: *const *const u8) { imp::init(argc, argv) } -/// One-time global cleanup. -pub unsafe fn cleanup() { - imp::cleanup() -} - /// Returns the command line arguments pub fn args() -> Args { imp::args() @@ -127,12 +122,6 @@ mod imp { init_wrapper }; - pub unsafe fn cleanup() { - let _guard = LOCK.lock(); - ARGC.store(0, Ordering::Relaxed); - ARGV.store(ptr::null_mut(), Ordering::Relaxed); - } - pub fn args() -> Args { Args { iter: clone().into_iter() } } @@ -159,8 +148,6 @@ mod imp { pub unsafe fn init(_argc: isize, _argv: *const *const u8) {} - pub fn cleanup() {} - #[cfg(target_os = "macos")] pub fn args() -> Args { use crate::os::unix::prelude::*; diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index 2da71b2a448ac..9e553ec7682b1 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -123,7 +123,6 @@ pub unsafe fn init(argc: isize, argv: *const *const u8) { // SAFETY: must be called only once during runtime cleanup. // NOTE: this is not guaranteed to run, for example when the program aborts. pub unsafe fn cleanup() { - args::cleanup(); stack_overflow::cleanup(); } From 9bb11ba51135b0398b5a8b9feca24149d96fa5e8 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sat, 17 Jul 2021 12:33:31 -0700 Subject: [PATCH 06/18] Remove an unnecessary `Mutex` around argument initialization. In the command-line argument initialization code, remove the Mutex around the `ARGV` and `ARGC` variables, and simply check whether ARGV is non-null before dereferencing it. This way, if either of ARGV or ARGC is not initialized, we'll get an empty argument list. This allows simple cdylibs to avoid having `pthread_mutex_lock`/`pthread_mutex_unlock` appear in their symbol tables if they don't otherwise use threads. --- library/std/src/sys/unix/args.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/library/std/src/sys/unix/args.rs b/library/std/src/sys/unix/args.rs index d9e3c29f36b1e..a6480199e7048 100644 --- a/library/std/src/sys/unix/args.rs +++ b/library/std/src/sys/unix/args.rs @@ -77,16 +77,10 @@ mod imp { use crate::ptr; use crate::sync::atomic::{AtomicIsize, AtomicPtr, Ordering}; - use crate::sys_common::mutex::StaticMutex; - static ARGC: AtomicIsize = AtomicIsize::new(0); static ARGV: AtomicPtr<*const u8> = AtomicPtr::new(ptr::null_mut()); - // We never call `ENV_LOCK.init()`, so it is UB to attempt to - // acquire this mutex reentrantly! - static LOCK: StaticMutex = StaticMutex::new(); unsafe fn really_init(argc: isize, argv: *const *const u8) { - let _guard = LOCK.lock(); ARGC.store(argc, Ordering::Relaxed); ARGV.store(argv as *mut _, Ordering::Relaxed); } @@ -128,9 +122,14 @@ mod imp { fn clone() -> Vec { unsafe { - let _guard = LOCK.lock(); - let argc = ARGC.load(Ordering::Relaxed); + // Load ARGC and ARGV without a lock. If the store to either ARGV or + // ARGC isn't visible yet, we'll return an empty argument list. let argv = ARGV.load(Ordering::Relaxed); + let argc = if argv.is_null() { + 0 + } else { + ARGC.load(Ordering::Relaxed) + }; (0..argc) .map(|i| { let cstr = CStr::from_ptr(*argv.offset(i) as *const libc::c_char); From c3df0ae97f9c03ce5937b9677c27da891a4a0fe0 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sat, 17 Jul 2021 18:31:51 -0700 Subject: [PATCH 07/18] x.py fmt --- library/std/src/sys/unix/args.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/library/std/src/sys/unix/args.rs b/library/std/src/sys/unix/args.rs index a6480199e7048..ad93fa610c481 100644 --- a/library/std/src/sys/unix/args.rs +++ b/library/std/src/sys/unix/args.rs @@ -125,11 +125,7 @@ mod imp { // Load ARGC and ARGV without a lock. If the store to either ARGV or // ARGC isn't visible yet, we'll return an empty argument list. let argv = ARGV.load(Ordering::Relaxed); - let argc = if argv.is_null() { - 0 - } else { - ARGC.load(Ordering::Relaxed) - }; + let argc = if argv.is_null() { 0 } else { ARGC.load(Ordering::Relaxed) }; (0..argc) .map(|i| { let cstr = CStr::from_ptr(*argv.offset(i) as *const libc::c_char); From 6ca0e5ed39dd9ff4661a0c99c15592da171bffcf Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 11 Jun 2021 16:53:32 +0200 Subject: [PATCH 08/18] Add --nocapture option to rustdoc --- src/librustdoc/config.rs | 5 +++++ src/librustdoc/doctest.rs | 7 +++++++ src/librustdoc/lib.rs | 3 +++ src/librustdoc/markdown.rs | 3 +++ 4 files changed, 18 insertions(+) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 4cf647a81ae4b..adbdde0d92cd6 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -156,6 +156,8 @@ crate struct Options { crate run_check: bool, /// Whether doctests should emit unused externs crate json_unused_externs: bool, + /// Whether to skip capturing stdout and stderr of tests. + crate nocapture: bool, } impl fmt::Debug for Options { @@ -199,6 +201,7 @@ impl fmt::Debug for Options { .field("enable-per-target-ignores", &self.enable_per_target_ignores) .field("run_check", &self.run_check) .field("no_run", &self.no_run) + .field("nocapture", &self.nocapture) .finish() } } @@ -627,6 +630,7 @@ impl Options { let run_check = matches.opt_present("check"); let generate_redirect_map = matches.opt_present("generate-redirect-map"); let show_type_layout = matches.opt_present("show-type-layout"); + let nocapture = matches.opt_present("nocapture"); let (lint_opts, describe_lints, lint_cap, _) = get_cmd_lint_options(matches, error_format, &debugging_opts); @@ -665,6 +669,7 @@ impl Options { test_builder, run_check, no_run, + nocapture, render_options: RenderOptions { output, external_html, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index c5ca396e72029..a9126049b58d4 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -107,6 +107,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> { let mut test_args = options.test_args.clone(); let display_warnings = options.display_warnings; + let nocapture = options.nocapture; let externs = options.externs.clone(); let json_unused_externs = options.json_unused_externs; @@ -166,6 +167,9 @@ crate fn run(options: Options) -> Result<(), ErrorReported> { }; test_args.insert(0, "rustdoctest".to_string()); + if nocapture { + test_args.push("--nocapture".to_string()); + } test::test_main(&test_args, tests, Some(test::Options::new().display_output(display_warnings))); @@ -463,6 +467,9 @@ fn run_test( return Err(TestFailure::UnexpectedRunPass); } else if !should_panic && !out.status.success() { return Err(TestFailure::ExecutionFailure(out)); + } else if options.nocapture { + io::stdout().write_all(&out.stdout).expect("failed to write stdout"); + io::stderr().write_all(&out.stderr).expect("failed to write stderr"); } } } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index d4d87819c0d7a..19deaa11388d8 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -604,6 +604,9 @@ fn opts() -> Vec { unstable("show-type-layout", |o| { o.optflagmulti("", "show-type-layout", "Include the memory layout of types in the docs") }), + unstable("nocapture", |o| { + o.optflag("", "nocapture", "Don't capture stdout and stderr of tests") + }), ] } diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index 45966c0058df4..6c8b95c04c9e4 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -136,6 +136,9 @@ crate fn test(mut options: Options) -> Result<(), String> { find_testable_code(&input_str, &mut collector, codes, options.enable_per_target_ignores, None); options.test_args.insert(0, "rustdoctest".to_string()); + if options.nocapture { + options.test_args.push("--nocapture".to_string()); + } test::test_main( &options.test_args, collector.tests, From 111cca1fa76e13956610cae02da13758daed8ddf Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 11 Jun 2021 22:11:35 +0200 Subject: [PATCH 09/18] Add test for rustdoc --nocapture option --- src/test/rustdoc-ui/nocapture.rs | 10 ++++++++++ src/test/rustdoc-ui/nocapture.stderr | 1 + src/test/rustdoc-ui/nocapture.stdout | 7 +++++++ 3 files changed, 18 insertions(+) create mode 100644 src/test/rustdoc-ui/nocapture.rs create mode 100644 src/test/rustdoc-ui/nocapture.stderr create mode 100644 src/test/rustdoc-ui/nocapture.stdout diff --git a/src/test/rustdoc-ui/nocapture.rs b/src/test/rustdoc-ui/nocapture.rs new file mode 100644 index 0000000000000..321f5ca08eded --- /dev/null +++ b/src/test/rustdoc-ui/nocapture.rs @@ -0,0 +1,10 @@ +// check-pass +// compile-flags:--test -Zunstable-options --nocapture +// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR" +// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME" + +/// ``` +/// println!("hello!"); +/// eprintln!("stderr"); +/// ``` +pub struct Foo; diff --git a/src/test/rustdoc-ui/nocapture.stderr b/src/test/rustdoc-ui/nocapture.stderr new file mode 100644 index 0000000000000..af6415db3c724 --- /dev/null +++ b/src/test/rustdoc-ui/nocapture.stderr @@ -0,0 +1 @@ +stderr diff --git a/src/test/rustdoc-ui/nocapture.stdout b/src/test/rustdoc-ui/nocapture.stdout new file mode 100644 index 0000000000000..4880e75da7062 --- /dev/null +++ b/src/test/rustdoc-ui/nocapture.stdout @@ -0,0 +1,7 @@ + +running 1 test +hello! +test $DIR/nocapture.rs - Foo (line 6) ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + From 893e07e1b0a93897bb931d8495f02ab731bd5a32 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 11 Jun 2021 22:20:40 +0200 Subject: [PATCH 10/18] Add doc for --nocapture --- src/doc/rustdoc/src/command-line-arguments.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/doc/rustdoc/src/command-line-arguments.md b/src/doc/rustdoc/src/command-line-arguments.md index 2e4016e24bc3f..c8af369a9695e 100644 --- a/src/doc/rustdoc/src/command-line-arguments.md +++ b/src/doc/rustdoc/src/command-line-arguments.md @@ -417,3 +417,10 @@ This flag is **deprecated** and **has no effect**. Rustdoc only supports Rust source code and Markdown input formats. If the file ends in `.md` or `.markdown`, `rustdoc` treats it as a Markdown file. Otherwise, it assumes that the input file is Rust. + +## `--nocapture` + +When this flag is used with `--test`, the output (stdout and stderr) of your tests won't be +captured by rustdoc. Instead, the output will be directed to your terminal, +as if you had run the test executable manually. This is especially useful +for debugging your tests! From 6461cde51f1885f3c5e96e26debcfc6d82285b7b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 9 Jul 2021 10:58:02 +0200 Subject: [PATCH 11/18] Don't capture child process output at all when --no-capture is used --- src/librustdoc/doctest.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index a9126049b58d4..5ce7c49278d23 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -460,16 +460,22 @@ fn run_test( cmd.current_dir(run_directory); } - match cmd.output() { + let result = if options.nocapture { + cmd.status().map(|status| process::Output { + status, + stdout: Vec::new(), + stderr: Vec::new(), + }) + } else { + cmd.output() + }; + match result { Err(e) => return Err(TestFailure::ExecutionError(e)), Ok(out) => { if should_panic && out.status.success() { return Err(TestFailure::UnexpectedRunPass); } else if !should_panic && !out.status.success() { return Err(TestFailure::ExecutionFailure(out)); - } else if options.nocapture { - io::stdout().write_all(&out.stdout).expect("failed to write stdout"); - io::stderr().write_all(&out.stderr).expect("failed to write stderr"); } } } From d5e32947344751a421c85aed2e4dd370160f5470 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 9 Jul 2021 11:06:20 +0200 Subject: [PATCH 12/18] Add invalid rust code for test --- src/test/rustdoc-ui/nocapture-fail.rs | 12 ++++++++++++ src/test/rustdoc-ui/nocapture-fail.stderr | 18 ++++++++++++++++++ src/test/rustdoc-ui/nocapture-fail.stdout | 6 ++++++ 3 files changed, 36 insertions(+) create mode 100644 src/test/rustdoc-ui/nocapture-fail.rs create mode 100644 src/test/rustdoc-ui/nocapture-fail.stderr create mode 100644 src/test/rustdoc-ui/nocapture-fail.stdout diff --git a/src/test/rustdoc-ui/nocapture-fail.rs b/src/test/rustdoc-ui/nocapture-fail.rs new file mode 100644 index 0000000000000..7706bd1f3e39c --- /dev/null +++ b/src/test/rustdoc-ui/nocapture-fail.rs @@ -0,0 +1,12 @@ +// check-pass +// compile-flags:--test -Zunstable-options --nocapture +// normalize-stderr-test: "src/test/rustdoc-ui" -> "$$DIR" +// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR" +// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME" + +/// ```compile_fail +/// fn foo() { +/// Input: 123 +/// } +/// ``` +pub struct Foo; diff --git a/src/test/rustdoc-ui/nocapture-fail.stderr b/src/test/rustdoc-ui/nocapture-fail.stderr new file mode 100644 index 0000000000000..16a5ac47cd257 --- /dev/null +++ b/src/test/rustdoc-ui/nocapture-fail.stderr @@ -0,0 +1,18 @@ +error: struct literal body without path + --> $DIR/nocapture-fail.rs:8:10 + | +LL | fn foo() { + | __________^ +LL | | Input: 123 +LL | | } + | |_^ + | +help: you might have forgotten to add the struct literal inside the block + | +LL | fn foo() { SomeStruct { +LL | Input: 123 +LL | } } + | + +error: aborting due to previous error + diff --git a/src/test/rustdoc-ui/nocapture-fail.stdout b/src/test/rustdoc-ui/nocapture-fail.stdout new file mode 100644 index 0000000000000..754f77db53ca3 --- /dev/null +++ b/src/test/rustdoc-ui/nocapture-fail.stdout @@ -0,0 +1,6 @@ + +running 1 test +test $DIR/nocapture-fail.rs - Foo (line 7) - compile fail ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + From d10703c616fe79522b41b9dc45dd1a97ba655517 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 18 Jul 2021 12:25:49 +0200 Subject: [PATCH 13/18] Fix item info display --- src/librustdoc/html/static/css/rustdoc.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index b86f012c0e168..e7a92e638467d 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -921,6 +921,9 @@ body.blur > :not(#help) { padding: 0 20px 20px 17px;; } +.item-info .stab { + display: table; +} .stab { border-width: 1px; border-style: solid; From 57f7501b1d0e276415cefdc1b8fba76563387744 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 18 Jul 2021 12:32:26 +0200 Subject: [PATCH 14/18] Add test to check width of item-info --- src/test/rustdoc-gui/item-info-width.goml | 7 +++++++ src/test/rustdoc-gui/src/lib2/lib.rs | 3 +++ 2 files changed, 10 insertions(+) create mode 100644 src/test/rustdoc-gui/item-info-width.goml diff --git a/src/test/rustdoc-gui/item-info-width.goml b/src/test/rustdoc-gui/item-info-width.goml new file mode 100644 index 0000000000000..44b79e60912c6 --- /dev/null +++ b/src/test/rustdoc-gui/item-info-width.goml @@ -0,0 +1,7 @@ +// This test ensures that the item information don't take 100% of the width if unnecessary. +goto: file://|DOC_PATH|/lib2/struct.Foo.html +// We set a fixed size so there is no chance of "random" resize. +size: (1100, 800) +// We check that ".item-info" is bigger than its content. +assert-css: (".item-info", {"width": "807px"}) +assert-css: (".item-info .stab", {"width": "343px"}) diff --git a/src/test/rustdoc-gui/src/lib2/lib.rs b/src/test/rustdoc-gui/src/lib2/lib.rs index 0466909479b67..cd00348cad3d1 100644 --- a/src/test/rustdoc-gui/src/lib2/lib.rs +++ b/src/test/rustdoc-gui/src/lib2/lib.rs @@ -1,5 +1,7 @@ // ignore-tidy-linelength +#![feature(doc_cfg)] + pub mod module { pub mod sub_module { pub mod sub_sub_module { @@ -14,6 +16,7 @@ pub fn foobar() {} pub type Alias = u32; +#[doc(cfg(feature = "foo-method"))] pub struct Foo { pub x: Alias, } From 93aa89023fb7eb9149e6739c7f54c3ae4a8235bf Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sun, 18 Jul 2021 10:36:07 -0500 Subject: [PATCH 15/18] Extend HIR-based WF checking to associated type defaults Previously, we would only look at associated types in `impl` blocks. --- compiler/rustc_typeck/src/hir_wf_check.rs | 6 +++++- src/test/ui/associated-types/defaults-wf.stderr | 4 ++-- src/test/ui/wf/wf-trait-associated-type-trait.rs | 2 +- src/test/ui/wf/wf-trait-associated-type-trait.stderr | 6 +++--- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_typeck/src/hir_wf_check.rs b/compiler/rustc_typeck/src/hir_wf_check.rs index fa9c44bb89191..a8ec7b79e571f 100644 --- a/compiler/rustc_typeck/src/hir_wf_check.rs +++ b/compiler/rustc_typeck/src/hir_wf_check.rs @@ -121,7 +121,11 @@ fn diagnostic_hir_wf_check<'tcx>( let ty = match tcx.hir().get(hir_id) { hir::Node::ImplItem(item) => match item.kind { - hir::ImplItemKind::TyAlias(ref ty) => Some(ty), + hir::ImplItemKind::TyAlias(ty) => Some(ty), + _ => None, + }, + hir::Node::TraitItem(item) => match item.kind { + hir::TraitItemKind::Type(_, ty) => ty, _ => None, }, _ => None, diff --git a/src/test/ui/associated-types/defaults-wf.stderr b/src/test/ui/associated-types/defaults-wf.stderr index d4fa5be742ff3..73ef567ffae6d 100644 --- a/src/test/ui/associated-types/defaults-wf.stderr +++ b/src/test/ui/associated-types/defaults-wf.stderr @@ -1,8 +1,8 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/defaults-wf.rs:7:5 + --> $DIR/defaults-wf.rs:7:15 | LL | type Ty = Vec<[u8]>; - | ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time + | ^^^^^^^^^ doesn't have a size known at compile-time | ::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | diff --git a/src/test/ui/wf/wf-trait-associated-type-trait.rs b/src/test/ui/wf/wf-trait-associated-type-trait.rs index ddc0b323a11a1..d67e110edeeee 100644 --- a/src/test/ui/wf/wf-trait-associated-type-trait.rs +++ b/src/test/ui/wf/wf-trait-associated-type-trait.rs @@ -8,7 +8,7 @@ struct IsCopy { x: T } trait SomeTrait { type Type1; - type Type2 = IsCopy; + type Type2 = (IsCopy, bool); //~^ ERROR E0277 } diff --git a/src/test/ui/wf/wf-trait-associated-type-trait.stderr b/src/test/ui/wf/wf-trait-associated-type-trait.stderr index a139186ebb673..d1c2c65043d21 100644 --- a/src/test/ui/wf/wf-trait-associated-type-trait.stderr +++ b/src/test/ui/wf/wf-trait-associated-type-trait.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `::Type1: Copy` is not satisfied - --> $DIR/wf-trait-associated-type-trait.rs:11:5 + --> $DIR/wf-trait-associated-type-trait.rs:11:19 | LL | struct IsCopy { x: T } | ---- required by this bound in `IsCopy` ... -LL | type Type2 = IsCopy; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `::Type1` +LL | type Type2 = (IsCopy, bool); + | ^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `::Type1` | help: consider further restricting the associated type | From 33a8e9f9ce68122bc8dcab9904249998906c7f68 Mon Sep 17 00:00:00 2001 From: Llandy Riveron Del Risco Date: Sun, 18 Jul 2021 21:52:18 +0200 Subject: [PATCH 16/18] triagebot shortcut config --- triagebot.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/triagebot.toml b/triagebot.toml index 968b80414bcfe..bf30927448a80 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -117,3 +117,5 @@ format = "rustc" project-name = "Rust" changelog-path = "RELEASES.md" changelog-branch = "master" + +[shortcut] From f26fbe2453806adc241ae07942621fa638369c30 Mon Sep 17 00:00:00 2001 From: bstrie <865233+bstrie@users.noreply.github.com> Date: Sat, 17 Jul 2021 14:48:00 -0400 Subject: [PATCH 17/18] Move asm! and global_asm! to core::arch --- library/core/src/lib.rs | 32 +++++++++++++++++++++++++++- library/core/src/macros/mod.rs | 38 ---------------------------------- library/core/src/prelude/v1.rs | 22 +++++++++++++++++--- library/std/src/lib.rs | 6 +++--- library/std/src/prelude/v1.rs | 24 +++++++++++++++++---- 5 files changed, 73 insertions(+), 49 deletions(-) diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 8bbce7e552c9b..540cdf124ee9c 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -316,5 +316,35 @@ pub mod primitive; #[unstable(feature = "stdsimd", issue = "48556")] mod core_arch; +#[doc = include_str!("../../stdarch/crates/core_arch/src/core_arch_docs.md")] #[stable(feature = "simd_arch", since = "1.27.0")] -pub use core_arch::arch; +pub mod arch { + #[stable(feature = "simd_arch", since = "1.27.0")] + pub use crate::core_arch::arch::*; + + /// Inline assembly. + /// + /// Read the [unstable book] for the usage. + /// + /// [unstable book]: ../../unstable-book/library-features/asm.html + #[unstable( + feature = "asm", + issue = "72016", + reason = "inline assembly is not stable enough for use and is subject to change" + )] + #[rustc_builtin_macro] + pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) { + /* compiler built-in */ + } + + /// Module-level inline assembly. + #[unstable( + feature = "global_asm", + issue = "35119", + reason = "`global_asm!` is not stable enough for use and is subject to change" + )] + #[rustc_builtin_macro] + pub macro global_asm("assembly template", $(operands,)* $(options($(option),*))?) { + /* compiler built-in */ + } +} diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 57eedde91643d..3ca8f27c79ab7 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -1312,27 +1312,6 @@ pub(crate) mod builtin { ($cond:expr, $($arg:tt)+) => {{ /* compiler built-in */ }}; } - /// Inline assembly. - /// - /// Read the [unstable book] for the usage. - /// - /// [unstable book]: ../unstable-book/library-features/asm.html - #[unstable( - feature = "asm", - issue = "72016", - reason = "inline assembly is not stable enough for use and is subject to change" - )] - #[rustc_builtin_macro] - #[macro_export] - macro_rules! asm { - ("assembly template", - $(operands,)* - $(options($(option),*))? - ) => { - /* compiler built-in */ - }; - } - /// LLVM-style inline assembly. /// /// Read the [unstable book] for the usage. @@ -1355,23 +1334,6 @@ pub(crate) mod builtin { }; } - /// Module-level inline assembly. - #[unstable( - feature = "global_asm", - issue = "35119", - reason = "`global_asm!` is not stable enough for use and is subject to change" - )] - #[rustc_builtin_macro] - #[macro_export] - macro_rules! global_asm { - ("assembly template", - $(operands,)* - $(options($(option),*))? - ) => { - /* compiler built-in */ - }; - } - /// Prints passed tokens into the standard output. #[unstable( feature = "log_syntax", diff --git a/library/core/src/prelude/v1.rs b/library/core/src/prelude/v1.rs index c89fe57cb05ce..6b51ef5b0122d 100644 --- a/library/core/src/prelude/v1.rs +++ b/library/core/src/prelude/v1.rs @@ -55,11 +55,27 @@ pub use crate::hash::macros::Hash; #[allow(deprecated)] #[doc(no_inline)] pub use crate::{ - asm, assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args, - format_args_nl, global_asm, include, include_bytes, include_str, line, llvm_asm, log_syntax, - module_path, option_env, stringify, trace_macros, + assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args, + format_args_nl, include, include_bytes, include_str, line, llvm_asm, log_syntax, module_path, + option_env, stringify, trace_macros, }; +#[unstable( + feature = "asm", + issue = "72016", + reason = "inline assembly is not stable enough for use and is subject to change" +)] +#[doc(no_inline)] +pub use crate::arch::asm; + +#[unstable( + feature = "global_asm", + issue = "35119", + reason = "`global_asm!` is not stable enough for use and is subject to change" +)] +#[doc(no_inline)] +pub use crate::arch::global_asm; + #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] #[allow(deprecated, deprecated_in_future)] #[doc(no_inline)] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index a157a222c43e9..cfbfe7cc19160 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -556,9 +556,9 @@ pub use core::{ #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] #[allow(deprecated)] pub use core::{ - asm, assert, assert_matches, cfg, column, compile_error, concat, concat_idents, env, file, - format_args, format_args_nl, global_asm, include, include_bytes, include_str, line, llvm_asm, - log_syntax, module_path, option_env, stringify, trace_macros, + assert, assert_matches, cfg, column, compile_error, concat, concat_idents, env, file, + format_args, format_args_nl, include, include_bytes, include_str, line, llvm_asm, log_syntax, + module_path, option_env, stringify, trace_macros, }; #[stable(feature = "core_primitive", since = "1.43.0")] diff --git a/library/std/src/prelude/v1.rs b/library/std/src/prelude/v1.rs index 4a3c3ba163598..772044f014920 100644 --- a/library/std/src/prelude/v1.rs +++ b/library/std/src/prelude/v1.rs @@ -39,12 +39,28 @@ pub use crate::result::Result::{self, Err, Ok}; #[allow(deprecated)] #[doc(no_inline)] pub use core::prelude::v1::{ - asm, assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args, - format_args_nl, global_asm, include, include_bytes, include_str, line, llvm_asm, log_syntax, - module_path, option_env, stringify, trace_macros, Clone, Copy, Debug, Default, Eq, Hash, Ord, - PartialEq, PartialOrd, + assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args, + format_args_nl, include, include_bytes, include_str, line, llvm_asm, log_syntax, module_path, + option_env, stringify, trace_macros, Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, + PartialOrd, }; +#[unstable( + feature = "asm", + issue = "72016", + reason = "inline assembly is not stable enough for use and is subject to change" +)] +#[doc(no_inline)] +pub use core::prelude::v1::asm; + +#[unstable( + feature = "global_asm", + issue = "35119", + reason = "`global_asm!` is not stable enough for use and is subject to change" +)] +#[doc(no_inline)] +pub use core::prelude::v1::global_asm; + // FIXME: Attribute and internal derive macros are not documented because for them rustdoc generates // dead links which fail link checker testing. #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] From 98e9d16d258154c319d7e48159ad2f65c3244713 Mon Sep 17 00:00:00 2001 From: Giacomo Stevanato Date: Mon, 19 Jul 2021 10:47:45 +0200 Subject: [PATCH 18/18] Don't create references to uninitialized data in List::from_arena --- compiler/rustc_middle/src/ty/list.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_middle/src/ty/list.rs b/compiler/rustc_middle/src/ty/list.rs index 44dfcbf1866a7..1dceda6c7aad0 100644 --- a/compiler/rustc_middle/src/ty/list.rs +++ b/compiler/rustc_middle/src/ty/list.rs @@ -63,17 +63,17 @@ impl List { let (layout, _offset) = Layout::new::().extend(Layout::for_value::<[T]>(slice)).unwrap(); - let mem = arena.dropless.alloc_raw(layout); + let mem = arena.dropless.alloc_raw(layout) as *mut List; unsafe { - let result = &mut *(mem as *mut List); // Write the length - result.len = slice.len(); + ptr::addr_of_mut!((*mem).len).write(slice.len()); // Write the elements - let arena_slice = slice::from_raw_parts_mut(result.data.as_mut_ptr(), result.len); - arena_slice.copy_from_slice(slice); + ptr::addr_of_mut!((*mem).data) + .cast::() + .copy_from_nonoverlapping(slice.as_ptr(), slice.len()); - result + &mut *mem } }