From 92246c099e6e6d4c5e88e2ce14ccce0da42a3b68 Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Mon, 4 Apr 2022 23:06:12 +0000 Subject: [PATCH 1/8] Rely on #[link] attribute for unwind on Fuchsia. Closes #95575. --- library/unwind/build.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/unwind/build.rs b/library/unwind/build.rs index a3f5224151d94..61d3f45ca6523 100644 --- a/library/unwind/build.rs +++ b/library/unwind/build.rs @@ -40,8 +40,6 @@ fn main() { // This is handled in the target spec with late_link_args_[static|dynamic] } else if target.contains("uwp-windows-gnu") { println!("cargo:rustc-link-lib=unwind"); - } else if target.contains("fuchsia") { - println!("cargo:rustc-link-lib=unwind"); } else if target.contains("haiku") { println!("cargo:rustc-link-lib=gcc_s"); } else if target.contains("redox") { From a404523fbdfcc9e9d8e99f781aca1e7b2e9e6c04 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 5 Apr 2022 18:03:30 +0200 Subject: [PATCH 2/8] Generate a
instead of a for item-info elements --- src/librustdoc/html/render/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index ac07547de703b..e223b30650541 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1772,7 +1772,7 @@ pub(crate) fn render_impl_summary( let is_trait = i.inner_impl().trait_.is_some(); if is_trait { if let Some(portability) = portability(&i.impl_item, Some(parent)) { - write!(w, "{}", portability); + write!(w, "
{}
", portability); } } From 3baac2af058aa4ab98e2ec2e3ec8a73f127f1140 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 5 Apr 2022 18:04:16 +0200 Subject: [PATCH 3/8] Add GUI test to ensure that the width of the item-info does not overflow its parent --- src/test/rustdoc-gui/item-info-overflow.goml | 28 ++++++++++++++++++++ src/test/rustdoc-gui/src/lib2/lib.rs | 10 +++++++ 2 files changed, 38 insertions(+) create mode 100644 src/test/rustdoc-gui/item-info-overflow.goml diff --git a/src/test/rustdoc-gui/item-info-overflow.goml b/src/test/rustdoc-gui/item-info-overflow.goml new file mode 100644 index 0000000000000..4ff719bfb7ddc --- /dev/null +++ b/src/test/rustdoc-gui/item-info-overflow.goml @@ -0,0 +1,28 @@ +// This test ensures that the "item-info" elements don't overflow. +goto: file://|DOC_PATH|/lib2/struct.LongItemInfo.html +// We set a fixed size so there is no chance of "random" resize. +size: (1200, 870) +// Logically, the "item-decl" and the "item-info" should have the same scroll width. +compare-elements-property: (".docblock.item-decl", ".item-info", ["scrollWidth"]) +assert-property: (".item-info", {"scrollWidth": "890"}) +// Just to be sure we're comparing the correct "item-info": +assert-text: ( + ".item-info", + "This is supported on Android or Linux or Emscripten or DragonFly BSD", + STARTS_WITH, +) + +// Checking the "item-info" on an impl block as well: +goto: file://|DOC_PATH|/lib2/struct.LongItemInfo2.html +compare-elements-property: ( + "#impl-SimpleTrait .item-info", + "#impl-SimpleTrait + .docblock", + ["scrollWidth"], +) +assert-property: ("#impl-SimpleTrait .item-info", {"scrollWidth": "866"}) +// Just to be sure we're comparing the correct "item-info": +assert-text: ( + "#impl-SimpleTrait .item-info", + "This is supported on Android or Linux or Emscripten or DragonFly BSD", + STARTS_WITH, +) diff --git a/src/test/rustdoc-gui/src/lib2/lib.rs b/src/test/rustdoc-gui/src/lib2/lib.rs index 5b6d236e8e00b..83e86c439344a 100644 --- a/src/test/rustdoc-gui/src/lib2/lib.rs +++ b/src/test/rustdoc-gui/src/lib2/lib.rs @@ -120,3 +120,13 @@ pub struct HasALongTraitWithParams {} pub trait LongTraitWithParamsBananaBananaBanana {} impl LongTraitWithParamsBananaBananaBanana for HasALongTraitWithParams {} + +#[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "emscripten", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))] +pub struct LongItemInfo; + +pub trait SimpleTrait {} +pub struct LongItemInfo2; + +/// Some docs. +#[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "emscripten", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))] +impl SimpleTrait for LongItemInfo2 {} From 41b0247ceca3c3cff653a03bcf041701c69fb76b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 5 Apr 2022 18:05:12 +0200 Subject: [PATCH 4/8] Update browser-ui-test version to 0.8.5 --- .../docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version index fcbb5375b7e1d..bbde4bee23f26 100644 --- a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version +++ b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version @@ -1 +1 @@ -0.8.4 \ No newline at end of file +0.8.5 \ No newline at end of file From fcdfc3e1c1c3da9f765364f73d306bf5d4fd6a63 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 5 Apr 2022 13:31:51 -0400 Subject: [PATCH 5/8] interp: pass TyCtxt to Machine methods that do not take InterpCx --- compiler/rustc_const_eval/src/const_eval/machine.rs | 3 ++- compiler/rustc_const_eval/src/interpret/machine.rs | 6 +++++- compiler/rustc_const_eval/src/interpret/memory.rs | 11 ++++++----- compiler/rustc_mir_transform/src/const_prop.rs | 1 + compiler/rustc_mir_transform/src/const_prop_lint.rs | 1 + 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 5aae4a9096004..c44e27fc4a098 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -1,6 +1,6 @@ use rustc_hir::def::DefKind; use rustc_middle::mir; -use rustc_middle::ty::{self, Ty}; +use rustc_middle::ty::{self, Ty, TyCtxt}; use std::borrow::Borrow; use std::collections::hash_map::Entry; use std::hash::Hash; @@ -471,6 +471,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, } fn before_access_global( + _tcx: TyCtxt<'tcx>, machine: &Self, alloc_id: AllocId, alloc: ConstAllocation<'tcx>, diff --git a/compiler/rustc_const_eval/src/interpret/machine.rs b/compiler/rustc_const_eval/src/interpret/machine.rs index 39aec33819ce8..ddfbcbdd22e16 100644 --- a/compiler/rustc_const_eval/src/interpret/machine.rs +++ b/compiler/rustc_const_eval/src/interpret/machine.rs @@ -7,7 +7,7 @@ use std::fmt::Debug; use std::hash::Hash; use rustc_middle::mir; -use rustc_middle::ty::{self, Ty}; +use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::def_id::DefId; use rustc_target::abi::Size; use rustc_target::spec::abi::Abi; @@ -246,6 +246,7 @@ pub trait Machine<'mir, 'tcx>: Sized { /// `def_id` is `Some` if this is the "lazy" allocation of a static. #[inline] fn before_access_global( + _tcx: TyCtxt<'tcx>, _machine: &Self, _alloc_id: AllocId, _allocation: ConstAllocation<'tcx>, @@ -317,6 +318,7 @@ pub trait Machine<'mir, 'tcx>: Sized { /// need to mutate. #[inline(always)] fn memory_read( + _tcx: TyCtxt<'tcx>, _machine: &Self, _alloc_extra: &Self::AllocExtra, _tag: Self::PointerTag, @@ -328,6 +330,7 @@ pub trait Machine<'mir, 'tcx>: Sized { /// Hook for performing extra checks on a memory write access. #[inline(always)] fn memory_written( + _tcx: TyCtxt<'tcx>, _machine: &mut Self, _alloc_extra: &mut Self::AllocExtra, _tag: Self::PointerTag, @@ -339,6 +342,7 @@ pub trait Machine<'mir, 'tcx>: Sized { /// Hook for performing extra operations on a memory deallocation. #[inline(always)] fn memory_deallocated( + _tcx: TyCtxt<'tcx>, _machine: &mut Self, _alloc_extra: &mut Self::AllocExtra, _tag: Self::PointerTag, diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index fcfcd5d8989f5..a02115a110b7b 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -327,6 +327,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // Let the machine take some extra action let size = alloc.size(); M::memory_deallocated( + *self.tcx, &mut self.machine, &mut alloc.extra, ptr.provenance, @@ -509,7 +510,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { (self.tcx.eval_static_initializer(def_id)?, Some(def_id)) } }; - M::before_access_global(&self.machine, id, alloc, def_id, is_write)?; + M::before_access_global(*self.tcx, &self.machine, id, alloc, def_id, is_write)?; // We got tcx memory. Let the machine initialize its "extra" stuff. let alloc = M::init_allocation_extra( self, @@ -575,7 +576,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { )?; if let Some((alloc_id, offset, ptr, alloc)) = ptr_and_alloc { let range = alloc_range(offset, size); - M::memory_read(&self.machine, &alloc.extra, ptr.provenance, range)?; + M::memory_read(*self.tcx, &self.machine, &alloc.extra, ptr.provenance, range)?; Ok(Some(AllocRef { alloc, range, tcx: *self.tcx, alloc_id })) } else { // Even in this branch we have to be sure that we actually access the allocation, in @@ -636,7 +637,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // We cannot call `get_raw_mut` inside `check_and_deref_ptr` as that would duplicate `&mut self`. let (alloc, machine) = self.get_alloc_raw_mut(alloc_id)?; let range = alloc_range(offset, size); - M::memory_written(machine, &mut alloc.extra, ptr.provenance, range)?; + M::memory_written(tcx, machine, &mut alloc.extra, ptr.provenance, range)?; Ok(Some(AllocRefMut { alloc, range, tcx, alloc_id })) } else { Ok(None) @@ -1009,7 +1010,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { }; let src_alloc = self.get_alloc_raw(src_alloc_id)?; let src_range = alloc_range(src_offset, size); - M::memory_read(&self.machine, &src_alloc.extra, src.provenance, src_range)?; + M::memory_read(*tcx, &self.machine, &src_alloc.extra, src.provenance, src_range)?; // We need the `dest` ptr for the next operation, so we get it now. // We already did the source checks and called the hooks so we are good to return early. let Some((dest_alloc_id, dest_offset, dest)) = dest_parts else { @@ -1034,7 +1035,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // Destination alloc preparations and access hooks. let (dest_alloc, extra) = self.get_alloc_raw_mut(dest_alloc_id)?; let dest_range = alloc_range(dest_offset, size * num_copies); - M::memory_written(extra, &mut dest_alloc.extra, dest.provenance, dest_range)?; + M::memory_written(*tcx, extra, &mut dest_alloc.extra, dest.provenance, dest_range)?; let dest_bytes = dest_alloc .get_bytes_mut_ptr(&tcx, dest_range) .map_err(|e| e.to_interp_error(dest_alloc_id))? diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 49ebdd302545a..a342aeed905e9 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -265,6 +265,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx> } fn before_access_global( + _tcx: TyCtxt<'tcx>, _machine: &Self, _alloc_id: AllocId, alloc: ConstAllocation<'tcx, Self::PointerTag, Self::AllocExtra>, diff --git a/compiler/rustc_mir_transform/src/const_prop_lint.rs b/compiler/rustc_mir_transform/src/const_prop_lint.rs index 602aa14b9e6c6..159503ad2d3f7 100644 --- a/compiler/rustc_mir_transform/src/const_prop_lint.rs +++ b/compiler/rustc_mir_transform/src/const_prop_lint.rs @@ -261,6 +261,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx> } fn before_access_global( + _tcx: TyCtxt<'tcx>, _machine: &Self, _alloc_id: AllocId, alloc: ConstAllocation<'tcx, Self::PointerTag, Self::AllocExtra>, From 31e79901454264b4e3ad22a207bf5df9d6aef9a5 Mon Sep 17 00:00:00 2001 From: SparkyPotato Date: Wed, 6 Apr 2022 01:32:26 +0530 Subject: [PATCH 6/8] fix Vec leak with 0 capacity --- library/alloc/src/raw_vec.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 0ce2beb63d681..5cf190423e399 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -170,6 +170,13 @@ impl RawVec { fn allocate_in(capacity: usize, init: AllocInit, alloc: A) -> Self { if mem::size_of::() == 0 { Self::new_in(alloc) + } else if capacity == 0 { + // Don't allocate here because `Drop` will not deallocate when `capacity` is 0. + Self { + ptr: unsafe { Unique::new_unchecked(NonNull::dangling().as_ptr()) }, + cap: capacity, + alloc, + } } else { // We avoid `unwrap_or_else` here because it bloats the amount of // LLVM IR generated. From 9e9881bcd803390bfbc1e3b1c64ad66330b01103 Mon Sep 17 00:00:00 2001 From: SparkyPotato Date: Wed, 6 Apr 2022 01:36:24 +0530 Subject: [PATCH 7/8] cleanup --- library/alloc/src/raw_vec.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 5cf190423e399..f73b3866c9cb5 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -168,15 +168,9 @@ impl RawVec { #[cfg(not(no_global_oom_handling))] fn allocate_in(capacity: usize, init: AllocInit, alloc: A) -> Self { - if mem::size_of::() == 0 { + // Don't allocate here because `Drop` will not deallocate when `capacity` is 0. + if mem::size_of::() == 0 || capacity == 0 { Self::new_in(alloc) - } else if capacity == 0 { - // Don't allocate here because `Drop` will not deallocate when `capacity` is 0. - Self { - ptr: unsafe { Unique::new_unchecked(NonNull::dangling().as_ptr()) }, - cap: capacity, - alloc, - } } else { // We avoid `unwrap_or_else` here because it bloats the amount of // LLVM IR generated. From 83f659b4bb2212037ec62028b1979ec31d956fdd Mon Sep 17 00:00:00 2001 From: SparkyPotato Date: Wed, 6 Apr 2022 01:36:46 +0530 Subject: [PATCH 8/8] formatting --- library/alloc/src/raw_vec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index f73b3866c9cb5..9dbac3c36ffb2 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -168,7 +168,7 @@ impl RawVec { #[cfg(not(no_global_oom_handling))] fn allocate_in(capacity: usize, init: AllocInit, alloc: A) -> Self { - // Don't allocate here because `Drop` will not deallocate when `capacity` is 0. + // Don't allocate here because `Drop` will not deallocate when `capacity` is 0. if mem::size_of::() == 0 || capacity == 0 { Self::new_in(alloc) } else {