Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #72639

Merged
merged 12 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,12 +867,10 @@ impl<T: ?Sized> Arc<T> {
unsafe fn drop_slow(&mut self) {
// Destroy the data at this time, even though we may not free the box
// allocation itself (there may still be weak pointers lying around).
ptr::drop_in_place(&mut self.ptr.as_mut().data);
ptr::drop_in_place(Self::get_mut_unchecked(self));

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

#[inline]
Expand Down Expand Up @@ -1204,7 +1202,7 @@ impl<T: Clone> Arc<T> {

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

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

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

/// Helper type to allow accessing the reference counts without
/// making any assertions about the data field.
struct WeakInner<'a> {
weak: &'a atomic::AtomicUsize,
strong: &'a atomic::AtomicUsize,
}

impl<T: ?Sized> Weak<T> {
/// Attempts to upgrade the `Weak` pointer to an [`Arc`], delaying
/// dropping of the inner value if successful.
Expand Down Expand Up @@ -1678,8 +1685,18 @@ impl<T: ?Sized> Weak<T> {
/// Returns `None` when the pointer is dangling and there is no allocated `ArcInner`,
/// (i.e., when this `Weak` was created by `Weak::new`).
#[inline]
fn inner(&self) -> Option<&ArcInner<T>> {
if is_dangling(self.ptr) { None } else { Some(unsafe { self.ptr.as_ref() }) }
fn inner(&self) -> Option<WeakInner<'_>> {
if is_dangling(self.ptr) {
None
} else {
// We are careful to *not* create a reference covering the "data" field, as
// the field may be mutated concurrently (for example, if the last `Arc`
// is dropped, the data field will be dropped in-place).
Some(unsafe {
let ptr = self.ptr.as_ptr();
WeakInner { strong: &(*ptr).strong, weak: &(*ptr).weak }
})
}
}

/// Returns `true` if the two `Weak`s point to the same allocation (similar to
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,11 @@ impl<T: ?Sized> RefCell<T> {
/// ```
/// use std::cell::RefCell;
///
/// let c = RefCell::new(5);
/// let c = RefCell::new("hello".to_owned());
///
/// *c.borrow_mut() = 7;
/// *c.borrow_mut() = "bonjour".to_owned();
///
/// assert_eq!(*c.borrow(), 7);
/// assert_eq!(&*c.borrow(), "bonjour");
/// ```
///
/// An example of panic:
Expand Down
26 changes: 26 additions & 0 deletions src/libcore/iter/traits/double_ended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,32 @@ pub trait DoubleEndedIterator: Iterator {
/// assert_eq!(None, iter.next());
/// assert_eq!(None, iter.next_back());
/// ```
///
/// # Remarks
///
/// The elements yielded by `DoubleEndedIterator`'s methods may differ from
/// the ones yielded by `Iterator`'s methods:
///
/// ```
/// let vec = vec![(1, 'a'), (1, 'b'), (1, 'c'), (2, 'a'), (2, 'b')];
/// let uniq_by_fst_comp = || {
/// let mut seen = std::collections::HashSet::new();
/// vec.iter().copied().filter(move |x| seen.insert(x.0))
/// };
///
/// assert_eq!(uniq_by_fst_comp().last(), Some((2, 'a')));
/// assert_eq!(uniq_by_fst_comp().next_back(), Some((2, 'b')));
///
/// assert_eq!(
/// uniq_by_fst_comp().fold(vec![], |mut v, x| {v.push(x); v}),
/// vec![(1, 'a'), (2, 'a')]
/// );
/// assert_eq!(
/// uniq_by_fst_comp().rfold(vec![], |mut v, x| {v.push(x); v}),
/// vec![(2, 'b'), (1, 'c')]
/// );
/// ```
///
#[stable(feature = "rust1", since = "1.0.0")]
fn next_back(&mut self) -> Option<Self::Item>;

Expand Down
13 changes: 13 additions & 0 deletions src/librustc_parse/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,19 @@ impl<'a> Parser<'a> {
return self.expect(&token::Semi).map(drop);
} else if !sm.is_multiline(self.prev_token.span.until(self.token.span)) {
// The current token is in the same line as the prior token, not recoverable.
} else if [token::Comma, token::Colon].contains(&self.token.kind)
&& &self.prev_token.kind == &token::CloseDelim(token::Paren)
{
// Likely typo: The current token is on a new line and is expected to be
// `.`, `;`, `?`, or an operator after a close delimiter token.
//
// let a = std::process::Command::new("echo")
// .arg("1")
// ,arg("2")
// ^
// https://github.com/rust-lang/rust/issues/72253
self.expect(&token::Semi)?;
return Ok(());
} else if self.look_ahead(1, |t| {
t == &token::CloseDelim(token::Brace) || t.can_begin_expr() && t.kind != token::Colon
}) && [token::Comma, token::Colon].contains(&self.token.kind)
Expand Down
9 changes: 0 additions & 9 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
font-family: 'Fira Sans';
font-style: normal;
font-weight: 400;
font-display: optional;
src: local('Fira Sans'), url("FiraSans-Regular.woff") format('woff');
}
@font-face {
font-family: 'Fira Sans';
font-style: normal;
font-weight: 500;
font-display: optional;
src: local('Fira Sans Medium'), url("FiraSans-Medium.woff") format('woff');
}

Expand All @@ -19,23 +17,18 @@
font-family: 'Source Serif Pro';
font-style: normal;
font-weight: 400;
/* The difference for body text without this font is greater than other fonts,
* so the 0~100ms block of fallback is preferred over optional, for legibility. */
font-display: fallback;
src: local('Source Serif Pro'), url("SourceSerifPro-Regular.ttf.woff") format('woff');
}
@font-face {
font-family: 'Source Serif Pro';
font-style: italic;
font-weight: 400;
font-display: optional;
src: local('Source Serif Pro Italic'), url("SourceSerifPro-It.ttf.woff") format('woff');
}
@font-face {
font-family: 'Source Serif Pro';
font-style: normal;
font-weight: 700;
font-display: optional;
src: local('Source Serif Pro Bold'), url("SourceSerifPro-Bold.ttf.woff") format('woff');
}

Expand All @@ -44,7 +37,6 @@
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 400;
font-display: optional;
/* Avoid using locally installed font because bad versions are in circulation:
* see https://github.com/rust-lang/rust/issues/24355 */
src: url("SourceCodePro-Regular.woff") format('woff');
Expand All @@ -53,7 +45,6 @@
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 600;
font-display: optional;
src: url("SourceCodePro-Semibold.woff") format('woff');
}

Expand Down
41 changes: 41 additions & 0 deletions src/test/ui/issues/issue-50687-ice-on-borrow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This previously caused an ICE at:
// librustc/traits/structural_impls.rs:180: impossible case reached

#![no_main]

use std::borrow::Borrow;
use std::io;
use std::io::Write;

trait Constraint {}

struct Container<T> {
t: T,
}

struct Borrowed;
struct Owned;

impl<'a, T> Write for &'a Container<T>
where
T: Constraint,
&'a T: Write,
{
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
Ok(buf.len())
}

fn flush(&mut self) -> io::Result<()> {
Ok(())
}
}

impl Borrow<Borrowed> for Owned {
fn borrow(&self) -> &Borrowed {
&Borrowed
}
}

fn func(owned: Owned) {
let _: () = Borrow::borrow(&owned); //~ ERROR mismatched types
}
16 changes: 16 additions & 0 deletions src/test/ui/issues/issue-50687-ice-on-borrow.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0308]: mismatched types
--> $DIR/issue-50687-ice-on-borrow.rs:40:17
|
LL | let _: () = Borrow::borrow(&owned);
| -- ^^^^^^^^^^^^^^^^^^^^^^
| | |
| | expected `()`, found reference
| | help: consider dereferencing the borrow: `*Borrow::borrow(&owned)`
| expected due to this
|
= note: expected unit type `()`
found reference `&_`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
6 changes: 6 additions & 0 deletions src/test/ui/issues/issue-72253.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
let a = std::process::Command::new("echo")
.arg("1")
,arg("2") //~ ERROR expected one of `.`, `;`, `?`, or an operator, found `,`
.output();
}
10 changes: 10 additions & 0 deletions src/test/ui/issues/issue-72253.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: expected one of `.`, `;`, `?`, or an operator, found `,`
--> $DIR/issue-72253.rs:4:9
|
LL | .arg("1")
| - expected one of `.`, `;`, `?`, or an operator
LL | ,arg("2")
| ^ unexpected token

error: aborting due to previous error