Skip to content

Commit 7f19f16

Browse files
committed
Auto merge of #58669 - Centril:rollup, r=Centril
Rollup of 16 pull requests Successful merges: - #58100 (Transition librustdoc to Rust 2018) - #58122 (RangeInclusive internal iteration performance improvement.) - #58199 (Add better error message for partial move) - #58227 (Updated RELEASES.md for 1.33.0) - #58353 (Check the Self-type of inherent associated constants) - #58453 (SGX target: fix panic = abort) - #58476 (Remove `LazyTokenStream`.) - #58526 (Special suggestion for illegal unicode curly quote pairs) - #58595 (Turn duration consts into associated consts) - #58609 (Allow Self::Module to be mutated.) - #58628 (Optimise vec![false; N] to zero-alloc) - #58643 (Don't generate minification variables if minification disabled) - #58648 (Update tests to account for cross-platform testing and miri.) - #58654 (Do not underflow after resetting unmatched braces count) - #58658 (Add expected/provided byte alignments to validation error message) - #58667 (Reduce Miri-related Code Repetition `like (n << amt) >> amt`) Failed merges: r? @ghost
2 parents bcfb5e8 + a36d1b9 commit 7f19f16

File tree

94 files changed

+1125
-765
lines changed

Some content is hidden

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

94 files changed

+1125
-765
lines changed

RELEASES.md

+148
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,151 @@
1+
Version 1.33.0 (2019-02-28)
2+
==========================
3+
4+
Language
5+
--------
6+
- [You can now use the `cfg(target_vendor)` attribute.][57465] E.g.
7+
`#[cfg(target_vendor="linux")] fn main() { println!("Hello Linux!"); }`
8+
- [Integer patterns such as in a match expression can now be exhaustive.][56362]
9+
E.g. You can have match statement on a `u8` that covers `0..=255` and
10+
you would no longer be required to have a `_ => unreachable!()` case.
11+
- [You can now have multiple patterns in `if let` and `while let`
12+
expressions.][57532] You can do this with the same syntax as a `match`
13+
expression. E.g.
14+
```rust
15+
enum Creature {
16+
Crab(String),
17+
Lobster(String),
18+
Person(String),
19+
}
20+
21+
fn main() {
22+
let state = Creature::Crab("Ferris");
23+
24+
if let Creature::Crab(name) | Creature::Person(name) = state {
25+
println!("This creature's name is: {}", name);
26+
}
27+
}
28+
```
29+
- [You can now have irrefutable `if let` and `while let` patterns.][57535] Using
30+
this feature will by default produce a warning as this behaviour can be
31+
unintuitive. E.g. `if let _ = 5 {}`
32+
- [You can now use `let` bindings, assignments, expression statements,
33+
and irrefutable pattern destructuring in const functions.][57175]
34+
- [You can now call unsafe const functions.][57067] E.g.
35+
```rust
36+
const unsafe fn foo() -> i32 { 5 }
37+
const fn bar() -> i32 {
38+
unsafe { foo() }
39+
}
40+
```
41+
- [You can now specify multiple attributes in a `cfg_attr` attribute.][57332]
42+
E.g. `#[cfg_attr(all(), must_use, optimize)]`
43+
- [You can now specify a specific alignment with the `#[repr(packed)]`
44+
attribute.][57049] E.g. `#[repr(packed(2))] struct Foo(i16, i32);` is a struct
45+
with an alignment of 2 bytes and a size of 6 bytes.
46+
- [You can now import an item from a module as an `_`.][56303] This allows you to
47+
import a trait's impls, and not have the name in the namespace. E.g.
48+
```rust
49+
use std::io::Read as _;
50+
51+
// Allowed as there is only one `Read` in the module.
52+
pub trait Read {}
53+
```
54+
- [`extern` functions will now abort by default when panicking.][55982]
55+
This was previously undefined behaviour.
56+
57+
Compiler
58+
--------
59+
- [You can now set a linker flavor for `rustc` with the `-Clinker-flavor`
60+
command line argument.][56351]
61+
- [The mininum required LLVM version has been bumped to 6.0.][56642]
62+
- [Added support for the PowerPC64 architecture on FreeBSD.][57615]
63+
- [The `x86_64-fortanix-unknown-sgx` target support has been upgraded to
64+
tier 2 support.][57130] Visit the [platform support][platform-support] page for
65+
information on Rust's platform support.
66+
- [Added support for the `thumbv7neon-linux-androideabi` and
67+
`thumbv7neon-unknown-linux-gnueabihf` targets.][56947]
68+
- [Added support for the `x86_64-unknown-uefi` target.][56769]
69+
70+
Libraries
71+
---------
72+
- [The methods `overflowing_{add, sub, mul, shl, shr}` are now `const`
73+
functions for all numeric types.][57566]
74+
- [The methods `rotate_left`, `rotate_right`, and `wrapping_{add, sub, mul, shl, shr}`
75+
are now `const` functions for all numeric types.][57105]
76+
- [The methods `is_positive` and `is_negative` are now `const` functions for
77+
all signed numeric types.][57105]
78+
- [The `get` method for all `NonZero` types is now `const`.][57167]
79+
- [The methods `count_ones`, `count_zeros`, `leading_zeros`, `trailing_zeros`,
80+
`swap_bytes`, `from_be`, `from_le`, `to_be`, `to_le` are now `const` for all
81+
numeric types.][57234]
82+
- [`Ipv4Addr::new` is now a `const` function][57234]
83+
84+
Stabilized APIs
85+
---------------
86+
- [`unix::FileExt::read_exact_at`]
87+
- [`unix::FileExt::write_all_at`]
88+
- [`Option::transpose`]
89+
- [`Result::transpose`]
90+
- [`convert::identity`]
91+
- [`pin::Pin`]
92+
- [`marker::Unpin`]
93+
- [`marker::PhantomPinned`]
94+
- [`Vec::resize_with`]
95+
- [`VecDeque::resize_with`]
96+
- [`Duration::as_millis`]
97+
- [`Duration::as_micros`]
98+
- [`Duration::as_nanos`]
99+
100+
101+
Cargo
102+
-----
103+
- [Cargo should now rebuild a crate if a file was modified during the initial
104+
build.][cargo/6484]
105+
106+
Compatibility Notes
107+
-------------------
108+
- The methods `str::{trim_left, trim_right, trim_left_matches, trim_right_matches}`
109+
are now deprecated in the standard library, and their usage will now produce a warning.
110+
Please use the `str::{trim_start, trim_end, trim_start_matches, trim_end_matches}`
111+
methods instead.
112+
113+
[57615]: https://github.com/rust-lang/rust/pull/57615/
114+
[57465]: https://github.com/rust-lang/rust/pull/57465/
115+
[57532]: https://github.com/rust-lang/rust/pull/57532/
116+
[57535]: https://github.com/rust-lang/rust/pull/57535/
117+
[57566]: https://github.com/rust-lang/rust/pull/57566/
118+
[57130]: https://github.com/rust-lang/rust/pull/57130/
119+
[57167]: https://github.com/rust-lang/rust/pull/57167/
120+
[57175]: https://github.com/rust-lang/rust/pull/57175/
121+
[57234]: https://github.com/rust-lang/rust/pull/57234/
122+
[57332]: https://github.com/rust-lang/rust/pull/57332/
123+
[56947]: https://github.com/rust-lang/rust/pull/56947/
124+
[57049]: https://github.com/rust-lang/rust/pull/57049/
125+
[57067]: https://github.com/rust-lang/rust/pull/57067/
126+
[56769]: https://github.com/rust-lang/rust/pull/56769/
127+
[56642]: https://github.com/rust-lang/rust/pull/56642/
128+
[56303]: https://github.com/rust-lang/rust/pull/56303/
129+
[56351]: https://github.com/rust-lang/rust/pull/56351/
130+
[55982]: https://github.com/rust-lang/rust/pull/55982/
131+
[56362]: https://github.com/rust-lang/rust/pull/56362
132+
[57105]: https://github.com/rust-lang/rust/pull/57105
133+
[cargo/6484]: https://github.com/rust-lang/cargo/pull/6484/
134+
[`unix::FileExt::read_exact_at`]: https://doc.rust-lang.org/std/os/unix/fs/trait.FileExt.html#method.read_exact_at
135+
[`unix::FileExt::write_all_at`]: https://doc.rust-lang.org/std/os/unix/fs/trait.FileExt.html#method.write_all_at
136+
[`Option::transpose`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.transpose
137+
[`Result::transpose`]: https://doc.rust-lang.org/std/result/enum.Result.html#method.transpose
138+
[`convert::identity`]: https://doc.rust-lang.org/std/convert/fn.identity.html
139+
[`pin::Pin`]: https://doc.rust-lang.org/std/pin/struct.Pin.html
140+
[`marker::Unpin`]: https://doc.rust-lang.org/stable/std/marker/trait.Unpin.html
141+
[`marker::PhantomPinned`]: https://doc.rust-lang.org/nightly/std/marker/struct.PhantomPinned.html
142+
[`Vec::resize_with`]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.resize_with
143+
[`VecDeque::resize_with`]: https://doc.rust-lang.org/std/collections/struct.VecDeque.html#method.resize_with
144+
[`Duration::as_millis`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.as_millis
145+
[`Duration::as_micros`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.as_micros
146+
[`Duration::as_nanos`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.as_nanos
147+
[platform-support]: https://forge.rust-lang.org/platform-support.html
148+
1149
Version 1.32.0 (2019-01-17)
2150
==========================
3151

src/liballoc/vec.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,7 @@ impl_is_zero!(u64, |x| x == 0);
16101610
impl_is_zero!(u128, |x| x == 0);
16111611
impl_is_zero!(usize, |x| x == 0);
16121612

1613+
impl_is_zero!(bool, |x| x == false);
16131614
impl_is_zero!(char, |x| x == '\0');
16141615

16151616
impl_is_zero!(f32, |x: f32| x.to_bits() == 0);

src/libcore/iter/range.rs

+58-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use convert::TryFrom;
22
use mem;
3-
use ops::{self, Add, Sub};
3+
use ops::{self, Add, Sub, Try};
44
use usize;
55

66
use super::{FusedIterator, TrustedLen};
@@ -368,11 +368,11 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
368368
Some(Less) => {
369369
self.is_empty = Some(false);
370370
self.start = plus_n.add_one();
371-
return Some(plus_n)
371+
return Some(plus_n);
372372
}
373373
Some(Equal) => {
374374
self.is_empty = Some(true);
375-
return Some(plus_n)
375+
return Some(plus_n);
376376
}
377377
_ => {}
378378
}
@@ -382,6 +382,34 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
382382
None
383383
}
384384

385+
#[inline]
386+
fn try_fold<B, F, R>(&mut self, init: B, mut f: F) -> R
387+
where
388+
Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Ok=B>
389+
{
390+
self.compute_is_empty();
391+
392+
if self.is_empty() {
393+
return Try::from_ok(init);
394+
}
395+
396+
let mut accum = init;
397+
398+
while self.start < self.end {
399+
let n = self.start.add_one();
400+
let n = mem::replace(&mut self.start, n);
401+
accum = f(accum, n)?;
402+
}
403+
404+
self.is_empty = Some(true);
405+
406+
if self.start == self.end {
407+
accum = f(accum, self.start.clone())?;
408+
}
409+
410+
Try::from_ok(accum)
411+
}
412+
385413
#[inline]
386414
fn last(mut self) -> Option<A> {
387415
self.next_back()
@@ -415,6 +443,33 @@ impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> {
415443
self.end.clone()
416444
})
417445
}
446+
447+
#[inline]
448+
fn try_rfold<B, F, R>(&mut self, init: B, mut f: F) -> R where
449+
Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Ok=B>
450+
{
451+
self.compute_is_empty();
452+
453+
if self.is_empty() {
454+
return Try::from_ok(init);
455+
}
456+
457+
let mut accum = init;
458+
459+
while self.start < self.end {
460+
let n = self.end.sub_one();
461+
let n = mem::replace(&mut self.end, n);
462+
accum = f(accum, n)?;
463+
}
464+
465+
self.is_empty = Some(true);
466+
467+
if self.start == self.end {
468+
accum = f(accum, self.start.clone())?;
469+
}
470+
471+
Try::from_ok(accum)
472+
}
418473
}
419474

420475
#[stable(feature = "fused", since = "1.26.0")]

src/libcore/ops/range.rs

+2
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,14 @@ pub struct RangeInclusive<Idx> {
334334
trait RangeInclusiveEquality: Sized {
335335
fn canonicalized_is_empty(range: &RangeInclusive<Self>) -> bool;
336336
}
337+
337338
impl<T> RangeInclusiveEquality for T {
338339
#[inline]
339340
default fn canonicalized_is_empty(range: &RangeInclusive<Self>) -> bool {
340341
range.is_empty.unwrap_or_default()
341342
}
342343
}
344+
343345
impl<T: PartialOrd> RangeInclusiveEquality for T {
344346
#[inline]
345347
fn canonicalized_is_empty(range: &RangeInclusive<Self>) -> bool {

src/libcore/tests/iter.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -1741,19 +1741,37 @@ fn test_range_inclusive_folds() {
17411741
assert_eq!((1..=10).sum::<i32>(), 55);
17421742
assert_eq!((1..=10).rev().sum::<i32>(), 55);
17431743

1744-
let mut it = 40..=50;
1744+
let mut it = 44..=50;
17451745
assert_eq!(it.try_fold(0, i8::checked_add), None);
1746-
assert_eq!(it, 44..=50);
1746+
assert_eq!(it, 47..=50);
1747+
assert_eq!(it.try_fold(0, i8::checked_add), None);
1748+
assert_eq!(it, 50..=50);
1749+
assert_eq!(it.try_fold(0, i8::checked_add), Some(50));
1750+
assert!(it.is_empty());
1751+
assert_eq!(it.try_fold(0, i8::checked_add), Some(0));
1752+
assert!(it.is_empty());
1753+
1754+
let mut it = 40..=47;
1755+
assert_eq!(it.try_rfold(0, i8::checked_add), None);
1756+
assert_eq!(it, 40..=44);
17471757
assert_eq!(it.try_rfold(0, i8::checked_add), None);
1748-
assert_eq!(it, 44..=47);
1758+
assert_eq!(it, 40..=41);
1759+
assert_eq!(it.try_rfold(0, i8::checked_add), Some(81));
1760+
assert!(it.is_empty());
1761+
assert_eq!(it.try_rfold(0, i8::checked_add), Some(0));
1762+
assert!(it.is_empty());
17491763

17501764
let mut it = 10..=20;
17511765
assert_eq!(it.try_fold(0, |a,b| Some(a+b)), Some(165));
17521766
assert!(it.is_empty());
1767+
assert_eq!(it.try_fold(0, |a,b| Some(a+b)), Some(0));
1768+
assert!(it.is_empty());
17531769

17541770
let mut it = 10..=20;
17551771
assert_eq!(it.try_rfold(0, |a,b| Some(a+b)), Some(165));
17561772
assert!(it.is_empty());
1773+
assert_eq!(it.try_rfold(0, |a,b| Some(a+b)), Some(0));
1774+
assert!(it.is_empty());
17571775
}
17581776

17591777
#[test]

src/libcore/time.rs

+52-16
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,6 @@ const MILLIS_PER_SEC: u64 = 1_000;
2323
const MICROS_PER_SEC: u64 = 1_000_000;
2424
const MAX_NANOS_F64: f64 = ((u64::MAX as u128 + 1)*(NANOS_PER_SEC as u128)) as f64;
2525

26-
/// The duration of one second.
27-
#[unstable(feature = "duration_constants", issue = "57391")]
28-
pub const SECOND: Duration = Duration::from_secs(1);
29-
30-
/// The duration of one millisecond.
31-
#[unstable(feature = "duration_constants", issue = "57391")]
32-
pub const MILLISECOND: Duration = Duration::from_millis(1);
33-
34-
/// The duration of one microsecond.
35-
#[unstable(feature = "duration_constants", issue = "57391")]
36-
pub const MICROSECOND: Duration = Duration::from_micros(1);
37-
38-
/// The duration of one nanosecond.
39-
#[unstable(feature = "duration_constants", issue = "57391")]
40-
pub const NANOSECOND: Duration = Duration::from_nanos(1);
41-
4226
/// A `Duration` type to represent a span of time, typically used for system
4327
/// timeouts.
4428
///
@@ -75,6 +59,58 @@ pub struct Duration {
7559
}
7660

7761
impl Duration {
62+
/// The duration of one second.
63+
///
64+
/// # Examples
65+
///
66+
/// ```
67+
/// #![feature(duration_constants)]
68+
/// use std::time::Duration;
69+
///
70+
/// assert_eq!(Duration::SECOND, Duration::from_secs(1));
71+
/// ```
72+
#[unstable(feature = "duration_constants", issue = "57391")]
73+
pub const SECOND: Duration = Duration::from_secs(1);
74+
75+
/// The duration of one millisecond.
76+
///
77+
/// # Examples
78+
///
79+
/// ```
80+
/// #![feature(duration_constants)]
81+
/// use std::time::Duration;
82+
///
83+
/// assert_eq!(Duration::MILLISECOND, Duration::from_millis(1));
84+
/// ```
85+
#[unstable(feature = "duration_constants", issue = "57391")]
86+
pub const MILLISECOND: Duration = Duration::from_millis(1);
87+
88+
/// The duration of one microsecond.
89+
///
90+
/// # Examples
91+
///
92+
/// ```
93+
/// #![feature(duration_constants)]
94+
/// use std::time::Duration;
95+
///
96+
/// assert_eq!(Duration::MICROSECOND, Duration::from_micros(1));
97+
/// ```
98+
#[unstable(feature = "duration_constants", issue = "57391")]
99+
pub const MICROSECOND: Duration = Duration::from_micros(1);
100+
101+
/// The duration of one nanosecond.
102+
///
103+
/// # Examples
104+
///
105+
/// ```
106+
/// #![feature(duration_constants)]
107+
/// use std::time::Duration;
108+
///
109+
/// assert_eq!(Duration::NANOSECOND, Duration::from_nanos(1));
110+
/// ```
111+
#[unstable(feature = "duration_constants", issue = "57391")]
112+
pub const NANOSECOND: Duration = Duration::from_nanos(1);
113+
78114
/// Creates a new `Duration` from the specified number of whole seconds and
79115
/// additional nanoseconds.
80116
///

0 commit comments

Comments
 (0)