From 5c77a0d7a7543addab9ca5c4c32c330fb8620e83 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 3 Jun 2023 17:08:29 +0200 Subject: [PATCH 1/8] Remove unneeded `Buffer` allocations when `&mut fmt::Write` can be used directly --- src/librustdoc/html/render/mod.rs | 4 +-- src/librustdoc/html/render/print_item.rs | 37 ++++++++++-------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index a5223bd6309d7..df17ab07b576d 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1038,9 +1038,9 @@ fn render_attributes_in_pre<'a, 'b: 'a>( // When an attribute is rendered inside a tag, it is formatted using // a div to produce a newline after it. -fn render_attributes_in_code(w: &mut Buffer, it: &clean::Item, tcx: TyCtxt<'_>) { +fn render_attributes_in_code(w: &mut impl fmt::Write, it: &clean::Item, tcx: TyCtxt<'_>) { for a in it.attributes(tcx, false) { - write!(w, "
{}
", a); + write!(w, "
{}
", a).unwrap(); } } diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 1d66805bd5c06..5bf5b9ef61809 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -1431,30 +1431,28 @@ fn item_proc_macro( it: &clean::Item, m: &clean::ProcMacro, ) { - let mut buffer = Buffer::new(); - wrap_item(&mut buffer, |buffer| { + wrap_item(w, |buffer| { let name = it.name.expect("proc-macros always have names"); match m.kind { MacroKind::Bang => { - write!(buffer, "{}!() {{ /* proc-macro */ }}", name); + write!(buffer, "{}!() {{ /* proc-macro */ }}", name).unwrap(); } MacroKind::Attr => { - write!(buffer, "#[{}]", name); + write!(buffer, "#[{}]", name).unwrap(); } MacroKind::Derive => { - write!(buffer, "#[derive({})]", name); + write!(buffer, "#[derive({})]", name).unwrap(); if !m.helpers.is_empty() { - buffer.push_str("\n{\n"); - buffer.push_str(" // Attributes available to this derive:\n"); + buffer.write_str("\n{\n // Attributes available to this derive:\n").unwrap(); for attr in &m.helpers { - writeln!(buffer, " #[{}]", attr); + writeln!(buffer, " #[{}]", attr).unwrap(); } - buffer.push_str("}\n"); + buffer.write_str("}\n").unwrap(); } } } }); - write!(w, "{}{}", buffer.into_inner(), document(cx, it, None, HeadingOffset::H2)).unwrap(); + write!(w, "{}", document(cx, it, None, HeadingOffset::H2)).unwrap(); } fn item_primitive(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item) { @@ -1571,8 +1569,7 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean } fn item_static(w: &mut impl fmt::Write, cx: &mut Context<'_>, it: &clean::Item, s: &clean::Static) { - let mut buffer = Buffer::new(); - wrap_item(&mut buffer, |buffer| { + wrap_item(w, |buffer| { render_attributes_in_code(buffer, it, cx.tcx()); write!( buffer, @@ -1581,29 +1578,27 @@ fn item_static(w: &mut impl fmt::Write, cx: &mut Context<'_>, it: &clean::Item, mutability = s.mutability.print_with_space(), name = it.name.unwrap(), typ = s.type_.print(cx) - ); + ) + .unwrap(); }); - write!(w, "{}", buffer.into_inner()).unwrap(); - write!(w, "{}", document(cx, it, None, HeadingOffset::H2)).unwrap(); } fn item_foreign_type(w: &mut impl fmt::Write, cx: &mut Context<'_>, it: &clean::Item) { - let mut buffer = Buffer::new(); - wrap_item(&mut buffer, |buffer| { - buffer.write_str("extern {\n"); + wrap_item(w, |buffer| { + buffer.write_str("extern {\n").unwrap(); render_attributes_in_code(buffer, it, cx.tcx()); write!( buffer, " {}type {};\n}}", visibility_print_with_space(it.visibility(cx.tcx()), it.item_id, cx), it.name.unwrap(), - ); + ) + .unwrap(); }); - write!(w, "{}{}", buffer.into_inner(), document(cx, it, None, HeadingOffset::H2)).unwrap(); - + write!(w, "{}", document(cx, it, None, HeadingOffset::H2)).unwrap(); write!(w, "{}", render_assoc_items(cx, it, it.item_id.expect_def_id(), AssocItemRender::All)) .unwrap(); } From dd2bd03d0a9c3950d19ecc8e907c5b150e27e0ce Mon Sep 17 00:00:00 2001 From: Grisha Vartanyan Date: Sun, 4 Jun 2023 08:06:25 +0200 Subject: [PATCH 2/8] Remove ExtendWith and ExtendElement --- library/alloc/src/vec/mod.rs | 30 ++++++------------------- library/alloc/src/vec/spec_from_elem.rs | 6 ++--- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 47661a3d38429..d89cdff8e366c 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2355,7 +2355,7 @@ impl Vec { let len = self.len(); if new_len > len { - self.extend_with(new_len - len, ExtendElement(value)) + self.extend_with(new_len - len, value) } else { self.truncate(new_len); } @@ -2469,26 +2469,10 @@ impl Vec<[T; N], A> { } } -// This code generalizes `extend_with_{element,default}`. -trait ExtendWith { - fn next(&mut self) -> T; - fn last(self) -> T; -} - -struct ExtendElement(T); -impl ExtendWith for ExtendElement { - fn next(&mut self) -> T { - self.0.clone() - } - fn last(self) -> T { - self.0 - } -} - -impl Vec { +impl Vec { #[cfg(not(no_global_oom_handling))] - /// Extend the vector by `n` values, using the given generator. - fn extend_with>(&mut self, n: usize, mut value: E) { + /// Extend the vector by `n` clones of value. + fn extend_with(&mut self, n: usize, value: T) { self.reserve(n); unsafe { @@ -2500,15 +2484,15 @@ impl Vec { // Write all elements except the last one for _ in 1..n { - ptr::write(ptr, value.next()); + ptr::write(ptr, value.clone()); ptr = ptr.add(1); - // Increment the length in every step in case next() panics + // Increment the length in every step in case clone() panics local_len.increment_len(1); } if n > 0 { // We can write the last element directly without cloning needlessly - ptr::write(ptr, value.last()); + ptr::write(ptr, value); local_len.increment_len(1); } diff --git a/library/alloc/src/vec/spec_from_elem.rs b/library/alloc/src/vec/spec_from_elem.rs index ff364c033ee98..da43d17bf3624 100644 --- a/library/alloc/src/vec/spec_from_elem.rs +++ b/library/alloc/src/vec/spec_from_elem.rs @@ -3,7 +3,7 @@ use core::ptr; use crate::alloc::Allocator; use crate::raw_vec::RawVec; -use super::{ExtendElement, IsZero, Vec}; +use super::{IsZero, Vec}; // Specialization trait used for Vec::from_elem pub(super) trait SpecFromElem: Sized { @@ -13,7 +13,7 @@ pub(super) trait SpecFromElem: Sized { impl SpecFromElem for T { default fn from_elem(elem: Self, n: usize, alloc: A) -> Vec { let mut v = Vec::with_capacity_in(n, alloc); - v.extend_with(n, ExtendElement(elem)); + v.extend_with(n, elem); v } } @@ -25,7 +25,7 @@ impl SpecFromElem for T { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; } let mut v = Vec::with_capacity_in(n, alloc); - v.extend_with(n, ExtendElement(elem)); + v.extend_with(n, elem); v } } From 1835d0333be220fc23d8b290298838dff5549cad Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Sun, 4 Jun 2023 18:06:34 -0400 Subject: [PATCH 3/8] Make RustAnalyzer check off by default --- src/bootstrap/check.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index f5a93854bf2c4..1a0f0047812ed 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -347,7 +347,7 @@ pub struct RustAnalyzer { impl Step for RustAnalyzer { type Output = (); const ONLY_HOSTS: bool = true; - const DEFAULT: bool = true; + const DEFAULT: bool = false; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { run.path("src/tools/rust-analyzer") From 7ed7e208abd9f807b96226eb47545f81bc4c9156 Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Sun, 4 Jun 2023 18:06:52 -0400 Subject: [PATCH 4/8] Run Rustfmt before RustAnalyzer --- src/bootstrap/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 848fb9eade917..916823edc1437 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -703,8 +703,8 @@ impl<'a> Builder<'a> { check::CargoMiri, check::MiroptTestTools, check::Rls, - check::RustAnalyzer, check::Rustfmt, + check::RustAnalyzer, check::Bootstrap ), Kind::Test => describe!( From af4e6c19377eca3f862bd2d7483c30831e998886 Mon Sep 17 00:00:00 2001 From: jyn Date: Sun, 4 Jun 2023 22:11:05 -0500 Subject: [PATCH 5/8] Don't double-print status messages in GHA Before: ``` Building stage0 tool jsondocck (x86_64-unknown-linux-gnu) Building stage0 tool jsondocck (x86_64-unknown-linux-gnu) Downloading crates ... ``` After: ``` Building stage0 tool jsondocck (x86_64-unknown-linux-gnu) Downloading crates ... ``` --- src/bootstrap/lib.rs | 1 - src/tools/build_helper/src/ci.rs | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index aa5d1bdd37f99..7ed8d2bfa7f54 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -1069,7 +1069,6 @@ impl Build { } fn group(&self, msg: &str) -> Option { - self.info(&msg); match self.config.dry_run { DryRun::SelfCheck => None, DryRun::Disabled | DryRun::UserSelected => Some(gha::group(&msg)), diff --git a/src/tools/build_helper/src/ci.rs b/src/tools/build_helper/src/ci.rs index d2e9c324af8c6..d106e5b339b2f 100644 --- a/src/tools/build_helper/src/ci.rs +++ b/src/tools/build_helper/src/ci.rs @@ -46,6 +46,8 @@ pub mod gha { pub fn group(name: impl std::fmt::Display) -> Group { if std::env::var_os("GITHUB_ACTIONS").is_some() { eprintln!("::group::{name}"); + } else { + eprintln!("{name}") } Group(()) } From 679f29aa73704c5e5bb9acdd7671fc85571e7393 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Mon, 5 Jun 2023 13:25:23 +0100 Subject: [PATCH 6/8] Ignore fluent message reordering in `git blame` --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 4c445f635d7d2..19078c1b842ae 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -14,3 +14,5 @@ c34fbfaad38cf5829ef5cfe780dc9d58480adeaa cf2dff2b1e3fa55fa5415d524200070d0d7aacfe # Run rustfmt on bootstrap b39a1d6f1a30ba29f25d7141038b9a5bf0126e36 +# reorder fluent message files +f97fddab91fbf290ea5b691fe355d6f915220b6e From 48c46f275b6431966edf243965b027aaf0f4e09d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 5 Jun 2023 15:31:18 +0200 Subject: [PATCH 7/8] Move write! arguments directly into the string --- src/librustdoc/html/render/mod.rs | 4 ++-- src/librustdoc/html/render/print_item.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index df17ab07b576d..d9b1cfcc11190 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1039,8 +1039,8 @@ fn render_attributes_in_pre<'a, 'b: 'a>( // When an attribute is rendered inside a tag, it is formatted using // a div to produce a newline after it. fn render_attributes_in_code(w: &mut impl fmt::Write, it: &clean::Item, tcx: TyCtxt<'_>) { - for a in it.attributes(tcx, false) { - write!(w, "
{}
", a).unwrap(); + for attr in it.attributes(tcx, false) { + write!(w, "
{attr}
").unwrap(); } } diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 5bf5b9ef61809..0ddd1a9ff7b73 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -1435,17 +1435,17 @@ fn item_proc_macro( let name = it.name.expect("proc-macros always have names"); match m.kind { MacroKind::Bang => { - write!(buffer, "{}!() {{ /* proc-macro */ }}", name).unwrap(); + write!(buffer, "{name}!() {{ /* proc-macro */ }}").unwrap(); } MacroKind::Attr => { - write!(buffer, "#[{}]", name).unwrap(); + write!(buffer, "#[{name}]").unwrap(); } MacroKind::Derive => { - write!(buffer, "#[derive({})]", name).unwrap(); + write!(buffer, "#[derive({name})]").unwrap(); if !m.helpers.is_empty() { buffer.write_str("\n{\n // Attributes available to this derive:\n").unwrap(); for attr in &m.helpers { - writeln!(buffer, " #[{}]", attr).unwrap(); + writeln!(buffer, " #[{attr}]").unwrap(); } buffer.write_str("}\n").unwrap(); } From e30c52d428a2e4347244fd382f956ab04c100d6c Mon Sep 17 00:00:00 2001 From: Luca Scherzer <83914554+lucascherzer@users.noreply.github.com> Date: Mon, 5 Jun 2023 16:01:09 +0200 Subject: [PATCH 8/8] fix spelling error --- compiler/rustc_driver/src/lib.rs | 2 +- src/librustdoc/visit_ast.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 4eabba575f42a..0cd0b51b6ad49 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -1,4 +1,4 @@ -// This crate is intentionally empty and a rexport of `rustc_driver_impl` to allow the code in +// This crate is intentionally empty and a re-export of `rustc_driver_impl` to allow the code in // `rustc_driver_impl` to be compiled in parallel with other crates. pub use rustc_driver_impl::*; diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 1689445b9ef7c..db35355289349 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -147,9 +147,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { // `#[macro_export] macro_rules!` items are reexported at the top level of the // crate, regardless of where they're defined. We want to document the - // top level rexport of the macro, not its original definition, since - // the rexport defines the path that a user will actually see. Accordingly, - // we add the rexport as an item here, and then skip over the original + // top level re-export of the macro, not its original definition, since + // the re-export defines the path that a user will actually see. Accordingly, + // we add the re-export as an item here, and then skip over the original // definition in `visit_item()` below. // // We also skip `#[macro_export] macro_rules!` that have already been inserted,