Skip to content

Commit 22855c5

Browse files
committed
Merge branch 'master' into no-unpin-in-pin-future-impl
2 parents 945d38c + 85bea49 commit 22855c5

File tree

327 files changed

+6685
-3845
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

327 files changed

+6685
-3845
lines changed

Diff for: alloc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ edition = "2018"
1111

1212
[dependencies]
1313
core = { path = "../core" }
14-
compiler_builtins = { version = "0.1.39", features = ['rustc-dep-of-std'] }
14+
compiler_builtins = { version = "0.1.40", features = ['rustc-dep-of-std'] }
1515

1616
[dev-dependencies]
1717
rand = "0.7"

Diff for: alloc/benches/vec.rs

+25-69
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,13 @@ use test::{black_box, Bencher};
44

55
#[bench]
66
fn bench_new(b: &mut Bencher) {
7-
b.iter(|| {
8-
let v: Vec<u32> = Vec::new();
9-
assert_eq!(v.len(), 0);
10-
assert_eq!(v.capacity(), 0);
11-
v
12-
})
7+
b.iter(|| Vec::<u32>::new())
138
}
149

1510
fn do_bench_with_capacity(b: &mut Bencher, src_len: usize) {
1611
b.bytes = src_len as u64;
1712

18-
b.iter(|| {
19-
let v: Vec<u32> = Vec::with_capacity(src_len);
20-
assert_eq!(v.len(), 0);
21-
assert_eq!(v.capacity(), src_len);
22-
v
23-
})
13+
b.iter(|| Vec::<u32>::with_capacity(src_len))
2414
}
2515

2616
#[bench]
@@ -46,12 +36,7 @@ fn bench_with_capacity_1000(b: &mut Bencher) {
4636
fn do_bench_from_fn(b: &mut Bencher, src_len: usize) {
4737
b.bytes = src_len as u64;
4838

49-
b.iter(|| {
50-
let dst = (0..src_len).collect::<Vec<_>>();
51-
assert_eq!(dst.len(), src_len);
52-
assert!(dst.iter().enumerate().all(|(i, x)| i == *x));
53-
dst
54-
})
39+
b.iter(|| (0..src_len).collect::<Vec<_>>())
5540
}
5641

5742
#[bench]
@@ -77,12 +62,7 @@ fn bench_from_fn_1000(b: &mut Bencher) {
7762
fn do_bench_from_elem(b: &mut Bencher, src_len: usize) {
7863
b.bytes = src_len as u64;
7964

80-
b.iter(|| {
81-
let dst: Vec<usize> = repeat(5).take(src_len).collect();
82-
assert_eq!(dst.len(), src_len);
83-
assert!(dst.iter().all(|x| *x == 5));
84-
dst
85-
})
65+
b.iter(|| repeat(5).take(src_len).collect::<Vec<usize>>())
8666
}
8767

8868
#[bench]
@@ -110,12 +90,7 @@ fn do_bench_from_slice(b: &mut Bencher, src_len: usize) {
11090

11191
b.bytes = src_len as u64;
11292

113-
b.iter(|| {
114-
let dst = src.clone()[..].to_vec();
115-
assert_eq!(dst.len(), src_len);
116-
assert!(dst.iter().enumerate().all(|(i, x)| i == *x));
117-
dst
118-
});
93+
b.iter(|| src.as_slice().to_vec());
11994
}
12095

12196
#[bench]
@@ -144,9 +119,7 @@ fn do_bench_from_iter(b: &mut Bencher, src_len: usize) {
144119
b.bytes = src_len as u64;
145120

146121
b.iter(|| {
147-
let dst: Vec<_> = FromIterator::from_iter(src.clone());
148-
assert_eq!(dst.len(), src_len);
149-
assert!(dst.iter().enumerate().all(|(i, x)| i == *x));
122+
let dst: Vec<_> = FromIterator::from_iter(src.iter().cloned());
150123
dst
151124
});
152125
}
@@ -180,8 +153,6 @@ fn do_bench_extend(b: &mut Bencher, dst_len: usize, src_len: usize) {
180153
b.iter(|| {
181154
let mut dst = dst.clone();
182155
dst.extend(src.clone());
183-
assert_eq!(dst.len(), dst_len + src_len);
184-
assert!(dst.iter().enumerate().all(|(i, x)| i == *x));
185156
dst
186157
});
187158
}
@@ -230,8 +201,6 @@ fn do_bench_extend_from_slice(b: &mut Bencher, dst_len: usize, src_len: usize) {
230201
b.iter(|| {
231202
let mut dst = dst.clone();
232203
dst.extend_from_slice(&src);
233-
assert_eq!(dst.len(), dst_len + src_len);
234-
assert!(dst.iter().enumerate().all(|(i, x)| i == *x));
235204
dst
236205
});
237206
}
@@ -290,12 +259,7 @@ fn do_bench_clone(b: &mut Bencher, src_len: usize) {
290259

291260
b.bytes = src_len as u64;
292261

293-
b.iter(|| {
294-
let dst = src.clone();
295-
assert_eq!(dst.len(), src_len);
296-
assert!(dst.iter().enumerate().all(|(i, x)| i == *x));
297-
dst
298-
});
262+
b.iter(|| src.clone());
299263
}
300264

301265
#[bench]
@@ -329,8 +293,7 @@ fn do_bench_clone_from(b: &mut Bencher, times: usize, dst_len: usize, src_len: u
329293

330294
for _ in 0..times {
331295
dst.clone_from(&src);
332-
assert_eq!(dst.len(), src_len);
333-
assert!(dst.iter().enumerate().all(|(i, x)| dst_len + i == *x));
296+
dst = black_box(dst);
334297
}
335298
dst
336299
});
@@ -463,11 +426,10 @@ macro_rules! bench_in_place {
463426
fn $fname(b: &mut Bencher) {
464427
b.iter(|| {
465428
let src: Vec<$type> = black_box(vec![$init; $count]);
466-
let mut sink = src.into_iter()
429+
src.into_iter()
467430
.enumerate()
468431
.map(|(idx, e)| idx as $type ^ e)
469-
.collect::<Vec<$type>>();
470-
black_box(sink.as_mut_ptr())
432+
.collect::<Vec<$type>>()
471433
});
472434
}
473435
)+
@@ -506,7 +468,6 @@ fn bench_in_place_recycle(b: &mut Bencher) {
506468
.enumerate()
507469
.map(|(idx, e)| idx.wrapping_add(e))
508470
.fuse()
509-
.peekable()
510471
.collect::<Vec<usize>>(),
511472
);
512473
});
@@ -527,7 +488,6 @@ fn bench_in_place_zip_recycle(b: &mut Bencher) {
527488
.enumerate()
528489
.map(|(i, (d, s))| d.wrapping_add(i as u8) ^ s)
529490
.collect::<Vec<_>>();
530-
assert_eq!(mangled.len(), 1000);
531491
data = black_box(mangled);
532492
});
533493
}
@@ -614,23 +574,6 @@ fn bench_nest_chain_chain_collect(b: &mut Bencher) {
614574
});
615575
}
616576

617-
pub fn example_plain_slow(l: &[u32]) -> Vec<u32> {
618-
let mut result = Vec::with_capacity(l.len());
619-
result.extend(l.iter().rev());
620-
result
621-
}
622-
623-
pub fn map_fast(l: &[(u32, u32)]) -> Vec<u32> {
624-
let mut result = Vec::with_capacity(l.len());
625-
for i in 0..l.len() {
626-
unsafe {
627-
*result.get_unchecked_mut(i) = l[i].0;
628-
result.set_len(i);
629-
}
630-
}
631-
result
632-
}
633-
634577
#[bench]
635578
fn bench_range_map_collect(b: &mut Bencher) {
636579
b.iter(|| (0..LEN).map(|_| u32::default()).collect::<Vec<_>>());
@@ -669,7 +612,11 @@ fn bench_rev_1(b: &mut Bencher) {
669612
#[bench]
670613
fn bench_rev_2(b: &mut Bencher) {
671614
let data = black_box([0; LEN]);
672-
b.iter(|| example_plain_slow(&data));
615+
b.iter(|| {
616+
let mut v = Vec::<u32>::with_capacity(data.len());
617+
v.extend(data.iter().rev());
618+
v
619+
});
673620
}
674621

675622
#[bench]
@@ -685,7 +632,16 @@ fn bench_map_regular(b: &mut Bencher) {
685632
#[bench]
686633
fn bench_map_fast(b: &mut Bencher) {
687634
let data = black_box([(0, 0); LEN]);
688-
b.iter(|| map_fast(&data));
635+
b.iter(|| {
636+
let mut result = Vec::with_capacity(data.len());
637+
for i in 0..data.len() {
638+
unsafe {
639+
*result.get_unchecked_mut(i) = data[i].0;
640+
result.set_len(i);
641+
}
642+
}
643+
result
644+
});
689645
}
690646

691647
fn random_sorted_fill(mut seed: u32, buf: &mut [u32]) {

Diff for: alloc/src/alloc.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ unsafe impl Allocator for Global {
308308

309309
/// The allocator for unique pointers.
310310
// This function must not unwind. If it does, MIR codegen will fail.
311-
#[cfg(not(test))]
311+
#[cfg(all(not(no_global_oom_handling), not(test)))]
312312
#[lang = "exchange_malloc"]
313313
#[inline]
314314
unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
@@ -337,6 +337,7 @@ pub(crate) unsafe fn box_free<T: ?Sized, A: Allocator>(ptr: Unique<T>, alloc: A)
337337

338338
// # Allocation error handler
339339

340+
#[cfg(not(no_global_oom_handling))]
340341
extern "Rust" {
341342
// This is the magic symbol to call the global alloc error handler. rustc generates
342343
// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the
@@ -358,7 +359,7 @@ extern "Rust" {
358359
/// [`set_alloc_error_hook`]: ../../std/alloc/fn.set_alloc_error_hook.html
359360
/// [`take_alloc_error_hook`]: ../../std/alloc/fn.take_alloc_error_hook.html
360361
#[stable(feature = "global_alloc", since = "1.28.0")]
361-
#[cfg(not(test))]
362+
#[cfg(all(not(no_global_oom_handling), not(test)))]
362363
#[rustc_allocator_nounwind]
363364
#[cold]
364365
pub fn handle_alloc_error(layout: Layout) -> ! {
@@ -368,10 +369,10 @@ pub fn handle_alloc_error(layout: Layout) -> ! {
368369
}
369370

370371
// For alloc test `std::alloc::handle_alloc_error` can be used directly.
371-
#[cfg(test)]
372+
#[cfg(all(not(no_global_oom_handling), test))]
372373
pub use std::alloc::handle_alloc_error;
373374

374-
#[cfg(not(any(target_os = "hermit", test)))]
375+
#[cfg(all(not(no_global_oom_handling), not(any(target_os = "hermit", test))))]
375376
#[doc(hidden)]
376377
#[allow(unused_attributes)]
377378
#[unstable(feature = "alloc_internals", issue = "none")]

Diff for: alloc/src/borrow.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
use core::cmp::Ordering;
66
use core::hash::{Hash, Hasher};
7-
use core::ops::{Add, AddAssign, Deref};
7+
use core::ops::Deref;
8+
#[cfg(not(no_global_oom_handling))]
9+
use core::ops::{Add, AddAssign};
810

911
#[stable(feature = "rust1", since = "1.0.0")]
1012
pub use core::borrow::{Borrow, BorrowMut};
1113

1214
use crate::fmt;
15+
#[cfg(not(no_global_oom_handling))]
1316
use crate::string::String;
1417

1518
use Cow::*;
@@ -429,6 +432,7 @@ impl<T: ?Sized + ToOwned> AsRef<T> for Cow<'_, T> {
429432
}
430433
}
431434

435+
#[cfg(not(no_global_oom_handling))]
432436
#[stable(feature = "cow_add", since = "1.14.0")]
433437
impl<'a> Add<&'a str> for Cow<'a, str> {
434438
type Output = Cow<'a, str>;
@@ -440,6 +444,7 @@ impl<'a> Add<&'a str> for Cow<'a, str> {
440444
}
441445
}
442446

447+
#[cfg(not(no_global_oom_handling))]
443448
#[stable(feature = "cow_add", since = "1.14.0")]
444449
impl<'a> Add<Cow<'a, str>> for Cow<'a, str> {
445450
type Output = Cow<'a, str>;
@@ -451,6 +456,7 @@ impl<'a> Add<Cow<'a, str>> for Cow<'a, str> {
451456
}
452457
}
453458

459+
#[cfg(not(no_global_oom_handling))]
454460
#[stable(feature = "cow_add", since = "1.14.0")]
455461
impl<'a> AddAssign<&'a str> for Cow<'a, str> {
456462
fn add_assign(&mut self, rhs: &'a str) {
@@ -467,6 +473,7 @@ impl<'a> AddAssign<&'a str> for Cow<'a, str> {
467473
}
468474
}
469475

476+
#[cfg(not(no_global_oom_handling))]
470477
#[stable(feature = "cow_add", since = "1.14.0")]
471478
impl<'a> AddAssign<Cow<'a, str>> for Cow<'a, str> {
472479
fn add_assign(&mut self, rhs: Cow<'a, str>) {

0 commit comments

Comments
 (0)