Skip to content

Commit 55e0063

Browse files
committed
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
2 parents 4a8c5b2 + 3cd7a17 commit 55e0063

File tree

122 files changed

+1064
-1138
lines changed

Some content is hidden

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

122 files changed

+1064
-1138
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3483,6 +3483,7 @@ dependencies = [
34833483
"rustc_data_structures",
34843484
"rustc_errors",
34853485
"rustc_interface",
3486+
"rustc_lint",
34863487
"rustc_metadata",
34873488
"rustc_mir",
34883489
"rustc_plugin",

src/liballoc/borrow.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,47 @@ impl<B: ?Sized + ToOwned> Clone for Cow<'_, B> {
207207
}
208208

209209
impl<B: ?Sized + ToOwned> Cow<'_, B> {
210+
/// Returns true if the data is borrowed, i.e. if `to_mut` would require additional work.
211+
///
212+
/// # Examples
213+
///
214+
/// ```
215+
/// #![feature(cow_is_borrowed)]
216+
/// use std::borrow::Cow;
217+
///
218+
/// let cow = Cow::Borrowed("moo");
219+
/// assert!(cow.is_borrowed());
220+
///
221+
/// let bull: Cow<'_, str> = Cow::Owned("...moo?".to_string());
222+
/// assert!(!bull.is_borrowed());
223+
/// ```
224+
#[unstable(feature = "cow_is_borrowed", issue = "65143")]
225+
pub fn is_borrowed(&self) -> bool {
226+
match *self {
227+
Borrowed(_) => true,
228+
Owned(_) => false,
229+
}
230+
}
231+
232+
/// Returns true if the data is owned, i.e. if `to_mut` would be a no-op.
233+
///
234+
/// # Examples
235+
///
236+
/// ```
237+
/// #![feature(cow_is_borrowed)]
238+
/// use std::borrow::Cow;
239+
///
240+
/// let cow: Cow<'_, str> = Cow::Owned("moo".to_string());
241+
/// assert!(cow.is_owned());
242+
///
243+
/// let bull = Cow::Borrowed("...moo?");
244+
/// assert!(!bull.is_owned());
245+
/// ```
246+
#[unstable(feature = "cow_is_borrowed", issue = "65143")]
247+
pub fn is_owned(&self) -> bool {
248+
!self.is_borrowed()
249+
}
250+
210251
/// Acquires a mutable reference to the owned form of the data.
211252
///
212253
/// Clones the data if it is not already owned.

src/liballoc/collections/vec_deque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,7 @@ impl<T> VecDeque<T> {
18171817
}
18181818
}
18191819

1820-
return elem;
1820+
elem
18211821
}
18221822

18231823
/// Splits the `VecDeque` into two at the given index.

src/liballoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#![feature(const_generic_impls_guard)]
8686
#![feature(const_generics)]
8787
#![feature(const_in_array_repeat_expressions)]
88+
#![feature(cow_is_borrowed)]
8889
#![feature(dispatch_from_dyn)]
8990
#![feature(core_intrinsics)]
9091
#![feature(container_error_extra)]

src/liballoc/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ impl str {
456456
}
457457
}
458458
}
459-
return s;
459+
s
460460
}
461461

462462
/// Converts a [`Box<str>`] into a [`String`] without copying or allocating.

src/liballoc/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,7 @@ impl<T: ?Sized> Clone for Weak<T> {
16381638
}
16391639
}
16401640

1641-
return Weak { ptr: self.ptr };
1641+
Weak { ptr: self.ptr }
16421642
}
16431643
}
16441644

src/libcore/fmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2025,7 +2025,7 @@ impl<T: ?Sized> Pointer for *const T {
20252025
if f.alternate() {
20262026
f.flags |= 1 << (FlagV1::SignAwareZeroPad as u32);
20272027

2028-
if let None = f.width {
2028+
if f.width.is_none() {
20292029
f.width = Some(((mem::size_of::<usize>() * 8) / 4) + 2);
20302030
}
20312031
}

src/libcore/macros.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,33 @@ macro_rules! debug_assert_ne {
238238
($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_ne!($($arg)*); })
239239
}
240240

241+
/// Returns whether the given expression matches any of the given patterns.
242+
///
243+
/// Like in a `match` expression, the pattern can be optionally followed by `if`
244+
/// and a guard expression that has access to names bound by the pattern.
245+
///
246+
/// # Examples
247+
///
248+
/// ```
249+
/// #![feature(matches_macro)]
250+
///
251+
/// let foo = 'f';
252+
/// assert!(matches!(foo, 'A'..='Z' | 'a'..='z'));
253+
///
254+
/// let bar = Some(4);
255+
/// assert!(matches!(bar, Some(x) if x > 2));
256+
/// ```
257+
#[macro_export]
258+
#[unstable(feature = "matches_macro", issue = "65721")]
259+
macro_rules! matches {
260+
($expression:expr, $( $pattern:pat )|+ $( if $guard: expr )?) => {
261+
match $expression {
262+
$( $pattern )|+ $( if $guard )? => true,
263+
_ => false
264+
}
265+
}
266+
}
267+
241268
/// Unwraps a result or propagates its error.
242269
///
243270
/// The `?` operator was added to replace `try!` and should be used instead.

src/libcore/num/dec2flt/algorithm.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,12 @@ pub fn fast_path<T: RawFloat>(integral: &[u8], fractional: &[u8], e: i64) -> Opt
143143
/// > not a bound for the true error, but bounds the difference between the approximation z and
144144
/// > the best possible approximation that uses p bits of significand.)
145145
pub fn bellerophon<T: RawFloat>(f: &Big, e: i16) -> T {
146-
let slop;
147-
if f <= &Big::from_u64(T::MAX_SIG) {
146+
let slop = if f <= &Big::from_u64(T::MAX_SIG) {
148147
// The cases abs(e) < log5(2^N) are in fast_path()
149-
slop = if e >= 0 { 0 } else { 3 };
148+
if e >= 0 { 0 } else { 3 }
150149
} else {
151-
slop = if e >= 0 { 1 } else { 4 };
152-
}
150+
if e >= 0 { 1 } else { 4 }
151+
};
153152
let z = rawfp::big_to_fp(f).mul(&power_of_ten(e)).normalize();
154153
let exp_p_n = 1 << (P - T::SIG_BITS as u32);
155154
let lowbits: i64 = (z.f % exp_p_n) as i64;

src/libcore/option.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -837,9 +837,8 @@ impl<T> Option<T> {
837837
#[inline]
838838
#[stable(feature = "option_entry", since = "1.20.0")]
839839
pub fn get_or_insert_with<F: FnOnce() -> T>(&mut self, f: F) -> &mut T {
840-
match *self {
841-
None => *self = Some(f()),
842-
_ => (),
840+
if let None = *self {
841+
*self = Some(f());
843842
}
844843

845844
match *self {

0 commit comments

Comments
 (0)