Skip to content

Commit 4988b09

Browse files
committed
Auto merge of #56549 - pietroalbini:rollup, r=pietroalbini
Rollup of 15 pull requests Successful merges: - #51753 (Document `From` implementations) - #55563 (Improve no result found sentence in doc search) - #55987 (Add Weak.ptr_eq) - #56119 (Utilize `?` instead of `return None`.) - #56372 (Refer to the second borrow as the "second borrow" in E0501.rs) - #56388 (More MIR borrow check cleanup) - #56424 (Mention raw-ident syntax) - #56452 (Remove redundant clones) - #56456 (Handle existential types in dead code analysis) - #56466 (data_structures: remove tuple_slice) - #56476 (Fix invalid line number match) - #56497 (cleanup: remove static lifetimes from consts in libstd) - #56498 (Fix line numbers display) - #56523 (Added a bare-bones eslint config (removing jslint)) - #56538 (Use inner iterator may_have_side_effect for Cloned) Failed merges: r? @ghost
2 parents 14997d5 + f8ee5ab commit 4988b09

File tree

59 files changed

+518
-418
lines changed

Some content is hidden

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

59 files changed

+518
-418
lines changed

src/liballoc/rc.rs

+48-1
Original file line numberDiff line numberDiff line change
@@ -1187,8 +1187,9 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Weak<U>> for Weak<T> {}
11871187

11881188
impl<T> Weak<T> {
11891189
/// Constructs a new `Weak<T>`, without allocating any memory.
1190-
/// Calling [`upgrade`][Weak::upgrade] on the return value always gives [`None`].
1190+
/// Calling [`upgrade`] on the return value always gives [`None`].
11911191
///
1192+
/// [`upgrade`]: #method.upgrade
11921193
/// [`None`]: ../../std/option/enum.Option.html
11931194
///
11941195
/// # Examples
@@ -1260,6 +1261,52 @@ impl<T: ?Sized> Weak<T> {
12601261
Some(unsafe { self.ptr.as_ref() })
12611262
}
12621263
}
1264+
1265+
/// Returns true if the two `Weak`s point to the same value (not just values
1266+
/// that compare as equal).
1267+
///
1268+
/// # Notes
1269+
///
1270+
/// Since this compares pointers it means that `Weak::new()` will equal each
1271+
/// other, even though they don't point to any value.
1272+
///
1273+
/// # Examples
1274+
///
1275+
/// ```
1276+
/// #![feature(weak_ptr_eq)]
1277+
/// use std::rc::{Rc, Weak};
1278+
///
1279+
/// let first_rc = Rc::new(5);
1280+
/// let first = Rc::downgrade(&first_rc);
1281+
/// let second = Rc::downgrade(&first_rc);
1282+
///
1283+
/// assert!(Weak::ptr_eq(&first, &second));
1284+
///
1285+
/// let third_rc = Rc::new(5);
1286+
/// let third = Rc::downgrade(&third_rc);
1287+
///
1288+
/// assert!(!Weak::ptr_eq(&first, &third));
1289+
/// ```
1290+
///
1291+
/// Comparing `Weak::new`.
1292+
///
1293+
/// ```
1294+
/// #![feature(weak_ptr_eq)]
1295+
/// use std::rc::{Rc, Weak};
1296+
///
1297+
/// let first = Weak::new();
1298+
/// let second = Weak::new();
1299+
/// assert!(Weak::ptr_eq(&first, &second));
1300+
///
1301+
/// let third_rc = Rc::new(());
1302+
/// let third = Rc::downgrade(&third_rc);
1303+
/// assert!(!Weak::ptr_eq(&first, &third));
1304+
/// ```
1305+
#[inline]
1306+
#[unstable(feature = "weak_ptr_eq", issue = "55981")]
1307+
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
1308+
this.ptr.as_ptr() == other.ptr.as_ptr()
1309+
}
12631310
}
12641311

12651312
#[stable(feature = "rc_weak", since = "1.4.0")]

src/liballoc/sync.rs

+47
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,53 @@ impl<T: ?Sized> Weak<T> {
11301130
Some(unsafe { self.ptr.as_ref() })
11311131
}
11321132
}
1133+
1134+
/// Returns true if the two `Weak`s point to the same value (not just values
1135+
/// that compare as equal).
1136+
///
1137+
/// # Notes
1138+
///
1139+
/// Since this compares pointers it means that `Weak::new()` will equal each
1140+
/// other, even though they don't point to any value.
1141+
///
1142+
///
1143+
/// # Examples
1144+
///
1145+
/// ```
1146+
/// #![feature(weak_ptr_eq)]
1147+
/// use std::sync::{Arc, Weak};
1148+
///
1149+
/// let first_rc = Arc::new(5);
1150+
/// let first = Arc::downgrade(&first_rc);
1151+
/// let second = Arc::downgrade(&first_rc);
1152+
///
1153+
/// assert!(Weak::ptr_eq(&first, &second));
1154+
///
1155+
/// let third_rc = Arc::new(5);
1156+
/// let third = Arc::downgrade(&third_rc);
1157+
///
1158+
/// assert!(!Weak::ptr_eq(&first, &third));
1159+
/// ```
1160+
///
1161+
/// Comparing `Weak::new`.
1162+
///
1163+
/// ```
1164+
/// #![feature(weak_ptr_eq)]
1165+
/// use std::sync::{Arc, Weak};
1166+
///
1167+
/// let first = Weak::new();
1168+
/// let second = Weak::new();
1169+
/// assert!(Weak::ptr_eq(&first, &second));
1170+
///
1171+
/// let third_rc = Arc::new(());
1172+
/// let third = Arc::downgrade(&third_rc);
1173+
/// assert!(!Weak::ptr_eq(&first, &third));
1174+
/// ```
1175+
#[inline]
1176+
#[unstable(feature = "weak_ptr_eq", issue = "55981")]
1177+
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
1178+
this.ptr.as_ptr() == other.ptr.as_ptr()
1179+
}
11331180
}
11341181

11351182
#[stable(feature = "arc_weak", since = "1.4.0")]

src/libcore/iter/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,9 @@ unsafe impl<'a, I, T: 'a> TrustedRandomAccess for Cloned<I>
602602
}
603603

604604
#[inline]
605-
fn may_have_side_effect() -> bool { false }
605+
fn may_have_side_effect() -> bool {
606+
I::may_have_side_effect()
607+
}
606608
}
607609

608610
#[unstable(feature = "trusted_len", issue = "37572")]

src/libcore/macros.rs

+4
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ macro_rules! debug_assert_ne {
238238
/// with converting downstream errors.
239239
///
240240
/// The `?` operator was added to replace `try!` and should be used instead.
241+
/// Furthermore, `try` is a reserved word in Rust 2018, so if you must use
242+
/// it, you will need to use the [raw-identifier syntax][ris]: `r#try`.
243+
///
244+
/// [ris]: https://doc.rust-lang.org/nightly/rust-by-example/compatibility/raw_identifiers.html
241245
///
242246
/// `try!` matches the given [`Result`]. In case of the `Ok` variant, the
243247
/// expression has the value of the wrapped value.

src/libcore/str/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,9 @@ fn next_code_point_reverse<'a, I>(bytes: &mut I) -> Option<u32>
536536
where I: DoubleEndedIterator<Item = &'a u8>,
537537
{
538538
// Decode UTF-8
539-
let w = match bytes.next_back() {
540-
None => return None,
541-
Some(&next_byte) if next_byte < 128 => return Some(next_byte as u32),
542-
Some(&back_byte) => back_byte,
539+
let w = match *bytes.next_back()? {
540+
next_byte if next_byte < 128 => return Some(next_byte as u32),
541+
back_byte => back_byte,
543542
};
544543

545544
// Multibyte case follows

src/libcore/tests/iter.rs

+17
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,23 @@ fn test_cloned() {
12491249
assert_eq!(it.next_back(), None);
12501250
}
12511251

1252+
#[test]
1253+
fn test_cloned_side_effects() {
1254+
let mut count = 0;
1255+
{
1256+
let iter = [1, 2, 3]
1257+
.iter()
1258+
.map(|x| {
1259+
count += 1;
1260+
x
1261+
})
1262+
.cloned()
1263+
.zip(&[1]);
1264+
for _ in iter {}
1265+
}
1266+
assert_eq!(count, 2);
1267+
}
1268+
12521269
#[test]
12531270
fn test_double_ended_map() {
12541271
let xs = [1, 2, 3, 4, 5, 6];

src/librustc/middle/dead.rs

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
166166
hir::ItemKind::Fn(..)
167167
| hir::ItemKind::Ty(..)
168168
| hir::ItemKind::Static(..)
169+
| hir::ItemKind::Existential(..)
169170
| hir::ItemKind::Const(..) => {
170171
intravisit::walk_item(self, &item);
171172
}

src/librustc/middle/region.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,7 @@ impl<'tcx> ScopeTree {
592592
return Some(scope.item_local_id());
593593
}
594594

595-
match self.opt_encl_scope(scope) {
596-
None => return None,
597-
Some(parent) => scope = parent,
598-
}
595+
scope = self.opt_encl_scope(scope)?;
599596
}
600597
}
601598

src/librustc/session/search_paths.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ impl<'a> Iterator for Iter<'a> {
6767

6868
fn next(&mut self) -> Option<(&'a Path, PathKind)> {
6969
loop {
70-
match self.iter.next() {
71-
Some(&(kind, ref p)) if self.kind == PathKind::All ||
72-
kind == PathKind::All ||
73-
kind == self.kind => {
70+
match *self.iter.next()? {
71+
(kind, ref p) if self.kind == PathKind::All ||
72+
kind == PathKind::All ||
73+
kind == self.kind => {
7474
return Some((p, kind))
7575
}
76-
Some(..) => {}
77-
None => return None,
76+
_ => {}
7877
}
7978
}
8079
}

src/librustc_borrowck/borrowck/check_loans.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
615615
let new_loan_str = &new_loan.kind.to_user_str();
616616
self.bccx.cannot_reborrow_already_uniquely_borrowed(
617617
new_loan.span, "closure", &nl, &new_loan_msg, new_loan_str,
618-
old_loan.span, &old_loan_msg, previous_end_span, Origin::Ast)
618+
old_loan.span, &old_loan_msg, previous_end_span, "", Origin::Ast)
619619
}
620620
(..) =>
621621
self.bccx.cannot_reborrow_already_borrowed(

src/librustc_data_structures/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ pub mod sync;
8181
pub mod tiny_list;
8282
pub mod thin_vec;
8383
pub mod transitive_relation;
84-
pub mod tuple_slice;
8584
pub use ena::unify;
8685
pub mod vec_linked_list;
8786
pub mod work_queue;

src/librustc_data_structures/tuple_slice.rs

-70
This file was deleted.

src/librustc_incremental/persist/work_product.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
2929
return None
3030
}
3131

32-
let saved_files: Option<Vec<_>> =
32+
let saved_files =
3333
files.iter()
3434
.map(|&(kind, ref path)| {
3535
let extension = match kind {
@@ -51,11 +51,7 @@ pub fn copy_cgu_workproducts_to_incr_comp_cache_dir(
5151
}
5252
}
5353
})
54-
.collect();
55-
let saved_files = match saved_files {
56-
None => return None,
57-
Some(v) => v,
58-
};
54+
.collect::<Option<Vec<_>>>()?;
5955

6056
let work_product = WorkProduct {
6157
cgu_name: cgu_name.to_string(),

0 commit comments

Comments
 (0)