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 10 pull requests #75474

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
165a6e5
Fix wasi::fs::OpenOptions to imply write when append is on
kawamuray Aug 5, 2020
8a4fecb
Fix some Clippy warnings in librustc_serialize
hirrolot Aug 5, 2020
5b8e177
Create lang item array and add map fn
JulianKnodt Aug 6, 2020
3a5fe37
Add drop guard
JulianKnodt Aug 6, 2020
1d768db
Add Array Impl Lang Item in various places
JulianKnodt Aug 6, 2020
2183237
Swap order of forget
JulianKnodt Aug 6, 2020
946233c
Add recommend changes to array
JulianKnodt Aug 6, 2020
94ec272
Update w/ pickfire's review
JulianKnodt Aug 7, 2020
664e456
Add suggestions from lcnr
JulianKnodt Aug 7, 2020
b7c33ac
Add tracking issue #75243
JulianKnodt Aug 7, 2020
751bdb8
Add note & example about iter order
JulianKnodt Aug 7, 2020
bac7182
Add doc changes
JulianKnodt Aug 7, 2020
43c76d1
Update doc comments
JulianKnodt Aug 7, 2020
48733b4
Rm hiding feature gate & add 1 more example
JulianKnodt Aug 8, 2020
cd5654e
`#[deny(unsafe_op_in_unsafe_fn)]` in sys/cloudabi
Aug 2, 2020
92ac60d
Update order docs for `map`
JulianKnodt Aug 11, 2020
709d105
Fix minor things in the `f32` primitive docs
LukasKalbertodt Aug 11, 2020
0f7205f
Fix suggestion to use lifetime in type
estebank Aug 10, 2020
7956b1c
Assoc `const`s don't have generics
estebank Aug 10, 2020
b9585fd
When suggesting `for` lts, consider existing lifetime names
estebank Aug 10, 2020
becd479
review comment: simplify code by using slice pat
estebank Aug 11, 2020
6a3deb0
Suggest using `'static` in assoc consts and suggest when multiple lts…
estebank Aug 11, 2020
7291c6d
Update cargo
ehuss Aug 11, 2020
1902983
Move forge platform-support to the rustc book.
ehuss Aug 11, 2020
392116e
Platform Support page updates.
ehuss Aug 11, 2020
ffda53f
merge `as_local_hir_id` with `local_def_id_to_hir_id`
lcnr Aug 12, 2020
0d6ff99
add regression test for #74739 (mir const-prop bug)
RalfJung Aug 12, 2020
ce71747
Add a script to verify the Platform Support page is up-to-date.
ehuss Aug 11, 2020
8e3e270
Add drop check test & MaybeUninit::first_ptr_mut
JulianKnodt Aug 11, 2020
29f508e
Rollup merge of #75115 - chansuke:sys-cloudabi-unsafe, r=KodrAus
Dylan-DPC Aug 13, 2020
bdde294
Rollup merge of #75189 - kawamuray:bugfix-wasi-append, r=KodrAus
Dylan-DPC Aug 13, 2020
0b08283
Rollup merge of #75201 - Hirrolot:hirrolot/fix-clippy-warnings, r=varkor
Dylan-DPC Aug 13, 2020
52995c6
Rollup merge of #75212 - JulianKnodt:array_map, r=LukasKalbertodt
Dylan-DPC Aug 13, 2020
a025fc3
Rollup merge of #75372 - estebank:lt-sugg-in-type, r=lcnr
Dylan-DPC Aug 13, 2020
757d85f
Rollup merge of #75400 - LukasKalbertodt:fix-f32-docs, r=KodrAus
Dylan-DPC Aug 13, 2020
b89f252
Rollup merge of #75426 - ehuss:update-cargo, r=ehuss
Dylan-DPC Aug 13, 2020
2013e11
Rollup merge of #75431 - ehuss:platform-support, r=Mark-Simulacrum
Dylan-DPC Aug 13, 2020
8cb3a0e
Rollup merge of #75448 - lcnr:rn-as_local_hir_id, r=davidtwco
Dylan-DPC Aug 13, 2020
efc4776
Rollup merge of #75449 - RalfJung:const-prop-test, r=wesleywiser
Dylan-DPC Aug 13, 2020
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
4 changes: 4 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4624,6 +4624,10 @@ dependencies = [
"walkdir",
]

[[package]]
name = "tier-check"
version = "0.1.0"

[[package]]
name = "time"
version = "0.1.42"
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"src/tools/rustbook",
"src/tools/unstable-book-gen",
"src/tools/tidy",
"src/tools/tier-check",
"src/tools/build-manifest",
"src/tools/remote-test-client",
"src/tools/remote-test-server",
Expand Down
63 changes: 63 additions & 0 deletions library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,66 @@ macro_rules! array_impl_default {
}

array_impl_default! {32, T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T}

#[cfg(not(bootstrap))]
#[lang = "array"]
impl<T, const N: usize> [T; N] {
/// Returns an array of the same size as `self`, with function `f` applied to each element
/// in order.
///
/// # Examples
///
/// ```
/// #![feature(array_map)]
/// let x = [1, 2, 3];
/// let y = x.map(|v| v + 1);
/// assert_eq!(y, [2, 3, 4]);
///
/// let x = [1, 2, 3];
/// let mut temp = 0;
/// let y = x.map(|v| { temp += 1; v * temp });
/// assert_eq!(y, [1, 4, 9]);
///
/// let x = ["Ferris", "Bueller's", "Day", "Off"];
/// let y = x.map(|v| v.len());
/// assert_eq!(y, [6, 9, 3, 3]);
/// ```
#[unstable(feature = "array_map", issue = "75243")]
pub fn map<F, U>(self, mut f: F) -> [U; N]
where
F: FnMut(T) -> U,
{
use crate::mem::MaybeUninit;
struct Guard<T, const N: usize> {
dst: *mut T,
initialized: usize,
}

impl<T, const N: usize> Drop for Guard<T, N> {
fn drop(&mut self) {
debug_assert!(self.initialized <= N);

let initialized_part =
crate::ptr::slice_from_raw_parts_mut(self.dst, self.initialized);
// SAFETY: this raw slice will contain only initialized objects
// that's why, it is allowed to drop it.
unsafe {
crate::ptr::drop_in_place(initialized_part);
}
}
}
let mut dst = MaybeUninit::uninit_array::<N>();
let mut guard: Guard<U, N> =
Guard { dst: MaybeUninit::first_ptr_mut(&mut dst), initialized: 0 };
for (src, dst) in IntoIter::new(self).zip(&mut dst) {
dst.write(f(src));
guard.initialized += 1;
}
// FIXME: Convert to crate::mem::transmute once it works with generics.
// unsafe { crate::mem::transmute::<[MaybeUninit<U>; N], [U; N]>(dst) }
crate::mem::forget(guard);
// SAFETY: At this point we've properly initialized the whole array
// and we just need to cast it to the correct type.
unsafe { (&mut dst as *mut _ as *mut [U; N]).read() }
}
}
1 change: 1 addition & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
#![feature(abi_unadjusted)]
#![feature(adx_target_feature)]
#![feature(maybe_uninit_slice)]
#![feature(maybe_uninit_extra)]
#![feature(external_doc)]
#![feature(associated_type_bounds)]
#![feature(const_caller_location)]
Expand Down
39 changes: 39 additions & 0 deletions library/core/tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,42 @@ fn empty_array_is_always_default() {

let _arr = <[DoesNotImplDefault; 0]>::default();
}

#[test]
fn array_map() {
let a = [1, 2, 3];
let b = a.map(|v| v + 1);
assert_eq!(b, [2, 3, 4]);

let a = [1u8, 2, 3];
let b = a.map(|v| v as u64);
assert_eq!(b, [1, 2, 3]);
}

#[test]
fn array_map_drop_safety() {
use core::sync::atomic::AtomicUsize;
use core::sync::atomic::Ordering;
static DROPPED: AtomicUsize = AtomicUsize::new(0);
struct DropCounter;
impl Drop for DropCounter {
fn drop(&mut self) {
DROPPED.fetch_add(1, Ordering::SeqCst);
}
}

let num_to_create = 5;
let success = std::panic::catch_unwind(|| {
let items = [0; 10];
let mut nth = 0;
items.map(|_| {
if nth == num_to_create {
panic!("Oh no!");
}
nth += 1;
DropCounter
});
});
assert!(success.is_err());
assert_eq!(DROPPED.load(Ordering::SeqCst), num_to_create);
}
1 change: 1 addition & 0 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![feature(alloc_layout_extra)]
#![feature(array_chunks)]
#![feature(array_map)]
#![feature(bool_to_option)]
#![feature(bound_cloned)]
#![feature(box_syntax)]
Expand Down
8 changes: 3 additions & 5 deletions library/std/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,8 @@ mod prim_tuple {}
///
/// This type can represent a wide range of decimal numbers, like `3.5`, `27`,
/// `-113.75`, `0.0078125`, `34359738368`, `0`, `-1`. So unlike integer types
/// (like `i32`), floating point types can represent non-integer numbers, too.
/// (such as `i32`), floating point types can represent non-integer numbers,
/// too.
///
/// However, being able to represent this wide range of numbers comes at the
/// cost of precision: floats can only represent some of the real numbers and
Expand All @@ -779,15 +780,12 @@ mod prim_tuple {}
/// often discard insignificant digits: `println!("{}", 1.0f32 / 5.0f32)` will
/// print `0.2`.
///
/// The precision is better for numbers near 0 and worse for large numbers. For
/// example, above 2<sup>24</sup>, not even all integers are representable.
///
/// Additionally, `f32` can represent a couple of special values:
///
/// - `-0`: this is just due to how floats are encoded. It is semantically
/// equivalent to `0` and `-0.0 == 0.0` results in `true`.
/// - [∞](#associatedconstant.INFINITY) and
/// [-∞](#associatedconstant.NEG_INFINITY): these result from calculations
/// [∞](#associatedconstant.NEG_INFINITY): these result from calculations
/// like `1.0 / 0.0`.
/// - [NaN (not a number)](#associatedconstant.NAN): this value results from
/// calculations like `(-1.0).sqrt()`. NaN has some potentially unexpected
Expand Down
Loading