Skip to content

Commit

Permalink
Address fallout
Browse files Browse the repository at this point in the history
  • Loading branch information
aturon committed Dec 17, 2016
1 parent fce6af2 commit 9a5cef4
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 83 deletions.
33 changes: 2 additions & 31 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl<T> Rc<T> {
#[inline]
#[stable(feature = "rc_unique", since = "1.4.0")]
pub fn try_unwrap(this: Self) -> Result<T, Self> {
if Rc::would_unwrap(&this) {
if Rc::strong_count(&this) == 1 {
unsafe {
let val = ptr::read(&*this); // copy the contained object

Expand All @@ -343,23 +343,6 @@ impl<T> Rc<T> {
///
/// [try_unwrap]: struct.Rc.html#method.try_unwrap
/// [`Ok`]: ../../std/result/enum.Result.html#variant.Ok
///
/// # Examples
///
/// ```
/// #![feature(rc_would_unwrap)]
///
/// use std::rc::Rc;
///
/// let x = Rc::new(3);
/// assert!(Rc::would_unwrap(&x));
/// assert_eq!(Rc::try_unwrap(x), Ok(3));
///
/// let x = Rc::new(4);
/// let _y = x.clone();
/// assert!(!Rc::would_unwrap(&x));
/// assert_eq!(*Rc::try_unwrap(x).unwrap_err(), 4);
/// ```
#[unstable(feature = "rc_would_unwrap",
reason = "just added for niche usecase",
issue = "28356")]
Expand Down Expand Up @@ -518,20 +501,8 @@ impl<T: ?Sized> Rc<T> {
/// this inner value.
///
/// [weak]: struct.Weak.html
///
/// # Examples
///
/// ```
/// #![feature(rc_counts)]
///
/// use std::rc::Rc;
///
/// let five = Rc::new(5);
///
/// assert!(Rc::is_unique(&five));
/// ```
#[inline]
#[unstable(feature = "rc_counts", reason = "uniqueness has unclear meaning",
#[unstable(feature = "is_unique", reason = "uniqueness has unclear meaning",
issue = "28356")]
#[rustc_deprecated(since = "1.15.0",
reason = "too niche; use `strong_count` and `weak_count` instead")]
Expand Down
1 change: 0 additions & 1 deletion src/libcollectionstest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#![feature(test)]
#![feature(unboxed_closures)]
#![feature(unicode)]
#![feature(vec_into_iter_as_slice)]

extern crate collections;
extern crate test;
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ pub struct RefCell<T: ?Sized> {
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[unstable(feature = "borrow_state", issue = "27733")]
#[rustc_deprecated(since = "1.15.0", reason = "use `try_borrow` instead")]
#[allow(deprecated)]
pub enum BorrowState {
/// The cell is currently being read, there is at least one active `borrow`.
Reading,
Expand Down Expand Up @@ -513,6 +514,7 @@ impl<T: ?Sized> RefCell<T> {
/// ```
#[unstable(feature = "borrow_state", issue = "27733")]
#[rustc_deprecated(since = "1.15.0", reason = "use `try_borrow` instead")]
#[allow(deprecated)]
#[inline]
pub fn borrow_state(&self) -> BorrowState {
match self.borrow.get() {
Expand Down
10 changes: 5 additions & 5 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#![stable(feature = "rust1", since = "1.0.0")]

use cell::{UnsafeCell, Cell, RefCell, Ref, RefMut, BorrowState};
use cell::{UnsafeCell, Cell, RefCell, Ref, RefMut};
use marker::PhantomData;
use mem;
use num::flt2dec;
Expand Down Expand Up @@ -1634,13 +1634,13 @@ impl<T: Copy + Debug> Debug for Cell<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized + Debug> Debug for RefCell<T> {
fn fmt(&self, f: &mut Formatter) -> Result {
match self.borrow_state() {
BorrowState::Unused | BorrowState::Reading => {
match self.try_borrow() {
Ok(borrow) => {
f.debug_struct("RefCell")
.field("value", &self.borrow())
.field("value", &borrow)
.finish()
}
BorrowState::Writing => {
Err(_) => {
f.debug_struct("RefCell")
.field("value", &"<borrowed>")
.finish()
Expand Down
2 changes: 0 additions & 2 deletions src/libcore/iter/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,6 @@ pub trait Iterator {
/// # Examples
///
/// ```
/// #![feature(iter_max_by)]
/// let a = [-3_i32, 0, 1, 5, -10];
/// assert_eq!(*a.iter().max_by(|x, y| x.cmp(y)).unwrap(), 5);
/// ```
Expand Down Expand Up @@ -1746,7 +1745,6 @@ pub trait Iterator {
/// # Examples
///
/// ```
/// #![feature(iter_min_by)]
/// let a = [-3_i32, 0, 1, 5, -10];
/// assert_eq!(*a.iter().min_by(|x, y| x.cmp(y)).unwrap(), -10);
/// ```
Expand Down
37 changes: 22 additions & 15 deletions src/libcoretest/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ fn double_imm_borrow() {
fn no_mut_then_imm_borrow() {
let x = RefCell::new(0);
let _b1 = x.borrow_mut();
assert_eq!(x.borrow_state(), BorrowState::Writing);
assert!(x.try_borrow().is_err());
}

#[test]
fn no_imm_then_borrow_mut() {
let x = RefCell::new(0);
let _b1 = x.borrow();
assert_eq!(x.borrow_state(), BorrowState::Reading);
assert!(x.try_borrow_mut().is_err());
}

#[test]
fn no_double_borrow_mut() {
let x = RefCell::new(0);
assert_eq!(x.borrow_state(), BorrowState::Unused);
assert!(x.try_borrow().is_ok());
let _b1 = x.borrow_mut();
assert_eq!(x.borrow_state(), BorrowState::Writing);
assert!(x.try_borrow().is_err());
}

#[test]
Expand Down Expand Up @@ -102,7 +102,8 @@ fn double_borrow_single_release_no_borrow_mut() {
{
let _b2 = x.borrow();
}
assert_eq!(x.borrow_state(), BorrowState::Reading);
assert!(x.try_borrow().is_ok());
assert!(x.try_borrow_mut().is_err());
}

#[test]
Expand All @@ -119,30 +120,38 @@ fn ref_clone_updates_flag() {
let x = RefCell::new(0);
{
let b1 = x.borrow();
assert_eq!(x.borrow_state(), BorrowState::Reading);
assert!(x.try_borrow().is_ok());
assert!(x.try_borrow_mut().is_err());
{
let _b2 = Ref::clone(&b1);
assert_eq!(x.borrow_state(), BorrowState::Reading);
assert!(x.try_borrow().is_ok());
assert!(x.try_borrow_mut().is_err());
}
assert_eq!(x.borrow_state(), BorrowState::Reading);
assert!(x.try_borrow().is_ok());
assert!(x.try_borrow_mut().is_err());
}
assert_eq!(x.borrow_state(), BorrowState::Unused);
assert!(x.try_borrow().is_ok());
assert!(x.try_borrow_mut().is_ok());
}

#[test]
fn ref_map_does_not_update_flag() {
let x = RefCell::new(Some(5));
{
let b1: Ref<Option<u32>> = x.borrow();
assert_eq!(x.borrow_state(), BorrowState::Reading);
assert!(x.try_borrow().is_ok());
assert!(x.try_borrow_mut().is_err());
{
let b2: Ref<u32> = Ref::map(b1, |o| o.as_ref().unwrap());
assert_eq!(*b2, 5);
assert_eq!(x.borrow_state(), BorrowState::Reading);
assert!(x.try_borrow().is_ok());
assert!(x.try_borrow_mut().is_err());
}
assert_eq!(x.borrow_state(), BorrowState::Unused);
assert!(x.try_borrow().is_ok());
assert!(x.try_borrow_mut().is_ok());
}
assert_eq!(x.borrow_state(), BorrowState::Unused);
assert!(x.try_borrow().is_ok());
assert!(x.try_borrow_mut().is_ok());
}

#[test]
Expand Down Expand Up @@ -247,5 +256,3 @@ fn refcell_ref_coercion() {
assert_eq!(&*coerced, comp);
}
}


4 changes: 0 additions & 4 deletions src/libcoretest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

#![deny(warnings)]

#![feature(borrow_state)]
#![feature(box_syntax)]
#![feature(cell_extras)]
#![feature(char_escape_debug)]
#![feature(const_fn)]
#![feature(core_private_bignum)]
Expand All @@ -32,8 +30,6 @@
#![feature(try_from)]
#![feature(unicode)]
#![feature(unique)]
#![feature(iter_max_by)]
#![feature(iter_min_by)]
#![feature(ordering_chaining)]
#![feature(result_unwrap_or_default)]
#![feature(ptr_unaligned)]
Expand Down
16 changes: 6 additions & 10 deletions src/librustc/dep_graph/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//! created. See `./README.md` for details.
use hir::def_id::DefId;
use std::cell::{BorrowState, RefCell};
use std::cell::RefCell;
use std::env;

use super::DepNode;
Expand Down Expand Up @@ -71,15 +71,11 @@ impl ShadowGraph {

pub fn enqueue(&self, message: &DepMessage) {
if ENABLED {
match self.stack.borrow_state() {
BorrowState::Unused => {}
_ => {
// When we apply edge filters, that invokes the
// Debug trait on DefIds, which in turn reads from
// various bits of state and creates reads! Ignore
// those recursive reads.
return;
}
if self.stack.try_borrow().is_err() {
// When we apply edge filters, that invokes the Debug trait on
// DefIds, which in turn reads from various bits of state and
// creates reads! Ignore those recursive reads.
return;
}

let mut stack = self.stack.borrow_mut();
Expand Down
1 change: 0 additions & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#![cfg_attr(not(stage0), deny(warnings))]

#![feature(associated_consts)]
#![feature(borrow_state)]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(collections)]
Expand Down
1 change: 0 additions & 1 deletion src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#![cfg_attr(not(stage0), deny(warnings))]

#![feature(associated_consts)]
#![feature(borrow_state)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
#![feature(staged_api)]
Expand Down
8 changes: 3 additions & 5 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,9 @@ impl<'a> Resolver<'a> {
-> Result<&'a NameBinding<'a>, Determinacy> {
self.populate_module_if_necessary(module);

let resolution = self.resolution(module, name, ns);
let resolution = match resolution.borrow_state() {
::std::cell::BorrowState::Unused => resolution.borrow_mut(),
_ => return Err(Determined), // This happens when there is a cycle of imports
};
let resolution = self.resolution(module, name, ns)
.try_borrow_mut()
.map_err(|_| Determined)?; // This happens when there is a cycle of imports

if let Some(span) = record_used {
if let Some(binding) = resolution.binding {
Expand Down
1 change: 0 additions & 1 deletion src/librustc_trans/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#![feature(associated_consts)]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(cell_extras)]
#![feature(const_fn)]
#![feature(custom_attribute)]
#![allow(unused_attributes)]
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use io::prelude::*;

use cell::{RefCell, BorrowState};
use cell::RefCell;
use fmt;
use io::lazy::Lazy;
use io::{self, BufReader, LineWriter};
Expand Down Expand Up @@ -638,8 +638,8 @@ pub fn _print(args: fmt::Arguments) {
LocalKeyState::Destroyed => stdout().write_fmt(args),
LocalKeyState::Valid => {
LOCAL_STDOUT.with(|s| {
if s.borrow_state() == BorrowState::Unused {
if let Some(w) = s.borrow_mut().as_mut() {
if let Ok(mut borrowed) = s.try_borrow_mut() {
if let Some(w) = borrowed.as_mut() {
return w.write_fmt(args);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/redox/ext/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub trait CommandExt {
/// When this closure is run, aspects such as the stdio file descriptors and
/// working directory have successfully been changed, so output to these
/// locations may not appear where intended.
#[unstable(feature = "process_exec", issue = "31398")]
#[stable(feature = "process_exec", since = "1.15.0")]
fn before_exec<F>(&mut self, f: F) -> &mut process::Command
where F: FnMut() -> io::Result<()> + Send + Sync + 'static;

Expand Down
2 changes: 0 additions & 2 deletions src/libstd_unicode/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ impl char {
/// A buffer that's too small:
///
/// ```
/// #![feature(unicode)]
/// use std::thread;
///
/// let result = thread::spawn(|| {
Expand Down Expand Up @@ -501,7 +500,6 @@ impl char {
/// A buffer that's too small:
///
/// ```
/// #![feature(unicode)]
/// use std::thread;
///
/// let result = thread::spawn(|| {
Expand Down
1 change: 0 additions & 1 deletion src/libstd_unicode/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#![feature(lang_items)]
#![feature(staged_api)]
#![feature(try_from)]
#![feature(unicode)]

mod tables;
mod u_str;
Expand Down

0 comments on commit 9a5cef4

Please sign in to comment.