From dfa094014c45ccde2e327dd3f17557ded3249ebf Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 19 Sep 2016 13:01:59 +0200 Subject: Add missing urls for Box doc --- src/liballoc/boxed.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index bc9b6e805ef..28f4dda1408 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -244,12 +244,14 @@ impl Box { /// the destructor of `T` and free the allocated memory. Since the /// way `Box` allocates and releases memory is unspecified, the /// only valid pointer to pass to this function is the one taken - /// from another `Box` via the `Box::into_raw` function. + /// from another `Box` via the [`Box::into_raw`] function. /// /// This function is unsafe because improper use may lead to /// memory problems. For example, a double-free may occur if the /// function is called twice on the same raw pointer. /// + /// [`Box::into_raw`]: struct.Box.html#method.into_raw + /// /// # Examples /// /// ``` @@ -269,12 +271,14 @@ impl Box { /// memory previously managed by the `Box`. In particular, the /// caller should properly destroy `T` and release the memory. The /// proper way to do so is to convert the raw pointer back into a - /// `Box` with the `Box::from_raw` function. + /// `Box` with the [`Box::from_raw`] function. /// /// Note: this is an associated function, which means that you have /// to call it as `Box::into_raw(b)` instead of `b.into_raw()`. This /// is so that there is no conflict with a method on the inner type. /// + /// [`Box::from_raw`]: struct.Box.html#method.from_raw + /// /// # Examples /// /// ``` -- cgit 1.4.1-3-g733a5 From c316ae56e65169edacda1faace93a09cdbaa3d7f Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Sat, 17 Sep 2016 11:22:04 -0700 Subject: Tweak std::rc docs Fixes #29372. --- src/liballoc/rc.rs | 470 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 310 insertions(+), 160 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 32e5587ff41..e0f635f195b 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -10,90 +10,138 @@ #![allow(deprecated)] -//! Unsynchronized reference-counted boxes (the `Rc` type) which are usable -//! only within a single thread. +//! Single-threaded reference-counting pointers. //! -//! The `Rc` type provides shared ownership of an immutable value. -//! Destruction is deterministic, and will occur as soon as the last owner is -//! gone. It is marked as non-sendable because it avoids the overhead of atomic -//! reference counting. +//! The type [`Rc`][rc] provides shared ownership of a value, allocated +//! in the heap. Invoking [`clone`][clone] on `Rc` produces a new pointer +//! to the same value in the heap. When the last `Rc` pointer to a given +//! value is destroyed, the pointed-to value is also destroyed. //! -//! The `downgrade` method can be used to create a non-owning `Weak` pointer -//! to the box. A `Weak` pointer can be upgraded to an `Rc` pointer, but -//! will return `None` if the value has already been dropped. +//! Shared pointers in Rust disallow mutation by default, and `Rc` is no +//! exception. If you need to mutate through an `Rc`, use [`Cell`][cell] or +//! [`RefCell`][refcell]. //! -//! For example, a tree with parent pointers can be represented by putting the -//! nodes behind strong `Rc` pointers, and then storing the parent pointers -//! as `Weak` pointers. +//! `Rc` uses non-atomic reference counting. This means that overhead is very +//! low, but an `Rc` cannot be sent between threads, and consequently `Rc` +//! does not implement [`Send`][send]. As a result, the Rust compiler +//! will check *at compile time* that you are not sending `Rc`s between +//! threads. If you need multi-threaded, atomic reference counting, use +//! [`sync::Arc`][arc]. +//! +//! The [`downgrade`][downgrade] method can be used to create a non-owning +//! [`Weak`][weak] pointer. A `Weak` pointer can be [`upgrade`][upgrade]d +//! to an `Rc`, but this will return [`None`][option] if the value has +//! already been dropped. +//! +//! A cycle between `Rc` pointers will never be deallocated. For this reason, +//! `Weak` is used to break cycles. For example, a tree could have strong +//! `Rc` pointers from parent nodes to children, and `Weak` pointers from +//! children back to their parents. +//! +//! `Rc` automatically dereferences to `T` (via the [`Deref`][deref] trait), +//! so you can call `T`'s methods on a value of type `Rc`. To avoid name +//! clashes with `T`'s methods, the methods of `Rc` itself are [associated +//! functions][assoc], called using function-like syntax: +//! +//! ``` +//! # use std::rc::Rc; +//! # let my_rc = Rc::new(()); +//! Rc::downgrade(&my_rc); +//! ``` +//! +//! `Weak` does not auto-dereference to `T`, because the value may have +//! already been destroyed. +//! +//! [rc]: struct.Rc.html +//! [weak]: struct.Weak.html +//! [clone]: ../../std/clone/trait.Clone.html#tymethod.clone +//! [cell]: ../../std/cell/struct.Cell.html +//! [refcell]: ../../std/cell/struct.RefCell.html +//! [send]: ../../std/marker/trait.Send.html +//! [arc]: ../../std/sync/struct.Arc.html +//! [deref]: ../../std/ops/trait.Deref.html +//! [downgrade]: struct.Rc.html#method.downgrade +//! [upgrade]: struct.Weak.html#method.upgrade +//! [option]: ../../std/option/enum.Option.html +//! [assoc]: ../../book/method-syntax.html#associated-functions //! //! # Examples //! //! Consider a scenario where a set of `Gadget`s are owned by a given `Owner`. //! We want to have our `Gadget`s point to their `Owner`. We can't do this with //! unique ownership, because more than one gadget may belong to the same -//! `Owner`. `Rc` allows us to share an `Owner` between multiple `Gadget`s, +//! `Owner`. `Rc` allows us to share an `Owner` between multiple `Gadget`s, //! and have the `Owner` remain allocated as long as any `Gadget` points at it. //! -//! ```rust +//! ``` //! use std::rc::Rc; //! //! struct Owner { -//! name: String +//! name: String, //! // ...other fields //! } //! //! struct Gadget { //! id: i32, -//! owner: Rc +//! owner: Rc, //! // ...other fields //! } //! //! fn main() { -//! // Create a reference counted Owner. -//! let gadget_owner : Rc = Rc::new( -//! Owner { name: String::from("Gadget Man") } +//! // Create a reference-counted `Owner`. +//! let gadget_owner: Rc = Rc::new( +//! Owner { +//! name: "Gadget Man".to_string(), +//! } //! ); //! -//! // Create Gadgets belonging to gadget_owner. To increment the reference -//! // count we clone the `Rc` object. -//! let gadget1 = Gadget { id: 1, owner: gadget_owner.clone() }; -//! let gadget2 = Gadget { id: 2, owner: gadget_owner.clone() }; +//! // Create `Gadget`s belonging to `gadget_owner`. Cloning the `Rc` +//! // value gives us a new pointer to the same `Owner` value, incrementing +//! // the reference count in the process. +//! let gadget1 = Gadget { +//! id: 1, +//! owner: gadget_owner.clone(), +//! }; +//! let gadget2 = Gadget { +//! id: 2, +//! owner: gadget_owner.clone(), +//! }; //! +//! // Dispose of our local variable `gadget_owner`. //! drop(gadget_owner); //! -//! // Despite dropping gadget_owner, we're still able to print out the name -//! // of the Owner of the Gadgets. This is because we've only dropped the -//! // reference count object, not the Owner it wraps. As long as there are -//! // other `Rc` objects pointing at the same Owner, it will remain -//! // allocated. Notice that the `Rc` wrapper around Gadget.owner gets -//! // automatically dereferenced for us. +//! // Despite dropping `gadget_owner`, we're still able to print out the name +//! // of the `Owner` of the `Gadget`s. This is because we've only dropped a +//! // single `Rc`, not the `Owner` it points to. As long as there are +//! // other `Rc` values pointing at the same `Owner`, it will remain +//! // allocated. The field projection `gadget1.owner.name` works because +//! // `Rc` automatically dereferences to `Owner`. //! println!("Gadget {} owned by {}", gadget1.id, gadget1.owner.name); //! println!("Gadget {} owned by {}", gadget2.id, gadget2.owner.name); //! -//! // At the end of the method, gadget1 and gadget2 get destroyed, and with -//! // them the last counted references to our Owner. Gadget Man now gets -//! // destroyed as well. +//! // At the end of the function, `gadget1` and `gadget2` are destroyed, and +//! // with them the last counted references to our `Owner`. Gadget Man now +//! // gets destroyed as well. //! } //! ``` //! //! If our requirements change, and we also need to be able to traverse from -//! Owner → Gadget, we will run into problems: an `Rc` pointer from Owner -//! → Gadget introduces a cycle between the objects. This means that their -//! reference counts can never reach 0, and the objects will remain allocated: a -//! memory leak. In order to get around this, we can use `Weak` pointers. -//! These pointers don't contribute to the total count. +//! `Owner` to `Gadget`, we will run into problems. An `Rc` pointer from `Owner` +//! to `Gadget` introduces a cycle between the values. This means that their +//! reference counts can never reach 0, and the values will remain allocated +//! forever: a memory leak. In order to get around this, we can use `Weak` +//! pointers. //! //! Rust actually makes it somewhat difficult to produce this loop in the first -//! place: in order to end up with two objects that point at each other, one of -//! them needs to be mutable. This is problematic because `Rc` enforces -//! memory safety by only giving out shared references to the object it wraps, +//! place. In order to end up with two values that point at each other, one of +//! them needs to be mutable. This is difficult because `Rc` enforces +//! memory safety by only giving out shared references to the value it wraps, //! and these don't allow direct mutation. We need to wrap the part of the -//! object we wish to mutate in a `RefCell`, which provides *interior +//! value we wish to mutate in a [`RefCell`][refcell], which provides *interior //! mutability*: a method to achieve mutability through a shared reference. -//! `RefCell` enforces Rust's borrowing rules at runtime. Read the `Cell` -//! documentation for more details on interior mutability. +//! `RefCell` enforces Rust's borrowing rules at runtime. //! -//! ```rust +//! ``` //! use std::rc::Rc; //! use std::rc::Weak; //! use std::cell::RefCell; @@ -111,41 +159,58 @@ //! } //! //! fn main() { -//! // Create a reference counted Owner. Note the fact that we've put the -//! // Owner's vector of Gadgets inside a RefCell so that we can mutate it -//! // through a shared reference. -//! let gadget_owner : Rc = Rc::new( +//! // Create a reference-counted `Owner`. Note that we've put the `Owner`'s +//! // vector of `Gadget`s inside a `RefCell` so that we can mutate it through +//! // a shared reference. +//! let gadget_owner: Rc = Rc::new( //! Owner { //! name: "Gadget Man".to_string(), -//! gadgets: RefCell::new(Vec::new()), +//! gadgets: RefCell::new(vec![]), //! } //! ); //! -//! // Create Gadgets belonging to gadget_owner as before. -//! let gadget1 = Rc::new(Gadget{id: 1, owner: gadget_owner.clone()}); -//! let gadget2 = Rc::new(Gadget{id: 2, owner: gadget_owner.clone()}); +//! // Create `Gadget`s belonging to `gadget_owner`, as before. +//! let gadget1 = Rc::new( +//! Gadget { +//! id: 1, +//! owner: gadget_owner.clone(), +//! } +//! ); +//! let gadget2 = Rc::new( +//! Gadget { +//! id: 2, +//! owner: gadget_owner.clone(), +//! } +//! ); +//! +//! // Add the `Gadget`s to their `Owner`. +//! { +//! let mut gadgets = gadget_owner.gadgets.borrow_mut(); +//! gadgets.push(Rc::downgrade(&gadget1)); +//! gadgets.push(Rc::downgrade(&gadget2)); //! -//! // Add the Gadgets to their Owner. To do this we mutably borrow from -//! // the RefCell holding the Owner's Gadgets. -//! gadget_owner.gadgets.borrow_mut().push(Rc::downgrade(&gadget1)); -//! gadget_owner.gadgets.borrow_mut().push(Rc::downgrade(&gadget2)); +//! // `RefCell` dynamic borrow ends here. +//! } //! -//! // Iterate over our Gadgets, printing their details out -//! for gadget_opt in gadget_owner.gadgets.borrow().iter() { +//! // Iterate over our `Gadget`s, printing their details out. +//! for gadget_weak in gadget_owner.gadgets.borrow().iter() { //! -//! // gadget_opt is a Weak. Since weak pointers can't guarantee -//! // that their object is still allocated, we need to call upgrade() -//! // on them to turn them into a strong reference. This returns an -//! // Option, which contains a reference to our object if it still -//! // exists. -//! let gadget = gadget_opt.upgrade().unwrap(); +//! // `gadget_weak` is a `Weak`. Since `Weak` pointers can't +//! // guarantee the value is still allocated, we need to call +//! // `upgrade`, which returns an `Option>`. +//! // +//! // In this case we know the value still exists, so we simply +//! // `unwrap` the `Option`. In a more complicated program, you might +//! // need graceful error handling for a `None` result. +//! +//! let gadget = gadget_weak.upgrade().unwrap(); //! println!("Gadget {} owned by {}", gadget.id, gadget.owner.name); //! } //! -//! // At the end of the method, gadget_owner, gadget1 and gadget2 get -//! // destroyed. There are now no strong (`Rc`) references to the gadgets. -//! // Once they get destroyed, the Gadgets get destroyed. This zeroes the -//! // reference count on Gadget Man, they get destroyed as well. +//! // At the end of the function, `gadget_owner`, `gadget1`, and `gadget2` +//! // are destroyed. There are now no strong (`Rc`) pointers to the +//! // gadgets, so they are destroyed. This zeroes the reference count on +//! // Gadget Man, so he gets destroyed as well. //! } //! ``` @@ -179,15 +244,14 @@ struct RcBox { } -/// A reference-counted pointer type over an immutable value. +/// A single-threaded reference-counting pointer. /// -/// See the [module level documentation](./index.html) for more details. +/// See the [module-level documentation](./index.html) for more details. /// -/// Note: the inherent methods defined on `Rc` are all associated functions, -/// which means that you have to call them as e.g. `Rc::get_mut(&value)` instead -/// of `value.get_mut()`. This is so that there are no conflicts with methods -/// on the inner type `T`, which are what you want to call in the majority of -/// cases. +/// The inherent methods of `Rc` are all associated functions, which means +/// that you have to call them as e.g. `Rc::get_mut(&value)` instead of +/// `value.get_mut()`. This avoids conflicts with methods of the inner +/// type `T`. #[cfg_attr(stage0, unsafe_no_drop_flag)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Rc { @@ -229,9 +293,9 @@ impl Rc { } } - /// Unwraps the contained value if the `Rc` has exactly one strong reference. + /// Returns the contained value, if the `Rc` has exactly one strong reference. /// - /// Otherwise, an `Err` is returned with the same `Rc`. + /// Otherwise, an `Err` is returned with the same `Rc` that was passed in. /// /// This will succeed even if there are outstanding weak references. /// @@ -245,7 +309,7 @@ impl Rc { /// /// let x = Rc::new(4); /// let _y = x.clone(); - /// assert_eq!(Rc::try_unwrap(x), Err(Rc::new(4))); + /// assert_eq!(*Rc::try_unwrap(x).unwrap_err(), 4); /// ``` #[inline] #[stable(feature = "rc_unique", since = "1.4.0")] @@ -268,7 +332,7 @@ impl Rc { } } - /// Checks if `Rc::try_unwrap` would return `Ok`. + /// Checks whether `Rc::try_unwrap` would return `Ok`. /// /// # Examples /// @@ -284,7 +348,7 @@ impl Rc { /// let x = Rc::new(4); /// let _y = x.clone(); /// assert!(!Rc::would_unwrap(&x)); - /// assert_eq!(Rc::try_unwrap(x), Err(Rc::new(4))); + /// assert_eq!(*Rc::try_unwrap(x).unwrap_err(), 4); /// ``` #[unstable(feature = "rc_would_unwrap", reason = "just added for niche usecase", @@ -295,7 +359,9 @@ impl Rc { } impl Rc { - /// Creates a new `Weak` reference from this value. + /// Creates a new [`Weak`][weak] pointer to this value. + /// + /// [weak]: struct.Weak.html /// /// # Examples /// @@ -312,7 +378,22 @@ impl Rc { Weak { ptr: this.ptr } } - /// Get the number of weak references to this value. + /// Gets the number of [`Weak`][weak] pointers to this value. + /// + /// [weak]: struct.Weak.html + /// + /// # Examples + /// + /// ``` + /// #![feature(rc_counts)] + /// + /// use std::rc::Rc; + /// + /// let five = Rc::new(5); + /// let _weak_five = Rc::downgrade(&five); + /// + /// assert_eq!(1, Rc::weak_count(&five)); + /// ``` #[inline] #[unstable(feature = "rc_counts", reason = "not clearly useful", issue = "28356")] @@ -320,7 +401,20 @@ impl Rc { this.weak() - 1 } - /// Get the number of strong references to this value. + /// Gets the number of strong (`Rc`) pointers to this value. + /// + /// # Examples + /// + /// ``` + /// #![feature(rc_counts)] + /// + /// use std::rc::Rc; + /// + /// let five = Rc::new(5); + /// let _also_five = five.clone(); + /// + /// assert_eq!(2, Rc::strong_count(&five)); + /// ``` #[inline] #[unstable(feature = "rc_counts", reason = "not clearly useful", issue = "28356")] @@ -328,8 +422,10 @@ impl Rc { this.strong() } - /// Returns true if there are no other `Rc` or `Weak` values that share - /// the same inner value. + /// Returns true if there are no other `Rc` or [`Weak`][weak] pointers to + /// this inner value. + /// + /// [weak]: struct.Weak.html /// /// # Examples /// @@ -349,10 +445,19 @@ impl Rc { Rc::weak_count(this) == 0 && Rc::strong_count(this) == 1 } - /// Returns a mutable reference to the contained value if the `Rc` has - /// one strong reference and no weak references. + /// Returns a mutable reference to the inner value, if there are + /// no other `Rc` or [`Weak`][weak] pointers to the same value. + /// + /// Returns [`None`][option] otherwise, because it is not safe to + /// mutate a shared value. /// - /// Returns `None` if the `Rc` is not unique. + /// See also [`make_mut`][make_mut], which will [`clone`][clone] + /// the inner value when it's shared. + /// + /// [weak]: struct.Weak.html + /// [option]: ../../std/option/enum.Option.html + /// [make_mut]: struct.Rc.html#method.make_mut + /// [clone]: ../../std/clone/trait.Clone.html#tymethod.clone /// /// # Examples /// @@ -381,8 +486,8 @@ impl Rc { #[unstable(feature = "ptr_eq", reason = "newly added", issue = "36497")] - /// Return whether two `Rc` references point to the same value - /// (not just values that compare equal). + /// Returns true if the two `Rc`s point to the same value (not + /// just values that compare as equal). /// /// # Examples /// @@ -406,11 +511,17 @@ impl Rc { } impl Rc { - /// Make a mutable reference into the given `Rc` by cloning the inner - /// data if the `Rc` doesn't have one strong reference and no weak - /// references. + /// Makes a mutable reference into the given `Rc`. + /// + /// If there are other `Rc` or [`Weak`][weak] pointers to the same value, + /// then `make_mut` will invoke [`clone`][clone] on the inner value to + /// ensure unique ownership. This is also referred to as clone-on-write. /// - /// This is also referred to as a copy-on-write. + /// See also [`get_mut`][get_mut], which will fail rather than cloning. + /// + /// [weak]: struct.Weak.html + /// [clone]: ../../std/clone/trait.Clone.html#tymethod.clone + /// [get_mut]: struct.Rc.html#method.get_mut /// /// # Examples /// @@ -419,16 +530,15 @@ impl Rc { /// /// let mut data = Rc::new(5); /// - /// *Rc::make_mut(&mut data) += 1; // Won't clone anything - /// let mut other_data = data.clone(); // Won't clone inner data - /// *Rc::make_mut(&mut data) += 1; // Clones inner data - /// *Rc::make_mut(&mut data) += 1; // Won't clone anything - /// *Rc::make_mut(&mut other_data) *= 2; // Won't clone anything + /// *Rc::make_mut(&mut data) += 1; // Won't clone anything + /// let mut other_data = data.clone(); // Won't clone inner data + /// *Rc::make_mut(&mut data) += 1; // Clones inner data + /// *Rc::make_mut(&mut data) += 1; // Won't clone anything + /// *Rc::make_mut(&mut other_data) *= 2; // Won't clone anything /// - /// // Note: data and other_data now point to different numbers + /// // Now `data` and `other_data` point to different values. /// assert_eq!(*data, 8); /// assert_eq!(*other_data, 12); - /// /// ``` #[inline] #[stable(feature = "rc_unique", since = "1.4.0")] @@ -470,30 +580,30 @@ impl Deref for Rc { #[stable(feature = "rust1", since = "1.0.0")] impl Drop for Rc { - /// Drops the `Rc`. + /// Drops the `Rc`. /// /// This will decrement the strong reference count. If the strong reference - /// count becomes zero and the only other references are `Weak` ones, - /// `drop`s the inner value. + /// count reaches zero then the only other references (if any) are `Weak`, + /// so we `drop` the inner value. /// /// # Examples /// /// ``` /// use std::rc::Rc; /// - /// { - /// let five = Rc::new(5); + /// struct Foo; /// - /// // stuff - /// - /// drop(five); // explicit drop + /// impl Drop for Foo { + /// fn drop(&mut self) { + /// println!("dropped!"); + /// } /// } - /// { - /// let five = Rc::new(5); /// - /// // stuff + /// let foo = Rc::new(Foo); + /// let foo2 = foo.clone(); /// - /// } // implicit drop + /// drop(foo); // Doesn't print anything + /// drop(foo2); // Prints "dropped!" /// ``` #[unsafe_destructor_blind_to_params] fn drop(&mut self) { @@ -519,10 +629,10 @@ impl Drop for Rc { #[stable(feature = "rust1", since = "1.0.0")] impl Clone for Rc { - /// Makes a clone of the `Rc`. + /// Makes a clone of the `Rc` pointer. /// - /// When you clone an `Rc`, it will create another pointer to the data and - /// increase the strong reference counter. + /// This creates another pointer to the same inner value, increasing the + /// strong reference count. /// /// # Examples /// @@ -550,6 +660,7 @@ impl Default for Rc { /// use std::rc::Rc; /// /// let x: Rc = Default::default(); + /// assert_eq!(*x, 0); /// ``` #[inline] fn default() -> Rc { @@ -559,9 +670,9 @@ impl Default for Rc { #[stable(feature = "rust1", since = "1.0.0")] impl PartialEq for Rc { - /// Equality for two `Rc`s. + /// Equality for two `Rc`s. /// - /// Two `Rc`s are equal if their inner value are equal. + /// Two `Rc`s are equal if their inner values are equal. /// /// # Examples /// @@ -570,16 +681,16 @@ impl PartialEq for Rc { /// /// let five = Rc::new(5); /// - /// five == Rc::new(5); + /// assert!(five == Rc::new(5)); /// ``` #[inline(always)] fn eq(&self, other: &Rc) -> bool { **self == **other } - /// Inequality for two `Rc`s. + /// Inequality for two `Rc`s. /// - /// Two `Rc`s are unequal if their inner value are unequal. + /// Two `Rc`s are unequal if their inner values are unequal. /// /// # Examples /// @@ -588,7 +699,7 @@ impl PartialEq for Rc { /// /// let five = Rc::new(5); /// - /// five != Rc::new(5); + /// assert!(five != Rc::new(6)); /// ``` #[inline(always)] fn ne(&self, other: &Rc) -> bool { @@ -601,7 +712,7 @@ impl Eq for Rc {} #[stable(feature = "rust1", since = "1.0.0")] impl PartialOrd for Rc { - /// Partial comparison for two `Rc`s. + /// Partial comparison for two `Rc`s. /// /// The two are compared by calling `partial_cmp()` on their inner values. /// @@ -609,17 +720,18 @@ impl PartialOrd for Rc { /// /// ``` /// use std::rc::Rc; + /// use std::cmp::Ordering; /// /// let five = Rc::new(5); /// - /// five.partial_cmp(&Rc::new(5)); + /// assert_eq!(Some(Ordering::Less), five.partial_cmp(&Rc::new(6))); /// ``` #[inline(always)] fn partial_cmp(&self, other: &Rc) -> Option { (**self).partial_cmp(&**other) } - /// Less-than comparison for two `Rc`s. + /// Less-than comparison for two `Rc`s. /// /// The two are compared by calling `<` on their inner values. /// @@ -630,14 +742,14 @@ impl PartialOrd for Rc { /// /// let five = Rc::new(5); /// - /// five < Rc::new(5); + /// assert!(five < Rc::new(6)); /// ``` #[inline(always)] fn lt(&self, other: &Rc) -> bool { **self < **other } - /// 'Less-than or equal to' comparison for two `Rc`s. + /// 'Less than or equal to' comparison for two `Rc`s. /// /// The two are compared by calling `<=` on their inner values. /// @@ -648,14 +760,14 @@ impl PartialOrd for Rc { /// /// let five = Rc::new(5); /// - /// five <= Rc::new(5); + /// assert!(five <= Rc::new(5)); /// ``` #[inline(always)] fn le(&self, other: &Rc) -> bool { **self <= **other } - /// Greater-than comparison for two `Rc`s. + /// Greater-than comparison for two `Rc`s. /// /// The two are compared by calling `>` on their inner values. /// @@ -666,14 +778,14 @@ impl PartialOrd for Rc { /// /// let five = Rc::new(5); /// - /// five > Rc::new(5); + /// assert!(five > Rc::new(4)); /// ``` #[inline(always)] fn gt(&self, other: &Rc) -> bool { **self > **other } - /// 'Greater-than or equal to' comparison for two `Rc`s. + /// 'Greater than or equal to' comparison for two `Rc`s. /// /// The two are compared by calling `>=` on their inner values. /// @@ -684,7 +796,7 @@ impl PartialOrd for Rc { /// /// let five = Rc::new(5); /// - /// five >= Rc::new(5); + /// assert!(five >= Rc::new(5)); /// ``` #[inline(always)] fn ge(&self, other: &Rc) -> bool { @@ -694,7 +806,7 @@ impl PartialOrd for Rc { #[stable(feature = "rust1", since = "1.0.0")] impl Ord for Rc { - /// Comparison for two `Rc`s. + /// Comparison for two `Rc`s. /// /// The two are compared by calling `cmp()` on their inner values. /// @@ -702,10 +814,11 @@ impl Ord for Rc { /// /// ``` /// use std::rc::Rc; + /// use std::cmp::Ordering; /// /// let five = Rc::new(5); /// - /// five.partial_cmp(&Rc::new(5)); + /// assert_eq!(Ordering::Less, five.cmp(&Rc::new(6))); /// ``` #[inline] fn cmp(&self, other: &Rc) -> Ordering { @@ -748,12 +861,18 @@ impl From for Rc { } } -/// A weak version of `Rc`. +/// A weak version of [`Rc`][rc]. +/// +/// `Weak` pointers do not count towards determining if the inner value +/// should be dropped. +/// +/// The typical way to obtain a `Weak` pointer is to call +/// [`Rc::downgrade`][downgrade]. /// -/// Weak references do not count when determining if the inner value should be -/// dropped. +/// See the [module-level documentation](./index.html) for more details. /// -/// See the [module level documentation](./index.html) for more. +/// [rc]: struct.Rc.html +/// [downgrade]: struct.Rc.html#method.downgrade #[cfg_attr(stage0, unsafe_no_drop_flag)] #[stable(feature = "rc_weak", since = "1.4.0")] pub struct Weak { @@ -769,10 +888,14 @@ impl !marker::Sync for Weak {} impl, U: ?Sized> CoerceUnsized> for Weak {} impl Weak { - /// Constructs a new `Weak` without an accompanying instance of T. + /// Constructs a new `Weak`, without an accompanying instance of `T`. /// - /// This allocates memory for T, but does not initialize it. Calling - /// Weak::upgrade() on the return value always gives None. + /// This allocates memory for `T`, but does not initialize it. Calling + /// [`upgrade`][upgrade] on the return value always gives + /// [`None`][option]. + /// + /// [upgrade]: struct.Weak.html#method.upgrade + /// [option]: ../../std/option/enum.Option.html /// /// # Examples /// @@ -780,6 +903,7 @@ impl Weak { /// use std::rc::Weak; /// /// let empty: Weak = Weak::new(); + /// assert!(empty.upgrade().is_none()); /// ``` #[stable(feature = "downgraded_weak", since = "1.10.0")] pub fn new() -> Weak { @@ -796,12 +920,13 @@ impl Weak { } impl Weak { - /// Upgrades a weak reference to a strong reference. + /// Upgrades the `Weak` pointer to an [`Rc`][rc], if possible. /// - /// Upgrades the `Weak` reference to an `Rc`, if possible. + /// Returns [`None`][option] if the strong count has reached zero and the + /// inner value was destroyed. /// - /// Returns `None` if there were no strong references and the data was - /// destroyed. + /// [rc]: struct.Rc.html + /// [option]: ../../std/option/enum.Option.html /// /// # Examples /// @@ -813,6 +938,13 @@ impl Weak { /// let weak_five = Rc::downgrade(&five); /// /// let strong_five: Option> = weak_five.upgrade(); + /// assert!(strong_five.is_some()); + /// + /// // Destroy all strong pointers. + /// drop(strong_five); + /// drop(five); + /// + /// assert!(weak_five.upgrade().is_none()); /// ``` #[stable(feature = "rc_weak", since = "1.4.0")] pub fn upgrade(&self) -> Option> { @@ -827,7 +959,7 @@ impl Weak { #[stable(feature = "rc_weak", since = "1.4.0")] impl Drop for Weak { - /// Drops the `Weak`. + /// Drops the `Weak` pointer. /// /// This will decrement the weak reference count. /// @@ -836,21 +968,22 @@ impl Drop for Weak { /// ``` /// use std::rc::Rc; /// - /// { - /// let five = Rc::new(5); - /// let weak_five = Rc::downgrade(&five); - /// - /// // stuff + /// struct Foo; /// - /// drop(weak_five); // explicit drop + /// impl Drop for Foo { + /// fn drop(&mut self) { + /// println!("dropped!"); + /// } /// } - /// { - /// let five = Rc::new(5); - /// let weak_five = Rc::downgrade(&five); /// - /// // stuff + /// let foo = Rc::new(Foo); + /// let weak_foo = Rc::downgrade(&foo); + /// let other_weak_foo = weak_foo.clone(); /// - /// } // implicit drop + /// drop(weak_foo); // Doesn't print anything + /// drop(foo); // Prints "dropped!" + /// + /// assert!(other_weak_foo.upgrade().is_none()); /// ``` fn drop(&mut self) { unsafe { @@ -868,9 +1001,10 @@ impl Drop for Weak { #[stable(feature = "rc_weak", since = "1.4.0")] impl Clone for Weak { - /// Makes a clone of the `Weak`. + /// Makes a clone of the `Weak` pointer. /// - /// This increases the weak reference count. + /// This creates another pointer to the same inner value, increasing the + /// weak reference count. /// /// # Examples /// @@ -897,7 +1031,23 @@ impl fmt::Debug for Weak { #[stable(feature = "downgraded_weak", since = "1.10.0")] impl Default for Weak { - /// Creates a new `Weak`. + /// Constructs a new `Weak`, without an accompanying instance of `T`. + /// + /// This allocates memory for `T`, but does not initialize it. Calling + /// [`upgrade`][upgrade] on the return value always gives + /// [`None`][option]. + /// + /// [upgrade]: struct.Weak.html#method.upgrade + /// [option]: ../../std/option/enum.Option.html + /// + /// # Examples + /// + /// ``` + /// use std::rc::Weak; + /// + /// let empty: Weak = Default::default(); + /// assert!(empty.upgrade().is_none()); + /// ``` fn default() -> Weak { Weak::new() } -- cgit 1.4.1-3-g733a5 From 3b49c60ab71547e6dbaef086eb4cd2bb7fe9ff94 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 28 Sep 2016 20:55:26 +0000 Subject: Remove stage0 hacks --- src/bootstrap/bin/rustc.rs | 3 +-- src/bootstrap/compile.rs | 16 +--------------- src/liballoc/arc.rs | 2 -- src/liballoc/lib.rs | 1 - src/liballoc/raw_vec.rs | 1 - src/liballoc/rc.rs | 2 -- src/libcollections/lib.rs | 1 - src/libcollections/vec.rs | 1 - src/libcompiler_builtins/lib.rs | 4 ++-- src/libcore/clone.rs | 7 ------- src/libcore/intrinsics.rs | 2 -- src/libstd/collections/hash/table.rs | 1 - src/libstd/lib.rs | 1 - 13 files changed, 4 insertions(+), 38 deletions(-) (limited to 'src/liballoc') diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index a70a15b383c..cdbbc229bc8 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -104,8 +104,7 @@ fn main() { let is_panic_abort = args.windows(2).any(|a| { &*a[0] == "--crate-name" && &*a[1] == "panic_abort" }); - // FIXME(stage0): remove this `stage != "0"` condition - if is_panic_abort && stage != "0" { + if is_panic_abort { cmd.arg("-C").arg("panic=abort"); } diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 9de438cfa7d..16dbcae99fa 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -25,7 +25,7 @@ use std::process::Command; use build_helper::output; use filetime::FileTime; -use util::{exe, staticlib, libdir, mtime, is_dylib, copy}; +use util::{exe, libdir, mtime, is_dylib, copy}; use {Build, Compiler, Mode}; /// Build the standard library. @@ -40,20 +40,6 @@ pub fn std<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) { let libdir = build.sysroot_libdir(compiler, target); let _ = fs::remove_dir_all(&libdir); t!(fs::create_dir_all(&libdir)); - // FIXME(stage0) remove this `if` after the next snapshot - // The stage0 compiler still passes the `-lcompiler-rt` flag to the linker but now `bootstrap` - // never builds a `libcopmiler-rt.a`! We'll fill the hole by simply copying stage0's - // `libcompiler-rt.a` to where the stage1's one is expected (though we could as well just use - // an empty `.a` archive). Note that the symbols of that stage0 `libcompiler-rt.a` won't make - // it to the final binary because now `libcore.rlib` also contains the symbols that - // `libcompiler-rt.a` provides. Since that rlib appears first in the linker arguments, its - // symbols are used instead of `libcompiler-rt.a`'s. - if compiler.stage == 0 { - let rtlib = &staticlib("compiler-rt", target); - let src = build.rustc.parent().unwrap().parent().unwrap().join("lib").join("rustlib") - .join(target).join("lib").join(rtlib); - copy(&src, &libdir.join(rtlib)); - } // Some platforms have startup objects that may be required to produce the // libstd dynamic library, for example. diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 5f9ccd1820c..e3c92fc1aa8 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -127,7 +127,6 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize; /// } /// ``` -#[cfg_attr(stage0, unsafe_no_drop_flag)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Arc { ptr: Shared>, @@ -153,7 +152,6 @@ impl, U: ?Sized> CoerceUnsized> for Arc {} /// nodes behind strong `Arc` pointers, and then storing the parent pointers /// as `Weak` pointers. -#[cfg_attr(stage0, unsafe_no_drop_flag)] #[stable(feature = "arc_weak", since = "1.4.0")] pub struct Weak { ptr: Shared>, diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index c6453da3f46..31491106d97 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -88,7 +88,6 @@ #![feature(staged_api)] #![feature(unboxed_closures)] #![feature(unique)] -#![cfg_attr(stage0, feature(unsafe_no_drop_flag))] #![feature(unsize)] #![cfg_attr(not(test), feature(fused, fn_traits, placement_new_protocol))] diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs index 23542215fa8..e153507956b 100644 --- a/src/liballoc/raw_vec.rs +++ b/src/liballoc/raw_vec.rs @@ -44,7 +44,6 @@ use core::cmp; /// `shrink_to_fit`, and `from_box` will actually set RawVec's private capacity /// field. This allows zero-sized types to not be special-cased by consumers of /// this type. -#[cfg_attr(stage0, unsafe_no_drop_flag)] pub struct RawVec { ptr: Unique, cap: usize, diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index e0f635f195b..4a4de419f2e 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -252,7 +252,6 @@ struct RcBox { /// that you have to call them as e.g. `Rc::get_mut(&value)` instead of /// `value.get_mut()`. This avoids conflicts with methods of the inner /// type `T`. -#[cfg_attr(stage0, unsafe_no_drop_flag)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Rc { ptr: Shared>, @@ -873,7 +872,6 @@ impl From for Rc { /// /// [rc]: struct.Rc.html /// [downgrade]: struct.Rc.html#method.downgrade -#[cfg_attr(stage0, unsafe_no_drop_flag)] #[stable(feature = "rc_weak", since = "1.4.0")] pub struct Weak { ptr: Shared>, diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index c5a92169347..990de541b67 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -52,7 +52,6 @@ #![feature(step_by)] #![feature(unicode)] #![feature(unique)] -#![cfg_attr(stage0, feature(unsafe_no_drop_flag))] #![cfg_attr(test, feature(rand, test))] #![no_std] diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index f8b4a92df2c..e868a542d55 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -268,7 +268,6 @@ use super::range::RangeArgument; /// Vec does not currently guarantee the order in which elements are dropped /// (the order has changed in the past, and may change again). /// -#[cfg_attr(stage0, unsafe_no_drop_flag)] #[stable(feature = "rust1", since = "1.0.0")] pub struct Vec { buf: RawVec, diff --git a/src/libcompiler_builtins/lib.rs b/src/libcompiler_builtins/lib.rs index fbcf5204d25..4a703b3da68 100644 --- a/src/libcompiler_builtins/lib.rs +++ b/src/libcompiler_builtins/lib.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg_attr(not(stage0), feature(compiler_builtins))] +#![feature(compiler_builtins)] #![no_std] -#![cfg_attr(not(stage0), compiler_builtins)] +#![compiler_builtins] #![unstable(feature = "compiler_builtins_lib", reason = "internal implementation detail of rustc right now", issue = "0")] diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs index 0b800cacfc1..d72b18ae345 100644 --- a/src/libcore/clone.rs +++ b/src/libcore/clone.rs @@ -129,13 +129,6 @@ pub struct AssertParamIsClone { _field: ::marker::PhantomData reason = "deriving hack, should not be public", issue = "0")] pub struct AssertParamIsCopy { _field: ::marker::PhantomData } -#[cfg(stage0)] -#[doc(hidden)] -#[inline(always)] -#[unstable(feature = "derive_clone_copy", - reason = "deriving hack, should not be public", - issue = "0")] -pub fn assert_receiver_is_clone(_: &T) {} #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T: ?Sized> Clone for &'a T { diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 22abe7a99b1..35fcfdf114e 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -194,14 +194,12 @@ extern "rust-intrinsic" { /// own, or if it does not enable any significant optimizations. pub fn assume(b: bool); - #[cfg(not(stage0))] /// Hints to the compiler that branch condition is likely to be true. /// Returns the value passed to it. /// /// Any use other than with `if` statements will probably not have an effect. pub fn likely(b: bool) -> bool; - #[cfg(not(stage0))] /// Hints to the compiler that branch condition is likely to be false. /// Returns the value passed to it. /// diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index 8f02c9c7d3d..afd833d8bdd 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -59,7 +59,6 @@ const EMPTY_BUCKET: u64 = 0; /// around just the "table" part of the hashtable. It enforces some /// invariants at the type level and employs some performance trickery, /// but in general is just a tricked out `Vec>`. -#[cfg_attr(stage0, unsafe_no_drop_flag)] pub struct RawTable { capacity: usize, size: usize, diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 912045453e0..b3e4351e9b2 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -278,7 +278,6 @@ #![feature(unboxed_closures)] #![feature(unicode)] #![feature(unique)] -#![cfg_attr(stage0, feature(unsafe_no_drop_flag))] #![feature(unwind_attributes)] #![feature(vec_push_all)] #![feature(zero_one)] -- cgit 1.4.1-3-g733a5 From 9c4a01ee9eea6fc50252f08afbf98a91270e9d5e Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 7 Sep 2016 05:34:15 +0000 Subject: Ignore lots and lots of std tests on emscripten --- src/liballoc/arc.rs | 1 + src/libcollections/linked_list.rs | 1 + src/libcollectionstest/slice.rs | 1 + src/libstd/env.rs | 3 +++ src/libstd/fs.rs | 49 +++++++++++++++++++++++++++++++++++ src/libstd/io/buffered.rs | 1 + src/libstd/io/mod.rs | 2 ++ src/libstd/io/stdio.rs | 1 + src/libstd/net/addr.rs | 3 +++ src/libstd/net/tcp.rs | 30 ++++++++++++++++++++++ src/libstd/net/udp.rs | 13 ++++++++++ src/libstd/process.rs | 17 +++++++++++++ src/libstd/rand/mod.rs | 1 + src/libstd/sync/barrier.rs | 1 + src/libstd/sync/condvar.rs | 4 +++ src/libstd/sync/mpsc/mod.rs | 52 ++++++++++++++++++++++++++++++++++++++ src/libstd/sync/mpsc/mpsc_queue.rs | 1 + src/libstd/sync/mpsc/select.rs | 11 ++++++++ src/libstd/sync/mpsc/spsc_queue.rs | 1 + src/libstd/sync/mutex.rs | 8 ++++++ src/libstd/sync/once.rs | 2 ++ src/libstd/sync/rwlock.rs | 9 +++++++ src/libstd/sys/common/io.rs | 1 + src/libstd/sys/common/remutex.rs | 3 +++ src/libstd/sys/unix/ext/net.rs | 13 ++++++++++ src/libstd/sys/unix/process.rs | 1 + src/libstd/thread/local.rs | 6 +++++ src/libstd/thread/mod.rs | 19 ++++++++++++++ 28 files changed, 255 insertions(+) (limited to 'src/liballoc') diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index e3c92fc1aa8..29e18781ce2 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -1000,6 +1000,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn manually_share_arc() { let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let arc_v = Arc::new(v); diff --git a/src/libcollections/linked_list.rs b/src/libcollections/linked_list.rs index 690c4f4af35..67f3708a62b 100644 --- a/src/libcollections/linked_list.rs +++ b/src/libcollections/linked_list.rs @@ -1294,6 +1294,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_send() { let n = list_from(&[1, 2, 3]); thread::spawn(move || { diff --git a/src/libcollectionstest/slice.rs b/src/libcollectionstest/slice.rs index 5b341ab62d0..9580714075a 100644 --- a/src/libcollectionstest/slice.rs +++ b/src/libcollectionstest/slice.rs @@ -1116,6 +1116,7 @@ fn test_box_slice_clone() { } #[test] +#[cfg_attr(target_os = "emscripten", ignore)] fn test_box_slice_clone_panics() { use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 5da6e5a8b80..76a2f93c162 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -1033,6 +1033,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_var_big() { let mut s = "".to_string(); let mut i = 0; @@ -1046,6 +1047,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_self_exe_path() { let path = current_exe(); assert!(path.is_ok()); @@ -1056,6 +1058,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_env_set_get_huge() { let n = make_rand_name(); let s = repeat("x").take(10000).collect::(); diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 576198564db..08d71c1d9f8 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1745,6 +1745,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn file_test_io_smoke_test() { let message = "it's alright. have a good time"; let tmpdir = tmpdir(); @@ -1766,6 +1767,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn invalid_path_raises() { let tmpdir = tmpdir(); let filename = &tmpdir.join("file_that_does_not_exist.txt"); @@ -1780,6 +1782,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn file_test_iounlinking_invalid_path_should_raise_condition() { let tmpdir = tmpdir(); let filename = &tmpdir.join("file_another_file_that_does_not_exist.txt"); @@ -1795,6 +1798,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn file_test_io_non_positional_read() { let message: &str = "ten-four"; let mut read_mem = [0; 8]; @@ -1821,6 +1825,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn file_test_io_seek_and_tell_smoke_test() { let message = "ten-four"; let mut read_mem = [0; 4]; @@ -1848,6 +1853,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn file_test_io_seek_and_write() { let initial_msg = "food-is-yummy"; let overwrite_msg = "-the-bar!!"; @@ -1872,6 +1878,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn file_test_io_seek_shakedown() { // 01234567890123 let initial_msg = "qwer-asdf-zxcv"; @@ -1904,6 +1911,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn file_test_stat_is_correct_on_is_file() { let tmpdir = tmpdir(); let filename = &tmpdir.join("file_stat_correct_on_is_file.txt"); @@ -1925,6 +1933,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn file_test_stat_is_correct_on_is_dir() { let tmpdir = tmpdir(); let filename = &tmpdir.join("file_stat_correct_on_is_dir"); @@ -1937,6 +1946,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn file_test_fileinfo_false_when_checking_is_file_on_a_directory() { let tmpdir = tmpdir(); let dir = &tmpdir.join("fileinfo_false_on_dir"); @@ -1946,6 +1956,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn file_test_fileinfo_check_exists_before_and_after_file_creation() { let tmpdir = tmpdir(); let file = &tmpdir.join("fileinfo_check_exists_b_and_a.txt"); @@ -1956,6 +1967,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn file_test_directoryinfo_check_exists_before_and_after_mkdir() { let tmpdir = tmpdir(); let dir = &tmpdir.join("before_and_after_dir"); @@ -1968,6 +1980,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn file_test_directoryinfo_readdir() { let tmpdir = tmpdir(); let dir = &tmpdir.join("di_readdir"); @@ -1997,6 +2010,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn file_create_new_already_exists_error() { let tmpdir = tmpdir(); let file = &tmpdir.join("file_create_new_error_exists"); @@ -2006,6 +2020,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn mkdir_path_already_exists_error() { let tmpdir = tmpdir(); let dir = &tmpdir.join("mkdir_error_twice"); @@ -2015,6 +2030,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn recursive_mkdir() { let tmpdir = tmpdir(); let dir = tmpdir.join("d1/d2"); @@ -2023,6 +2039,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn recursive_mkdir_failure() { let tmpdir = tmpdir(); let dir = tmpdir.join("d1"); @@ -2037,11 +2054,13 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn recursive_mkdir_slash() { check!(fs::create_dir_all(&Path::new("/"))); } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn recursive_rmdir() { let tmpdir = tmpdir(); let d1 = tmpdir.join("d1"); @@ -2061,6 +2080,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn recursive_rmdir_of_symlink() { // test we do not recursively delete a symlink but only dirs. let tmpdir = tmpdir(); @@ -2094,6 +2114,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn unicode_path_is_dir() { assert!(Path::new(".").is_dir()); assert!(!Path::new("test/stdtest/fs.rs").is_dir()); @@ -2113,6 +2134,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn unicode_path_exists() { assert!(Path::new(".").exists()); assert!(!Path::new("test/nonexistent-bogus-path").exists()); @@ -2126,6 +2148,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn copy_file_does_not_exist() { let from = Path::new("test/nonexistent-bogus-path"); let to = Path::new("test/other-bogus-path"); @@ -2140,6 +2163,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn copy_src_does_not_exist() { let tmpdir = tmpdir(); let from = Path::new("test/nonexistent-bogus-path"); @@ -2153,6 +2177,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn copy_file_ok() { let tmpdir = tmpdir(); let input = tmpdir.join("in.txt"); @@ -2169,6 +2194,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn copy_file_dst_dir() { let tmpdir = tmpdir(); let out = tmpdir.join("out"); @@ -2180,6 +2206,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn copy_file_dst_exists() { let tmpdir = tmpdir(); let input = tmpdir.join("in"); @@ -2195,6 +2222,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn copy_file_src_dir() { let tmpdir = tmpdir(); let out = tmpdir.join("out"); @@ -2206,6 +2234,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn copy_file_preserves_perm_bits() { let tmpdir = tmpdir(); let input = tmpdir.join("in.txt"); @@ -2234,6 +2263,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn symlinks_work() { let tmpdir = tmpdir(); if !got_symlink_permission(&tmpdir) { return }; @@ -2252,6 +2282,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn symlink_noexist() { // Symlinks can point to things that don't exist let tmpdir = tmpdir(); @@ -2265,6 +2296,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn read_link() { if cfg!(windows) { // directory symlink @@ -2285,6 +2317,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn readlink_not_symlink() { let tmpdir = tmpdir(); match fs::read_link(tmpdir.path()) { @@ -2294,6 +2327,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn links_work() { let tmpdir = tmpdir(); let input = tmpdir.join("in.txt"); @@ -2322,6 +2356,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn chmod_works() { let tmpdir = tmpdir(); let file = tmpdir.join("in.txt"); @@ -2345,6 +2380,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn sync_doesnt_kill_anything() { let tmpdir = tmpdir(); let path = tmpdir.join("in.txt"); @@ -2358,6 +2394,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn truncate_works() { let tmpdir = tmpdir(); let path = tmpdir.join("in.txt"); @@ -2392,6 +2429,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn open_flavors() { use fs::OpenOptions as OO; fn c(t: &T) -> T { t.clone() } @@ -2511,6 +2549,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn binary_file() { let mut bytes = [0; 1024]; StdRng::new().unwrap().fill_bytes(&mut bytes); @@ -2524,6 +2563,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn file_try_clone() { let tmpdir = tmpdir(); @@ -2546,6 +2586,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] #[cfg(not(windows))] fn unlink_readonly() { let tmpdir = tmpdir(); @@ -2558,6 +2599,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn mkdir_trailing_slash() { let tmpdir = tmpdir(); let path = tmpdir.join("file"); @@ -2565,6 +2607,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn canonicalize_works_simple() { let tmpdir = tmpdir(); let tmpdir = fs::canonicalize(tmpdir.path()).unwrap(); @@ -2574,6 +2617,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn realpath_works() { let tmpdir = tmpdir(); if !got_symlink_permission(&tmpdir) { return }; @@ -2599,6 +2643,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn realpath_works_tricky() { let tmpdir = tmpdir(); if !got_symlink_permission(&tmpdir) { return }; @@ -2628,6 +2673,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn dir_entry_methods() { let tmpdir = tmpdir(); @@ -2662,12 +2708,14 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn read_dir_not_found() { let res = fs::read_dir("/path/that/does/not/exist"); assert_eq!(res.err().unwrap().kind(), ErrorKind::NotFound); } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn create_dir_all_with_junctions() { let tmpdir = tmpdir(); let target = tmpdir.join("target"); @@ -2695,6 +2743,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn metadata_access_times() { let tmpdir = tmpdir(); diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 4ff8c6ac128..21a0cc1fb3b 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -1107,6 +1107,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn panic_in_write_doesnt_flush_in_drop() { static WRITES: AtomicUsize = AtomicUsize::new(0); diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 0de02cbf19c..2ba2e8de71b 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1761,6 +1761,7 @@ mod tests { use super::repeat; #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn read_until() { let mut buf = Cursor::new(&b"12"[..]); let mut v = Vec::new(); @@ -1971,6 +1972,7 @@ mod tests { } #[bench] + #[cfg_attr(target_os = "emscripten", ignore)] fn bench_read_to_end(b: &mut test::Bencher) { b.iter(|| { let mut lr = repeat(1).take(10000000); diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 9a782e95f6e..89cb9909956 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -668,6 +668,7 @@ mod tests { use super::*; #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn panic_doesnt_poison() { thread::spawn(|| { let _a = stdin(); diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index d0b59b42c17..930f2c721a7 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -533,6 +533,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn to_socket_addr_str_u16() { let a = sa4(Ipv4Addr::new(77, 88, 21, 11), 24352); assert_eq!(Ok(vec![a]), tsa(("77.88.21.11", 24352))); @@ -545,6 +546,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn to_socket_addr_str() { let a = sa4(Ipv4Addr::new(77, 88, 21, 11), 24352); assert_eq!(Ok(vec![a]), tsa("77.88.21.11:24352")); @@ -559,6 +561,7 @@ mod tests { // FIXME: figure out why this fails on openbsd and bitrig and fix it #[test] #[cfg(not(any(windows, target_os = "openbsd", target_os = "bitrig")))] + #[cfg_attr(target_os = "emscripten", ignore)] fn to_socket_addr_str_bad() { assert!(tsa("1200::AB00:1234::2552:7777:1313:34300").is_err()); } diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index 3c5f07c3e33..d34fce2be43 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -454,6 +454,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn bind_error() { match TcpListener::bind("1.1.1.1:9999") { Ok(..) => panic!(), @@ -463,6 +464,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn connect_error() { match TcpStream::connect("0.0.0.0:1") { Ok(..) => panic!(), @@ -475,6 +477,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn listen_localhost() { let socket_addr = next_test_ip4(); let listener = t!(TcpListener::bind(&socket_addr)); @@ -492,6 +495,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn connect_loopback() { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); @@ -513,6 +517,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn smoke_test() { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); @@ -533,6 +538,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn read_eof() { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); @@ -552,6 +558,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn write_close() { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); @@ -578,6 +585,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn multiple_connect_serial() { each_ip(&mut |addr| { let max = 10; @@ -600,6 +608,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn multiple_connect_interleaved_greedy_schedule() { const MAX: usize = 10; each_ip(&mut |addr| { @@ -635,6 +644,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn multiple_connect_interleaved_lazy_schedule() { const MAX: usize = 10; each_ip(&mut |addr| { @@ -668,6 +678,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn socket_and_peer_name() { each_ip(&mut |addr| { let listener = t!(TcpListener::bind(&addr)); @@ -683,6 +694,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn partial_read() { each_ip(&mut |addr| { let (tx, rx) = channel(); @@ -704,6 +716,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn double_bind() { each_ip(&mut |addr| { let _listener = t!(TcpListener::bind(&addr)); @@ -720,6 +733,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn fast_rebind() { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); @@ -735,6 +749,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn tcp_clone_smoke() { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); @@ -766,6 +781,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn tcp_clone_two_read() { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); @@ -800,6 +816,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn tcp_clone_two_write() { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); @@ -827,6 +844,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn shutdown_smoke() { each_ip(&mut |addr| { let a = t!(TcpListener::bind(&addr)); @@ -847,6 +865,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn close_readwrite_smoke() { each_ip(&mut |addr| { let a = t!(TcpListener::bind(&addr)); @@ -885,6 +904,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn close_read_wakes_up() { each_ip(&mut |addr| { let a = t!(TcpListener::bind(&addr)); @@ -912,6 +932,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn clone_while_reading() { each_ip(&mut |addr| { let accept = t!(TcpListener::bind(&addr)); @@ -952,6 +973,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn clone_accept_smoke() { each_ip(&mut |addr| { let a = t!(TcpListener::bind(&addr)); @@ -970,6 +992,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn clone_accept_concurrent() { each_ip(&mut |addr| { let a = t!(TcpListener::bind(&addr)); @@ -998,6 +1021,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn debug() { let name = if cfg!(windows) {"socket"} else {"fd"}; let socket_addr = next_test_ip4(); @@ -1024,6 +1048,7 @@ mod tests { // no longer has rounding errors. #[cfg_attr(any(target_os = "bitrig", target_os = "netbsd", target_os = "openbsd"), ignore)] #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn timeouts() { let addr = next_test_ip4(); let listener = t!(TcpListener::bind(&addr)); @@ -1050,6 +1075,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_read_timeout() { let addr = next_test_ip4(); let listener = t!(TcpListener::bind(&addr)); @@ -1066,6 +1092,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_read_with_timeout() { let addr = next_test_ip4(); let listener = t!(TcpListener::bind(&addr)); @@ -1088,6 +1115,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn nodelay() { let addr = next_test_ip4(); let _listener = t!(TcpListener::bind(&addr)); @@ -1102,6 +1130,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn ttl() { let ttl = 100; @@ -1118,6 +1147,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn set_nonblocking() { let addr = next_test_ip4(); let listener = t!(TcpListener::bind(&addr)); diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index 781f026c12c..7315b6aaeb6 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -378,6 +378,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn bind_error() { match UdpSocket::bind("1.1.1.1:9999") { Ok(..) => panic!(), @@ -388,6 +389,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn socket_smoke_test_ip4() { each_ip(&mut |server_ip, client_ip| { let (tx1, rx1) = channel(); @@ -412,6 +414,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn socket_name_ip4() { each_ip(&mut |addr, _| { let server = t!(UdpSocket::bind(&addr)); @@ -420,6 +423,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn udp_clone_smoke() { each_ip(&mut |addr1, addr2| { let sock1 = t!(UdpSocket::bind(&addr1)); @@ -449,6 +453,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn udp_clone_two_read() { each_ip(&mut |addr1, addr2| { let sock1 = t!(UdpSocket::bind(&addr1)); @@ -481,6 +486,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn udp_clone_two_write() { each_ip(&mut |addr1, addr2| { let sock1 = t!(UdpSocket::bind(&addr1)); @@ -519,6 +525,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn debug() { let name = if cfg!(windows) {"socket"} else {"fd"}; let socket_addr = next_test_ip4(); @@ -534,6 +541,7 @@ mod tests { // no longer has rounding errors. #[cfg_attr(any(target_os = "bitrig", target_os = "netbsd", target_os = "openbsd"), ignore)] #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn timeouts() { let addr = next_test_ip4(); @@ -558,6 +566,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_read_timeout() { let addr = next_test_ip4(); @@ -573,6 +582,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_read_with_timeout() { let addr = next_test_ip4(); @@ -592,6 +602,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn connect_send_recv() { let addr = next_test_ip4(); @@ -606,6 +617,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn ttl() { let ttl = 100; @@ -618,6 +630,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn set_nonblocking() { let addr = next_test_ip4(); diff --git a/src/libstd/process.rs b/src/libstd/process.rs index f0c44430700..233a4d3639c 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -819,6 +819,7 @@ mod tests { #[test] #[cfg_attr(target_os = "android", ignore)] + #[cfg_attr(target_os = "emscripten", ignore)] fn smoke() { let p = Command::new("true").spawn(); assert!(p.is_ok()); @@ -837,6 +838,7 @@ mod tests { #[test] #[cfg_attr(target_os = "android", ignore)] + #[cfg_attr(target_os = "emscripten", ignore)] fn exit_reported_right() { let p = Command::new("false").spawn(); assert!(p.is_ok()); @@ -848,6 +850,7 @@ mod tests { #[test] #[cfg(unix)] #[cfg_attr(target_os = "android", ignore)] + #[cfg_attr(target_os = "emscripten", ignore)] fn signal_reported_right() { use os::unix::process::ExitStatusExt; @@ -876,6 +879,7 @@ mod tests { #[test] #[cfg_attr(target_os = "android", ignore)] + #[cfg_attr(target_os = "emscripten", ignore)] fn stdout_works() { let mut cmd = Command::new("echo"); cmd.arg("foobar").stdout(Stdio::piped()); @@ -884,6 +888,7 @@ mod tests { #[test] #[cfg_attr(any(windows, target_os = "android"), ignore)] + #[cfg_attr(target_os = "emscripten", ignore)] fn set_current_dir_works() { let mut cmd = Command::new("/bin/sh"); cmd.arg("-c").arg("pwd") @@ -894,6 +899,7 @@ mod tests { #[test] #[cfg_attr(any(windows, target_os = "android"), ignore)] + #[cfg_attr(target_os = "emscripten", ignore)] fn stdin_works() { let mut p = Command::new("/bin/sh") .arg("-c").arg("read line; echo $line") @@ -912,6 +918,7 @@ mod tests { #[test] #[cfg_attr(target_os = "android", ignore)] #[cfg(unix)] + #[cfg_attr(target_os = "emscripten", ignore)] fn uid_works() { use os::unix::prelude::*; use libc; @@ -938,6 +945,7 @@ mod tests { #[test] #[cfg_attr(target_os = "android", ignore)] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_process_status() { let mut status = Command::new("false").status().unwrap(); assert!(status.code() == Some(1)); @@ -947,6 +955,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_process_output_fail_to_start() { match Command::new("/no-binary-by-this-name-should-exist").output() { Err(e) => assert_eq!(e.kind(), ErrorKind::NotFound), @@ -956,6 +965,7 @@ mod tests { #[test] #[cfg_attr(target_os = "android", ignore)] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_process_output_output() { let Output {status, stdout, stderr} = Command::new("echo").arg("hello").output().unwrap(); @@ -968,6 +978,7 @@ mod tests { #[test] #[cfg_attr(target_os = "android", ignore)] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_process_output_error() { let Output {status, stdout, stderr} = Command::new("mkdir").arg(".").output().unwrap(); @@ -979,6 +990,7 @@ mod tests { #[test] #[cfg_attr(target_os = "android", ignore)] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_finish_once() { let mut prog = Command::new("false").spawn().unwrap(); assert!(prog.wait().unwrap().code() == Some(1)); @@ -986,6 +998,7 @@ mod tests { #[test] #[cfg_attr(target_os = "android", ignore)] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_finish_twice() { let mut prog = Command::new("false").spawn().unwrap(); assert!(prog.wait().unwrap().code() == Some(1)); @@ -994,6 +1007,7 @@ mod tests { #[test] #[cfg_attr(target_os = "android", ignore)] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_wait_with_output_once() { let prog = Command::new("echo").arg("hello").stdout(Stdio::piped()) .spawn().unwrap(); @@ -1024,6 +1038,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_inherit_env() { use env; @@ -1049,6 +1064,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_override_env() { use env; @@ -1069,6 +1085,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_add_to_env() { let result = env_cmd().env("RUN_TEST_NEW_ENV", "123").output().unwrap(); let output = String::from_utf8_lossy(&result.stdout).to_string(); diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 3f14fcd239f..69cd37651d5 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -242,6 +242,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_os_rng_tasks() { let mut txs = vec!(); diff --git a/src/libstd/sync/barrier.rs b/src/libstd/sync/barrier.rs index ac0f400379e..f46eab68484 100644 --- a/src/libstd/sync/barrier.rs +++ b/src/libstd/sync/barrier.rs @@ -118,6 +118,7 @@ mod tests { use thread; #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_barrier() { const N: usize = 10; diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 3db8b05b954..a983ae716a4 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -270,6 +270,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn notify_one() { let m = Arc::new(Mutex::new(())); let m2 = m.clone(); @@ -286,6 +287,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn notify_all() { const N: usize = 10; @@ -322,6 +324,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn wait_timeout_ms() { let m = Arc::new(Mutex::new(())); let m2 = m.clone(); @@ -343,6 +346,7 @@ mod tests { #[test] #[should_panic] + #[cfg_attr(target_os = "emscripten", ignore)] fn two_mutexes() { let m = Arc::new(Mutex::new(())); let m2 = m.clone(); diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 3d9f81413dc..b8101ae85cf 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -1314,6 +1314,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn smoke_threads() { let (tx, rx) = channel::(); let _t = thread::spawn(move|| { @@ -1346,6 +1347,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn port_gone_concurrent() { let (tx, rx) = channel::(); let _t = thread::spawn(move|| { @@ -1355,6 +1357,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn port_gone_concurrent_shared() { let (tx, rx) = channel::(); let tx2 = tx.clone(); @@ -1381,6 +1384,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn chan_gone_concurrent() { let (tx, rx) = channel::(); let _t = thread::spawn(move|| { @@ -1391,6 +1395,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn stress() { let (tx, rx) = channel::(); let t = thread::spawn(move|| { @@ -1403,6 +1408,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn stress_shared() { const AMT: u32 = 10000; const NTHREADS: u32 = 8; @@ -1429,6 +1435,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn send_from_outside_runtime() { let (tx1, rx1) = channel::<()>(); let (tx2, rx2) = channel::(); @@ -1449,6 +1456,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn recv_from_outside_runtime() { let (tx, rx) = channel::(); let t = thread::spawn(move|| { @@ -1463,6 +1471,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn no_runtime() { let (tx1, rx1) = channel::(); let (tx2, rx2) = channel::(); @@ -1501,6 +1510,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn oneshot_single_thread_recv_chan_close() { // Receiving on a closed chan will panic let res = thread::spawn(move|| { @@ -1570,6 +1580,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn oneshot_multi_task_recv_then_send() { let (tx, rx) = channel::>(); let _t = thread::spawn(move|| { @@ -1580,6 +1591,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn oneshot_multi_task_recv_then_close() { let (tx, rx) = channel::>(); let _t = thread::spawn(move|| { @@ -1592,6 +1604,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn oneshot_multi_thread_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = channel::(); @@ -1603,6 +1616,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn oneshot_multi_thread_send_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = channel::(); @@ -1616,6 +1630,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn oneshot_multi_thread_recv_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = channel::(); @@ -1634,6 +1649,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn oneshot_multi_thread_send_recv_stress() { for _ in 0..stress_factor() { let (tx, rx) = channel::>(); @@ -1645,6 +1661,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn stream_send_recv_stress() { for _ in 0..stress_factor() { let (tx, rx) = channel(); @@ -1683,6 +1700,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn stress_recv_timeout_two_threads() { let (tx, rx) = channel(); let stress = stress_factor() + 100; @@ -1724,6 +1742,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn stress_recv_timeout_shared() { let (tx, rx) = channel(); let stress = stress_factor() + 100; @@ -1762,6 +1781,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn shared_recv_timeout() { let (tx, rx) = channel(); let total = 5; @@ -1780,6 +1800,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn shared_chan_stress() { let (tx, rx) = channel(); let total = stress_factor() + 100; @@ -1796,6 +1817,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_nested_recv_iter() { let (tx, rx) = channel::(); let (total_tx, total_rx) = channel::(); @@ -1816,6 +1838,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_recv_iter_break() { let (tx, rx) = channel::(); let (count_tx, count_rx) = channel(); @@ -1841,6 +1864,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_recv_try_iter() { let (request_tx, request_rx) = channel(); let (response_tx, response_rx) = channel(); @@ -1895,6 +1919,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn try_recv_states() { let (tx1, rx1) = channel::(); let (tx2, rx2) = channel::<()>(); @@ -1921,6 +1946,7 @@ mod tests { // This bug used to end up in a livelock inside of the Receiver destructor // because the internal state of the Shared packet was corrupted #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn destroy_upgraded_shared_port_when_sender_still_active() { let (tx, rx) = channel(); let (tx2, rx2) = channel(); @@ -1988,6 +2014,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn smoke_threads() { let (tx, rx) = sync_channel::(0); let _t = thread::spawn(move|| { @@ -2013,6 +2040,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn port_gone_concurrent() { let (tx, rx) = sync_channel::(0); let _t = thread::spawn(move|| { @@ -2022,6 +2050,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn port_gone_concurrent_shared() { let (tx, rx) = sync_channel::(0); let tx2 = tx.clone(); @@ -2048,6 +2077,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn chan_gone_concurrent() { let (tx, rx) = sync_channel::(0); thread::spawn(move|| { @@ -2058,6 +2088,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn stress() { let (tx, rx) = sync_channel::(0); thread::spawn(move|| { @@ -2069,6 +2100,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn stress_recv_timeout_two_threads() { let (tx, rx) = sync_channel::(0); @@ -2092,6 +2124,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn stress_recv_timeout_shared() { const AMT: u32 = 1000; const NTHREADS: u32 = 8; @@ -2130,6 +2163,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn stress_shared() { const AMT: u32 = 1000; const NTHREADS: u32 = 8; @@ -2180,6 +2214,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn oneshot_single_thread_recv_chan_close() { // Receiving on a closed chan will panic let res = thread::spawn(move|| { @@ -2264,6 +2299,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn oneshot_multi_task_recv_then_send() { let (tx, rx) = sync_channel::>(0); let _t = thread::spawn(move|| { @@ -2274,6 +2310,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn oneshot_multi_task_recv_then_close() { let (tx, rx) = sync_channel::>(0); let _t = thread::spawn(move|| { @@ -2286,6 +2323,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn oneshot_multi_thread_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = sync_channel::(0); @@ -2297,6 +2335,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn oneshot_multi_thread_send_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = sync_channel::(0); @@ -2310,6 +2349,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn oneshot_multi_thread_recv_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = sync_channel::(0); @@ -2328,6 +2368,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn oneshot_multi_thread_send_recv_stress() { for _ in 0..stress_factor() { let (tx, rx) = sync_channel::>(0); @@ -2339,6 +2380,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn stream_send_recv_stress() { for _ in 0..stress_factor() { let (tx, rx) = sync_channel::>(0); @@ -2375,6 +2417,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn shared_chan_stress() { let (tx, rx) = sync_channel(0); let total = stress_factor() + 100; @@ -2391,6 +2434,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_nested_recv_iter() { let (tx, rx) = sync_channel::(0); let (total_tx, total_rx) = sync_channel::(0); @@ -2411,6 +2455,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_recv_iter_break() { let (tx, rx) = sync_channel::(0); let (count_tx, count_rx) = sync_channel(0); @@ -2436,6 +2481,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn try_recv_states() { let (tx1, rx1) = sync_channel::(1); let (tx2, rx2) = sync_channel::<()>(1); @@ -2462,6 +2508,7 @@ mod sync_tests { // This bug used to end up in a livelock inside of the Receiver destructor // because the internal state of the Shared packet was corrupted #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn destroy_upgraded_shared_port_when_sender_still_active() { let (tx, rx) = sync_channel::<()>(0); let (tx2, rx2) = sync_channel::<()>(0); @@ -2483,6 +2530,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn send1() { let (tx, rx) = sync_channel::(0); let _t = thread::spawn(move|| { rx.recv().unwrap(); }); @@ -2490,6 +2538,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn send2() { let (tx, rx) = sync_channel::(0); let _t = thread::spawn(move|| { drop(rx); }); @@ -2497,6 +2546,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn send3() { let (tx, rx) = sync_channel::(1); assert_eq!(tx.send(1), Ok(())); @@ -2505,6 +2555,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn send4() { let (tx, rx) = sync_channel::(0); let tx2 = tx.clone(); @@ -2545,6 +2596,7 @@ mod sync_tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn issue_15761() { fn repro() { let (tx1, rx1) = sync_channel::<()>(3); diff --git a/src/libstd/sync/mpsc/mpsc_queue.rs b/src/libstd/sync/mpsc/mpsc_queue.rs index d926043fbbc..2ff9ffe6d08 100644 --- a/src/libstd/sync/mpsc/mpsc_queue.rs +++ b/src/libstd/sync/mpsc/mpsc_queue.rs @@ -161,6 +161,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test() { let nthreads = 8; let nmsgs = 1000; diff --git a/src/libstd/sync/mpsc/select.rs b/src/libstd/sync/mpsc/select.rs index 51b08bd75c4..3058282edf3 100644 --- a/src/libstd/sync/mpsc/select.rs +++ b/src/libstd/sync/mpsc/select.rs @@ -444,6 +444,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn unblocks() { let (tx1, rx1) = channel::(); let (_tx2, rx2) = channel::(); @@ -468,6 +469,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn both_ready() { let (tx1, rx1) = channel::(); let (tx2, rx2) = channel::(); @@ -494,6 +496,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn stress() { const AMT: i32 = 10000; let (tx1, rx1) = channel::(); @@ -521,6 +524,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn cloning() { let (tx1, rx1) = channel::(); let (_tx2, rx2) = channel::(); @@ -543,6 +547,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn cloning2() { let (tx1, rx1) = channel::(); let (_tx2, rx2) = channel::(); @@ -565,6 +570,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn cloning3() { let (tx1, rx1) = channel::<()>(); let (tx2, rx2) = channel::<()>(); @@ -682,6 +688,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn oneshot_data_waiting() { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); @@ -698,6 +705,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn stream_data_waiting() { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); @@ -718,6 +726,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn shared_data_waiting() { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); @@ -746,6 +755,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn sync2() { let (tx, rx) = sync_channel::(0); let _t = thread::spawn(move|| { @@ -758,6 +768,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn sync3() { let (tx1, rx1) = sync_channel::(0); let (tx2, rx2): (Sender, Receiver) = channel(); diff --git a/src/libstd/sync/mpsc/spsc_queue.rs b/src/libstd/sync/mpsc/spsc_queue.rs index 724d7b1be73..cb9577f155e 100644 --- a/src/libstd/sync/mpsc/spsc_queue.rs +++ b/src/libstd/sync/mpsc/spsc_queue.rs @@ -305,6 +305,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn stress() { unsafe { stress_bound(0); diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 098a3e44258..07d60f0610f 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -375,6 +375,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn lots_and_lots() { const J: u32 = 1000; const K: u32 = 3; @@ -435,6 +436,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_into_inner_poison() { let m = Arc::new(Mutex::new(NonCopy(10))); let m2 = m.clone(); @@ -458,6 +460,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_get_mut_poison() { let m = Arc::new(Mutex::new(NonCopy(10))); let m2 = m.clone(); @@ -474,6 +477,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_mutex_arc_condvar() { let packet = Packet(Arc::new((Mutex::new(false), Condvar::new()))); let packet2 = Packet(packet.0.clone()); @@ -497,6 +501,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_arc_condvar_poison() { let packet = Packet(Arc::new((Mutex::new(1), Condvar::new()))); let packet2 = Packet(packet.0.clone()); @@ -526,6 +531,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_mutex_arc_poison() { let arc = Arc::new(Mutex::new(1)); assert!(!arc.is_poisoned()); @@ -539,6 +545,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_mutex_arc_nested() { // Tests nested mutexes and access // to underlying data. @@ -555,6 +562,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_mutex_arc_access_in_unwind() { let arc = Arc::new(Mutex::new(1)); let arc2 = arc.clone(); diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 86d2986959c..64c3e2bb42f 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -385,6 +385,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn stampede_once() { static O: Once = Once::new(); static mut run: bool = false; @@ -447,6 +448,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn wait_for_force_to_finish() { static O: Once = Once::new(); diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 7f053c6704b..cb46b694f37 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -403,6 +403,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn frob() { const N: usize = 10; const M: usize = 1000; @@ -430,6 +431,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_rw_arc_poison_wr() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); @@ -441,6 +443,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_rw_arc_poison_ww() { let arc = Arc::new(RwLock::new(1)); assert!(!arc.is_poisoned()); @@ -454,6 +457,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_rw_arc_no_poison_rr() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); @@ -465,6 +469,7 @@ mod tests { assert_eq!(*lock, 1); } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_rw_arc_no_poison_rw() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); @@ -477,6 +482,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_rw_arc() { let arc = Arc::new(RwLock::new(0)); let arc2 = arc.clone(); @@ -515,6 +521,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_rw_arc_access_in_unwind() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); @@ -587,6 +594,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_into_inner_poison() { let m = Arc::new(RwLock::new(NonCopy(10))); let m2 = m.clone(); @@ -610,6 +618,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_get_mut_poison() { let m = Arc::new(RwLock::new(NonCopy(10))); let m2 = m.clone(); diff --git a/src/libstd/sys/common/io.rs b/src/libstd/sys/common/io.rs index 3cd70eddb85..2778ed9326c 100644 --- a/src/libstd/sys/common/io.rs +++ b/src/libstd/sys/common/io.rs @@ -165,6 +165,7 @@ mod tests { } #[bench] + #[cfg_attr(target_os = "emscripten", ignore)] fn bench_uninitialized(b: &mut ::test::Bencher) { b.iter(|| { let mut lr = repeat(1).take(10000000); diff --git a/src/libstd/sys/common/remutex.rs b/src/libstd/sys/common/remutex.rs index cbdeaad7f6b..4935afe6afc 100644 --- a/src/libstd/sys/common/remutex.rs +++ b/src/libstd/sys/common/remutex.rs @@ -181,6 +181,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn is_mutex() { let m = Arc::new(ReentrantMutex::new(RefCell::new(0))); let m2 = m.clone(); @@ -198,6 +199,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn trylock_works() { let m = Arc::new(ReentrantMutex::new(())); let m2 = m.clone(); @@ -218,6 +220,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn poison_works() { let m = Arc::new(ReentrantMutex::new(RefCell::new(0))); let mc = m.clone(); diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index 3f93fce1935..8224696db2f 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -806,6 +806,7 @@ mod test { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn basic() { let dir = tmpdir(); let socket_path = dir.path().join("sock"); @@ -834,6 +835,7 @@ mod test { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn pair() { let msg1 = b"hello"; let msg2 = b"world!"; @@ -857,6 +859,7 @@ mod test { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn try_clone() { let dir = tmpdir(); let socket_path = dir.path().join("sock"); @@ -883,6 +886,7 @@ mod test { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn iter() { let dir = tmpdir(); let socket_path = dir.path().join("sock"); @@ -905,6 +909,7 @@ mod test { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn long_path() { let dir = tmpdir(); let socket_path = dir.path() @@ -930,6 +935,7 @@ mod test { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn timeouts() { let dir = tmpdir(); let socket_path = dir.path().join("sock"); @@ -957,6 +963,7 @@ mod test { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_read_timeout() { let dir = tmpdir(); let socket_path = dir.path().join("sock"); @@ -972,6 +979,7 @@ mod test { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_read_with_timeout() { let dir = tmpdir(); let socket_path = dir.path().join("sock"); @@ -993,6 +1001,7 @@ mod test { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_unix_datagram() { let dir = tmpdir(); let path1 = dir.path().join("sock1"); @@ -1009,6 +1018,7 @@ mod test { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_unnamed_unix_datagram() { let dir = tmpdir(); let path1 = dir.path().join("sock1"); @@ -1026,6 +1036,7 @@ mod test { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_connect_unix_datagram() { let dir = tmpdir(); let path1 = dir.path().join("sock1"); @@ -1052,6 +1063,7 @@ mod test { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_unix_datagram_recv() { let dir = tmpdir(); let path1 = dir.path().join("sock1"); @@ -1069,6 +1081,7 @@ mod test { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn datagram_pair() { let msg1 = b"hello"; let msg2 = b"world!"; diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 50014f51f6c..85aba4b9b15 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -630,6 +630,7 @@ mod tests { #[test] #[cfg_attr(target_os = "macos", ignore)] #[cfg_attr(target_os = "nacl", ignore)] // no signals on NaCl. + #[cfg_attr(target_os = "emscripten", ignore)] fn test_process_mask() { unsafe { // Test to make sure that a signal mask does not get inherited. diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index c44dee49f14..59748b47d81 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -541,6 +541,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn smoke_no_dtor() { thread_local!(static FOO: Cell = Cell::new(1)); @@ -563,6 +564,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn states() { struct Foo; impl Drop for Foo { @@ -586,6 +588,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn smoke_dtor() { thread_local!(static FOO: UnsafeCell> = UnsafeCell::new(None)); @@ -600,6 +603,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn circular() { struct S1; struct S2; @@ -640,6 +644,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn self_referential() { struct S1; thread_local!(static K1: UnsafeCell> = UnsafeCell::new(None)); @@ -661,6 +666,7 @@ mod tests { // test on OSX. #[test] #[cfg_attr(target_os = "macos", ignore)] + #[cfg_attr(target_os = "emscripten", ignore)] fn dtors_in_dtors_in_dtors() { struct S1(Sender<()>); thread_local!(static K1: UnsafeCell> = UnsafeCell::new(None)); diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index d8e021bb04f..b42a0fa3ac1 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -755,6 +755,7 @@ mod tests { // !!! instead of exiting cleanly. This might wedge the buildbots. !!! #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_unnamed_thread() { thread::spawn(move|| { assert!(thread::current().name().is_none()); @@ -762,6 +763,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_named_thread() { Builder::new().name("ada lovelace".to_string()).spawn(move|| { assert!(thread::current().name().unwrap() == "ada lovelace".to_string()); @@ -770,11 +772,13 @@ mod tests { #[test] #[should_panic] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_invalid_named_thread() { let _ = Builder::new().name("ada l\0velace".to_string()).spawn(|| {}); } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_run_basic() { let (tx, rx) = channel(); thread::spawn(move|| { @@ -784,6 +788,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_join_panic() { match thread::spawn(move|| { panic!() @@ -794,6 +799,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_spawn_sched() { let (tx, rx) = channel(); @@ -813,6 +819,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_spawn_sched_childs_on_default_sched() { let (tx, rx) = channel(); @@ -841,6 +848,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_avoid_copying_the_body_spawn() { avoid_copying_the_body(|v| { thread::spawn(move || v()); @@ -848,6 +856,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_avoid_copying_the_body_thread_spawn() { avoid_copying_the_body(|f| { thread::spawn(move|| { @@ -857,6 +866,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_avoid_copying_the_body_join() { avoid_copying_the_body(|f| { let _ = thread::spawn(move|| { @@ -866,6 +876,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_child_doesnt_ref_parent() { // If the child refcounts the parent thread, this will stack overflow when // climbing the thread tree to dereference each ancestor. (See #1789) @@ -883,11 +894,13 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_simple_newsched_spawn() { thread::spawn(move || {}); } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_try_panic_message_static_str() { match thread::spawn(move|| { panic!("static string"); @@ -902,6 +915,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_try_panic_message_owned_str() { match thread::spawn(move|| { panic!("owned string".to_string()); @@ -916,6 +930,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_try_panic_message_any() { match thread::spawn(move|| { panic!(box 413u16 as Box); @@ -932,6 +947,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_try_panic_message_unit_struct() { struct Juju; @@ -944,6 +960,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_park_timeout_unpark_before() { for _ in 0..10 { thread::current().unpark(); @@ -952,6 +969,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_park_timeout_unpark_not_called() { for _ in 0..10 { thread::park_timeout(Duration::from_millis(10)); @@ -959,6 +977,7 @@ mod tests { } #[test] + #[cfg_attr(target_os = "emscripten", ignore)] fn test_park_timeout_unpark_called_other_thread() { for _ in 0..10 { let th = thread::current(); -- cgit 1.4.1-3-g733a5 From 05b6d6861937d04f097e80615d1cb88e583284c2 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Wed, 21 Sep 2016 10:24:45 -0700 Subject: Update Arc docs to match new Rc docs --- src/liballoc/arc.rs | 426 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 281 insertions(+), 145 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 29e18781ce2..7a07e007ce1 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -10,35 +10,11 @@ #![stable(feature = "rust1", since = "1.0.0")] -//! Threadsafe reference-counted boxes (the `Arc` type). +//! Thread-safe reference-counting pointers. //! -//! The `Arc` type provides shared ownership of an immutable value through -//! atomic reference counting. +//! See the [`Arc`][arc] documentation for more details. //! -//! `Weak` is a weak reference to the `Arc` box, and it is created by -//! the `downgrade` method. -//! # Examples -//! -//! Sharing some immutable data between threads: -//! -// Note that we **do not** run these tests here. The windows builders get super -// unhappy of a thread outlives the main thread and then exits at the same time -// (something deadlocks) so we just avoid this entirely by not running these -// tests. -//! ```no_run -//! use std::sync::Arc; -//! use std::thread; -//! -//! let five = Arc::new(5); -//! -//! for _ in 0..10 { -//! let five = five.clone(); -//! -//! thread::spawn(move || { -//! println!("{:?}", five); -//! }); -//! } -//! ``` +//! [arc]: struct.Arc.html use boxed::Box; @@ -62,71 +38,114 @@ use heap::deallocate; const MAX_REFCOUNT: usize = (isize::MAX) as usize; -/// An atomically reference counted wrapper for shared state. -/// Destruction is deterministic, and will occur as soon as the last owner is -/// gone. It is marked as `Send` because it uses atomic reference counting. +/// A thread-safe reference-counting pointer. /// -/// If you do not need thread-safety, and just need shared ownership, consider -/// the [`Rc` type](../rc/struct.Rc.html). It is the same as `Arc`, but -/// does not use atomics, making it both thread-unsafe as well as significantly -/// faster when updating the reference count. +/// The type `Arc` provides shared ownership of a value of type `T`, +/// allocated in the heap. Invoking [`clone`][clone] on `Arc` produces +/// a new pointer to the same value in the heap. When the last `Arc` +/// pointer to a given value is destroyed, the pointed-to value is +/// also destroyed. /// -/// Note: the inherent methods defined on `Arc` are all associated functions, -/// which means that you have to call them as e.g. `Arc::get_mut(&value)` -/// instead of `value.get_mut()`. This is so that there are no conflicts with -/// methods on the inner type `T`, which are what you want to call in the -/// majority of cases. +/// Shared references in Rust disallow mutation by default, and `Arc` is no +/// exception. If you need to mutate through an `Arc`, use [`Mutex`][mutex], +/// [`RwLock`][rwlock], or one of the [`Atomic`][atomic] types. /// -/// # Examples +/// `Arc` uses atomic operations for reference counting, so `Arc`s can be +/// sent between threads. In other words, `Arc` implements [`Send`][send] +/// as long as `T` implements `Send` and [`Sync`][sync]. The disadvantage is +/// that atomic operations are more expensive than ordinary memory accesses. +/// If you are not sharing reference-counted values between threads, consider +/// using [`rc::Rc`][rc] for lower overhead. `Rc` is a safe default, because +/// the compiler will catch any attempt to send an `Rc` between threads. +/// However, a library might choose `Arc` in order to give library consumers +/// more flexibility. +/// +/// The [`downgrade`][downgrade] method can be used to create a non-owning +/// [`Weak`][weak] pointer. A `Weak` pointer can be [`upgrade`][upgrade]d +/// to an `Arc`, but this will return [`None`][option] if the value has +/// already been dropped. /// -/// In this example, a large vector of data will be shared by several threads. First we -/// wrap it with a `Arc::new` and then clone the `Arc` reference for every thread (which will -/// increase the reference count atomically). +/// A cycle between `Arc` pointers will never be deallocated. For this reason, +/// `Weak` is used to break cycles. For example, a tree could have strong +/// `Arc` pointers from parent nodes to children, and `Weak` pointers from +/// children back to their parents. +/// +/// `Arc` automatically dereferences to `T` (via the [`Deref`][deref] trait), +/// so you can call `T`'s methods on a value of type `Arc`. To avoid name +/// clashes with `T`'s methods, the methods of `Arc` itself are [associated +/// functions][assoc], called using function-like syntax: /// /// ``` /// use std::sync::Arc; -/// use std::thread; +/// let my_arc = Arc::new(()); +/// +/// Arc::downgrade(&my_arc); +/// ``` /// -/// fn main() { -/// let numbers: Vec<_> = (0..100).collect(); -/// let shared_numbers = Arc::new(numbers); +/// `Weak` does not auto-dereference to `T`, because the value may have +/// already been destroyed. /// -/// for _ in 0..10 { -/// // prepare a copy of reference here and it will be moved to the thread -/// let child_numbers = shared_numbers.clone(); +/// [arc]: struct.Arc.html +/// [weak]: struct.Weak.html +/// [rc]: ../../std/rc/struct.Rc.html +/// [clone]: ../../std/clone/trait.Clone.html#tymethod.clone +/// [mutex]: ../../std/sync/struct.Mutex.html +/// [rwlock]: ../../std/sync/struct.RwLock.html +/// [atomic]: ../../std/sync/atomic/index.html +/// [send]: ../../std/marker/trait.Send.html +/// [sync]: ../../std/marker/trait.Sync.html +/// [deref]: ../../std/ops/trait.Deref.html +/// [downgrade]: struct.Arc.html#method.downgrade +/// [upgrade]: struct.Weak.html#method.upgrade +/// [option]: ../../std/option/enum.Option.html +/// [assoc]: ../../book/method-syntax.html#associated-functions /// -/// thread::spawn(move || { -/// let local_numbers = &child_numbers[..]; +/// # Examples /// -/// // Work with the local numbers -/// }); -/// } -/// } -/// ``` -/// You can also share mutable data between threads safely -/// by putting it inside `Mutex` and then share `Mutex` immutably -/// with `Arc` as shown below. +/// Sharing some immutable data between threads: /// -// See comment at the top of this file for why the test is no_run +// Note that we **do not** run these tests here. The windows builders get super +// unhappy if a thread outlives the main thread and then exits at the same time +// (something deadlocks) so we just avoid this entirely by not running these +// tests. /// ```no_run -/// use std::sync::{Arc, Mutex}; +/// use std::sync::Arc; /// use std::thread; /// -/// let five = Arc::new(Mutex::new(5)); +/// let five = Arc::new(5); /// /// for _ in 0..10 { /// let five = five.clone(); /// /// thread::spawn(move || { -/// let mut number = five.lock().unwrap(); +/// println!("{:?}", five); +/// }); +/// } +/// ``` /// -/// *number += 1; +/// Sharing a mutable `AtomicUsize`: /// -/// println!("{}", *number); // prints 6 +/// ```no_run +/// use std::sync::Arc; +/// use std::sync::atomic::{AtomicUsize, Ordering}; +/// use std::thread; +/// +/// let val = Arc::new(AtomicUsize::new(5)); +/// +/// for _ in 0..10 { +/// let val = val.clone(); +/// +/// thread::spawn(move || { +/// let v = val.fetch_add(1, Ordering::SeqCst); +/// println!("{:?}", v); /// }); /// } /// ``` - +/// +/// See the [`rc` documentation][rc_examples] for more examples of reference +/// counting in general. +/// +/// [rc_examples]: ../../std/rc/index.html#examples #[stable(feature = "rust1", since = "1.0.0")] pub struct Arc { ptr: Shared>, @@ -140,18 +159,18 @@ unsafe impl Sync for Arc {} #[unstable(feature = "coerce_unsized", issue = "27732")] impl, U: ?Sized> CoerceUnsized> for Arc {} -/// A weak pointer to an `Arc`. +/// A weak version of [`Arc`][arc]. /// -/// Weak pointers will not keep the data inside of the `Arc` alive, and can be -/// used to break cycles between `Arc` pointers. +/// `Weak` pointers do not count towards determining if the inner value +/// should be dropped. /// -/// A `Weak` pointer can be upgraded to an `Arc` pointer, but -/// will return `None` if the value has already been dropped. +/// The typical way to obtain a `Weak` pointer is to call +/// [`Arc::downgrade`][downgrade]. /// -/// For example, a tree with parent pointers can be represented by putting the -/// nodes behind strong `Arc` pointers, and then storing the parent pointers -/// as `Weak` pointers. - +/// See the [`Arc`][arc] documentation for more details. +/// +/// [arc]: struct.Arc.html +/// [downgrade]: struct.Arc.html#method.downgrade #[stable(feature = "arc_weak", since = "1.4.0")] pub struct Weak { ptr: Shared>, @@ -209,12 +228,15 @@ impl Arc { Arc { ptr: unsafe { Shared::new(Box::into_raw(x)) } } } - /// Unwraps the contained value if the `Arc` has exactly one strong reference. + /// Returns the contained value, if the `Arc` has exactly one strong reference. /// - /// Otherwise, an `Err` is returned with the same `Arc`. + /// Otherwise, an [`Err`][result] is returned with the same `Arc` that was + /// passed in. /// /// This will succeed even if there are outstanding weak references. /// + /// [result]: ../../std/result/enum.Result.html + /// /// # Examples /// /// ``` @@ -225,7 +247,7 @@ impl Arc { /// /// let x = Arc::new(4); /// let _y = x.clone(); - /// assert_eq!(Arc::try_unwrap(x), Err(Arc::new(4))); + /// assert_eq!(*Arc::try_unwrap(x).unwrap_err(), 4); /// ``` #[inline] #[stable(feature = "arc_unique", since = "1.4.0")] @@ -251,7 +273,9 @@ impl Arc { } impl Arc { - /// Downgrades the `Arc` to a `Weak` reference. + /// Creates a new [`Weak`][weak] pointer to this value. + /// + /// [weak]: struct.Weak.html /// /// # Examples /// @@ -289,7 +313,27 @@ impl Arc { } } - /// Get the number of weak references to this value. + /// Gets the number of [`Weak`][weak] pointers to this value. + /// + /// Be careful how you use this information, because another thread + /// may change the weak count at any time. + /// + /// [weak]: struct.Weak.html + /// + /// # Examples + /// + /// ``` + /// #![feature(arc_counts)] + /// + /// use std::sync::Arc; + /// + /// let five = Arc::new(5); + /// let _weak_five = Arc::downgrade(&five); + /// + /// // This assertion is deterministic because we haven't shared + /// // the `Arc` or `Weak` between threads. + /// assert_eq!(1, Arc::weak_count(&five)); + /// ``` #[inline] #[unstable(feature = "arc_counts", reason = "not clearly useful, and racy", issue = "28356")] @@ -297,7 +341,25 @@ impl Arc { this.inner().weak.load(SeqCst) - 1 } - /// Get the number of strong references to this value. + /// Gets the number of strong (`Arc`) pointers to this value. + /// + /// Be careful how you use this information, because another thread + /// may change the strong count at any time. + /// + /// # Examples + /// + /// ``` + /// #![feature(arc_counts)] + /// + /// use std::sync::Arc; + /// + /// let five = Arc::new(5); + /// let _also_five = five.clone(); + /// + /// // This assertion is deterministic because we haven't shared + /// // the `Arc` between threads. + /// assert_eq!(2, Arc::strong_count(&five)); + /// ``` #[inline] #[unstable(feature = "arc_counts", reason = "not clearly useful, and racy", issue = "28356")] @@ -334,8 +396,8 @@ impl Arc { #[unstable(feature = "ptr_eq", reason = "newly added", issue = "36497")] - /// Return whether two `Arc` references point to the same value - /// (not just values that compare equal). + /// Returns true if the two `Arc`s point to the same value (not + /// just values that compare as equal). /// /// # Examples /// @@ -360,9 +422,10 @@ impl Arc { #[stable(feature = "rust1", since = "1.0.0")] impl Clone for Arc { - /// Makes a clone of the `Arc`. + /// Makes a clone of the `Arc` pointer. /// - /// This increases the strong reference count. + /// This creates another pointer to the same inner value, increasing the + /// strong reference count. /// /// # Examples /// @@ -418,11 +481,17 @@ impl Deref for Arc { } impl Arc { - /// Make a mutable reference into the given `Arc`. - /// If the `Arc` has more than one strong reference, or any weak - /// references, the inner data is cloned. + /// Makes a mutable reference into the given `Arc`. + /// + /// If there are other `Arc` or [`Weak`][weak] pointers to the same value, + /// then `make_mut` will invoke [`clone`][clone] on the inner value to + /// ensure unique ownership. This is also referred to as clone-on-write. + /// + /// See also [`get_mut`][get_mut], which will fail rather than cloning. /// - /// This is also referred to as a copy-on-write. + /// [weak]: struct.Weak.html + /// [clone]: ../../std/clone/trait.Clone.html#tymethod.clone + /// [get_mut]: struct.Arc.html#method.get_mut /// /// # Examples /// @@ -437,10 +506,9 @@ impl Arc { /// *Arc::make_mut(&mut data) += 1; // Won't clone anything /// *Arc::make_mut(&mut other_data) *= 2; // Won't clone anything /// - /// // Note: data and other_data now point to different numbers + /// // Now `data` and `other_data` point to different values. /// assert_eq!(*data, 8); /// assert_eq!(*other_data, 12); - /// /// ``` #[inline] #[stable(feature = "arc_unique", since = "1.4.0")] @@ -499,8 +567,19 @@ impl Arc { } impl Arc { - /// Returns a mutable reference to the contained value if the `Arc` has - /// one strong reference and no weak references. + /// Returns a mutable reference to the inner value, if there are + /// no other `Arc` or [`Weak`][weak] pointers to the same value. + /// + /// Returns [`None`][option] otherwise, because it is not safe to + /// mutate a shared value. + /// + /// See also [`make_mut`][make_mut], which will [`clone`][clone] + /// the inner value when it's shared. + /// + /// [weak]: struct.Weak.html + /// [option]: ../../std/option/enum.Option.html + /// [make_mut]: struct.Arc.html#method.make_mut + /// [clone]: ../../std/clone/trait.Clone.html#tymethod.clone /// /// # Examples /// @@ -562,30 +641,32 @@ impl Arc { #[stable(feature = "rust1", since = "1.0.0")] impl Drop for Arc { - /// Drops the `Arc`. + /// Drops the `Arc`. /// /// This will decrement the strong reference count. If the strong reference - /// count becomes zero and the only other references are `Weak` ones, - /// `drop`s the inner value. + /// count reaches zero then the only other references (if any) are + /// [`Weak`][weak], so we `drop` the inner value. + /// + /// [weak]: struct.Weak.html /// /// # Examples /// /// ``` /// use std::sync::Arc; /// - /// { - /// let five = Arc::new(5); - /// - /// // stuff + /// struct Foo; /// - /// drop(five); // explicit drop + /// impl Drop for Foo { + /// fn drop(&mut self) { + /// println!("dropped!"); + /// } /// } - /// { - /// let five = Arc::new(5); /// - /// // stuff + /// let foo = Arc::new(Foo); + /// let foo2 = foo.clone(); /// - /// } // implicit drop + /// drop(foo); // Doesn't print anything + /// drop(foo2); // Prints "dropped!" /// ``` #[unsafe_destructor_blind_to_params] #[inline] @@ -623,10 +704,14 @@ impl Drop for Arc { } impl Weak { - /// Constructs a new `Weak` without an accompanying instance of T. + /// Constructs a new `Weak`, without an accompanying instance of `T`. /// - /// This allocates memory for T, but does not initialize it. Calling - /// Weak::upgrade() on the return value always gives None. + /// This allocates memory for `T`, but does not initialize it. Calling + /// [`upgrade`][upgrade] on the return value always gives + /// [`None`][option]. + /// + /// [upgrade]: struct.Weak.html#method.upgrade + /// [option]: ../../std/option/enum.Option.html /// /// # Examples /// @@ -634,6 +719,7 @@ impl Weak { /// use std::sync::Weak; /// /// let empty: Weak = Weak::new(); + /// assert!(empty.upgrade().is_none()); /// ``` #[stable(feature = "downgraded_weak", since = "1.10.0")] pub fn new() -> Weak { @@ -650,12 +736,13 @@ impl Weak { } impl Weak { - /// Upgrades a weak reference to a strong reference. + /// Upgrades the `Weak` pointer to an [`Arc`][arc], if possible. /// - /// Upgrades the `Weak` reference to an `Arc`, if possible. + /// Returns [`None`][option] if the strong count has reached zero and the + /// inner value was destroyed. /// - /// Returns `None` if there were no strong references and the data was - /// destroyed. + /// [arc]: struct.Arc.html + /// [option]: ../../std/option/enum.Option.html /// /// # Examples /// @@ -667,6 +754,13 @@ impl Weak { /// let weak_five = Arc::downgrade(&five); /// /// let strong_five: Option> = weak_five.upgrade(); + /// assert!(strong_five.is_some()); + /// + /// // Destroy all strong pointers. + /// drop(strong_five); + /// drop(five); + /// + /// assert!(weak_five.upgrade().is_none()); /// ``` #[stable(feature = "arc_weak", since = "1.4.0")] pub fn upgrade(&self) -> Option> { @@ -709,9 +803,10 @@ impl Weak { #[stable(feature = "arc_weak", since = "1.4.0")] impl Clone for Weak { - /// Makes a clone of the `Weak`. + /// Makes a clone of the `Weak` pointer. /// - /// This increases the weak reference count. + /// This creates another pointer to the same inner value, increasing the + /// weak reference count. /// /// # Examples /// @@ -743,7 +838,23 @@ impl Clone for Weak { #[stable(feature = "downgraded_weak", since = "1.10.0")] impl Default for Weak { - /// Constructs a new `Weak` without an accompanying instance of T. + /// Constructs a new `Weak`, without an accompanying instance of `T`. + /// + /// This allocates memory for `T`, but does not initialize it. Calling + /// [`upgrade`][upgrade] on the return value always gives + /// [`None`][option]. + /// + /// [upgrade]: struct.Weak.html#method.upgrade + /// [option]: ../../std/option/enum.Option.html + /// + /// # Examples + /// + /// ``` + /// use std::sync::Weak; + /// + /// let empty: Weak = Default::default(); + /// assert!(empty.upgrade().is_none()); + /// ``` fn default() -> Weak { Weak::new() } @@ -751,7 +862,7 @@ impl Default for Weak { #[stable(feature = "arc_weak", since = "1.4.0")] impl Drop for Weak { - /// Drops the `Weak`. + /// Drops the `Weak` pointer. /// /// This will decrement the weak reference count. /// @@ -760,21 +871,22 @@ impl Drop for Weak { /// ``` /// use std::sync::Arc; /// - /// { - /// let five = Arc::new(5); - /// let weak_five = Arc::downgrade(&five); - /// - /// // stuff + /// struct Foo; /// - /// drop(weak_five); // explicit drop + /// impl Drop for Foo { + /// fn drop(&mut self) { + /// println!("dropped!"); + /// } /// } - /// { - /// let five = Arc::new(5); - /// let weak_five = Arc::downgrade(&five); /// - /// // stuff + /// let foo = Arc::new(Foo); + /// let weak_foo = Arc::downgrade(&foo); + /// let other_weak_foo = weak_foo.clone(); /// - /// } // implicit drop + /// drop(weak_foo); // Doesn't print anything + /// drop(foo); // Prints "dropped!" + /// + /// assert!(other_weak_foo.upgrade().is_none()); /// ``` fn drop(&mut self) { let ptr = *self.ptr; @@ -796,9 +908,9 @@ impl Drop for Weak { #[stable(feature = "rust1", since = "1.0.0")] impl PartialEq for Arc { - /// Equality for two `Arc`s. + /// Equality for two `Arc`s. /// - /// Two `Arc`s are equal if their inner value are equal. + /// Two `Arc`s are equal if their inner values are equal. /// /// # Examples /// @@ -807,15 +919,15 @@ impl PartialEq for Arc { /// /// let five = Arc::new(5); /// - /// five == Arc::new(5); + /// assert!(five == Arc::new(5)); /// ``` fn eq(&self, other: &Arc) -> bool { *(*self) == *(*other) } - /// Inequality for two `Arc`s. + /// Inequality for two `Arc`s. /// - /// Two `Arc`s are unequal if their inner value are unequal. + /// Two `Arc`s are unequal if their inner values are unequal. /// /// # Examples /// @@ -824,7 +936,7 @@ impl PartialEq for Arc { /// /// let five = Arc::new(5); /// - /// five != Arc::new(5); + /// assert!(five != Arc::new(6)); /// ``` fn ne(&self, other: &Arc) -> bool { *(*self) != *(*other) @@ -832,7 +944,7 @@ impl PartialEq for Arc { } #[stable(feature = "rust1", since = "1.0.0")] impl PartialOrd for Arc { - /// Partial comparison for two `Arc`s. + /// Partial comparison for two `Arc`s. /// /// The two are compared by calling `partial_cmp()` on their inner values. /// @@ -840,16 +952,17 @@ impl PartialOrd for Arc { /// /// ``` /// use std::sync::Arc; + /// use std::cmp::Ordering; /// /// let five = Arc::new(5); /// - /// five.partial_cmp(&Arc::new(5)); + /// assert_eq!(Some(Ordering::Less), five.partial_cmp(&Arc::new(6))); /// ``` fn partial_cmp(&self, other: &Arc) -> Option { (**self).partial_cmp(&**other) } - /// Less-than comparison for two `Arc`s. + /// Less-than comparison for two `Arc`s. /// /// The two are compared by calling `<` on their inner values. /// @@ -860,13 +973,13 @@ impl PartialOrd for Arc { /// /// let five = Arc::new(5); /// - /// five < Arc::new(5); + /// assert!(five < Arc::new(6)); /// ``` fn lt(&self, other: &Arc) -> bool { *(*self) < *(*other) } - /// 'Less-than or equal to' comparison for two `Arc`s. + /// 'Less than or equal to' comparison for two `Arc`s. /// /// The two are compared by calling `<=` on their inner values. /// @@ -877,13 +990,13 @@ impl PartialOrd for Arc { /// /// let five = Arc::new(5); /// - /// five <= Arc::new(5); + /// assert!(five <= Arc::new(5)); /// ``` fn le(&self, other: &Arc) -> bool { *(*self) <= *(*other) } - /// Greater-than comparison for two `Arc`s. + /// Greater-than comparison for two `Arc`s. /// /// The two are compared by calling `>` on their inner values. /// @@ -894,13 +1007,13 @@ impl PartialOrd for Arc { /// /// let five = Arc::new(5); /// - /// five > Arc::new(5); + /// assert!(five > Arc::new(4)); /// ``` fn gt(&self, other: &Arc) -> bool { *(*self) > *(*other) } - /// 'Greater-than or equal to' comparison for two `Arc`s. + /// 'Greater than or equal to' comparison for two `Arc`s. /// /// The two are compared by calling `>=` on their inner values. /// @@ -911,7 +1024,7 @@ impl PartialOrd for Arc { /// /// let five = Arc::new(5); /// - /// five >= Arc::new(5); + /// assert!(five >= Arc::new(5)); /// ``` fn ge(&self, other: &Arc) -> bool { *(*self) >= *(*other) @@ -919,6 +1032,20 @@ impl PartialOrd for Arc { } #[stable(feature = "rust1", since = "1.0.0")] impl Ord for Arc { + /// Comparison for two `Arc`s. + /// + /// The two are compared by calling `cmp()` on their inner values. + /// + /// # Examples + /// + /// ``` + /// use std::sync::Arc; + /// use std::cmp::Ordering; + /// + /// let five = Arc::new(5); + /// + /// assert_eq!(Ordering::Less, five.cmp(&Arc::new(6))); + /// ``` fn cmp(&self, other: &Arc) -> Ordering { (**self).cmp(&**other) } @@ -949,7 +1076,16 @@ impl fmt::Pointer for Arc { #[stable(feature = "rust1", since = "1.0.0")] impl Default for Arc { - /// Creates a new `Arc`, with the `Default` value for T. + /// Creates a new `Arc`, with the `Default` value for `T`. + /// + /// # Examples + /// + /// ``` + /// use std::sync::Arc; + /// + /// let x: Arc = Default::default(); + /// assert_eq!(*x, 0); + /// ``` fn default() -> Arc { Arc::new(Default::default()) } -- cgit 1.4.1-3-g733a5 From 29d3e570a5ecb767aca977194fc8ab80277af312 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Tue, 27 Sep 2016 12:45:29 -0700 Subject: Apply some Arc doc changes to Rc --- src/liballoc/rc.rs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 4a4de419f2e..699f777138d 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -12,12 +12,12 @@ //! Single-threaded reference-counting pointers. //! -//! The type [`Rc`][rc] provides shared ownership of a value, allocated -//! in the heap. Invoking [`clone`][clone] on `Rc` produces a new pointer -//! to the same value in the heap. When the last `Rc` pointer to a given -//! value is destroyed, the pointed-to value is also destroyed. +//! The type [`Rc`][rc] provides shared ownership of a value of type `T`, +//! allocated in the heap. Invoking [`clone`][clone] on `Rc` produces a new +//! pointer to the same value in the heap. When the last `Rc` pointer to a +//! given value is destroyed, the pointed-to value is also destroyed. //! -//! Shared pointers in Rust disallow mutation by default, and `Rc` is no +//! Shared references in Rust disallow mutation by default, and `Rc` is no //! exception. If you need to mutate through an `Rc`, use [`Cell`][cell] or //! [`RefCell`][refcell]. //! @@ -44,8 +44,9 @@ //! functions][assoc], called using function-like syntax: //! //! ``` -//! # use std::rc::Rc; -//! # let my_rc = Rc::new(()); +//! use std::rc::Rc; +//! let my_rc = Rc::new(()); +//! //! Rc::downgrade(&my_rc); //! ``` //! @@ -294,10 +295,13 @@ impl Rc { /// Returns the contained value, if the `Rc` has exactly one strong reference. /// - /// Otherwise, an `Err` is returned with the same `Rc` that was passed in. + /// Otherwise, an [`Err`][result] is returned with the same `Rc` that was + /// passed in. /// /// This will succeed even if there are outstanding weak references. /// + /// [result]: ../../std/result/enum.Result.html + /// /// # Examples /// /// ``` @@ -331,7 +335,11 @@ impl Rc { } } - /// Checks whether `Rc::try_unwrap` would return `Ok`. + /// Checks whether [`Rc::try_unwrap`][try_unwrap] would return + /// [`Ok`][result]. + /// + /// [try_unwrap]: struct.Rc.html#method.try_unwrap + /// [result]: ../../std/result/enum.Result.html /// /// # Examples /// @@ -582,8 +590,10 @@ impl Drop for Rc { /// Drops the `Rc`. /// /// This will decrement the strong reference count. If the strong reference - /// count reaches zero then the only other references (if any) are `Weak`, - /// so we `drop` the inner value. + /// count reaches zero then the only other references (if any) are + /// [`Weak`][weak], so we `drop` the inner value. + /// + /// [weak]: struct.Weak.html /// /// # Examples /// -- cgit 1.4.1-3-g733a5 From ef3a6a8ee6e0c38def279df77885fc8b995d9635 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 12 Oct 2016 20:54:41 +0300 Subject: Add an unstable constructor for creating `Rc` from `str` --- src/liballoc/rc.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/liballoc') diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 699f777138d..18a345630d1 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -230,13 +230,14 @@ use core::hash::{Hash, Hasher}; use core::intrinsics::{abort, assume}; use core::marker; use core::marker::Unsize; -use core::mem::{self, align_of_val, forget, size_of_val, uninitialized}; +use core::mem::{self, align_of_val, forget, size_of, size_of_val, uninitialized}; use core::ops::Deref; use core::ops::CoerceUnsized; use core::ptr::{self, Shared}; use core::convert::From; use heap::deallocate; +use raw_vec::RawVec; struct RcBox { strong: Cell, @@ -365,6 +366,30 @@ impl Rc { } } +impl Rc { + /// Constructs a new `Rc` from a string slice. + #[doc(hidden)] + #[unstable(feature = "rustc_private", + reason = "for internal use in rustc", + issue = "0")] + pub fn __from_str(value: &str) -> Rc { + unsafe { + // Allocate enough space for `RcBox`. + let aligned_len = (value.len() + size_of::() - 1) / size_of::(); + let vec = RawVec::::with_capacity(2 + aligned_len); + let ptr = vec.ptr(); + forget(vec); + // Initialize fields of `RcBox`. + *ptr.offset(0) = 1; // strong: Cell::new(1) + *ptr.offset(1) = 1; // weak: Cell::new(1) + ptr::copy_nonoverlapping(value.as_ptr(), ptr.offset(2) as *mut u8, value.len()); + // Combine the allocation address and the string length into a fat pointer to `RcBox`. + let rcbox_ptr = mem::transmute([ptr as usize, value.len()]); + Rc { ptr: Shared::new(rcbox_ptr) } + } + } +} + impl Rc { /// Creates a new [`Weak`][weak] pointer to this value. /// -- cgit 1.4.1-3-g733a5 From 348c3fb0851c155f06768e54c44990d39b6eb142 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 13 Oct 2016 14:05:59 +0300 Subject: Add assert checking that allocation and deallocation sizes are equal --- src/liballoc/rc.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 18a345630d1..740d13c4762 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -375,8 +375,8 @@ impl Rc { pub fn __from_str(value: &str) -> Rc { unsafe { // Allocate enough space for `RcBox`. - let aligned_len = (value.len() + size_of::() - 1) / size_of::(); - let vec = RawVec::::with_capacity(2 + aligned_len); + let aligned_len = 2 + (value.len() + size_of::() - 1) / size_of::(); + let vec = RawVec::::with_capacity(aligned_len); let ptr = vec.ptr(); forget(vec); // Initialize fields of `RcBox`. @@ -384,7 +384,8 @@ impl Rc { *ptr.offset(1) = 1; // weak: Cell::new(1) ptr::copy_nonoverlapping(value.as_ptr(), ptr.offset(2) as *mut u8, value.len()); // Combine the allocation address and the string length into a fat pointer to `RcBox`. - let rcbox_ptr = mem::transmute([ptr as usize, value.len()]); + let rcbox_ptr: *mut RcBox = mem::transmute([ptr as usize, value.len()]); + assert!(aligned_len * size_of::() == size_of_val(&*rcbox_ptr)); Rc { ptr: Shared::new(rcbox_ptr) } } } -- cgit 1.4.1-3-g733a5 From 54e320d4bce4a397d165739fda8329a0567b35c4 Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Sun, 16 Oct 2016 15:41:01 +0530 Subject: run rustfmt on various folders --- src/build_helper/lib.rs | 8 ++++++-- src/liballoc/raw_vec.rs | 14 +++----------- src/liballoc_jemalloc/build.rs | 32 ++++++++++++++------------------ src/liballoc_system/lib.rs | 6 +----- src/libarena/lib.rs | 5 ++--- 5 files changed, 26 insertions(+), 39 deletions(-) (limited to 'src/liballoc') diff --git a/src/build_helper/lib.rs b/src/build_helper/lib.rs index 838cc4f07a9..38844fb6c9e 100644 --- a/src/build_helper/lib.rs +++ b/src/build_helper/lib.rs @@ -25,7 +25,9 @@ pub fn run_silent(cmd: &mut Command) { }; if !status.success() { fail(&format!("command did not execute successfully: {:?}\n\ - expected success, got: {}", cmd, status)); + expected success, got: {}", + cmd, + status)); } } @@ -65,7 +67,9 @@ pub fn output(cmd: &mut Command) -> String { }; if !output.status.success() { panic!("command did not execute successfully: {:?}\n\ - expected success, got: {}", cmd, output.status); + expected success, got: {}", + cmd, + output.status); } String::from_utf8(output.stdout).unwrap() } diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs index e153507956b..f23ea0ea8bf 100644 --- a/src/liballoc/raw_vec.rs +++ b/src/liballoc/raw_vec.rs @@ -57,11 +57,7 @@ impl RawVec { pub fn new() -> Self { unsafe { // !0 is usize::MAX. This branch should be stripped at compile time. - let cap = if mem::size_of::() == 0 { - !0 - } else { - 0 - }; + let cap = if mem::size_of::() == 0 { !0 } else { 0 }; // heap::EMPTY doubles as "unallocated" and "zero-sized allocation" RawVec { @@ -209,11 +205,7 @@ impl RawVec { let (new_cap, ptr) = if self.cap == 0 { // skip to 4 because tiny Vec's are dumb; but not if that would cause overflow - let new_cap = if elem_size > (!0) / 8 { - 1 - } else { - 4 - }; + let new_cap = if elem_size > (!0) / 8 { 1 } else { 4 }; let ptr = heap::allocate(new_cap * elem_size, align); (new_cap, ptr) } else { @@ -347,7 +339,7 @@ impl RawVec { let elem_size = mem::size_of::(); // Nothing we can really do about these checks :( let required_cap = used_cap.checked_add(needed_extra_cap) - .expect("capacity overflow"); + .expect("capacity overflow"); // Cannot overflow, because `cap <= isize::MAX`, and type of `cap` is `usize`. let double_cap = self.cap * 2; // `double_cap` guarantees exponential growth. diff --git a/src/liballoc_jemalloc/build.rs b/src/liballoc_jemalloc/build.rs index 028d742cc83..369db8e75a3 100644 --- a/src/liballoc_jemalloc/build.rs +++ b/src/liballoc_jemalloc/build.rs @@ -35,12 +35,8 @@ fn main() { // that the feature set used by std is the same across all // targets, which means we have to build the alloc_jemalloc crate // for targets like emscripten, even if we don't use it. - if target.contains("rumprun") || - target.contains("bitrig") || - target.contains("openbsd") || - target.contains("msvc") || - target.contains("emscripten") - { + if target.contains("rumprun") || target.contains("bitrig") || target.contains("openbsd") || + target.contains("msvc") || target.contains("emscripten") { println!("cargo:rustc-cfg=dummy_jemalloc"); return; } @@ -64,16 +60,16 @@ fn main() { // only msvc returns None for ar so unwrap is okay let ar = build_helper::cc2ar(compiler.path(), &target).unwrap(); let cflags = compiler.args() - .iter() - .map(|s| s.to_str().unwrap()) - .collect::>() - .join(" "); + .iter() + .map(|s| s.to_str().unwrap()) + .collect::>() + .join(" "); let mut stack = src_dir.join("../jemalloc") - .read_dir() - .unwrap() - .map(|e| e.unwrap()) - .collect::>(); + .read_dir() + .unwrap() + .map(|e| e.unwrap()) + .collect::>(); while let Some(entry) = stack.pop() { let path = entry.path(); if entry.file_type().unwrap().is_dir() { @@ -155,10 +151,10 @@ fn main() { run(&mut cmd); run(Command::new("make") - .current_dir(&build_dir) - .arg("build_lib_static") - .arg("-j") - .arg(env::var("NUM_JOBS").expect("NUM_JOBS was not set"))); + .current_dir(&build_dir) + .arg("build_lib_static") + .arg("-j") + .arg(env::var("NUM_JOBS").expect("NUM_JOBS was not set"))); if target.contains("windows") { println!("cargo:rustc-link-lib=static=jemalloc"); diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs index dacafe771ed..b380ba180f4 100644 --- a/src/liballoc_system/lib.rs +++ b/src/liballoc_system/lib.rs @@ -221,11 +221,7 @@ mod imp { HEAP_REALLOC_IN_PLACE_ONLY, ptr as LPVOID, size as SIZE_T) as *mut u8; - if new.is_null() { - old_size - } else { - size - } + if new.is_null() { old_size } else { size } } else { old_size } diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 4986c9850d7..72785b9cc83 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -302,9 +302,8 @@ mod tests { let arena = Wrap(TypedArena::new()); - let result = arena.alloc_outer(|| { - Outer { inner: arena.alloc_inner(|| Inner { value: 10 }) } - }); + let result = + arena.alloc_outer(|| Outer { inner: arena.alloc_inner(|| Inner { value: 10 }) }); assert_eq!(result.inner.value, 10); } -- cgit 1.4.1-3-g733a5