Skip to content

Commit

Permalink
Auto merge of rust-lang#125020 - GuillaumeGomez:rollup-3vxwqef, r=Gui…
Browse files Browse the repository at this point in the history
…llaumeGomez

Rollup of 6 pull requests

Successful merges:

 - rust-lang#124807 (Migrate `run-make/rustdoc-io-error` to `rmake.rs`)
 - rust-lang#124829 (Enable profiler for armv7-unknown-linux-gnueabihf.)
 - rust-lang#124939 (Always hide private fields in aliased type)
 - rust-lang#124963 (Migrate `run-make/rustdoc-shared-flags` to rmake)
 - rust-lang#124981 (Relax allocator requirements on some Rc/Arc APIs.)
 - rust-lang#125008 (Add test for rust-lang#122775)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 11, 2024
2 parents 3349155 + 9d1cff1 commit 61241e8
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 73 deletions.
49 changes: 24 additions & 25 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
unsafe { self.ptr.as_ref() }
}

#[inline]
fn into_inner_with_allocator(this: Self) -> (NonNull<RcBox<T>>, A) {
let this = mem::ManuallyDrop::new(this);
(this.ptr, unsafe { ptr::read(&this.alloc) })
}

#[inline]
unsafe fn from_inner_in(ptr: NonNull<RcBox<T>>, alloc: A) -> Self {
Self { ptr, phantom: PhantomData, alloc }
Expand Down Expand Up @@ -1145,12 +1151,9 @@ impl<T, A: Allocator> Rc<mem::MaybeUninit<T>, A> {
/// ```
#[unstable(feature = "new_uninit", issue = "63291")]
#[inline]
pub unsafe fn assume_init(self) -> Rc<T, A>
where
A: Clone,
{
let md_self = mem::ManuallyDrop::new(self);
unsafe { Rc::from_inner_in(md_self.ptr.cast(), md_self.alloc.clone()) }
pub unsafe fn assume_init(self) -> Rc<T, A> {
let (ptr, alloc) = Rc::into_inner_with_allocator(self);
unsafe { Rc::from_inner_in(ptr.cast(), alloc) }
}
}

Expand Down Expand Up @@ -1189,12 +1192,9 @@ impl<T, A: Allocator> Rc<[mem::MaybeUninit<T>], A> {
/// ```
#[unstable(feature = "new_uninit", issue = "63291")]
#[inline]
pub unsafe fn assume_init(self) -> Rc<[T], A>
where
A: Clone,
{
let md_self = mem::ManuallyDrop::new(self);
unsafe { Rc::from_ptr_in(md_self.ptr.as_ptr() as _, md_self.alloc.clone()) }
pub unsafe fn assume_init(self) -> Rc<[T], A> {
let (ptr, alloc) = Rc::into_inner_with_allocator(self);
unsafe { Rc::from_ptr_in(ptr.as_ptr() as _, alloc) }
}
}

Expand Down Expand Up @@ -1809,7 +1809,9 @@ impl<T: Clone, A: Allocator + Clone> Rc<T, A> {
// reference to the allocation.
unsafe { &mut this.ptr.as_mut().value }
}
}

impl<T: Clone, A: Allocator> Rc<T, A> {
/// If we have the only reference to `T` then unwrap it. Otherwise, clone `T` and return the
/// clone.
///
Expand Down Expand Up @@ -1845,7 +1847,7 @@ impl<T: Clone, A: Allocator + Clone> Rc<T, A> {
}
}

impl<A: Allocator + Clone> Rc<dyn Any, A> {
impl<A: Allocator> Rc<dyn Any, A> {
/// Attempt to downcast the `Rc<dyn Any>` to a concrete type.
///
/// # Examples
Expand All @@ -1869,10 +1871,8 @@ impl<A: Allocator + Clone> Rc<dyn Any, A> {
pub fn downcast<T: Any>(self) -> Result<Rc<T, A>, Self> {
if (*self).is::<T>() {
unsafe {
let ptr = self.ptr.cast::<RcBox<T>>();
let alloc = self.alloc.clone();
forget(self);
Ok(Rc::from_inner_in(ptr, alloc))
let (ptr, alloc) = Rc::into_inner_with_allocator(self);
Ok(Rc::from_inner_in(ptr.cast(), alloc))
}
} else {
Err(self)
Expand Down Expand Up @@ -1909,10 +1909,8 @@ impl<A: Allocator + Clone> Rc<dyn Any, A> {
#[unstable(feature = "downcast_unchecked", issue = "90850")]
pub unsafe fn downcast_unchecked<T: Any>(self) -> Rc<T, A> {
unsafe {
let ptr = self.ptr.cast::<RcBox<T>>();
let alloc = self.alloc.clone();
mem::forget(self);
Rc::from_inner_in(ptr, alloc)
let (ptr, alloc) = Rc::into_inner_with_allocator(self);
Rc::from_inner_in(ptr.cast(), alloc)
}
}
}
Expand Down Expand Up @@ -2661,12 +2659,13 @@ impl From<Rc<str>> for Rc<[u8]> {
}

#[stable(feature = "boxed_slice_try_from", since = "1.43.0")]
impl<T, const N: usize> TryFrom<Rc<[T]>> for Rc<[T; N]> {
type Error = Rc<[T]>;
impl<T, A: Allocator, const N: usize> TryFrom<Rc<[T], A>> for Rc<[T; N], A> {
type Error = Rc<[T], A>;

fn try_from(boxed_slice: Rc<[T]>) -> Result<Self, Self::Error> {
fn try_from(boxed_slice: Rc<[T], A>) -> Result<Self, Self::Error> {
if boxed_slice.len() == N {
Ok(unsafe { Rc::from_raw(Rc::into_raw(boxed_slice) as *mut [T; N]) })
let (ptr, alloc) = Rc::into_inner_with_allocator(boxed_slice);
Ok(unsafe { Rc::from_inner_in(ptr.cast(), alloc) })
} else {
Err(boxed_slice)
}
Expand Down
16 changes: 9 additions & 7 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ impl<T: ?Sized> Arc<T> {

impl<T: ?Sized, A: Allocator> Arc<T, A> {
#[inline]
fn internal_into_inner_with_allocator(self) -> (NonNull<ArcInner<T>>, A) {
let this = mem::ManuallyDrop::new(self);
fn into_inner_with_allocator(this: Self) -> (NonNull<ArcInner<T>>, A) {
let this = mem::ManuallyDrop::new(this);
(this.ptr, unsafe { ptr::read(&this.alloc) })
}

Expand Down Expand Up @@ -1290,7 +1290,7 @@ impl<T, A: Allocator> Arc<mem::MaybeUninit<T>, A> {
#[must_use = "`self` will be dropped if the result is not used"]
#[inline]
pub unsafe fn assume_init(self) -> Arc<T, A> {
let (ptr, alloc) = self.internal_into_inner_with_allocator();
let (ptr, alloc) = Arc::into_inner_with_allocator(self);
unsafe { Arc::from_inner_in(ptr.cast(), alloc) }
}
}
Expand Down Expand Up @@ -1332,7 +1332,7 @@ impl<T, A: Allocator> Arc<[mem::MaybeUninit<T>], A> {
#[must_use = "`self` will be dropped if the result is not used"]
#[inline]
pub unsafe fn assume_init(self) -> Arc<[T], A> {
let (ptr, alloc) = self.internal_into_inner_with_allocator();
let (ptr, alloc) = Arc::into_inner_with_allocator(self);
unsafe { Arc::from_ptr_in(ptr.as_ptr() as _, alloc) }
}
}
Expand Down Expand Up @@ -2227,7 +2227,9 @@ impl<T: Clone, A: Allocator + Clone> Arc<T, A> {
// either unique to begin with, or became one upon cloning the contents.
unsafe { Self::get_mut_unchecked(this) }
}
}

impl<T: Clone, A: Allocator> Arc<T, A> {
/// If we have the only reference to `T` then unwrap it. Otherwise, clone `T` and return the
/// clone.
///
Expand Down Expand Up @@ -2499,7 +2501,7 @@ impl<A: Allocator> Arc<dyn Any + Send + Sync, A> {
{
if (*self).is::<T>() {
unsafe {
let (ptr, alloc) = self.internal_into_inner_with_allocator();
let (ptr, alloc) = Arc::into_inner_with_allocator(self);
Ok(Arc::from_inner_in(ptr.cast(), alloc))
}
} else {
Expand Down Expand Up @@ -2540,7 +2542,7 @@ impl<A: Allocator> Arc<dyn Any + Send + Sync, A> {
T: Any + Send + Sync,
{
unsafe {
let (ptr, alloc) = self.internal_into_inner_with_allocator();
let (ptr, alloc) = Arc::into_inner_with_allocator(self);
Arc::from_inner_in(ptr.cast(), alloc)
}
}
Expand Down Expand Up @@ -3506,7 +3508,7 @@ impl<T, A: Allocator, const N: usize> TryFrom<Arc<[T], A>> for Arc<[T; N], A> {

fn try_from(boxed_slice: Arc<[T], A>) -> Result<Self, Self::Error> {
if boxed_slice.len() == N {
let (ptr, alloc) = boxed_slice.internal_into_inner_with_allocator();
let (ptr, alloc) = Arc::into_inner_with_allocator(boxed_slice);
Ok(unsafe { Arc::from_inner_in(ptr.cast(), alloc) })
} else {
Err(boxed_slice)
Expand Down
2 changes: 1 addition & 1 deletion src/ci/docker/host-x86_64/dist-armv7-linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ ENV CC_armv7_unknown_linux_gnueabihf=armv7-unknown-linux-gnueabihf-gcc \

ENV HOSTS=armv7-unknown-linux-gnueabihf

ENV RUST_CONFIGURE_ARGS --enable-full-tools --disable-docs
ENV RUST_CONFIGURE_ARGS --enable-full-tools --enable-profiler --disable-docs
ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS
5 changes: 5 additions & 0 deletions src/librustdoc/passes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use crate::core::DocContext;
mod stripper;
pub(crate) use stripper::*;

mod strip_aliased_non_local;
pub(crate) use self::strip_aliased_non_local::STRIP_ALIASED_NON_LOCAL;

mod strip_hidden;
pub(crate) use self::strip_hidden::STRIP_HIDDEN;

Expand Down Expand Up @@ -71,6 +74,7 @@ pub(crate) enum Condition {
pub(crate) const PASSES: &[Pass] = &[
CHECK_CUSTOM_CODE_CLASSES,
CHECK_DOC_TEST_VISIBILITY,
STRIP_ALIASED_NON_LOCAL,
STRIP_HIDDEN,
STRIP_PRIVATE,
STRIP_PRIV_IMPORTS,
Expand All @@ -86,6 +90,7 @@ pub(crate) const DEFAULT_PASSES: &[ConditionalPass] = &[
ConditionalPass::always(CHECK_CUSTOM_CODE_CLASSES),
ConditionalPass::always(COLLECT_TRAIT_IMPLS),
ConditionalPass::always(CHECK_DOC_TEST_VISIBILITY),
ConditionalPass::always(STRIP_ALIASED_NON_LOCAL),
ConditionalPass::new(STRIP_HIDDEN, WhenNotDocumentHidden),
ConditionalPass::new(STRIP_PRIVATE, WhenNotDocumentPrivate),
ConditionalPass::new(STRIP_PRIV_IMPORTS, WhenDocumentPrivate),
Expand Down
57 changes: 57 additions & 0 deletions src/librustdoc/passes/strip_aliased_non_local.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use rustc_middle::ty::TyCtxt;
use rustc_middle::ty::Visibility;

use crate::clean;
use crate::clean::Item;
use crate::core::DocContext;
use crate::fold::{strip_item, DocFolder};
use crate::passes::Pass;

pub(crate) const STRIP_ALIASED_NON_LOCAL: Pass = Pass {
name: "strip-aliased-non-local",
run: strip_aliased_non_local,
description: "strips all non-local private aliased items from the output",
};

fn strip_aliased_non_local(krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate {
let mut stripper = AliasedNonLocalStripper { tcx: cx.tcx };
stripper.fold_crate(krate)
}

struct AliasedNonLocalStripper<'tcx> {
tcx: TyCtxt<'tcx>,
}

impl<'tcx> DocFolder for AliasedNonLocalStripper<'tcx> {
fn fold_item(&mut self, i: Item) -> Option<Item> {
Some(match *i.kind {
clean::TypeAliasItem(..) => {
let mut stripper = NonLocalStripper { tcx: self.tcx };
// don't call `fold_item` as that could strip the type-alias it-self
// which we don't want to strip out
stripper.fold_item_recur(i)
}
_ => self.fold_item_recur(i),
})
}
}

struct NonLocalStripper<'tcx> {
tcx: TyCtxt<'tcx>,
}

impl<'tcx> DocFolder for NonLocalStripper<'tcx> {
fn fold_item(&mut self, i: Item) -> Option<Item> {
// If not local, we want to respect the original visibility of
// the field and not the one given by the user for the currrent crate.
//
// FIXME(#125009): Not-local should probably consider same Cargo workspace
if !i.def_id().map_or(true, |did| did.is_local()) {
if i.visibility(self.tcx) != Some(Visibility::Public) || i.is_doc_hidden() {
return Some(strip_item(i));
}
}

Some(self.fold_item_recur(i))
}
}
2 changes: 0 additions & 2 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,13 @@ run-make/rlib-format-packed-bundled-libs-3/Makefile
run-make/rlib-format-packed-bundled-libs/Makefile
run-make/rmeta-preferred/Makefile
run-make/rustc-macro-dep-files/Makefile
run-make/rustdoc-io-error/Makefile
run-make/rustdoc-scrape-examples-invalid-expr/Makefile
run-make/rustdoc-scrape-examples-macros/Makefile
run-make/rustdoc-scrape-examples-multiple/Makefile
run-make/rustdoc-scrape-examples-ordering/Makefile
run-make/rustdoc-scrape-examples-remap/Makefile
run-make/rustdoc-scrape-examples-test/Makefile
run-make/rustdoc-scrape-examples-whitespace/Makefile
run-make/rustdoc-shared-flags/Makefile
run-make/rustdoc-target-spec-json-path/Makefile
run-make/rustdoc-themes/Makefile
run-make/rustdoc-verify-output-files/Makefile
Expand Down
20 changes: 0 additions & 20 deletions tests/run-make/rustdoc-io-error/Makefile

This file was deleted.

32 changes: 32 additions & 0 deletions tests/run-make/rustdoc-io-error/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// This test verifies that rustdoc doesn't ICE when it encounters an IO error
// while generating files. Ideally this would be a rustdoc-ui test, so we could
// verify the error message as well.
//
// It operates by creating a temporary directory and modifying its
// permissions so that it is not writable. We have to take special care to set
// the permissions back to normal so that it's able to be deleted later.

use run_make_support::{rustdoc, tmp_dir};
use std::fs;

fn main() {
let out_dir = tmp_dir().join("rustdoc-io-error");
let output = fs::create_dir(&out_dir).unwrap();
let mut permissions = fs::metadata(&out_dir).unwrap().permissions();
permissions.set_readonly(true);
fs::set_permissions(&out_dir, permissions.clone()).unwrap();

let output = rustdoc().input("foo.rs").output(&out_dir).command_output();

// Changing back permissions.
permissions.set_readonly(false);
fs::set_permissions(&out_dir, permissions).unwrap();

// Checks that rustdoc failed with the error code 1.
#[cfg(unix)]
assert_eq!(output.status.code().unwrap(), 1);
assert!(!output.status.success());
let stderr = String::from_utf8(output.stderr).unwrap();

assert!(stderr.contains("error: couldn't generate documentation: Permission denied"));
}
18 changes: 0 additions & 18 deletions tests/run-make/rustdoc-shared-flags/Makefile

This file was deleted.

14 changes: 14 additions & 0 deletions tests/run-make/rustdoc-shared-flags/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use run_make_support::{rustc, rustdoc, Diff};

fn compare_outputs(args: &[&str]) {
let rustc_output = String::from_utf8(rustc().args(args).command_output().stdout).unwrap();
let rustdoc_output = String::from_utf8(rustdoc().args(args).command_output().stdout).unwrap();

Diff::new().expected_text("rustc", rustc_output).actual_text("rustdoc", rustdoc_output).run();
}

fn main() {
compare_outputs(&["-C", "help"]);
compare_outputs(&["-Z", "help"]);
compare_outputs(&["-C", "passes=list"]);
}
2 changes: 2 additions & 0 deletions tests/rustdoc-ui/issues/issue-91713.stdout
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Available passes for running rustdoc:
check-custom-code-classes - check for custom code classes without the feature-gate enabled
check_doc_test_visibility - run various visibility-related lints on doctests
strip-aliased-non-local - strips all non-local private aliased items from the output
strip-hidden - strips all `#[doc(hidden)]` items from the output
strip-private - strips all private items from a crate which cannot be seen externally, implies strip-priv-imports
strip-priv-imports - strips all private import statements (`use`, `extern crate`) from a crate
Expand All @@ -14,6 +15,7 @@ Default passes for rustdoc:
check-custom-code-classes
collect-trait-impls
check_doc_test_visibility
strip-aliased-non-local
strip-hidden (when not --document-hidden-items)
strip-private (when not --document-private-items)
strip-priv-imports (when --document-private-items)
Expand Down
11 changes: 11 additions & 0 deletions tests/rustdoc/private-non-local-fields-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! This test makes sure that with never show the inner fields in the
//! aliased type view of type alias.

//@ compile-flags: -Z unstable-options --document-private-items

#![crate_name = "foo"]

use std::collections::BTreeMap;

// @has 'foo/type.FooBar.html' '//*[@class="rust item-decl"]/code' 'struct FooBar { /* private fields */ }'
pub type FooBar = BTreeMap<u32, String>;
Loading

0 comments on commit 61241e8

Please sign in to comment.