Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #59715

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5c1cd6c
Update cargo
dtolnay Apr 3, 2019
a37c33b
Mark unix::ffi::OsStrExt methods as inline
KamilaBorowska Apr 4, 2019
a964921
Use declare_lint_pass! and impl_lint_pass! in more places
hgallagher1993 Apr 4, 2019
d6b91fe
Update cargo
dtolnay Apr 4, 2019
1bf04c9
std: Upgrade `compiler_builtins` to fix wasi linkage
alexcrichton Apr 2, 2019
7994197
Make FnBox a subtrait of FnOnce.
qnighy Oct 28, 2018
059ec76
Add Fn* blanket impls for Box.
qnighy Oct 28, 2018
480dcb4
Add tests for boxed_closure_impls.
qnighy Oct 28, 2018
219097e
Add unstable-book articles on fnbox and boxed_closure_impls.
qnighy Oct 28, 2018
e55d82c
Fix expectations on some ui tests involving FnOnce.
qnighy Oct 28, 2018
4dcd6cc
Fix failing tests.
qnighy Feb 3, 2019
a38f292
We already have unsized_locals in stage0.
qnighy Feb 10, 2019
45c0b28
Remove FnBox specialization of impl FnOnce for Box<impl FnOnce>.
qnighy Feb 11, 2019
ecc3e89
Stabilize boxed_closure_impls in 1.35.0.
crlf0710 Feb 11, 2019
440e873
Simplify fnbox docs.
qnighy Feb 11, 2019
7a63c7f
Add ignore to doc code
qnighy Feb 11, 2019
471db2b
wasm32: Default to a "static" relocation model
alexcrichton Apr 4, 2019
8c0e786
Rollup merge of #59500 - crlf0710:boxed-closure-impls, r=cramertj
Centril Apr 5, 2019
1f05de7
Rollup merge of #59643 - alexcrichton:wasi-symbols, r=sanxiyn
Centril Apr 5, 2019
bc995f4
Rollup merge of #59681 - dtolnay:cargo, r=alexcrichton
Centril Apr 5, 2019
6070d47
Rollup merge of #59690 - xfix:patch-17, r=cramertj
Centril Apr 5, 2019
3600e4d
Rollup merge of #59702 - hgallagher1993:origin, r=Centril
Centril Apr 5, 2019
c03fa7b
Rollup merge of #59712 - alexcrichton:wasm-static-not-pic, r=eddyb
Centril Apr 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies = [
name = "alloc"
version = "0.0.0"
dependencies = [
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
"rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_xorshift 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -107,7 +107,7 @@ version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-std-workspace-core 1.0.0",
]
Expand Down Expand Up @@ -465,7 +465,7 @@ dependencies = [

[[package]]
name = "compiler_builtins"
version = "0.1.8"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -751,7 +751,7 @@ name = "dlmalloc"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-std-workspace-core 1.0.0",
]
Expand Down Expand Up @@ -917,7 +917,7 @@ name = "fortanix-sgx-abi"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-std-workspace-core 1.0.0",
]

Expand Down Expand Up @@ -1769,7 +1769,7 @@ dependencies = [
name = "panic_abort"
version = "0.0.0"
dependencies = [
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
]
Expand All @@ -1779,7 +1779,7 @@ name = "panic_unwind"
version = "0.0.0"
dependencies = [
"alloc 0.0.0",
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
"unwind 0.0.0",
Expand Down Expand Up @@ -1964,7 +1964,7 @@ name = "profiler_builtins"
version = "0.0.0"
dependencies = [
"cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
]

Expand Down Expand Up @@ -2479,7 +2479,7 @@ name = "rustc-demangle"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-std-workspace-core 1.0.0",
]

Expand Down Expand Up @@ -2579,7 +2579,7 @@ dependencies = [
"alloc 0.0.0",
"build_helper 0.1.0",
"cmake 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
]

Expand Down Expand Up @@ -2806,7 +2806,7 @@ dependencies = [
"alloc 0.0.0",
"build_helper 0.1.0",
"cmake 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
]

Expand Down Expand Up @@ -2868,7 +2868,7 @@ dependencies = [
"alloc 0.0.0",
"build_helper 0.1.0",
"cmake 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
]

Expand Down Expand Up @@ -2989,7 +2989,7 @@ dependencies = [
"alloc 0.0.0",
"build_helper 0.1.0",
"cmake 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
]

Expand Down Expand Up @@ -3256,7 +3256,7 @@ dependencies = [
"alloc 0.0.0",
"backtrace-sys 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
"dlmalloc 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"fortanix-sgx-abi 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -3830,7 +3830,7 @@ name = "unwind"
version = "0.0.0"
dependencies = [
"cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
"core 0.0.0",
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
]
Expand Down Expand Up @@ -4026,7 +4026,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b0aa3473e85a3161b59845d6096b289bb577874cafeaf75ea1b1beaa6572c7fc"
"checksum commoncrypto 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d056a8586ba25a1e4d61cb090900e495952c7886786fc55f909ab2f819b69007"
"checksum commoncrypto-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1fed34f46747aa73dfaa578069fd8279d2818ade2b55f38f22a9401c7f4083e2"
"checksum compiler_builtins 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "a28c3898d0c57b26fa6f92de141ba665fa5ac5179f795db06db408be84302395"
"checksum compiler_builtins 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "d7de11892d9f9f1bc76d43011c8233d27d58300d629dc9dfb51b6626ef7f6077"
"checksum compiletest_rs 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "56c799b1f7142badf3b047b4c1f2074cc96b6b784fb2432f2ed9c87da0a03749"
"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e"
"checksum core-foundation 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4e2640d6d0bf22e82bed1b73c6aef8d5dd31e5abe6666c57e6d45e2649f4f887"
Expand Down
32 changes: 32 additions & 0 deletions src/doc/unstable-book/src/library-features/fnbox.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# `fnbox`

The tracking issue for this feature is [#28796]

[#28796]: https://github.com/rust-lang/rust/issues/28796

------------------------

This had been a temporary alternative to the following impls:

```rust,ignore
impl<A, F> FnOnce for Box<F> where F: FnOnce<A> + ?Sized {}
impl<A, F> FnMut for Box<F> where F: FnMut<A> + ?Sized {}
impl<A, F> Fn for Box<F> where F: Fn<A> + ?Sized {}
```

The impls are parallel to these (relatively old) impls:

```rust,ignore
impl<A, F> FnOnce for &mut F where F: FnMut<A> + ?Sized {}
impl<A, F> FnMut for &mut F where F: FnMut<A> + ?Sized {}
impl<A, F> Fn for &mut F where F: Fn<A> + ?Sized {}
impl<A, F> FnOnce for &F where F: Fn<A> + ?Sized {}
impl<A, F> FnMut for &F where F: Fn<A> + ?Sized {}
impl<A, F> Fn for &F where F: Fn<A> + ?Sized {}
```

Before the introduction of [`unsized_locals`][unsized_locals], we had been unable to provide the former impls. That means, unlike `&dyn Fn()` or `&mut dyn FnMut()` we could not use `Box<dyn FnOnce()>` at that time.

[unsized_locals]: language-features/unsized-locals.html

`FnBox()` is an alternative approach to `Box<dyn FnBox()>` is delegated to `FnBox::call_box` which doesn't need unsized locals. As we now have `Box<dyn FnOnce()>` working, the `fnbox` feature is going to be removed.
48 changes: 23 additions & 25 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,28 @@ impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I> {
#[stable(feature = "fused", since = "1.26.0")]
impl<I: FusedIterator + ?Sized> FusedIterator for Box<I> {}

#[stable(feature = "boxed_closure_impls", since = "1.35.0")]
impl<A, F: FnOnce<A> + ?Sized> FnOnce<A> for Box<F> {
type Output = <F as FnOnce<A>>::Output;

extern "rust-call" fn call_once(self, args: A) -> Self::Output {
<F as FnOnce<A>>::call_once(*self, args)
}
}

#[stable(feature = "boxed_closure_impls", since = "1.35.0")]
impl<A, F: FnMut<A> + ?Sized> FnMut<A> for Box<F> {
extern "rust-call" fn call_mut(&mut self, args: A) -> Self::Output {
<F as FnMut<A>>::call_mut(self, args)
}
}

#[stable(feature = "boxed_closure_impls", since = "1.35.0")]
impl<A, F: Fn<A> + ?Sized> Fn<A> for Box<F> {
extern "rust-call" fn call(&self, args: A) -> Self::Output {
<F as Fn<A>>::call(self, args)
}
}

/// `FnBox` is a version of the `FnOnce` intended for use with boxed
/// closure objects. The idea is that where one would normally store a
Expand Down Expand Up @@ -735,9 +757,7 @@ impl<I: FusedIterator + ?Sized> FusedIterator for Box<I> {}
#[rustc_paren_sugar]
#[unstable(feature = "fnbox",
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
pub trait FnBox<A> {
type Output;

pub trait FnBox<A>: FnOnce<A> {
fn call_box(self: Box<Self>, args: A) -> Self::Output;
}

Expand All @@ -746,33 +766,11 @@ pub trait FnBox<A> {
impl<A, F> FnBox<A> for F
where F: FnOnce<A>
{
type Output = F::Output;

fn call_box(self: Box<F>, args: A) -> F::Output {
self.call_once(args)
}
}

#[unstable(feature = "fnbox",
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
impl<A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + '_> {
type Output = R;

extern "rust-call" fn call_once(self, args: A) -> R {
self.call_box(args)
}
}

#[unstable(feature = "fnbox",
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
impl<A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + Send + '_> {
type Output = R;

extern "rust-call" fn call_once(self, args: A) -> R {
self.call_box(args)
}
}

#[unstable(feature = "coerce_unsized", issue = "27732")]
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}

Expand Down
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
#![feature(unboxed_closures)]
#![feature(unicode_internals)]
#![feature(unsize)]
#![feature(unsized_locals)]
#![feature(allocator_internals)]
#![feature(on_unimplemented)]
#![feature(rustc_const_unstable)]
Expand Down
22 changes: 2 additions & 20 deletions src/librustc/lint/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,7 @@ impl DefaultHashTypes {
}
}

impl LintPass for DefaultHashTypes {
fn get_lints(&self) -> LintArray {
lint_array!(DEFAULT_HASH_TYPES)
}

fn name(&self) -> &'static str {
"DefaultHashTypes"
}
}
impl_lint_pass!(DefaultHashTypes => [DEFAULT_HASH_TYPES]);

impl EarlyLintPass for DefaultHashTypes {
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: Ident) {
Expand Down Expand Up @@ -68,17 +60,7 @@ declare_lint! {
"Usage of `ty::TyKind` outside of the `ty::sty` module"
}

pub struct TyKindUsage;

impl LintPass for TyKindUsage {
fn get_lints(&self) -> LintArray {
lint_array!(USAGE_OF_TY_TYKIND)
}

fn name(&self) -> &'static str {
"TyKindUsage"
}
}
declare_lint_pass!(TyKindUsage => [USAGE_OF_TY_TYKIND]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyKindUsage {
fn check_path(&mut self, cx: &LateContext<'_, '_>, path: &'tcx Path, _: HirId) {
Expand Down
9 changes: 9 additions & 0 deletions src/librustc_target/spec/wasm32_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ pub fn options() -> TargetOptions {

pre_link_args,

// This has no effect in LLVM 8 or prior, but in LLVM 9 and later when
// PIC code is implemented this has quite a drastric effect if it stays
// at the default, `pic`. In an effort to keep wasm binaries as minimal
// as possible we're defaulting to `static` for now, but the hope is
// that eventually we can ship a `pic`-compatible standard library which
// works with `static` as well (or works with some method of generating
// non-relative calls and such later on).
relocation_model: "static".to_string(),

.. Default::default()
}
}
2 changes: 1 addition & 1 deletion src/libstd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ panic_unwind = { path = "../libpanic_unwind", optional = true }
panic_abort = { path = "../libpanic_abort" }
core = { path = "../libcore" }
libc = { version = "0.2.51", default-features = false, features = ['rustc-dep-of-std'] }
compiler_builtins = { version = "0.1.8" }
compiler_builtins = { version = "0.1.9" }
profiler_builtins = { path = "../libprofiler_builtins", optional = true }
unwind = { path = "../libunwind" }
rustc-demangle = { version = "0.1.10", features = ['rustc-dep-of-std'] }
Expand Down
1 change: 1 addition & 0 deletions src/libstd/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ impl IntoInner<Buf> for OsString {
}

impl AsInner<Slice> for OsStr {
#[inline]
fn as_inner(&self) -> &Slice {
&self.inner
}
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/sys_common/os_str_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,11 @@ pub trait OsStrExt {

#[stable(feature = "rust1", since = "1.0.0")]
impl OsStrExt for OsStr {
#[inline]
fn from_bytes(slice: &[u8]) -> &OsStr {
unsafe { mem::transmute(slice) }
}
#[inline]
fn as_bytes(&self) -> &[u8] {
&self.as_inner().inner
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/run-pass/unsized-locals/box-fnonce.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn call_it<T>(f: Box<dyn FnOnce() -> T>) -> T {
f()
}

fn main() {
let s = "hello".to_owned();
assert_eq!(&call_it(Box::new(|| s)) as &str, "hello");
}
12 changes: 12 additions & 0 deletions src/test/run-pass/unsized-locals/fnbox-compat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![feature(fnbox)]

use std::boxed::FnBox;

fn call_it<T>(f: Box<dyn FnBox() -> T>) -> T {
f()
}

fn main() {
let s = "hello".to_owned();
assert_eq!(&call_it(Box::new(|| s)) as &str, "hello");
}
Loading