Skip to content

Commit 61241e8

Browse files
committed
Auto merge of rust-lang#125020 - GuillaumeGomez:rollup-3vxwqef, r=GuillaumeGomez
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
2 parents 3349155 + 9d1cff1 commit 61241e8

File tree

14 files changed

+181
-73
lines changed

14 files changed

+181
-73
lines changed

library/alloc/src/rc.rs

+24-25
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
365365
unsafe { self.ptr.as_ref() }
366366
}
367367

368+
#[inline]
369+
fn into_inner_with_allocator(this: Self) -> (NonNull<RcBox<T>>, A) {
370+
let this = mem::ManuallyDrop::new(this);
371+
(this.ptr, unsafe { ptr::read(&this.alloc) })
372+
}
373+
368374
#[inline]
369375
unsafe fn from_inner_in(ptr: NonNull<RcBox<T>>, alloc: A) -> Self {
370376
Self { ptr, phantom: PhantomData, alloc }
@@ -1145,12 +1151,9 @@ impl<T, A: Allocator> Rc<mem::MaybeUninit<T>, A> {
11451151
/// ```
11461152
#[unstable(feature = "new_uninit", issue = "63291")]
11471153
#[inline]
1148-
pub unsafe fn assume_init(self) -> Rc<T, A>
1149-
where
1150-
A: Clone,
1151-
{
1152-
let md_self = mem::ManuallyDrop::new(self);
1153-
unsafe { Rc::from_inner_in(md_self.ptr.cast(), md_self.alloc.clone()) }
1154+
pub unsafe fn assume_init(self) -> Rc<T, A> {
1155+
let (ptr, alloc) = Rc::into_inner_with_allocator(self);
1156+
unsafe { Rc::from_inner_in(ptr.cast(), alloc) }
11541157
}
11551158
}
11561159

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

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

1814+
impl<T: Clone, A: Allocator> Rc<T, A> {
18131815
/// If we have the only reference to `T` then unwrap it. Otherwise, clone `T` and return the
18141816
/// clone.
18151817
///
@@ -1845,7 +1847,7 @@ impl<T: Clone, A: Allocator + Clone> Rc<T, A> {
18451847
}
18461848
}
18471849

1848-
impl<A: Allocator + Clone> Rc<dyn Any, A> {
1850+
impl<A: Allocator> Rc<dyn Any, A> {
18491851
/// Attempt to downcast the `Rc<dyn Any>` to a concrete type.
18501852
///
18511853
/// # Examples
@@ -1869,10 +1871,8 @@ impl<A: Allocator + Clone> Rc<dyn Any, A> {
18691871
pub fn downcast<T: Any>(self) -> Result<Rc<T, A>, Self> {
18701872
if (*self).is::<T>() {
18711873
unsafe {
1872-
let ptr = self.ptr.cast::<RcBox<T>>();
1873-
let alloc = self.alloc.clone();
1874-
forget(self);
1875-
Ok(Rc::from_inner_in(ptr, alloc))
1874+
let (ptr, alloc) = Rc::into_inner_with_allocator(self);
1875+
Ok(Rc::from_inner_in(ptr.cast(), alloc))
18761876
}
18771877
} else {
18781878
Err(self)
@@ -1909,10 +1909,8 @@ impl<A: Allocator + Clone> Rc<dyn Any, A> {
19091909
#[unstable(feature = "downcast_unchecked", issue = "90850")]
19101910
pub unsafe fn downcast_unchecked<T: Any>(self) -> Rc<T, A> {
19111911
unsafe {
1912-
let ptr = self.ptr.cast::<RcBox<T>>();
1913-
let alloc = self.alloc.clone();
1914-
mem::forget(self);
1915-
Rc::from_inner_in(ptr, alloc)
1912+
let (ptr, alloc) = Rc::into_inner_with_allocator(self);
1913+
Rc::from_inner_in(ptr.cast(), alloc)
19161914
}
19171915
}
19181916
}
@@ -2661,12 +2659,13 @@ impl From<Rc<str>> for Rc<[u8]> {
26612659
}
26622660

26632661
#[stable(feature = "boxed_slice_try_from", since = "1.43.0")]
2664-
impl<T, const N: usize> TryFrom<Rc<[T]>> for Rc<[T; N]> {
2665-
type Error = Rc<[T]>;
2662+
impl<T, A: Allocator, const N: usize> TryFrom<Rc<[T], A>> for Rc<[T; N], A> {
2663+
type Error = Rc<[T], A>;
26662664

2667-
fn try_from(boxed_slice: Rc<[T]>) -> Result<Self, Self::Error> {
2665+
fn try_from(boxed_slice: Rc<[T], A>) -> Result<Self, Self::Error> {
26682666
if boxed_slice.len() == N {
2669-
Ok(unsafe { Rc::from_raw(Rc::into_raw(boxed_slice) as *mut [T; N]) })
2667+
let (ptr, alloc) = Rc::into_inner_with_allocator(boxed_slice);
2668+
Ok(unsafe { Rc::from_inner_in(ptr.cast(), alloc) })
26702669
} else {
26712670
Err(boxed_slice)
26722671
}

library/alloc/src/sync.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ impl<T: ?Sized> Arc<T> {
280280

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

@@ -1290,7 +1290,7 @@ impl<T, A: Allocator> Arc<mem::MaybeUninit<T>, A> {
12901290
#[must_use = "`self` will be dropped if the result is not used"]
12911291
#[inline]
12921292
pub unsafe fn assume_init(self) -> Arc<T, A> {
1293-
let (ptr, alloc) = self.internal_into_inner_with_allocator();
1293+
let (ptr, alloc) = Arc::into_inner_with_allocator(self);
12941294
unsafe { Arc::from_inner_in(ptr.cast(), alloc) }
12951295
}
12961296
}
@@ -1332,7 +1332,7 @@ impl<T, A: Allocator> Arc<[mem::MaybeUninit<T>], A> {
13321332
#[must_use = "`self` will be dropped if the result is not used"]
13331333
#[inline]
13341334
pub unsafe fn assume_init(self) -> Arc<[T], A> {
1335-
let (ptr, alloc) = self.internal_into_inner_with_allocator();
1335+
let (ptr, alloc) = Arc::into_inner_with_allocator(self);
13361336
unsafe { Arc::from_ptr_in(ptr.as_ptr() as _, alloc) }
13371337
}
13381338
}
@@ -2227,7 +2227,9 @@ impl<T: Clone, A: Allocator + Clone> Arc<T, A> {
22272227
// either unique to begin with, or became one upon cloning the contents.
22282228
unsafe { Self::get_mut_unchecked(this) }
22292229
}
2230+
}
22302231

2232+
impl<T: Clone, A: Allocator> Arc<T, A> {
22312233
/// If we have the only reference to `T` then unwrap it. Otherwise, clone `T` and return the
22322234
/// clone.
22332235
///
@@ -2499,7 +2501,7 @@ impl<A: Allocator> Arc<dyn Any + Send + Sync, A> {
24992501
{
25002502
if (*self).is::<T>() {
25012503
unsafe {
2502-
let (ptr, alloc) = self.internal_into_inner_with_allocator();
2504+
let (ptr, alloc) = Arc::into_inner_with_allocator(self);
25032505
Ok(Arc::from_inner_in(ptr.cast(), alloc))
25042506
}
25052507
} else {
@@ -2540,7 +2542,7 @@ impl<A: Allocator> Arc<dyn Any + Send + Sync, A> {
25402542
T: Any + Send + Sync,
25412543
{
25422544
unsafe {
2543-
let (ptr, alloc) = self.internal_into_inner_with_allocator();
2545+
let (ptr, alloc) = Arc::into_inner_with_allocator(self);
25442546
Arc::from_inner_in(ptr.cast(), alloc)
25452547
}
25462548
}
@@ -3506,7 +3508,7 @@ impl<T, A: Allocator, const N: usize> TryFrom<Arc<[T], A>> for Arc<[T; N], A> {
35063508

35073509
fn try_from(boxed_slice: Arc<[T], A>) -> Result<Self, Self::Error> {
35083510
if boxed_slice.len() == N {
3509-
let (ptr, alloc) = boxed_slice.internal_into_inner_with_allocator();
3511+
let (ptr, alloc) = Arc::into_inner_with_allocator(boxed_slice);
35103512
Ok(unsafe { Arc::from_inner_in(ptr.cast(), alloc) })
35113513
} else {
35123514
Err(boxed_slice)

src/ci/docker/host-x86_64/dist-armv7-linux/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ ENV CC_armv7_unknown_linux_gnueabihf=armv7-unknown-linux-gnueabihf-gcc \
2525

2626
ENV HOSTS=armv7-unknown-linux-gnueabihf
2727

28-
ENV RUST_CONFIGURE_ARGS --enable-full-tools --disable-docs
28+
ENV RUST_CONFIGURE_ARGS --enable-full-tools --enable-profiler --disable-docs
2929
ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS

src/librustdoc/passes/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use crate::core::DocContext;
88
mod stripper;
99
pub(crate) use stripper::*;
1010

11+
mod strip_aliased_non_local;
12+
pub(crate) use self::strip_aliased_non_local::STRIP_ALIASED_NON_LOCAL;
13+
1114
mod strip_hidden;
1215
pub(crate) use self::strip_hidden::STRIP_HIDDEN;
1316

@@ -71,6 +74,7 @@ pub(crate) enum Condition {
7174
pub(crate) const PASSES: &[Pass] = &[
7275
CHECK_CUSTOM_CODE_CLASSES,
7376
CHECK_DOC_TEST_VISIBILITY,
77+
STRIP_ALIASED_NON_LOCAL,
7478
STRIP_HIDDEN,
7579
STRIP_PRIVATE,
7680
STRIP_PRIV_IMPORTS,
@@ -86,6 +90,7 @@ pub(crate) const DEFAULT_PASSES: &[ConditionalPass] = &[
8690
ConditionalPass::always(CHECK_CUSTOM_CODE_CLASSES),
8791
ConditionalPass::always(COLLECT_TRAIT_IMPLS),
8892
ConditionalPass::always(CHECK_DOC_TEST_VISIBILITY),
93+
ConditionalPass::always(STRIP_ALIASED_NON_LOCAL),
8994
ConditionalPass::new(STRIP_HIDDEN, WhenNotDocumentHidden),
9095
ConditionalPass::new(STRIP_PRIVATE, WhenNotDocumentPrivate),
9196
ConditionalPass::new(STRIP_PRIV_IMPORTS, WhenDocumentPrivate),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use rustc_middle::ty::TyCtxt;
2+
use rustc_middle::ty::Visibility;
3+
4+
use crate::clean;
5+
use crate::clean::Item;
6+
use crate::core::DocContext;
7+
use crate::fold::{strip_item, DocFolder};
8+
use crate::passes::Pass;
9+
10+
pub(crate) const STRIP_ALIASED_NON_LOCAL: Pass = Pass {
11+
name: "strip-aliased-non-local",
12+
run: strip_aliased_non_local,
13+
description: "strips all non-local private aliased items from the output",
14+
};
15+
16+
fn strip_aliased_non_local(krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate {
17+
let mut stripper = AliasedNonLocalStripper { tcx: cx.tcx };
18+
stripper.fold_crate(krate)
19+
}
20+
21+
struct AliasedNonLocalStripper<'tcx> {
22+
tcx: TyCtxt<'tcx>,
23+
}
24+
25+
impl<'tcx> DocFolder for AliasedNonLocalStripper<'tcx> {
26+
fn fold_item(&mut self, i: Item) -> Option<Item> {
27+
Some(match *i.kind {
28+
clean::TypeAliasItem(..) => {
29+
let mut stripper = NonLocalStripper { tcx: self.tcx };
30+
// don't call `fold_item` as that could strip the type-alias it-self
31+
// which we don't want to strip out
32+
stripper.fold_item_recur(i)
33+
}
34+
_ => self.fold_item_recur(i),
35+
})
36+
}
37+
}
38+
39+
struct NonLocalStripper<'tcx> {
40+
tcx: TyCtxt<'tcx>,
41+
}
42+
43+
impl<'tcx> DocFolder for NonLocalStripper<'tcx> {
44+
fn fold_item(&mut self, i: Item) -> Option<Item> {
45+
// If not local, we want to respect the original visibility of
46+
// the field and not the one given by the user for the currrent crate.
47+
//
48+
// FIXME(#125009): Not-local should probably consider same Cargo workspace
49+
if !i.def_id().map_or(true, |did| did.is_local()) {
50+
if i.visibility(self.tcx) != Some(Visibility::Public) || i.is_doc_hidden() {
51+
return Some(strip_item(i));
52+
}
53+
}
54+
55+
Some(self.fold_item_recur(i))
56+
}
57+
}

src/tools/tidy/src/allowed_run_make_makefiles.txt

-2
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,13 @@ run-make/rlib-format-packed-bundled-libs-3/Makefile
244244
run-make/rlib-format-packed-bundled-libs/Makefile
245245
run-make/rmeta-preferred/Makefile
246246
run-make/rustc-macro-dep-files/Makefile
247-
run-make/rustdoc-io-error/Makefile
248247
run-make/rustdoc-scrape-examples-invalid-expr/Makefile
249248
run-make/rustdoc-scrape-examples-macros/Makefile
250249
run-make/rustdoc-scrape-examples-multiple/Makefile
251250
run-make/rustdoc-scrape-examples-ordering/Makefile
252251
run-make/rustdoc-scrape-examples-remap/Makefile
253252
run-make/rustdoc-scrape-examples-test/Makefile
254253
run-make/rustdoc-scrape-examples-whitespace/Makefile
255-
run-make/rustdoc-shared-flags/Makefile
256254
run-make/rustdoc-target-spec-json-path/Makefile
257255
run-make/rustdoc-themes/Makefile
258256
run-make/rustdoc-verify-output-files/Makefile

tests/run-make/rustdoc-io-error/Makefile

-20
This file was deleted.
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// This test verifies that rustdoc doesn't ICE when it encounters an IO error
2+
// while generating files. Ideally this would be a rustdoc-ui test, so we could
3+
// verify the error message as well.
4+
//
5+
// It operates by creating a temporary directory and modifying its
6+
// permissions so that it is not writable. We have to take special care to set
7+
// the permissions back to normal so that it's able to be deleted later.
8+
9+
use run_make_support::{rustdoc, tmp_dir};
10+
use std::fs;
11+
12+
fn main() {
13+
let out_dir = tmp_dir().join("rustdoc-io-error");
14+
let output = fs::create_dir(&out_dir).unwrap();
15+
let mut permissions = fs::metadata(&out_dir).unwrap().permissions();
16+
permissions.set_readonly(true);
17+
fs::set_permissions(&out_dir, permissions.clone()).unwrap();
18+
19+
let output = rustdoc().input("foo.rs").output(&out_dir).command_output();
20+
21+
// Changing back permissions.
22+
permissions.set_readonly(false);
23+
fs::set_permissions(&out_dir, permissions).unwrap();
24+
25+
// Checks that rustdoc failed with the error code 1.
26+
#[cfg(unix)]
27+
assert_eq!(output.status.code().unwrap(), 1);
28+
assert!(!output.status.success());
29+
let stderr = String::from_utf8(output.stderr).unwrap();
30+
31+
assert!(stderr.contains("error: couldn't generate documentation: Permission denied"));
32+
}

tests/run-make/rustdoc-shared-flags/Makefile

-18
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use run_make_support::{rustc, rustdoc, Diff};
2+
3+
fn compare_outputs(args: &[&str]) {
4+
let rustc_output = String::from_utf8(rustc().args(args).command_output().stdout).unwrap();
5+
let rustdoc_output = String::from_utf8(rustdoc().args(args).command_output().stdout).unwrap();
6+
7+
Diff::new().expected_text("rustc", rustc_output).actual_text("rustdoc", rustdoc_output).run();
8+
}
9+
10+
fn main() {
11+
compare_outputs(&["-C", "help"]);
12+
compare_outputs(&["-Z", "help"]);
13+
compare_outputs(&["-C", "passes=list"]);
14+
}

tests/rustdoc-ui/issues/issue-91713.stdout

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Available passes for running rustdoc:
22
check-custom-code-classes - check for custom code classes without the feature-gate enabled
33
check_doc_test_visibility - run various visibility-related lints on doctests
4+
strip-aliased-non-local - strips all non-local private aliased items from the output
45
strip-hidden - strips all `#[doc(hidden)]` items from the output
56
strip-private - strips all private items from a crate which cannot be seen externally, implies strip-priv-imports
67
strip-priv-imports - strips all private import statements (`use`, `extern crate`) from a crate
@@ -14,6 +15,7 @@ Default passes for rustdoc:
1415
check-custom-code-classes
1516
collect-trait-impls
1617
check_doc_test_visibility
18+
strip-aliased-non-local
1719
strip-hidden (when not --document-hidden-items)
1820
strip-private (when not --document-private-items)
1921
strip-priv-imports (when --document-private-items)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! This test makes sure that with never show the inner fields in the
2+
//! aliased type view of type alias.
3+
4+
//@ compile-flags: -Z unstable-options --document-private-items
5+
6+
#![crate_name = "foo"]
7+
8+
use std::collections::BTreeMap;
9+
10+
// @has 'foo/type.FooBar.html' '//*[@class="rust item-decl"]/code' 'struct FooBar { /* private fields */ }'
11+
pub type FooBar = BTreeMap<u32, String>;

0 commit comments

Comments
 (0)