diff options
| author | bors <bors@rust-lang.org> | 2019-10-24 03:38:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-10-24 03:38:57 +0000 |
| commit | 55e00631e5bc5b16d40232914e57deeea197a8e4 (patch) | |
| tree | aa2b50a73237dd118df3faef760be2bf3dd7723f /src/libcore | |
| parent | 4a8c5b20c7772bc5342b83d4b0696ea216ef75a7 (diff) | |
| parent | 3cd7a1740692ec34825d916550141b299caf458b (diff) | |
Auto merge of #65733 - Centril:rollup-0zth66f, r=Centril
Rollup of 12 pull requests
Successful merges:
- #64178 (More Clippy fixes for alloc, core and std)
- #65144 (Add Cow::is_borrowed and Cow::is_owned)
- #65193 (Lockless LintStore)
- #65479 (Add the `matches!( $expr, $pat ) -> bool` macro)
- #65518 (Avoid ICE when checking `Destination` of `break` inside a closure)
- #65583 (rustc_metadata: use a table for super_predicates, fn_sig, impl_trait_ref.)
- #65641 (Derive `Rustc{En,De}codable` for `TokenStream`.)
- #65648 (Eliminate `intersect_opt`.)
- #65657 (Remove `InternedString`)
- #65691 (Update E0659 error code long explanation to 2018 edition)
- #65696 (Fix an issue with const inference variables sticking around under Chalk + NLL)
- #65704 (relax ExactSizeIterator bound on write_bytes)
Failed merges:
r? @ghost
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/fmt/mod.rs | 2 | ||||
| -rw-r--r-- | src/libcore/macros.rs | 27 | ||||
| -rw-r--r-- | src/libcore/num/dec2flt/algorithm.rs | 9 | ||||
| -rw-r--r-- | src/libcore/option.rs | 5 |
4 files changed, 34 insertions, 9 deletions
diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 8413b2e0ac4..0e83a282b18 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -2025,7 +2025,7 @@ impl<T: ?Sized> Pointer for *const T { if f.alternate() { f.flags |= 1 << (FlagV1::SignAwareZeroPad as u32); - if let None = f.width { + if f.width.is_none() { f.width = Some(((mem::size_of::<usize>() * 8) / 4) + 2); } } diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 1320e63df06..35558e3abcd 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -238,6 +238,33 @@ macro_rules! debug_assert_ne { ($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_ne!($($arg)*); }) } +/// Returns whether the given expression matches any of the given patterns. +/// +/// Like in a `match` expression, the pattern can be optionally followed by `if` +/// and a guard expression that has access to names bound by the pattern. +/// +/// # Examples +/// +/// ``` +/// #![feature(matches_macro)] +/// +/// let foo = 'f'; +/// assert!(matches!(foo, 'A'..='Z' | 'a'..='z')); +/// +/// let bar = Some(4); +/// assert!(matches!(bar, Some(x) if x > 2)); +/// ``` +#[macro_export] +#[unstable(feature = "matches_macro", issue = "65721")] +macro_rules! matches { + ($expression:expr, $( $pattern:pat )|+ $( if $guard: expr )?) => { + match $expression { + $( $pattern )|+ $( if $guard )? => true, + _ => false + } + } +} + /// Unwraps a result or propagates its error. /// /// The `?` operator was added to replace `try!` and should be used instead. diff --git a/src/libcore/num/dec2flt/algorithm.rs b/src/libcore/num/dec2flt/algorithm.rs index fa3c8075378..ed89852dc48 100644 --- a/src/libcore/num/dec2flt/algorithm.rs +++ b/src/libcore/num/dec2flt/algorithm.rs @@ -143,13 +143,12 @@ pub fn fast_path<T: RawFloat>(integral: &[u8], fractional: &[u8], e: i64) -> Opt /// > not a bound for the true error, but bounds the difference between the approximation z and /// > the best possible approximation that uses p bits of significand.) pub fn bellerophon<T: RawFloat>(f: &Big, e: i16) -> T { - let slop; - if f <= &Big::from_u64(T::MAX_SIG) { + let slop = if f <= &Big::from_u64(T::MAX_SIG) { // The cases abs(e) < log5(2^N) are in fast_path() - slop = if e >= 0 { 0 } else { 3 }; + if e >= 0 { 0 } else { 3 } } else { - slop = if e >= 0 { 1 } else { 4 }; - } + if e >= 0 { 1 } else { 4 } + }; let z = rawfp::big_to_fp(f).mul(&power_of_ten(e)).normalize(); let exp_p_n = 1 << (P - T::SIG_BITS as u32); let lowbits: i64 = (z.f % exp_p_n) as i64; diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 9eb29eae7f7..89f2d7ab29c 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -837,9 +837,8 @@ impl<T> Option<T> { #[inline] #[stable(feature = "option_entry", since = "1.20.0")] pub fn get_or_insert_with<F: FnOnce() -> T>(&mut self, f: F) -> &mut T { - match *self { - None => *self = Some(f()), - _ => (), + if let None = *self { + *self = Some(f()); } match *self { |
