Skip to content

Commit

Permalink
Auto merge of #65733 - Centril:rollup-0zth66f, r=Centril
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Oct 24, 2019
2 parents 4a8c5b2 + 3cd7a17 commit 55e0063
Show file tree
Hide file tree
Showing 122 changed files with 1,064 additions and 1,138 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3483,6 +3483,7 @@ dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_interface",
"rustc_lint",
"rustc_metadata",
"rustc_mir",
"rustc_plugin",
Expand Down
41 changes: 41 additions & 0 deletions src/liballoc/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,47 @@ impl<B: ?Sized + ToOwned> Clone for Cow<'_, B> {
}

impl<B: ?Sized + ToOwned> Cow<'_, B> {
/// Returns true if the data is borrowed, i.e. if `to_mut` would require additional work.
///
/// # Examples
///
/// ```
/// #![feature(cow_is_borrowed)]
/// use std::borrow::Cow;
///
/// let cow = Cow::Borrowed("moo");
/// assert!(cow.is_borrowed());
///
/// let bull: Cow<'_, str> = Cow::Owned("...moo?".to_string());
/// assert!(!bull.is_borrowed());
/// ```
#[unstable(feature = "cow_is_borrowed", issue = "65143")]
pub fn is_borrowed(&self) -> bool {
match *self {
Borrowed(_) => true,
Owned(_) => false,
}
}

/// Returns true if the data is owned, i.e. if `to_mut` would be a no-op.
///
/// # Examples
///
/// ```
/// #![feature(cow_is_borrowed)]
/// use std::borrow::Cow;
///
/// let cow: Cow<'_, str> = Cow::Owned("moo".to_string());
/// assert!(cow.is_owned());
///
/// let bull = Cow::Borrowed("...moo?");
/// assert!(!bull.is_owned());
/// ```
#[unstable(feature = "cow_is_borrowed", issue = "65143")]
pub fn is_owned(&self) -> bool {
!self.is_borrowed()
}

/// Acquires a mutable reference to the owned form of the data.
///
/// Clones the data if it is not already owned.
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/collections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,7 @@ impl<T> VecDeque<T> {
}
}

return elem;
elem
}

/// Splits the `VecDeque` into two at the given index.
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
#![feature(const_generic_impls_guard)]
#![feature(const_generics)]
#![feature(const_in_array_repeat_expressions)]
#![feature(cow_is_borrowed)]
#![feature(dispatch_from_dyn)]
#![feature(core_intrinsics)]
#![feature(container_error_extra)]
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ impl str {
}
}
}
return s;
s
}

/// Converts a [`Box<str>`] into a [`String`] without copying or allocating.
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ impl<T: ?Sized> Clone for Weak<T> {
}
}

return Weak { ptr: self.ptr };
Weak { ptr: self.ptr }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
27 changes: 27 additions & 0 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 4 additions & 5 deletions src/libcore/num/dec2flt/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions src/libpanic_unwind/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,21 @@ unsafe extern "C" fn rust_eh_personality(version: c_int,
if actions as i32 & uw::_UA_SEARCH_PHASE as i32 != 0 {
match eh_action {
EHAction::None |
EHAction::Cleanup(_) => return uw::_URC_CONTINUE_UNWIND,
EHAction::Catch(_) => return uw::_URC_HANDLER_FOUND,
EHAction::Terminate => return uw::_URC_FATAL_PHASE1_ERROR,
EHAction::Cleanup(_) => uw::_URC_CONTINUE_UNWIND,
EHAction::Catch(_) => uw::_URC_HANDLER_FOUND,
EHAction::Terminate => uw::_URC_FATAL_PHASE1_ERROR,
}
} else {
match eh_action {
EHAction::None => return uw::_URC_CONTINUE_UNWIND,
EHAction::None => uw::_URC_CONTINUE_UNWIND,
EHAction::Cleanup(lpad) |
EHAction::Catch(lpad) => {
uw::_Unwind_SetGR(context, UNWIND_DATA_REG.0, exception_object as uintptr_t);
uw::_Unwind_SetGR(context, UNWIND_DATA_REG.1, 0);
uw::_Unwind_SetIP(context, lpad);
return uw::_URC_INSTALL_CONTEXT;
uw::_URC_INSTALL_CONTEXT
}
EHAction::Terminate => return uw::_URC_FATAL_PHASE2_ERROR,
EHAction::Terminate => uw::_URC_FATAL_PHASE2_ERROR,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libpanic_unwind/seh64_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn payload() -> *mut u8 {

pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
let panic_ctx = Box::from_raw(ptr as *mut PanicData);
return panic_ctx.data;
panic_ctx.data
}

// SEH doesn't support resuming unwinds after calling a landing pad like
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use crate::ich::{Fingerprint, StableHashingContext};
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
use std::fmt;
use std::hash::Hash;
use syntax_pos::symbol::InternedString;
use syntax_pos::symbol::Symbol;
use crate::traits;
use crate::traits::query::{
CanonicalProjectionGoal, CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
Expand Down Expand Up @@ -426,7 +426,7 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>

[anon] TraitSelect,

[] CompileCodegenUnit(InternedString),
[] CompileCodegenUnit(Symbol),

[eval_always] Analysis(CrateNum),
]);
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,15 +792,15 @@ impl<'a> LoweringContext<'a> {
// really show up for end-user.
let (str_name, kind) = match hir_name {
ParamName::Plain(ident) => (
ident.as_interned_str(),
ident.name,
hir::LifetimeParamKind::InBand,
),
ParamName::Fresh(_) => (
kw::UnderscoreLifetime.as_interned_str(),
kw::UnderscoreLifetime,
hir::LifetimeParamKind::Elided,
),
ParamName::Error => (
kw::UnderscoreLifetime.as_interned_str(),
kw::UnderscoreLifetime,
hir::LifetimeParamKind::Error,
),
};
Expand Down Expand Up @@ -1590,7 +1590,7 @@ impl<'a> LoweringContext<'a> {
self.context.resolver.definitions().create_def_with_parent(
self.parent,
def_node_id,
DefPathData::LifetimeNs(name.ident().as_interned_str()),
DefPathData::LifetimeNs(name.ident().name),
ExpnId::root(),
lifetime.span);

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
});

let mut upstream_crates: Vec<_> = cstore.crates_untracked().iter().map(|&cnum| {
let name = cstore.crate_name_untracked(cnum).as_interned_str();
let name = cstore.crate_name_untracked(cnum);
let disambiguator = cstore.crate_disambiguator_untracked(cnum).to_fingerprint();
let hash = cstore.crate_hash_untracked(cnum);
(name, disambiguator, hash)
}).collect();

upstream_crates.sort_unstable_by_key(|&(name, dis, _)| (name, dis));
upstream_crates.sort_unstable_by_key(|&(name, dis, _)| (name.as_str(), dis));

// We hash the final, remapped names of all local source files so we
// don't have to include the path prefix remapping commandline args.
Expand Down
29 changes: 13 additions & 16 deletions src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'a> DefCollector<'a> {

// For async functions, we need to create their inner defs inside of a
// closure to match their desugared representation.
let fn_def_data = DefPathData::ValueNs(name.as_interned_str());
let fn_def_data = DefPathData::ValueNs(name);
let fn_def = self.create_def(id, fn_def_data, span);
return self.with_parent(fn_def, |this| {
this.create_def(return_impl_trait_id, DefPathData::ImplTrait, span);
Expand All @@ -83,8 +83,7 @@ impl<'a> DefCollector<'a> {
.unwrap_or_else(|| {
let node_id = NodeId::placeholder_from_expn_id(self.expansion);
sym::integer(self.definitions.placeholder_field_indices[&node_id])
})
.as_interned_str();
});
let def = self.create_def(field.id, DefPathData::ValueNs(name), field.span);
self.with_parent(def, |this| visit::walk_struct_field(this, field));
}
Expand All @@ -109,7 +108,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) |
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) |
ItemKind::OpaqueTy(..) | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) |
ItemKind::TyAlias(..) => DefPathData::TypeNs(i.ident.as_interned_str()),
ItemKind::TyAlias(..) => DefPathData::TypeNs(i.ident.name),
ItemKind::Fn(
ref decl,
ref header,
Expand All @@ -127,8 +126,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
)
}
ItemKind::Static(..) | ItemKind::Const(..) | ItemKind::Fn(..) =>
DefPathData::ValueNs(i.ident.as_interned_str()),
ItemKind::MacroDef(..) => DefPathData::MacroNs(i.ident.as_interned_str()),
DefPathData::ValueNs(i.ident.name),
ItemKind::MacroDef(..) => DefPathData::MacroNs(i.ident.name),
ItemKind::Mac(..) => return self.visit_macro_invoc(i.id),
ItemKind::GlobalAsm(..) => DefPathData::Misc,
ItemKind::Use(..) => {
Expand Down Expand Up @@ -162,7 +161,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
}

let def = self.create_def(foreign_item.id,
DefPathData::ValueNs(foreign_item.ident.as_interned_str()),
DefPathData::ValueNs(foreign_item.ident.name),
foreign_item.span);

self.with_parent(def, |this| {
Expand All @@ -175,7 +174,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
return self.visit_macro_invoc(v.id);
}
let def = self.create_def(v.id,
DefPathData::TypeNs(v.ident.as_interned_str()),
DefPathData::TypeNs(v.ident.name),
v.span);
self.with_parent(def, |this| {
if let Some(ctor_hir_id) = v.data.ctor_id() {
Expand All @@ -202,7 +201,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
self.visit_macro_invoc(param.id);
return;
}
let name = param.ident.as_interned_str();
let name = param.ident.name;
let def_path_data = match param.kind {
GenericParamKind::Lifetime { .. } => DefPathData::LifetimeNs(name),
GenericParamKind::Type { .. } => DefPathData::TypeNs(name),
Expand All @@ -216,9 +215,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
fn visit_trait_item(&mut self, ti: &'a TraitItem) {
let def_data = match ti.kind {
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
DefPathData::ValueNs(ti.ident.as_interned_str()),
DefPathData::ValueNs(ti.ident.name),
TraitItemKind::Type(..) => {
DefPathData::TypeNs(ti.ident.as_interned_str())
DefPathData::TypeNs(ti.ident.name)
},
TraitItemKind::Macro(..) => return self.visit_macro_invoc(ti.id),
};
Expand All @@ -243,12 +242,10 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
body,
)
}
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
DefPathData::ValueNs(ii.ident.as_interned_str()),
ImplItemKind::Method(..) |
ImplItemKind::Const(..) => DefPathData::ValueNs(ii.ident.name),
ImplItemKind::TyAlias(..) |
ImplItemKind::OpaqueTy(..) => {
DefPathData::TypeNs(ii.ident.as_interned_str())
},
ImplItemKind::OpaqueTy(..) => DefPathData::TypeNs(ii.ident.name),
ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id),
};

Expand Down
Loading

0 comments on commit 55e0063

Please sign in to comment.