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

+1
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

+41
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

+1-1
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

+1
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

+1-1
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

+1-1
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

+1-1
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

+27
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

+4-5
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

+2-3
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 {

src/libpanic_unwind/gcc.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,21 @@ unsafe extern "C" fn rust_eh_personality(version: c_int,
156156
if actions as i32 & uw::_UA_SEARCH_PHASE as i32 != 0 {
157157
match eh_action {
158158
EHAction::None |
159-
EHAction::Cleanup(_) => return uw::_URC_CONTINUE_UNWIND,
160-
EHAction::Catch(_) => return uw::_URC_HANDLER_FOUND,
161-
EHAction::Terminate => return uw::_URC_FATAL_PHASE1_ERROR,
159+
EHAction::Cleanup(_) => uw::_URC_CONTINUE_UNWIND,
160+
EHAction::Catch(_) => uw::_URC_HANDLER_FOUND,
161+
EHAction::Terminate => uw::_URC_FATAL_PHASE1_ERROR,
162162
}
163163
} else {
164164
match eh_action {
165-
EHAction::None => return uw::_URC_CONTINUE_UNWIND,
165+
EHAction::None => uw::_URC_CONTINUE_UNWIND,
166166
EHAction::Cleanup(lpad) |
167167
EHAction::Catch(lpad) => {
168168
uw::_Unwind_SetGR(context, UNWIND_DATA_REG.0, exception_object as uintptr_t);
169169
uw::_Unwind_SetGR(context, UNWIND_DATA_REG.1, 0);
170170
uw::_Unwind_SetIP(context, lpad);
171-
return uw::_URC_INSTALL_CONTEXT;
171+
uw::_URC_INSTALL_CONTEXT
172172
}
173-
EHAction::Terminate => return uw::_URC_FATAL_PHASE2_ERROR,
173+
EHAction::Terminate => uw::_URC_FATAL_PHASE2_ERROR,
174174
}
175175
}
176176
}

src/libpanic_unwind/seh64_gnu.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn payload() -> *mut u8 {
4646

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

5252
// SEH doesn't support resuming unwinds after calling a landing pad like

src/librustc/dep_graph/dep_node.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use crate::ich::{Fingerprint, StableHashingContext};
5959
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
6060
use std::fmt;
6161
use std::hash::Hash;
62-
use syntax_pos::symbol::InternedString;
62+
use syntax_pos::symbol::Symbol;
6363
use crate::traits;
6464
use crate::traits::query::{
6565
CanonicalProjectionGoal, CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
@@ -426,7 +426,7 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
426426

427427
[anon] TraitSelect,
428428

429-
[] CompileCodegenUnit(InternedString),
429+
[] CompileCodegenUnit(Symbol),
430430

431431
[eval_always] Analysis(CrateNum),
432432
]);

src/librustc/hir/lowering.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -792,15 +792,15 @@ impl<'a> LoweringContext<'a> {
792792
// really show up for end-user.
793793
let (str_name, kind) = match hir_name {
794794
ParamName::Plain(ident) => (
795-
ident.as_interned_str(),
795+
ident.name,
796796
hir::LifetimeParamKind::InBand,
797797
),
798798
ParamName::Fresh(_) => (
799-
kw::UnderscoreLifetime.as_interned_str(),
799+
kw::UnderscoreLifetime,
800800
hir::LifetimeParamKind::Elided,
801801
),
802802
ParamName::Error => (
803-
kw::UnderscoreLifetime.as_interned_str(),
803+
kw::UnderscoreLifetime,
804804
hir::LifetimeParamKind::Error,
805805
),
806806
};
@@ -1590,7 +1590,7 @@ impl<'a> LoweringContext<'a> {
15901590
self.context.resolver.definitions().create_def_with_parent(
15911591
self.parent,
15921592
def_node_id,
1593-
DefPathData::LifetimeNs(name.ident().as_interned_str()),
1593+
DefPathData::LifetimeNs(name.ident().name),
15941594
ExpnId::root(),
15951595
lifetime.span);
15961596

src/librustc/hir/map/collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,13 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
186186
});
187187

188188
let mut upstream_crates: Vec<_> = cstore.crates_untracked().iter().map(|&cnum| {
189-
let name = cstore.crate_name_untracked(cnum).as_interned_str();
189+
let name = cstore.crate_name_untracked(cnum);
190190
let disambiguator = cstore.crate_disambiguator_untracked(cnum).to_fingerprint();
191191
let hash = cstore.crate_hash_untracked(cnum);
192192
(name, disambiguator, hash)
193193
}).collect();
194194

195-
upstream_crates.sort_unstable_by_key(|&(name, dis, _)| (name, dis));
195+
upstream_crates.sort_unstable_by_key(|&(name, dis, _)| (name.as_str(), dis));
196196

197197
// We hash the final, remapped names of all local source files so we
198198
// don't have to include the path prefix remapping commandline args.

src/librustc/hir/map/def_collector.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'a> DefCollector<'a> {
5757

5858
// For async functions, we need to create their inner defs inside of a
5959
// closure to match their desugared representation.
60-
let fn_def_data = DefPathData::ValueNs(name.as_interned_str());
60+
let fn_def_data = DefPathData::ValueNs(name);
6161
let fn_def = self.create_def(id, fn_def_data, span);
6262
return self.with_parent(fn_def, |this| {
6363
this.create_def(return_impl_trait_id, DefPathData::ImplTrait, span);
@@ -83,8 +83,7 @@ impl<'a> DefCollector<'a> {
8383
.unwrap_or_else(|| {
8484
let node_id = NodeId::placeholder_from_expn_id(self.expansion);
8585
sym::integer(self.definitions.placeholder_field_indices[&node_id])
86-
})
87-
.as_interned_str();
86+
});
8887
let def = self.create_def(field.id, DefPathData::ValueNs(name), field.span);
8988
self.with_parent(def, |this| visit::walk_struct_field(this, field));
9089
}
@@ -109,7 +108,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
109108
ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) |
110109
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) |
111110
ItemKind::OpaqueTy(..) | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) |
112-
ItemKind::TyAlias(..) => DefPathData::TypeNs(i.ident.as_interned_str()),
111+
ItemKind::TyAlias(..) => DefPathData::TypeNs(i.ident.name),
113112
ItemKind::Fn(
114113
ref decl,
115114
ref header,
@@ -127,8 +126,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
127126
)
128127
}
129128
ItemKind::Static(..) | ItemKind::Const(..) | ItemKind::Fn(..) =>
130-
DefPathData::ValueNs(i.ident.as_interned_str()),
131-
ItemKind::MacroDef(..) => DefPathData::MacroNs(i.ident.as_interned_str()),
129+
DefPathData::ValueNs(i.ident.name),
130+
ItemKind::MacroDef(..) => DefPathData::MacroNs(i.ident.name),
132131
ItemKind::Mac(..) => return self.visit_macro_invoc(i.id),
133132
ItemKind::GlobalAsm(..) => DefPathData::Misc,
134133
ItemKind::Use(..) => {
@@ -162,7 +161,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
162161
}
163162

164163
let def = self.create_def(foreign_item.id,
165-
DefPathData::ValueNs(foreign_item.ident.as_interned_str()),
164+
DefPathData::ValueNs(foreign_item.ident.name),
166165
foreign_item.span);
167166

168167
self.with_parent(def, |this| {
@@ -175,7 +174,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
175174
return self.visit_macro_invoc(v.id);
176175
}
177176
let def = self.create_def(v.id,
178-
DefPathData::TypeNs(v.ident.as_interned_str()),
177+
DefPathData::TypeNs(v.ident.name),
179178
v.span);
180179
self.with_parent(def, |this| {
181180
if let Some(ctor_hir_id) = v.data.ctor_id() {
@@ -202,7 +201,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
202201
self.visit_macro_invoc(param.id);
203202
return;
204203
}
205-
let name = param.ident.as_interned_str();
204+
let name = param.ident.name;
206205
let def_path_data = match param.kind {
207206
GenericParamKind::Lifetime { .. } => DefPathData::LifetimeNs(name),
208207
GenericParamKind::Type { .. } => DefPathData::TypeNs(name),
@@ -216,9 +215,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
216215
fn visit_trait_item(&mut self, ti: &'a TraitItem) {
217216
let def_data = match ti.kind {
218217
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
219-
DefPathData::ValueNs(ti.ident.as_interned_str()),
218+
DefPathData::ValueNs(ti.ident.name),
220219
TraitItemKind::Type(..) => {
221-
DefPathData::TypeNs(ti.ident.as_interned_str())
220+
DefPathData::TypeNs(ti.ident.name)
222221
},
223222
TraitItemKind::Macro(..) => return self.visit_macro_invoc(ti.id),
224223
};
@@ -243,12 +242,10 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
243242
body,
244243
)
245244
}
246-
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
247-
DefPathData::ValueNs(ii.ident.as_interned_str()),
245+
ImplItemKind::Method(..) |
246+
ImplItemKind::Const(..) => DefPathData::ValueNs(ii.ident.name),
248247
ImplItemKind::TyAlias(..) |
249-
ImplItemKind::OpaqueTy(..) => {
250-
DefPathData::TypeNs(ii.ident.as_interned_str())
251-
},
248+
ImplItemKind::OpaqueTy(..) => DefPathData::TypeNs(ii.ident.name),
252249
ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id),
253250
};
254251

0 commit comments

Comments
 (0)