Skip to content

Commit acfc558

Browse files
committed
Auto merge of #72639 - Dylan-DPC:rollup-76upj51, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #72348 (Fix confusing error message for comma typo in multiline statement) - #72533 (Resolve UB in Arc/Weak interaction (2)) - #72548 (Add test for old compiler ICE when using `Borrow`) - #72606 (Small cell example update) - #72610 (Remove font-display settings) - #72626 (Add remark regarding DoubleEndedIterator) Failed merges: r? @ghost
2 parents 783139b + e6353aa commit acfc558

File tree

9 files changed

+141
-21
lines changed

9 files changed

+141
-21
lines changed

src/liballoc/sync.rs

+26-9
Original file line numberDiff line numberDiff line change
@@ -867,12 +867,10 @@ impl<T: ?Sized> Arc<T> {
867867
unsafe fn drop_slow(&mut self) {
868868
// Destroy the data at this time, even though we may not free the box
869869
// allocation itself (there may still be weak pointers lying around).
870-
ptr::drop_in_place(&mut self.ptr.as_mut().data);
870+
ptr::drop_in_place(Self::get_mut_unchecked(self));
871871

872-
if self.inner().weak.fetch_sub(1, Release) == 1 {
873-
acquire!(self.inner().weak);
874-
Global.dealloc(self.ptr.cast(), Layout::for_value(self.ptr.as_ref()))
875-
}
872+
// Drop the weak ref collectively held by all strong references
873+
drop(Weak { ptr: self.ptr });
876874
}
877875

878876
#[inline]
@@ -1204,7 +1202,7 @@ impl<T: Clone> Arc<T> {
12041202

12051203
// As with `get_mut()`, the unsafety is ok because our reference was
12061204
// either unique to begin with, or became one upon cloning the contents.
1207-
unsafe { &mut this.ptr.as_mut().data }
1205+
unsafe { Self::get_mut_unchecked(this) }
12081206
}
12091207
}
12101208

@@ -1280,7 +1278,9 @@ impl<T: ?Sized> Arc<T> {
12801278
#[inline]
12811279
#[unstable(feature = "get_mut_unchecked", issue = "63292")]
12821280
pub unsafe fn get_mut_unchecked(this: &mut Self) -> &mut T {
1283-
&mut this.ptr.as_mut().data
1281+
// We are careful to *not* create a reference covering the "count" fields, as
1282+
// this would alias with concurrent access to the reference counts (e.g. by `Weak`).
1283+
&mut (*this.ptr.as_ptr()).data
12841284
}
12851285

12861286
/// Determine whether this is the unique reference (including weak refs) to
@@ -1571,6 +1571,13 @@ impl<T> Weak<T> {
15711571
}
15721572
}
15731573

1574+
/// Helper type to allow accessing the reference counts without
1575+
/// making any assertions about the data field.
1576+
struct WeakInner<'a> {
1577+
weak: &'a atomic::AtomicUsize,
1578+
strong: &'a atomic::AtomicUsize,
1579+
}
1580+
15741581
impl<T: ?Sized> Weak<T> {
15751582
/// Attempts to upgrade the `Weak` pointer to an [`Arc`], delaying
15761583
/// dropping of the inner value if successful.
@@ -1678,8 +1685,18 @@ impl<T: ?Sized> Weak<T> {
16781685
/// Returns `None` when the pointer is dangling and there is no allocated `ArcInner`,
16791686
/// (i.e., when this `Weak` was created by `Weak::new`).
16801687
#[inline]
1681-
fn inner(&self) -> Option<&ArcInner<T>> {
1682-
if is_dangling(self.ptr) { None } else { Some(unsafe { self.ptr.as_ref() }) }
1688+
fn inner(&self) -> Option<WeakInner<'_>> {
1689+
if is_dangling(self.ptr) {
1690+
None
1691+
} else {
1692+
// We are careful to *not* create a reference covering the "data" field, as
1693+
// the field may be mutated concurrently (for example, if the last `Arc`
1694+
// is dropped, the data field will be dropped in-place).
1695+
Some(unsafe {
1696+
let ptr = self.ptr.as_ptr();
1697+
WeakInner { strong: &(*ptr).strong, weak: &(*ptr).weak }
1698+
})
1699+
}
16831700
}
16841701

16851702
/// Returns `true` if the two `Weak`s point to the same allocation (similar to

src/libcore/cell.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -849,11 +849,11 @@ impl<T: ?Sized> RefCell<T> {
849849
/// ```
850850
/// use std::cell::RefCell;
851851
///
852-
/// let c = RefCell::new(5);
852+
/// let c = RefCell::new("hello".to_owned());
853853
///
854-
/// *c.borrow_mut() = 7;
854+
/// *c.borrow_mut() = "bonjour".to_owned();
855855
///
856-
/// assert_eq!(*c.borrow(), 7);
856+
/// assert_eq!(&*c.borrow(), "bonjour");
857857
/// ```
858858
///
859859
/// An example of panic:

src/libcore/iter/traits/double_ended.rs

+26
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,32 @@ pub trait DoubleEndedIterator: Iterator {
6363
/// assert_eq!(None, iter.next());
6464
/// assert_eq!(None, iter.next_back());
6565
/// ```
66+
///
67+
/// # Remarks
68+
///
69+
/// The elements yielded by `DoubleEndedIterator`'s methods may differ from
70+
/// the ones yielded by `Iterator`'s methods:
71+
///
72+
/// ```
73+
/// let vec = vec![(1, 'a'), (1, 'b'), (1, 'c'), (2, 'a'), (2, 'b')];
74+
/// let uniq_by_fst_comp = || {
75+
/// let mut seen = std::collections::HashSet::new();
76+
/// vec.iter().copied().filter(move |x| seen.insert(x.0))
77+
/// };
78+
///
79+
/// assert_eq!(uniq_by_fst_comp().last(), Some((2, 'a')));
80+
/// assert_eq!(uniq_by_fst_comp().next_back(), Some((2, 'b')));
81+
///
82+
/// assert_eq!(
83+
/// uniq_by_fst_comp().fold(vec![], |mut v, x| {v.push(x); v}),
84+
/// vec![(1, 'a'), (2, 'a')]
85+
/// );
86+
/// assert_eq!(
87+
/// uniq_by_fst_comp().rfold(vec![], |mut v, x| {v.push(x); v}),
88+
/// vec![(2, 'b'), (1, 'c')]
89+
/// );
90+
/// ```
91+
///
6692
#[stable(feature = "rust1", since = "1.0.0")]
6793
fn next_back(&mut self) -> Option<Self::Item>;
6894

src/librustc_parse/parser/diagnostics.rs

+13
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,19 @@ impl<'a> Parser<'a> {
935935
return self.expect(&token::Semi).map(drop);
936936
} else if !sm.is_multiline(self.prev_token.span.until(self.token.span)) {
937937
// The current token is in the same line as the prior token, not recoverable.
938+
} else if [token::Comma, token::Colon].contains(&self.token.kind)
939+
&& &self.prev_token.kind == &token::CloseDelim(token::Paren)
940+
{
941+
// Likely typo: The current token is on a new line and is expected to be
942+
// `.`, `;`, `?`, or an operator after a close delimiter token.
943+
//
944+
// let a = std::process::Command::new("echo")
945+
// .arg("1")
946+
// ,arg("2")
947+
// ^
948+
// https://github.com/rust-lang/rust/issues/72253
949+
self.expect(&token::Semi)?;
950+
return Ok(());
938951
} else if self.look_ahead(1, |t| {
939952
t == &token::CloseDelim(token::Brace) || t.can_begin_expr() && t.kind != token::Colon
940953
}) && [token::Comma, token::Colon].contains(&self.token.kind)

src/librustdoc/html/static/rustdoc.css

-9
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
font-family: 'Fira Sans';
44
font-style: normal;
55
font-weight: 400;
6-
font-display: optional;
76
src: local('Fira Sans'), url("FiraSans-Regular.woff") format('woff');
87
}
98
@font-face {
109
font-family: 'Fira Sans';
1110
font-style: normal;
1211
font-weight: 500;
13-
font-display: optional;
1412
src: local('Fira Sans Medium'), url("FiraSans-Medium.woff") format('woff');
1513
}
1614

@@ -19,23 +17,18 @@
1917
font-family: 'Source Serif Pro';
2018
font-style: normal;
2119
font-weight: 400;
22-
/* The difference for body text without this font is greater than other fonts,
23-
* so the 0~100ms block of fallback is preferred over optional, for legibility. */
24-
font-display: fallback;
2520
src: local('Source Serif Pro'), url("SourceSerifPro-Regular.ttf.woff") format('woff');
2621
}
2722
@font-face {
2823
font-family: 'Source Serif Pro';
2924
font-style: italic;
3025
font-weight: 400;
31-
font-display: optional;
3226
src: local('Source Serif Pro Italic'), url("SourceSerifPro-It.ttf.woff") format('woff');
3327
}
3428
@font-face {
3529
font-family: 'Source Serif Pro';
3630
font-style: normal;
3731
font-weight: 700;
38-
font-display: optional;
3932
src: local('Source Serif Pro Bold'), url("SourceSerifPro-Bold.ttf.woff") format('woff');
4033
}
4134

@@ -44,7 +37,6 @@
4437
font-family: 'Source Code Pro';
4538
font-style: normal;
4639
font-weight: 400;
47-
font-display: optional;
4840
/* Avoid using locally installed font because bad versions are in circulation:
4941
* see https://github.com/rust-lang/rust/issues/24355 */
5042
src: url("SourceCodePro-Regular.woff") format('woff');
@@ -53,7 +45,6 @@
5345
font-family: 'Source Code Pro';
5446
font-style: normal;
5547
font-weight: 600;
56-
font-display: optional;
5748
src: url("SourceCodePro-Semibold.woff") format('woff');
5849
}
5950

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This previously caused an ICE at:
2+
// librustc/traits/structural_impls.rs:180: impossible case reached
3+
4+
#![no_main]
5+
6+
use std::borrow::Borrow;
7+
use std::io;
8+
use std::io::Write;
9+
10+
trait Constraint {}
11+
12+
struct Container<T> {
13+
t: T,
14+
}
15+
16+
struct Borrowed;
17+
struct Owned;
18+
19+
impl<'a, T> Write for &'a Container<T>
20+
where
21+
T: Constraint,
22+
&'a T: Write,
23+
{
24+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
25+
Ok(buf.len())
26+
}
27+
28+
fn flush(&mut self) -> io::Result<()> {
29+
Ok(())
30+
}
31+
}
32+
33+
impl Borrow<Borrowed> for Owned {
34+
fn borrow(&self) -> &Borrowed {
35+
&Borrowed
36+
}
37+
}
38+
39+
fn func(owned: Owned) {
40+
let _: () = Borrow::borrow(&owned); //~ ERROR mismatched types
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-50687-ice-on-borrow.rs:40:17
3+
|
4+
LL | let _: () = Borrow::borrow(&owned);
5+
| -- ^^^^^^^^^^^^^^^^^^^^^^
6+
| | |
7+
| | expected `()`, found reference
8+
| | help: consider dereferencing the borrow: `*Borrow::borrow(&owned)`
9+
| expected due to this
10+
|
11+
= note: expected unit type `()`
12+
found reference `&_`
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0308`.

src/test/ui/issues/issue-72253.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
let a = std::process::Command::new("echo")
3+
.arg("1")
4+
,arg("2") //~ ERROR expected one of `.`, `;`, `?`, or an operator, found `,`
5+
.output();
6+
}

src/test/ui/issues/issue-72253.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: expected one of `.`, `;`, `?`, or an operator, found `,`
2+
--> $DIR/issue-72253.rs:4:9
3+
|
4+
LL | .arg("1")
5+
| - expected one of `.`, `;`, `?`, or an operator
6+
LL | ,arg("2")
7+
| ^ unexpected token
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)