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
This commit is contained in:
commit
fe03fb9569
@ -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 }
|
||||
@ -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) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -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.
|
||||
///
|
||||
@ -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
|
||||
@ -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)
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
|
@ -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) })
|
||||
}
|
||||
|
||||
@ -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) }
|
||||
}
|
||||
}
|
||||
@ -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) }
|
||||
}
|
||||
}
|
||||
@ -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.
|
||||
///
|
||||
@ -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 {
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
@ -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,
|
||||
@ -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),
|
||||
|
57
src/librustdoc/passes/strip_aliased_non_local.rs
Normal file
57
src/librustdoc/passes/strip_aliased_non_local.rs
Normal file
@ -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))
|
||||
}
|
||||
}
|
@ -252,7 +252,6 @@ 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
|
||||
|
@ -27,10 +27,10 @@ rust_dbg_extern_identity_u8(char u) {
|
||||
return u;
|
||||
}
|
||||
|
||||
typedef void *(*dbg_callback)(void*);
|
||||
typedef uint64_t (*dbg_callback)(uint64_t);
|
||||
|
||||
void *
|
||||
rust_dbg_call(dbg_callback cb, void *data) {
|
||||
uint64_t
|
||||
rust_dbg_call(dbg_callback cb, uint64_t data) {
|
||||
return cb(data);
|
||||
}
|
||||
|
||||
|
@ -1,18 +0,0 @@
|
||||
include ../tools.mk
|
||||
|
||||
all: z_help c_help list_passes
|
||||
|
||||
c_help:
|
||||
$(RUSTC) -C help > $(TMPDIR)/rustc.c_help.txt
|
||||
$(RUSTDOC) -C help > $(TMPDIR)/rustdoc.c_help.txt
|
||||
$(DIFF) $(TMPDIR)/rustc.c_help.txt $(TMPDIR)/rustdoc.c_help.txt
|
||||
|
||||
z_help:
|
||||
$(RUSTC) -Z help > $(TMPDIR)/rustc.z_help.txt
|
||||
$(RUSTDOC) -Z help > $(TMPDIR)/rustdoc.z_help.txt
|
||||
$(DIFF) $(TMPDIR)/rustc.z_help.txt $(TMPDIR)/rustdoc.z_help.txt
|
||||
|
||||
list_passes:
|
||||
$(RUSTC) -C passes=list > $(TMPDIR)/rustc.passes.txt
|
||||
$(RUSTDOC) -C passes=list > $(TMPDIR)/rustdoc.passes.txt
|
||||
$(DIFF) $(TMPDIR)/rustc.passes.txt $(TMPDIR)/rustdoc.passes.txt
|
14
tests/run-make/rustdoc-shared-flags/rmake.rs
Normal file
14
tests/run-make/rustdoc-shared-flags/rmake.rs
Normal file
@ -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"]);
|
||||
}
|
@ -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
|
||||
@ -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)
|
||||
|
11
tests/rustdoc/private-non-local-fields-2.rs
Normal file
11
tests/rustdoc/private-non-local-fields-2.rs
Normal file
@ -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>;
|
9
tests/rustdoc/private-non-local-fields.rs
Normal file
9
tests/rustdoc/private-non-local-fields.rs
Normal file
@ -0,0 +1,9 @@
|
||||
//! This test makes sure that with never show the inner fields in the
|
||||
//! aliased type view of type alias.
|
||||
|
||||
#![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>;
|
@ -1,28 +1,21 @@
|
||||
#![crate_name = "externcallback"]
|
||||
#![crate_type = "lib"]
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
pub mod rustrt {
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern "C" {
|
||||
pub fn rust_dbg_call(
|
||||
cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
|
||||
data: libc::uintptr_t,
|
||||
) -> libc::uintptr_t;
|
||||
}
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern "C" {
|
||||
pub fn rust_dbg_call(
|
||||
cb: extern "C" fn(u64) -> u64,
|
||||
data: u64,
|
||||
) -> u64;
|
||||
}
|
||||
|
||||
pub fn fact(n: libc::uintptr_t) -> libc::uintptr_t {
|
||||
pub fn fact(n: u64) -> u64 {
|
||||
unsafe {
|
||||
println!("n = {}", n);
|
||||
rustrt::rust_dbg_call(cb, n)
|
||||
rust_dbg_call(cb, n)
|
||||
}
|
||||
}
|
||||
|
||||
pub extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
|
||||
pub extern "C" fn cb(data: u64) -> u64 {
|
||||
if data == 1 { data } else { fact(data - 1) * data }
|
||||
}
|
||||
|
28
tests/ui/abi/extern/extern-call-deep.rs
vendored
28
tests/ui/abi/extern/extern-call-deep.rs
vendored
@ -1,35 +1,27 @@
|
||||
//@ run-pass
|
||||
//@ ignore-emscripten blows the JS stack
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
mod rustrt {
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern "C" {
|
||||
pub fn rust_dbg_call(
|
||||
cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
|
||||
data: libc::uintptr_t,
|
||||
) -> libc::uintptr_t;
|
||||
}
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern "C" {
|
||||
pub fn rust_dbg_call(
|
||||
cb: extern "C" fn(u64) -> u64,
|
||||
data: u64,
|
||||
) -> u64;
|
||||
}
|
||||
|
||||
extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
|
||||
extern "C" fn cb(data: u64) -> u64 {
|
||||
if data == 1 { data } else { count(data - 1) + 1 }
|
||||
}
|
||||
|
||||
fn count(n: libc::uintptr_t) -> libc::uintptr_t {
|
||||
fn count(n: u64) -> u64 {
|
||||
unsafe {
|
||||
println!("n = {}", n);
|
||||
rustrt::rust_dbg_call(cb, n)
|
||||
rust_dbg_call(cb, n)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let result = count(1000);
|
||||
println!("result = {}", result);
|
||||
println!("result = {:?}", result);
|
||||
assert_eq!(result, 1000);
|
||||
}
|
||||
|
29
tests/ui/abi/extern/extern-call-deep2.rs
vendored
29
tests/ui/abi/extern/extern-call-deep2.rs
vendored
@ -1,31 +1,24 @@
|
||||
//@ run-pass
|
||||
#![allow(unused_must_use)]
|
||||
//@ needs-threads
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
use std::thread;
|
||||
|
||||
mod rustrt {
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern "C" {
|
||||
pub fn rust_dbg_call(
|
||||
cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
|
||||
data: libc::uintptr_t,
|
||||
) -> libc::uintptr_t;
|
||||
}
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern "C" {
|
||||
pub fn rust_dbg_call(
|
||||
cb: extern "C" fn(u64) -> u64,
|
||||
data: u64,
|
||||
) -> u64;
|
||||
}
|
||||
|
||||
extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
|
||||
if data == 1 { data } else { count(data - 1) + 1 }
|
||||
extern "C" fn cb(data: u64) -> u64 {
|
||||
if data == 1 { data } else { count(data - 1 ) + 1 }
|
||||
}
|
||||
|
||||
fn count(n: libc::uintptr_t) -> libc::uintptr_t {
|
||||
fn count(n: u64) -> u64 {
|
||||
unsafe {
|
||||
println!("n = {}", n);
|
||||
rustrt::rust_dbg_call(cb, n)
|
||||
rust_dbg_call(cb, n)
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,5 +30,5 @@ pub fn main() {
|
||||
println!("result = {}", result);
|
||||
assert_eq!(result, 1000);
|
||||
})
|
||||
.join();
|
||||
.join().unwrap();
|
||||
}
|
||||
|
26
tests/ui/abi/extern/extern-call-indirect.rs
vendored
26
tests/ui/abi/extern/extern-call-indirect.rs
vendored
@ -1,29 +1,21 @@
|
||||
//@ run-pass
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
mod rustrt {
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern "C" {
|
||||
pub fn rust_dbg_call(
|
||||
cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
|
||||
data: libc::uintptr_t,
|
||||
) -> libc::uintptr_t;
|
||||
}
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern "C" {
|
||||
pub fn rust_dbg_call(
|
||||
cb: extern "C" fn(u64) -> u64,
|
||||
data: u64,
|
||||
) -> u64;
|
||||
}
|
||||
|
||||
extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
|
||||
extern "C" fn cb(data: u64) -> u64 {
|
||||
if data == 1 { data } else { fact(data - 1) * data }
|
||||
}
|
||||
|
||||
fn fact(n: libc::uintptr_t) -> libc::uintptr_t {
|
||||
fn fact(n: u64) -> u64 {
|
||||
unsafe {
|
||||
println!("n = {}", n);
|
||||
rustrt::rust_dbg_call(cb, n)
|
||||
rust_dbg_call(cb, n)
|
||||
}
|
||||
}
|
||||
|
||||
|
30
tests/ui/abi/extern/extern-call-scrub.rs
vendored
30
tests/ui/abi/extern/extern-call-scrub.rs
vendored
@ -1,35 +1,27 @@
|
||||
//@ run-pass
|
||||
#![allow(unused_must_use)]
|
||||
//@ needs-threads
|
||||
// This time we're testing repeatedly going up and down both stacks to
|
||||
// make sure the stack pointers are maintained properly in both
|
||||
// directions
|
||||
|
||||
//@ needs-threads
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
use std::thread;
|
||||
|
||||
mod rustrt {
|
||||
extern crate libc;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern "C" {
|
||||
pub fn rust_dbg_call(
|
||||
cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
|
||||
data: libc::uintptr_t,
|
||||
) -> libc::uintptr_t;
|
||||
}
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern "C" {
|
||||
pub fn rust_dbg_call(
|
||||
cb: extern "C" fn(u64) -> u64,
|
||||
data: u64,
|
||||
) -> u64;
|
||||
}
|
||||
|
||||
extern "C" fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
|
||||
extern "C" fn cb(data: u64) -> u64 {
|
||||
if data == 1 { data } else { count(data - 1) + count(data - 1) }
|
||||
}
|
||||
|
||||
fn count(n: libc::uintptr_t) -> libc::uintptr_t {
|
||||
fn count(n: u64) -> u64 {
|
||||
unsafe {
|
||||
println!("n = {}", n);
|
||||
rustrt::rust_dbg_call(cb, n)
|
||||
rust_dbg_call(cb, n)
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,5 +33,5 @@ pub fn main() {
|
||||
println!("result = {}", result);
|
||||
assert_eq!(result, 2048);
|
||||
})
|
||||
.join();
|
||||
.join().unwrap();
|
||||
}
|
||||
|
9
tests/ui/abi/extern/extern-crosscrate.rs
vendored
9
tests/ui/abi/extern/extern-crosscrate.rs
vendored
@ -1,15 +1,12 @@
|
||||
//@ run-pass
|
||||
//@ aux-build:extern-crosscrate-source.rs
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate externcallback;
|
||||
extern crate libc;
|
||||
|
||||
fn fact(n: libc::uintptr_t) -> libc::uintptr_t {
|
||||
fn fact(n: u64) -> u64 {
|
||||
unsafe {
|
||||
println!("n = {}", n);
|
||||
externcallback::rustrt::rust_dbg_call(externcallback::cb, n)
|
||||
println!("n = {:?}", n);
|
||||
externcallback::rust_dbg_call(externcallback::cb, n)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,60 +0,0 @@
|
||||
//@ run-pass
|
||||
//@ needs-threads
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
use std::mem;
|
||||
use std::thread;
|
||||
|
||||
#[link(name = "rust_test_helpers", kind = "static")]
|
||||
extern "C" {
|
||||
fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t), data: libc::uintptr_t) -> libc::uintptr_t;
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
unsafe {
|
||||
thread::spawn(move || {
|
||||
let i: isize = 100;
|
||||
rust_dbg_call(callback_isize, mem::transmute(&i));
|
||||
})
|
||||
.join()
|
||||
.unwrap();
|
||||
|
||||
thread::spawn(move || {
|
||||
let i: i32 = 100;
|
||||
rust_dbg_call(callback_i32, mem::transmute(&i));
|
||||
})
|
||||
.join()
|
||||
.unwrap();
|
||||
|
||||
thread::spawn(move || {
|
||||
let i: i64 = 100;
|
||||
rust_dbg_call(callback_i64, mem::transmute(&i));
|
||||
})
|
||||
.join()
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn callback_isize(data: libc::uintptr_t) {
|
||||
unsafe {
|
||||
let data = data as *const isize;
|
||||
assert_eq!(*data, 100);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn callback_i64(data: libc::uintptr_t) {
|
||||
unsafe {
|
||||
let data = data as *const i64;
|
||||
assert_eq!(*data, 100);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn callback_i32(data: libc::uintptr_t) {
|
||||
unsafe {
|
||||
let data = data as *const i32;
|
||||
assert_eq!(*data, 100);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
//@ check-pass
|
||||
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
fn spawn<T, F>(future: F) -> impl Sized
|
||||
where
|
||||
F: FnOnce() -> T,
|
||||
{
|
||||
future
|
||||
}
|
||||
|
||||
fn spawn_task(sender: &'static ()) -> impl Sized {
|
||||
type Tait = impl Sized + 'static;
|
||||
spawn::<Tait, _>(move || sender)
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
x
Reference in New Issue
Block a user