Skip to content

Commit fe03fb9

Browse files
committed
Auto merge of #125028 - matthiaskrgr:rollup-3qk782d, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #124096 (Clean up users of rust_dbg_call) - #124829 (Enable profiler for armv7-unknown-linux-gnueabihf.) - #124939 (Always hide private fields in aliased type) - #124963 (Migrate `run-make/rustdoc-shared-flags` to rmake) - #124981 (Relax allocator requirements on some Rc/Arc APIs.) - #125008 (Add test for #122775) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 78a7751 + d2b0555 commit fe03fb9

File tree

20 files changed

+205
-209
lines changed

20 files changed

+205
-209
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

-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ run-make/rustdoc-scrape-examples-ordering/Makefile
252252
run-make/rustdoc-scrape-examples-remap/Makefile
253253
run-make/rustdoc-scrape-examples-test/Makefile
254254
run-make/rustdoc-scrape-examples-whitespace/Makefile
255-
run-make/rustdoc-shared-flags/Makefile
256255
run-make/rustdoc-target-spec-json-path/Makefile
257256
run-make/rustdoc-themes/Makefile
258257
run-make/rustdoc-verify-output-files/Makefile

tests/auxiliary/rust_test_helpers.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ rust_dbg_extern_identity_u8(char u) {
2727
return u;
2828
}
2929

30-
typedef void *(*dbg_callback)(void*);
30+
typedef uint64_t (*dbg_callback)(uint64_t);
3131

32-
void *
33-
rust_dbg_call(dbg_callback cb, void *data) {
32+
uint64_t
33+
rust_dbg_call(dbg_callback cb, uint64_t data) {
3434
return cb(data);
3535
}
3636

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>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//! This test makes sure that with never show the inner fields in the
2+
//! aliased type view of type alias.
3+
4+
#![crate_name = "foo"]
5+
6+
use std::collections::BTreeMap;
7+
8+
// @has 'foo/type.FooBar.html' '//*[@class="rust item-decl"]/code' 'struct FooBar { /* private fields */ }'
9+
pub type FooBar = BTreeMap<u32, String>;
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
#![crate_name = "externcallback"]
22
#![crate_type = "lib"]
3-
#![feature(rustc_private)]
43

5-
extern crate libc;
6-
7-
pub mod rustrt {
8-
extern crate libc;
9-
10-
#[link(name = "rust_test_helpers", kind = "static")]
11-
extern "C" {
12-
pub fn rust_dbg_call(
13-
cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
14-
data: libc::uintptr_t,
15-
) -> libc::uintptr_t;
16-
}
4+
#[link(name = "rust_test_helpers", kind = "static")]
5+
extern "C" {
6+
pub fn rust_dbg_call(
7+
cb: extern "C" fn(u64) -> u64,
8+
data: u64,
9+
) -> u64;
1710
}
1811

19-
pub fn fact(n: libc::uintptr_t) -> libc::uintptr_t {
12+
pub fn fact(n: u64) -> u64 {
2013
unsafe {
2114
println!("n = {}", n);
22-
rustrt::rust_dbg_call(cb, n)
15+
rust_dbg_call(cb, n)
2316
}
2417
}
2518

26-
pub extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
19+
pub extern "C" fn cb(data: u64) -> u64 {
2720
if data == 1 { data } else { fact(data - 1) * data }
2821
}

0 commit comments

Comments
 (0)