From edc67817a312d2c7924ae333facb9294ff751008 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 23 Jan 2015 15:02:05 -0500 Subject: [PATCH 01/15] Improve libcore/cell.rs docs --- src/libcore/cell.rs | 294 +++++++++++++++++++++++++++++++------------- 1 file changed, 209 insertions(+), 85 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 7f73be9eb5f4..202d860021ee 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -10,39 +10,30 @@ //! Shareable mutable containers. //! -//! Values of the `Cell` and `RefCell` types may be mutated through -//! shared references (i.e. the common `&T` type), whereas most Rust -//! types can only be mutated through unique (`&mut T`) references. We -//! say that `Cell` and `RefCell` provide *interior mutability*, in -//! contrast with typical Rust types that exhibit *inherited -//! mutability*. +//! Values of the `Cell` and `RefCell` types may be mutated through shared references (i.e. +//! the common `&T` type), whereas most Rust types can only be mutated through unique (`&mut T`) +//! references. We say that `Cell` and `RefCell` provide 'interior mutability', in contrast +//! with typical Rust types that exhibit 'inherited mutability'. //! -//! Cell types come in two flavors: `Cell` and `RefCell`. `Cell` -//! provides `get` and `set` methods that change the -//! interior value with a single method call. `Cell` though is only -//! compatible with types that implement `Copy`. For other types, -//! one must use the `RefCell` type, acquiring a write lock before -//! mutating. +//! Cell types come in two flavors: `Cell` and `RefCell`. `Cell` provides `get` and `set` +//! methods that change the interior value with a single method call. `Cell` though is only +//! compatible with types that implement `Copy`. For other types, one must use the `RefCell` +//! type, acquiring a write lock before mutating. //! -//! `RefCell` uses Rust's lifetimes to implement *dynamic borrowing*, -//! a process whereby one can claim temporary, exclusive, mutable -//! access to the inner value. Borrows for `RefCell`s are tracked *at -//! runtime*, unlike Rust's native reference types which are entirely -//! tracked statically, at compile time. Because `RefCell` borrows are -//! dynamic it is possible to attempt to borrow a value that is -//! already mutably borrowed; when this happens it results in task -//! panic. +//! `RefCell` uses Rust's lifetimes to implement 'dynamic borrowing', a process whereby one can +//! claim temporary, exclusive, mutable access to the inner value. Borrows for `RefCell`s are +//! tracked 'at runtime', unlike Rust's native reference types which are entirely tracked +//! statically, at compile time. Because `RefCell` borrows are dynamic it is possible to attempt +//! to borrow a value that is already mutably borrowed; when this happens it results in task panic. //! //! # When to choose interior mutability //! -//! The more common inherited mutability, where one must have unique -//! access to mutate a value, is one of the key language elements that -//! enables Rust to reason strongly about pointer aliasing, statically -//! preventing crash bugs. Because of that, inherited mutability is -//! preferred, and interior mutability is something of a last -//! resort. Since cell types enable mutation where it would otherwise -//! be disallowed though, there are occasions when interior -//! mutability might be appropriate, or even *must* be used, e.g. +//! The more common inherited mutability, where one must have unique access to mutate a value, is +//! one of the key language elements that enables Rust to reason strongly about pointer aliasing, +//! statically preventing crash bugs. Because of that, inherited mutability is preferred, and +//! interior mutability is something of a last resort. Since cell types enable mutation where it +//! would otherwise be disallowed though, there are occasions when interior mutability might be +//! appropriate, or even *must* be used, e.g. //! //! * Introducing inherited mutability roots to shared types. //! * Implementation details of logically-immutable methods. @@ -50,15 +41,13 @@ //! //! ## Introducing inherited mutability roots to shared types //! -//! Shared smart pointer types, including `Rc` and `Arc`, provide -//! containers that can be cloned and shared between multiple parties. -//! Because the contained values may be multiply-aliased, they can -//! only be borrowed as shared references, not mutable references. -//! Without cells it would be impossible to mutate data inside of -//! shared boxes at all! +//! Shared smart pointer types, including `Rc` and `Arc`, provide containers that can be +//! cloned and shared between multiple parties. Because the contained values may be +//! multiply-aliased, they can only be borrowed as shared references, not mutable references. +//! Without cells it would be impossible to mutate data inside of shared boxes at all! //! -//! It's very common then to put a `RefCell` inside shared pointer -//! types to reintroduce mutability: +//! It's very common then to put a `RefCell` inside shared pointer types to reintroduce +//! mutability: //! //! ``` //! use std::collections::HashMap; @@ -80,12 +69,10 @@ //! //! ## Implementation details of logically-immutable methods //! -//! Occasionally it may be desirable not to expose in an API that -//! there is mutation happening "under the hood". This may be because -//! logically the operation is immutable, but e.g. caching forces the -//! implementation to perform mutation; or because you must employ -//! mutation to implement a trait method that was originally defined -//! to take `&self`. +//! Occasionally it may be desirable not to expose in an API that there is mutation happening +//! "under the hood". This may be because logically the operation is immutable, but e.g. caching +//! forces the implementation to perform mutation; or because you must employ mutation to implement +//! a trait method that was originally defined to take `&self`. //! //! ``` //! use std::cell::RefCell; @@ -123,13 +110,11 @@ //! //! ## Mutating implementations of `clone` //! -//! This is simply a special - but common - case of the previous: -//! hiding mutability for operations that appear to be immutable. -//! The `clone` method is expected to not change the source value, and -//! is declared to take `&self`, not `&mut self`. Therefore any -//! mutation that happens in the `clone` method must use cell -//! types. For example, `Rc` maintains its reference counts within a -//! `Cell`. +//! This is simply a special - but common - case of the previous: hiding mutability for operations +//! that appear to be immutable. The `clone` method is expected to not change the source value, and +//! is declared to take `&self`, not `&mut self`. Therefore any mutation that happens in the +//! `clone` method must use cell types. For example, `Rc` maintains its reference counts within a +//! `Cell`. //! //! ``` //! use std::cell::Cell; @@ -153,10 +138,6 @@ //! } //! ``` //! -// FIXME: Explain difference between Cell and RefCell -// FIXME: Downsides to interior mutability -// FIXME: Can't be shared between threads. Dynamic borrows -// FIXME: Relationship to Atomic types and RWLock #![stable] @@ -169,6 +150,8 @@ use option::Option; use option::Option::{None, Some}; /// A mutable memory location that admits only `Copy` data. +/// +/// See the [module-level documentation](../index.html) for more. #[stable] pub struct Cell { value: UnsafeCell, @@ -176,6 +159,14 @@ pub struct Cell { impl Cell { /// Creates a new `Cell` containing the given value. + /// + /// # Examples + /// + /// ``` + /// use std::cell::Cell; + /// + /// let c = Cell::new(5); + /// ``` #[stable] pub fn new(value: T) -> Cell { Cell { @@ -184,6 +175,16 @@ impl Cell { } /// Returns a copy of the contained value. + /// + /// # Examples + /// + /// ``` + /// use std::cell::Cell; + /// + /// let c = Cell::new(5); + /// + /// let five = c.get(); + /// ``` #[inline] #[stable] pub fn get(&self) -> T { @@ -191,6 +192,16 @@ impl Cell { } /// Sets the contained value. + /// + /// # Examples + /// + /// ``` + /// use std::cell::Cell; + /// + /// let c = Cell::new(5); + /// + /// c.set(10); + /// ``` #[inline] #[stable] pub fn set(&self, value: T) { @@ -201,9 +212,19 @@ impl Cell { /// Get a reference to the underlying `UnsafeCell`. /// - /// This can be used to circumvent `Cell`'s safety checks. + /// # Unsafety /// /// This function is `unsafe` because `UnsafeCell`'s field is public. + /// + /// # Examples + /// + /// ``` + /// use std::cell::Cell; + /// + /// let c = Cell::new(5); + /// + /// let uc = unsafe { c.as_unsafe_cell() }; + /// ``` #[inline] #[unstable] pub unsafe fn as_unsafe_cell<'a>(&'a self) -> &'a UnsafeCell { @@ -237,6 +258,8 @@ impl PartialEq for Cell { } /// A mutable memory location with dynamically checked borrow rules +/// +/// See the [module-level documentation](../index.html) for more. #[stable] pub struct RefCell { value: UnsafeCell, @@ -250,7 +273,15 @@ const UNUSED: BorrowFlag = 0; const WRITING: BorrowFlag = -1; impl RefCell { - /// Create a new `RefCell` containing `value` + /// Creates a new `RefCell` containing `value`. + /// + /// # Examples + /// + /// ``` + /// use std::cell::RefCell; + /// + /// let c = RefCell::new(5); + /// ``` #[stable] pub fn new(value: T) -> RefCell { RefCell { @@ -260,6 +291,16 @@ impl RefCell { } /// Consumes the `RefCell`, returning the wrapped value. + /// + /// # Examples + /// + /// ``` + /// use std::cell::RefCell; + /// + /// let c = RefCell::new(5); + /// + /// let five = c.into_inner(); + /// ``` #[stable] pub fn into_inner(self) -> T { // Since this function takes `self` (the `RefCell`) by value, the @@ -285,12 +326,39 @@ impl RefCell { /// Immutably borrows the wrapped value. /// - /// The borrow lasts until the returned `Ref` exits scope. Multiple - /// immutable borrows can be taken out at the same time. + /// The borrow lasts until the returned `Ref` exits scope. Multiple immutable borrows can be + /// taken out at the same time. /// /// # Panics /// /// Panics if the value is currently mutably borrowed. + /// + /// # Examples + /// + /// ``` + /// use std::cell::RefCell; + /// + /// let c = RefCell::new(5); + /// + /// let borrowed_five = c.borrow(); + /// let borrowed_five2 = c.borrow(); + /// ``` + /// + /// An example of panic: + /// + /// ``` + /// use std::cell::RefCell; + /// use std::thread::Thread; + /// + /// let result = Thread::scoped(move || { + /// let c = RefCell::new(5); + /// let m = c.borrow_mut(); + /// + /// let b = c.borrow(); // this causes a panic + /// }).join(); + /// + /// assert!(result.is_err()); + /// ``` #[stable] pub fn borrow<'a>(&'a self) -> Ref<'a, T> { match self.try_borrow() { @@ -315,12 +383,38 @@ impl RefCell { /// Mutably borrows the wrapped value. /// - /// The borrow lasts until the returned `RefMut` exits scope. The value - /// cannot be borrowed while this borrow is active. + /// The borrow lasts until the returned `RefMut` exits scope. The value cannot be borrowed + /// while this borrow is active. /// /// # Panics /// /// Panics if the value is currently borrowed. + /// + /// # Examples + /// + /// ``` + /// use std::cell::RefCell; + /// + /// let c = RefCell::new(5); + /// + /// let borrowed_five = c.borrow_mut(); + /// ``` + /// + /// An example of panic: + /// + /// ``` + /// use std::cell::RefCell; + /// use std::thread::Thread; + /// + /// let result = Thread::scoped(move || { + /// let c = RefCell::new(5); + /// let m = c.borrow_mut(); + /// + /// let b = c.borrow_mut(); // this causes a panic + /// }).join(); + /// + /// assert!(result.is_err()); + /// ``` #[stable] pub fn borrow_mut<'a>(&'a self) -> RefMut<'a, T> { match self.try_borrow_mut() { @@ -402,7 +496,9 @@ impl<'b> Clone for BorrowRef<'b> { } } -/// Wraps a borrowed reference to a value in a `RefCell` box. +/// A wrapper type for an immutably borrowed value from a `RefCell`. +/// +/// See the [module-level documentation](../index.html) for more. #[stable] pub struct Ref<'b, T:'b> { // FIXME #12808: strange name to try to avoid interfering with @@ -460,7 +556,9 @@ impl<'b> BorrowRefMut<'b> { } } -/// Wraps a mutable borrowed reference to a value in a `RefCell` box. +/// A wrapper type for a mutably borrowed value from a `RefCell`. +/// +/// See the [module-level documentation](../index.html) for more. #[stable] pub struct RefMut<'b, T:'b> { // FIXME #12808: strange name to try to avoid interfering with @@ -489,28 +587,25 @@ impl<'b, T> DerefMut for RefMut<'b, T> { /// The core primitive for interior mutability in Rust. /// -/// `UnsafeCell` type that wraps a type T and indicates unsafe interior -/// operations on the wrapped type. Types with an `UnsafeCell` field are -/// considered to have an *unsafe interior*. The `UnsafeCell` type is the only -/// legal way to obtain aliasable data that is considered mutable. In general, -/// transmuting an &T type into an &mut T is considered undefined behavior. +/// `UnsafeCell` is a type that wraps some `T` and indicates unsafe interior operations on the +/// wrapped type. Types with an `UnsafeCell` field are considered to have an 'unsafe interior'. +/// The `UnsafeCell` type is the only legal way to obtain aliasable data that is considered +/// mutable. In general, transmuting an `&T` type into an `&mut T` is considered undefined behavior. /// -/// Although it is possible to put an `UnsafeCell` into static item, it is -/// not permitted to take the address of the static item if the item is not -/// declared as mutable. This rule exists because immutable static items are -/// stored in read-only memory, and thus any attempt to mutate their interior -/// can cause segfaults. Immutable static items containing `UnsafeCell` -/// instances are still useful as read-only initializers, however, so we do not -/// forbid them altogether. +/// Although it is possible to put an `UnsafeCell` into static item, it is not permitted to take +/// the address of the static item if the item is not declared as mutable. This rule exists because +/// immutable static items are stored in read-only memory, and thus any attempt to mutate their +/// interior can cause segfaults. Immutable static items containing `UnsafeCell` instances are +/// still useful as read-only initializers, however, so we do not forbid them altogether. /// -/// Types like `Cell` and `RefCell` use this type to wrap their internal data. +/// Types like `Cell` and `RefCell` use this type to wrap their internal data. /// -/// `UnsafeCell` doesn't opt-out from any kind, instead, types with an -/// `UnsafeCell` interior are expected to opt-out from kinds themselves. +/// `UnsafeCell` doesn't opt-out from any marker traits, instead, types with an `UnsafeCell` +/// interior are expected to opt-out from those traits themselves. /// -/// # Example: +/// # Examples /// -/// ```rust +/// ``` /// use std::cell::UnsafeCell; /// use std::marker::Sync; /// @@ -521,9 +616,8 @@ impl<'b, T> DerefMut for RefMut<'b, T> { /// unsafe impl Sync for NotThreadSafe {} /// ``` /// -/// **NOTE:** `UnsafeCell` fields are public to allow static initializers. It -/// is not recommended to access its fields directly, `get` should be used -/// instead. +/// **NOTE:** `UnsafeCell`'s fields are public to allow static initializers. It is not +/// recommended to access its fields directly, `get` should be used instead. #[lang="unsafe"] #[stable] pub struct UnsafeCell { @@ -539,22 +633,52 @@ impl UnsafeCell { /// Construct a new instance of `UnsafeCell` which will wrap the specified /// value. /// - /// All access to the inner value through methods is `unsafe`, and it is - /// highly discouraged to access the fields directly. + /// All access to the inner value through methods is `unsafe`, and it is highly discouraged to + /// access the fields directly. + /// + /// # Examples + /// + /// ``` + /// use std::cell::UnsafeCell; + /// + /// let uc = UnsafeCell::new(5); + /// ``` #[stable] pub fn new(value: T) -> UnsafeCell { UnsafeCell { value: value } } /// Gets a mutable pointer to the wrapped value. + /// + /// # Examples + /// + /// ``` + /// use std::cell::UnsafeCell; + /// + /// let uc = UnsafeCell::new(5); + /// + /// let five = uc.get(); + /// ``` #[inline] #[stable] pub fn get(&self) -> *mut T { &self.value as *const T as *mut T } /// Unwraps the value /// - /// This function is unsafe because there is no guarantee that this or other - /// tasks are currently inspecting the inner value. + /// # Unsafety + /// + /// This function is unsafe because there is no guarantee that this or other threads are + /// currently inspecting the inner value. + /// + /// # Examples + /// + /// ``` + /// use std::cell::UnsafeCell; + /// + /// let uc = UnsafeCell::new(5); + /// + /// let five = unsafe { uc.into_inner() }; + /// ``` #[inline] #[stable] pub unsafe fn into_inner(self) -> T { self.value } From 0736ad3c2abdd899eb625fc8bfdc632b876abe5a Mon Sep 17 00:00:00 2001 From: Pyfisch Date: Sat, 24 Jan 2015 14:54:43 +0100 Subject: [PATCH 02/15] Spellfix for Debug trait Spellfix for `Debug` trait documentation. Change "most all types should implement this" to "all types should implement this". Same fix for deprecated `Show` trait. --- src/libcore/fmt/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 0e8d31a62eed..d4ffea3371ef 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -231,7 +231,7 @@ impl<'a> Display for Arguments<'a> { } } -/// Format trait for the `:?` format. Useful for debugging, most all types +/// Format trait for the `:?` format. Useful for debugging, all types /// should implement this. #[deprecated = "renamed to Debug"] #[cfg(not(stage0))] @@ -240,7 +240,7 @@ pub trait Show { fn fmt(&self, &mut Formatter) -> Result; } -/// Format trait for the `:?` format. Useful for debugging, most all types +/// Format trait for the `:?` format. Useful for debugging, all types /// should implement this. #[unstable = "I/O and core have yet to be reconciled"] pub trait Debug { From e7245252ccb5de3d8002a2cc3ecb25595ea23e90 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Sun, 25 Jan 2015 01:44:49 +0200 Subject: [PATCH 03/15] Cleanup check_cast. Fixes #21554 This also makes the cast error messages somewhat more uniform. --- src/librustc/middle/ty.rs | 1 - src/librustc_typeck/check/mod.rs | 186 ++++++++++-------- src/test/compile-fail/cast-from-nil.rs | 2 +- src/test/compile-fail/cast-to-nil.rs | 2 +- src/test/compile-fail/issue-10991.rs | 2 +- src/test/compile-fail/issue-21554.rs | 15 ++ .../typeck-cast-pointer-to-float.rs | 2 +- 7 files changed, 119 insertions(+), 91 deletions(-) create mode 100644 src/test/compile-fail/issue-21554.rs diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index bae41b78c08a..3e0801d65989 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3128,7 +3128,6 @@ pub fn type_is_scalar(ty: Ty) -> bool { ty_bool | ty_char | ty_int(_) | ty_float(_) | ty_uint(_) | ty_infer(IntVar(_)) | ty_infer(FloatVar(_)) | ty_bare_fn(..) | ty_ptr(_) => true, - ty_tup(ref tys) if tys.is_empty() => true, _ => false } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index a9f81d3a2663..9489f0cc01b9 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -993,86 +993,65 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, } } -fn check_cast(fcx: &FnCtxt, - cast_expr: &ast::Expr, - e: &ast::Expr, - t: &ast::Ty) { - let id = cast_expr.id; - let span = cast_expr.span; - - // Find the type of `e`. Supply hints based on the type we are casting to, - // if appropriate. - let t_1 = fcx.to_ty(t); - let t_1 = structurally_resolved_type(fcx, span, t_1); - - check_expr_with_expectation(fcx, e, ExpectCastableToType(t_1)); - - let t_e = fcx.expr_ty(e); - - debug!("t_1={}", fcx.infcx().ty_to_string(t_1)); - debug!("t_e={}", fcx.infcx().ty_to_string(t_e)); - - if ty::type_is_error(t_e) { - fcx.write_error(id); - return - } - - if !fcx.type_is_known_to_be_sized(t_1, cast_expr.span) { - let tstr = fcx.infcx().ty_to_string(t_1); - fcx.type_error_message(span, |actual| { - format!("cast to unsized type: `{}` as `{}`", actual, tstr) - }, t_e, None); - match t_e.sty { - ty::ty_rptr(_, ty::mt { mutbl: mt, .. }) => { - let mtstr = match mt { - ast::MutMutable => "mut ", - ast::MutImmutable => "" - }; - if ty::type_is_trait(t_1) { - span_help!(fcx.tcx().sess, t.span, "did you mean `&{}{}`?", mtstr, tstr); - } else { - span_help!(fcx.tcx().sess, span, - "consider using an implicit coercion to `&{}{}` instead", - mtstr, tstr); - } - } - ty::ty_uniq(..) => { - span_help!(fcx.tcx().sess, t.span, "did you mean `Box<{}>`?", tstr); - } - _ => { - span_help!(fcx.tcx().sess, e.span, - "consider using a box or reference as appropriate"); +fn report_cast_to_unsized_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + span: Span, + t_span: Span, + e_span: Span, + t_1: Ty<'tcx>, + t_e: Ty<'tcx>, + id: ast::NodeId) { + let tstr = fcx.infcx().ty_to_string(t_1); + fcx.type_error_message(span, |actual| { + format!("cast to unsized type: `{}` as `{}`", actual, tstr) + }, t_e, None); + match t_e.sty { + ty::ty_rptr(_, ty::mt { mutbl: mt, .. }) => { + let mtstr = match mt { + ast::MutMutable => "mut ", + ast::MutImmutable => "" + }; + if ty::type_is_trait(t_1) { + span_help!(fcx.tcx().sess, t_span, "did you mean `&{}{}`?", mtstr, tstr); + } else { + span_help!(fcx.tcx().sess, span, + "consider using an implicit coercion to `&{}{}` instead", + mtstr, tstr); } } - fcx.write_error(id); - return + ty::ty_uniq(..) => { + span_help!(fcx.tcx().sess, t_span, "did you mean `Box<{}>`?", tstr); + } + _ => { + span_help!(fcx.tcx().sess, e_span, + "consider using a box or reference as appropriate"); + } } + fcx.write_error(id); +} - if ty::type_is_trait(t_1) { - // This will be looked up later on. - vtable::check_object_cast(fcx, cast_expr, e, t_1); - fcx.write_ty(id, t_1); - return - } - let t_1 = structurally_resolved_type(fcx, span, t_1); - let t_e = structurally_resolved_type(fcx, span, t_e); - - if ty::type_is_nil(t_e) { +fn check_cast_inner<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + span: Span, + t_1: Ty<'tcx>, + t_e: Ty<'tcx>, + e: &ast::Expr) { + fn cast_through_integer_err<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + span: Span, + t_1: Ty<'tcx>, + t_e: Ty<'tcx>) { fcx.type_error_message(span, |actual| { - format!("cast from nil: `{}` as `{}`", - actual, - fcx.infcx().ty_to_string(t_1)) - }, t_e, None); - } else if ty::type_is_nil(t_1) { - fcx.type_error_message(span, |actual| { - format!("cast to nil: `{}` as `{}`", + format!("illegal cast; cast through an \ + integer first: `{}` as `{}`", actual, fcx.infcx().ty_to_string(t_1)) }, t_e, None); } let t_e_is_bare_fn_item = ty::type_is_bare_fn_item(t_e); + let t_e_is_scalar = ty::type_is_scalar(t_e); + let t_e_is_integral = ty::type_is_integral(t_e); + let t_e_is_float = ty::type_is_floating_point(t_e); + let t_e_is_c_enum = ty::type_is_c_like_enum(fcx.tcx(), t_e); let t_1_is_scalar = ty::type_is_scalar(t_1); let t_1_is_char = ty::type_is_char(t_1); @@ -1081,18 +1060,9 @@ fn check_cast(fcx: &FnCtxt, // casts to scalars other than `char` and `bare fn` are trivial let t_1_is_trivial = t_1_is_scalar && !t_1_is_char && !t_1_is_bare_fn; + if t_e_is_bare_fn_item && t_1_is_bare_fn { demand::coerce(fcx, e.span, t_1, &*e); - } else if ty::type_is_c_like_enum(fcx.tcx(), t_e) && t_1_is_trivial { - if t_1_is_float || ty::type_is_unsafe_ptr(t_1) { - fcx.type_error_message(span, |actual| { - format!("illegal cast; cast through an \ - integer first: `{}` as `{}`", - actual, - fcx.infcx().ty_to_string(t_1)) - }, t_e, None); - } - // casts from C-like enums are allowed } else if t_1_is_char { let t_e = fcx.infcx().shallow_resolve(t_e); if t_e.sty != ty::ty_uint(ast::TyU8) { @@ -1104,6 +1074,16 @@ fn check_cast(fcx: &FnCtxt, } else if t_1.sty == ty::ty_bool { span_err!(fcx.tcx().sess, span, E0054, "cannot cast as `bool`, compare with zero instead"); + } else if t_1_is_float && (t_e_is_scalar || t_e_is_c_enum) && !( + t_e_is_integral || t_e_is_float || t_e.sty == ty::ty_bool) { + // Casts to float must go through an integer or boolean + cast_through_integer_err(fcx, span, t_1, t_e) + } else if t_e_is_c_enum && t_1_is_trivial { + if ty::type_is_unsafe_ptr(t_1) { + // ... and likewise with C enum -> *T + cast_through_integer_err(fcx, span, t_1, t_e) + } + // casts from C-like enums are allowed } else if ty::type_is_region_ptr(t_e) && ty::type_is_unsafe_ptr(t_1) { fn types_compatible<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span, t1: Ty<'tcx>, t2: Ty<'tcx>) -> bool { @@ -1145,7 +1125,7 @@ fn check_cast(fcx: &FnCtxt, demand::coerce(fcx, e.span, t_1, &*e); } } - } else if !(ty::type_is_scalar(t_e) && t_1_is_trivial) { + } else if !(t_e_is_scalar && t_1_is_trivial) { /* If more type combinations should be supported than are supported here, then file an enhancement issue and @@ -1156,15 +1136,49 @@ fn check_cast(fcx: &FnCtxt, actual, fcx.infcx().ty_to_string(t_1)) }, t_e, None); - } else if ty::type_is_unsafe_ptr(t_e) && t_1_is_float { - fcx.type_error_message(span, |actual| { - format!("cannot cast from pointer to float directly: `{}` as `{}`; cast through an \ - integer first", - actual, - fcx.infcx().ty_to_string(t_1)) - }, t_e, None); + } +} + +fn check_cast(fcx: &FnCtxt, + cast_expr: &ast::Expr, + e: &ast::Expr, + t: &ast::Ty) { + let id = cast_expr.id; + let span = cast_expr.span; + + // Find the type of `e`. Supply hints based on the type we are casting to, + // if appropriate. + let t_1 = fcx.to_ty(t); + let t_1 = structurally_resolved_type(fcx, span, t_1); + + check_expr_with_expectation(fcx, e, ExpectCastableToType(t_1)); + + let t_e = fcx.expr_ty(e); + + debug!("t_1={}", fcx.infcx().ty_to_string(t_1)); + debug!("t_e={}", fcx.infcx().ty_to_string(t_e)); + + if ty::type_is_error(t_e) { + fcx.write_error(id); + return } + if !fcx.type_is_known_to_be_sized(t_1, cast_expr.span) { + report_cast_to_unsized_type(fcx, span, t.span, e.span, t_1, t_e, id); + return + } + + if ty::type_is_trait(t_1) { + // This will be looked up later on. + vtable::check_object_cast(fcx, cast_expr, e, t_1); + fcx.write_ty(id, t_1); + return + } + + let t_1 = structurally_resolved_type(fcx, span, t_1); + let t_e = structurally_resolved_type(fcx, span, t_e); + + check_cast_inner(fcx, span, t_1, t_e, e); fcx.write_ty(id, t_1); } diff --git a/src/test/compile-fail/cast-from-nil.rs b/src/test/compile-fail/cast-from-nil.rs index 558a54787183..4c6dcaccc9ae 100644 --- a/src/test/compile-fail/cast-from-nil.rs +++ b/src/test/compile-fail/cast-from-nil.rs @@ -8,5 +8,5 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern: cast from nil: `()` as `u32` +// error-pattern: non-scalar cast: `()` as `u32` fn main() { let u = (assert!(true) as u32); } diff --git a/src/test/compile-fail/cast-to-nil.rs b/src/test/compile-fail/cast-to-nil.rs index 1a5c0744f70a..e5fd5bb33eb9 100644 --- a/src/test/compile-fail/cast-to-nil.rs +++ b/src/test/compile-fail/cast-to-nil.rs @@ -8,5 +8,5 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern: cast to nil: `u32` as `()` +// error-pattern: non-scalar cast: `u32` as `()` fn main() { let u = 0u32 as (); } diff --git a/src/test/compile-fail/issue-10991.rs b/src/test/compile-fail/issue-10991.rs index 2913ddf395fb..25060b94dcf3 100644 --- a/src/test/compile-fail/issue-10991.rs +++ b/src/test/compile-fail/issue-10991.rs @@ -10,5 +10,5 @@ fn main() { let nil = (); - let _t = nil as usize; //~ ERROR: cast from nil: `()` as `usize` + let _t = nil as usize; //~ ERROR: non-scalar cast: `()` as `usize` } diff --git a/src/test/compile-fail/issue-21554.rs b/src/test/compile-fail/issue-21554.rs new file mode 100644 index 000000000000..a2cac55033c1 --- /dev/null +++ b/src/test/compile-fail/issue-21554.rs @@ -0,0 +1,15 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Inches(i32); + +fn main() { + Inches as f32; //~ ERROR illegal cast; cast through an integer first +} diff --git a/src/test/compile-fail/typeck-cast-pointer-to-float.rs b/src/test/compile-fail/typeck-cast-pointer-to-float.rs index 22a0978ef7c7..285a5dbee053 100644 --- a/src/test/compile-fail/typeck-cast-pointer-to-float.rs +++ b/src/test/compile-fail/typeck-cast-pointer-to-float.rs @@ -11,5 +11,5 @@ fn main() { let x : i16 = 22; ((&x) as *const i16) as f32; - //~^ ERROR: cannot cast from pointer to float directly: `*const i16` as `f32` + //~^ ERROR illegal cast; cast through an integer first: `*const i16` as `f32` } From 0dac5685783631dc4ecf3e865229a3747fe81943 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 24 Jan 2015 22:43:11 -0800 Subject: [PATCH 04/15] syntax: Don't put quotes around filenames in codemap This ends up propagating all the way out to the output of dep-info which then makes Cargo think that files are not existent (it thinks the files have quotes in their name) when they in fact do. --- src/libsyntax/codemap.rs | 7 ++++--- src/libsyntax/ext/source_util.rs | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index a5e10f42750b..e0d4f69a34cd 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -364,9 +364,10 @@ impl CodeMap { }; // Append '\n' in case it's not already there. - // This is a workaround to prevent CodeMap.lookup_filemap_idx from accidentally - // overflowing into the next filemap in case the last byte of span is also the last - // byte of filemap, which leads to incorrect results from CodeMap.span_to_*. + // This is a workaround to prevent CodeMap.lookup_filemap_idx from + // accidentally overflowing into the next filemap in case the last byte + // of span is also the last byte of filemap, which leads to incorrect + // results from CodeMap.span_to_*. if src.len() > 0 && !src.ends_with("\n") { src.push('\n'); } diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index a74adbf40851..0d74af5caa40 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -135,7 +135,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) let bytes = match File::open(&file).read_to_end() { Err(e) => { cx.span_err(sp, - &format!("couldn't read {:?}: {}", + &format!("couldn't read {}: {}", file.display(), e)[]); return DummyResult::expr(sp); @@ -146,7 +146,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) Ok(src) => { // Add this input file to the code map to make it available as // dependency information - let filename = format!("{:?}", file.display()); + let filename = format!("{}", file.display()); let interned = token::intern_and_get_ident(&src[]); cx.codemap().new_filemap(filename, src); @@ -154,7 +154,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) } Err(_) => { cx.span_err(sp, - &format!("{:?} wasn't a utf-8 file", + &format!("{} wasn't a utf-8 file", file.display())[]); return DummyResult::expr(sp); } @@ -171,7 +171,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) match File::open(&file).read_to_end() { Err(e) => { cx.span_err(sp, - &format!("couldn't read {:?}: {}", file.display(), e)[]); + &format!("couldn't read {}: {}", file.display(), e)[]); return DummyResult::expr(sp); } Ok(bytes) => { From bca25aeeb40b220d7330d71cd4906acafc32ebe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Mon, 26 Jan 2015 09:45:16 +0100 Subject: [PATCH 05/15] Use more specific target CPUs on Darwin Macs don't come with anything older than a Yonah (32bit) or Core2 (64bit), so we can default to those targets. Clang does the same. --- src/librustc_back/target/i686_apple_darwin.rs | 1 + src/librustc_back/target/x86_64_apple_darwin.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librustc_back/target/i686_apple_darwin.rs b/src/librustc_back/target/i686_apple_darwin.rs index 1b079323bf9c..fcea900283d2 100644 --- a/src/librustc_back/target/i686_apple_darwin.rs +++ b/src/librustc_back/target/i686_apple_darwin.rs @@ -12,6 +12,7 @@ use target::Target; pub fn target() -> Target { let mut base = super::apple_base::opts(); + base.cpu = "yonah".to_string(); base.pre_link_args.push("-m32".to_string()); Target { diff --git a/src/librustc_back/target/x86_64_apple_darwin.rs b/src/librustc_back/target/x86_64_apple_darwin.rs index f2abfd4564c7..0b3b2bea62d7 100644 --- a/src/librustc_back/target/x86_64_apple_darwin.rs +++ b/src/librustc_back/target/x86_64_apple_darwin.rs @@ -12,7 +12,7 @@ use target::Target; pub fn target() -> Target { let mut base = super::apple_base::opts(); - base.cpu = "x86-64".to_string(); + base.cpu = "core2".to_string(); base.eliminate_frame_pointer = false; base.pre_link_args.push("-m64".to_string()); From 296c74de96e2ca78289ee0a127cca3b7e58af734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Mon, 26 Jan 2015 09:54:19 +0100 Subject: [PATCH 06/15] Default to Pentium 4 as the x86 target CPU on Windows/Linux/DragonFly Limiting ourselves to a generic x86 instruction set doesn't seem useful. Both users running those systems on original i386 hardware might as well manually specify a target cpu ;-) Clang uses the same default. --- src/librustc_back/target/i686_pc_windows_gnu.rs | 1 + src/librustc_back/target/i686_unknown_dragonfly.rs | 1 + src/librustc_back/target/i686_unknown_linux_gnu.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/src/librustc_back/target/i686_pc_windows_gnu.rs b/src/librustc_back/target/i686_pc_windows_gnu.rs index c2ab68ee0525..249f2d440e68 100644 --- a/src/librustc_back/target/i686_pc_windows_gnu.rs +++ b/src/librustc_back/target/i686_pc_windows_gnu.rs @@ -12,6 +12,7 @@ use target::Target; pub fn target() -> Target { let mut options = super::windows_base::opts(); + options.cpu = "pentium4".to_string(); // Mark all dynamic libraries and executables as compatible with the larger 4GiB address // space available to x86 Windows binaries on x86_64. diff --git a/src/librustc_back/target/i686_unknown_dragonfly.rs b/src/librustc_back/target/i686_unknown_dragonfly.rs index 7910eba7ea12..4450d8d67782 100644 --- a/src/librustc_back/target/i686_unknown_dragonfly.rs +++ b/src/librustc_back/target/i686_unknown_dragonfly.rs @@ -12,6 +12,7 @@ use target::Target; pub fn target() -> Target { let mut base = super::dragonfly_base::opts(); + base.cpu = "pentium4".to_string(); base.pre_link_args.push("-m32".to_string()); Target { diff --git a/src/librustc_back/target/i686_unknown_linux_gnu.rs b/src/librustc_back/target/i686_unknown_linux_gnu.rs index c93a564fef5f..f21f6adfb4c0 100644 --- a/src/librustc_back/target/i686_unknown_linux_gnu.rs +++ b/src/librustc_back/target/i686_unknown_linux_gnu.rs @@ -12,6 +12,7 @@ use target::Target; pub fn target() -> Target { let mut base = super::linux_base::opts(); + base.cpu = "pentium4".to_string(); base.pre_link_args.push("-m32".to_string()); Target { From f72b1645103e12b581f7022b893c37b5fe41aef7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 22 Jan 2015 16:27:48 -0800 Subject: [PATCH 07/15] std: Rename io to old_io In preparation for the I/O rejuvination of the standard library, this commit renames the current `io` module to `old_io` in order to make room for the new I/O modules. It is expected that the I/O RFCs will land incrementally over time instead of all at once, and this provides a fresh clean path for new modules to enter into as well as guaranteeing that all old infrastructure will remain in place for some time. As each `old_io` module is replaced it will be deprecated in-place for new structures in `std::{io, fs, net}` (as appropriate). This commit does *not* leave a reexport of `old_io as io` as the deprecation lint does not currently warn on this form of use. This is quite a large breaking change for all imports in existing code, but all functionality is retained precisely as-is and path statements simply need to be renamed from `io` to `old_io`. [breaking-change] --- src/libstd/lib.rs | 7 +- src/libstd/{io => old_io}/buffered.rs | 30 ++-- src/libstd/{io => old_io}/comm_adapters.rs | 22 +-- src/libstd/{io => old_io}/extensions.rs | 28 +-- src/libstd/{io => old_io}/fs.rs | 191 +++++++++++---------- src/libstd/{io => old_io}/mem.rs | 44 ++--- src/libstd/{io => old_io}/mod.rs | 62 ++++--- src/libstd/{io => old_io}/net/addrinfo.rs | 6 +- src/libstd/{io => old_io}/net/ip.rs | 16 +- src/libstd/{io => old_io}/net/mod.rs | 2 +- src/libstd/{io => old_io}/net/pipe.rs | 18 +- src/libstd/{io => old_io}/net/tcp.rs | 38 ++-- src/libstd/{io => old_io}/net/udp.rs | 14 +- src/libstd/{io => old_io}/pipe.rs | 6 +- src/libstd/{io => old_io}/process.rs | 28 +-- src/libstd/{io => old_io}/result.rs | 0 src/libstd/{io => old_io}/stdio.rs | 10 +- src/libstd/{io => old_io}/tempfile.rs | 8 +- src/libstd/{io => old_io}/test.rs | 2 +- src/libstd/{io => old_io}/timer.rs | 16 +- src/libstd/{io => old_io}/util.rs | 54 +++--- 21 files changed, 311 insertions(+), 291 deletions(-) rename src/libstd/{io => old_io}/buffered.rs (95%) rename src/libstd/{io => old_io}/comm_adapters.rs (92%) rename src/libstd/{io => old_io}/extensions.rs (94%) rename src/libstd/{io => old_io}/fs.rs (90%) rename src/libstd/{io => old_io}/mem.rs (94%) rename src/libstd/{io => old_io}/mod.rs (97%) rename src/libstd/{io => old_io}/net/addrinfo.rs (97%) rename src/libstd/{io => old_io}/net/ip.rs (98%) rename src/libstd/{io => old_io}/net/mod.rs (96%) rename src/libstd/{io => old_io}/net/pipe.rs (98%) rename src/libstd/{io => old_io}/net/tcp.rs (98%) rename src/libstd/{io => old_io}/net/udp.rs (97%) rename src/libstd/{io => old_io}/pipe.rs (97%) rename src/libstd/{io => old_io}/process.rs (98%) rename src/libstd/{io => old_io}/result.rs (100%) rename src/libstd/{io => old_io}/stdio.rs (98%) rename src/libstd/{io => old_io}/tempfile.rs (97%) rename src/libstd/{io => old_io}/test.rs (99%) rename src/libstd/{io => old_io}/timer.rs (98%) rename src/libstd/{io => old_io}/util.rs (86%) diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 9bfc15f14389..119e7c501969 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -79,7 +79,8 @@ //! memory types, including [`atomic`](sync/atomic/index.html). //! //! Common types of I/O, including files, TCP, UDP, pipes, Unix domain sockets, -//! timers, and process spawning, are defined in the [`io`](io/index.html) module. +//! timers, and process spawning, are defined in the +//! [`old_io`](old_io/index.html) module. //! //! Rust's I/O and concurrency depends on a small runtime interface //! that lives, along with its support code, in mod [`rt`](rt/index.html). @@ -239,7 +240,7 @@ pub mod thread_local; pub mod dynamic_lib; pub mod ffi; pub mod fmt; -pub mod io; +pub mod old_io; pub mod os; pub mod path; pub mod rand; @@ -284,7 +285,7 @@ mod std { pub use sync; // used for select!() pub use error; // used for try!() pub use fmt; // used for any formatting strings - pub use io; // used for println!() + pub use old_io; // used for println!() pub use option; // used for bitflags!{} pub use rt; // used for panic!() pub use vec; // used for vec![] diff --git a/src/libstd/io/buffered.rs b/src/libstd/old_io/buffered.rs similarity index 95% rename from src/libstd/io/buffered.rs rename to src/libstd/old_io/buffered.rs index 73c73209f00f..c04af865af88 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/old_io/buffered.rs @@ -14,7 +14,7 @@ use cmp; use fmt; -use io::{Reader, Writer, Stream, Buffer, DEFAULT_BUF_SIZE, IoResult}; +use old_io::{Reader, Writer, Stream, Buffer, DEFAULT_BUF_SIZE, IoResult}; use iter::{IteratorExt, ExactSizeIterator, repeat}; use ops::Drop; use option::Option; @@ -34,7 +34,7 @@ use vec::Vec; /// # Example /// /// ```rust -/// use std::io::{BufferedReader, File}; +/// use std::old_io::{BufferedReader, File}; /// /// let file = File::open(&Path::new("message.txt")); /// let mut reader = BufferedReader::new(file); @@ -137,7 +137,7 @@ impl Reader for BufferedReader { /// # Example /// /// ```rust -/// use std::io::{BufferedWriter, File}; +/// use std::old_io::{BufferedWriter, File}; /// /// let file = File::create(&Path::new("message.txt")).unwrap(); /// let mut writer = BufferedWriter::new(file); @@ -324,7 +324,7 @@ impl Reader for InternalBufferedWriter { /// /// ```rust /// # #![allow(unused_must_use)] -/// use std::io::{BufferedStream, File}; +/// use std::old_io::{BufferedStream, File}; /// /// let file = File::open(&Path::new("message.txt")); /// let mut stream = BufferedStream::new(file); @@ -437,13 +437,13 @@ mod test { pub struct NullStream; impl Reader for NullStream { - fn read(&mut self, _: &mut [u8]) -> io::IoResult { - Err(io::standard_error(io::EndOfFile)) + fn read(&mut self, _: &mut [u8]) -> old_io::IoResult { + Err(old_io::standard_error(old_io::EndOfFile)) } } impl Writer for NullStream { - fn write(&mut self, _: &[u8]) -> io::IoResult<()> { Ok(()) } + fn write(&mut self, _: &[u8]) -> old_io::IoResult<()> { Ok(()) } } /// A dummy reader intended at testing short-reads propagation. @@ -452,9 +452,9 @@ mod test { } impl Reader for ShortReader { - fn read(&mut self, _: &mut [u8]) -> io::IoResult { + fn read(&mut self, _: &mut [u8]) -> old_io::IoResult { if self.lengths.is_empty() { - Err(io::standard_error(io::EndOfFile)) + Err(old_io::standard_error(old_io::EndOfFile)) } else { Ok(self.lengths.remove(0)) } @@ -555,13 +555,13 @@ mod test { fn test_buffered_stream() { struct S; - impl io::Writer for S { - fn write(&mut self, _: &[u8]) -> io::IoResult<()> { Ok(()) } + impl old_io::Writer for S { + fn write(&mut self, _: &[u8]) -> old_io::IoResult<()> { Ok(()) } } - impl io::Reader for S { - fn read(&mut self, _: &mut [u8]) -> io::IoResult { - Err(io::standard_error(io::EndOfFile)) + impl old_io::Reader for S { + fn read(&mut self, _: &mut [u8]) -> old_io::IoResult { + Err(old_io::standard_error(old_io::EndOfFile)) } } @@ -664,7 +664,7 @@ mod test { impl Writer for FailFlushWriter { fn write(&mut self, _buf: &[u8]) -> IoResult<()> { Ok(()) } - fn flush(&mut self) -> IoResult<()> { Err(io::standard_error(EndOfFile)) } + fn flush(&mut self) -> IoResult<()> { Err(old_io::standard_error(EndOfFile)) } } let writer = FailFlushWriter; diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/old_io/comm_adapters.rs similarity index 92% rename from src/libstd/io/comm_adapters.rs rename to src/libstd/old_io/comm_adapters.rs index 4649012d454b..3c684e4cc6a9 100644 --- a/src/libstd/io/comm_adapters.rs +++ b/src/libstd/old_io/comm_adapters.rs @@ -11,7 +11,7 @@ use clone::Clone; use cmp; use sync::mpsc::{Sender, Receiver}; -use io; +use old_io; use option::Option::{None, Some}; use result::Result::{Ok, Err}; use slice::{bytes, SliceExt}; @@ -24,7 +24,7 @@ use vec::Vec; /// /// ``` /// use std::sync::mpsc::channel; -/// use std::io::ChanReader; +/// use std::old_io::ChanReader; /// /// let (tx, rx) = channel(); /// # drop(tx); @@ -70,7 +70,7 @@ impl Buffer for ChanReader { } } if self.closed { - Err(io::standard_error(io::EndOfFile)) + Err(old_io::standard_error(old_io::EndOfFile)) } else { Ok(&self.buf[self.pos..]) } @@ -102,7 +102,7 @@ impl Reader for ChanReader { } } if self.closed && num_read == 0 { - Err(io::standard_error(io::EndOfFile)) + Err(old_io::standard_error(old_io::EndOfFile)) } else { Ok(num_read) } @@ -116,7 +116,7 @@ impl Reader for ChanReader { /// ``` /// # #![allow(unused_must_use)] /// use std::sync::mpsc::channel; -/// use std::io::ChanWriter; +/// use std::old_io::ChanWriter; /// /// let (tx, rx) = channel(); /// # drop(rx); @@ -144,8 +144,8 @@ impl Clone for ChanWriter { impl Writer for ChanWriter { fn write(&mut self, buf: &[u8]) -> IoResult<()> { self.tx.send(buf.to_vec()).map_err(|_| { - io::IoError { - kind: io::BrokenPipe, + old_io::IoError { + kind: old_io::BrokenPipe, desc: "Pipe closed", detail: None } @@ -193,14 +193,14 @@ mod test { match reader.read(buf.as_mut_slice()) { Ok(..) => panic!(), - Err(e) => assert_eq!(e.kind, io::EndOfFile), + Err(e) => assert_eq!(e.kind, old_io::EndOfFile), } assert_eq!(a, buf); // Ensure it continues to panic in the same way. match reader.read(buf.as_mut_slice()) { Ok(..) => panic!(), - Err(e) => assert_eq!(e.kind, io::EndOfFile), + Err(e) => assert_eq!(e.kind, old_io::EndOfFile), } assert_eq!(a, buf); } @@ -223,7 +223,7 @@ mod test { assert_eq!(Ok("how are you?".to_string()), reader.read_line()); match reader.read_line() { Ok(..) => panic!(), - Err(e) => assert_eq!(e.kind, io::EndOfFile), + Err(e) => assert_eq!(e.kind, old_io::EndOfFile), } } @@ -242,7 +242,7 @@ mod test { match writer.write_u8(1) { Ok(..) => panic!(), - Err(e) => assert_eq!(e.kind, io::BrokenPipe), + Err(e) => assert_eq!(e.kind, old_io::BrokenPipe), } } } diff --git a/src/libstd/io/extensions.rs b/src/libstd/old_io/extensions.rs similarity index 94% rename from src/libstd/io/extensions.rs rename to src/libstd/old_io/extensions.rs index af08eea210e7..259242d0cd85 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/old_io/extensions.rs @@ -15,8 +15,8 @@ // FIXME: Not sure how this should be structured // FIXME: Iteration should probably be considered separately -use io::{IoError, IoResult, Reader}; -use io; +use old_io::{IoError, IoResult, Reader}; +use old_io; use iter::Iterator; use num::Int; use ops::FnOnce; @@ -59,7 +59,7 @@ impl<'r, R: Reader> Iterator for Bytes<'r, R> { fn next(&mut self) -> Option> { match self.reader.read_byte() { Ok(x) => Some(Ok(x)), - Err(IoError { kind: io::EndOfFile, .. }) => None, + Err(IoError { kind: old_io::EndOfFile, .. }) => None, Err(e) => Some(Err(e)) } } @@ -179,14 +179,14 @@ pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 { mod test { use prelude::v1::*; use io; - use io::{MemReader, BytesReader}; + use old_io::{MemReader, BytesReader}; struct InitialZeroByteReader { count: int, } impl Reader for InitialZeroByteReader { - fn read(&mut self, buf: &mut [u8]) -> io::IoResult { + fn read(&mut self, buf: &mut [u8]) -> old_io::IoResult { if self.count == 0 { self.count = 1; Ok(0) @@ -200,16 +200,16 @@ mod test { struct EofReader; impl Reader for EofReader { - fn read(&mut self, _: &mut [u8]) -> io::IoResult { - Err(io::standard_error(io::EndOfFile)) + fn read(&mut self, _: &mut [u8]) -> old_io::IoResult { + Err(old_io::standard_error(old_io::EndOfFile)) } } struct ErroringReader; impl Reader for ErroringReader { - fn read(&mut self, _: &mut [u8]) -> io::IoResult { - Err(io::standard_error(io::InvalidInput)) + fn read(&mut self, _: &mut [u8]) -> old_io::IoResult { + Err(old_io::standard_error(old_io::InvalidInput)) } } @@ -218,7 +218,7 @@ mod test { } impl Reader for PartialReader { - fn read(&mut self, buf: &mut [u8]) -> io::IoResult { + fn read(&mut self, buf: &mut [u8]) -> old_io::IoResult { if self.count == 0 { self.count = 1; buf[0] = 10; @@ -237,13 +237,13 @@ mod test { } impl Reader for ErroringLaterReader { - fn read(&mut self, buf: &mut [u8]) -> io::IoResult { + fn read(&mut self, buf: &mut [u8]) -> old_io::IoResult { if self.count == 0 { self.count = 1; buf[0] = 10; Ok(1) } else { - Err(io::standard_error(io::InvalidInput)) + Err(old_io::standard_error(old_io::InvalidInput)) } } } @@ -253,7 +253,7 @@ mod test { } impl Reader for ThreeChunkReader { - fn read(&mut self, buf: &mut [u8]) -> io::IoResult { + fn read(&mut self, buf: &mut [u8]) -> old_io::IoResult { if self.count == 0 { self.count = 1; buf[0] = 10; @@ -265,7 +265,7 @@ mod test { buf[1] = 13; Ok(2) } else { - Err(io::standard_error(io::EndOfFile)) + Err(old_io::standard_error(old_io::EndOfFile)) } } } diff --git a/src/libstd/io/fs.rs b/src/libstd/old_io/fs.rs similarity index 90% rename from src/libstd/io/fs.rs rename to src/libstd/old_io/fs.rs index cc36c5640d0a..ee6dbafe6885 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/old_io/fs.rs @@ -18,21 +18,21 @@ //! At the top-level of the module are a set of freestanding functions, associated //! with various filesystem operations. They all operate on `Path` objects. //! -//! All operations in this module, including those as part of `File` et al -//! block the task during execution. In the event of failure, all functions/methods +//! All operations in this module, including those as part of `File` et al block +//! the task during execution. In the event of failure, all functions/methods //! will return an `IoResult` type with an `Err` value. //! //! Also included in this module is an implementation block on the `Path` object -//! defined in `std::path::Path`. The impl adds useful methods about inspecting the -//! metadata of a file. This includes getting the `stat` information, reading off -//! particular bits of it, etc. +//! defined in `std::path::Path`. The impl adds useful methods about inspecting +//! the metadata of a file. This includes getting the `stat` information, +//! reading off particular bits of it, etc. //! //! # Example //! //! ```rust //! # #![allow(unused_must_use)] -//! use std::io::fs::PathExtensions; -//! use std::io::{File, fs}; +//! use std::old_io::fs::PathExtensions; +//! use std::old_io::{File, fs}; //! //! let path = Path::new("foo.txt"); //! @@ -51,13 +51,13 @@ //! ``` use clone::Clone; -use io::standard_error; -use io::{FilePermission, Write, Open, FileAccess, FileMode, FileType}; -use io::{IoResult, IoError, InvalidInput}; -use io::{FileStat, SeekStyle, Seek, Writer, Reader}; -use io::{Read, Truncate, ReadWrite, Append}; -use io::UpdateIoError; -use io; +use old_io::standard_error; +use old_io::{FilePermission, Write, Open, FileAccess, FileMode, FileType}; +use old_io::{IoResult, IoError, InvalidInput}; +use old_io::{FileStat, SeekStyle, Seek, Writer, Reader}; +use old_io::{Read, Truncate, ReadWrite, Append}; +use old_io::UpdateIoError; +use old_io; use iter::{Iterator, Extend}; use option::Option; use option::Option::{Some, None}; @@ -101,7 +101,7 @@ impl File { /// # Example /// /// ```rust,should_fail - /// use std::io::{File, Open, ReadWrite}; + /// use std::old_io::{File, Open, ReadWrite}; /// /// let p = Path::new("/some/file/path.txt"); /// @@ -170,7 +170,7 @@ impl File { /// # Example /// /// ```rust - /// use std::io::File; + /// use std::old_io::File; /// /// let contents = File::open(&Path::new("foo.txt")).read_to_end(); /// ``` @@ -188,12 +188,12 @@ impl File { /// /// ```rust /// # #![allow(unused_must_use)] - /// use std::io::File; + /// use std::old_io::File; /// /// let mut f = File::create(&Path::new("foo.txt")); /// f.write(b"This is a sample file"); /// # drop(f); - /// # ::std::io::fs::unlink(&Path::new("foo.txt")); + /// # ::std::old_io::fs::unlink(&Path::new("foo.txt")); /// ``` pub fn create(path: &Path) -> IoResult { File::open_mode(path, Truncate, Write) @@ -265,7 +265,7 @@ impl File { /// /// ```rust /// # #![allow(unused_must_use)] -/// use std::io::fs; +/// use std::old_io::fs; /// /// let p = Path::new("/some/file/path.txt"); /// fs::unlink(&p); @@ -293,7 +293,7 @@ pub fn unlink(path: &Path) -> IoResult<()> { /// # Example /// /// ```rust -/// use std::io::fs; +/// use std::old_io::fs; /// /// let p = Path::new("/some/file/path.txt"); /// match fs::stat(&p) { @@ -333,7 +333,7 @@ pub fn lstat(path: &Path) -> IoResult { /// /// ```rust /// # #![allow(unused_must_use)] -/// use std::io::fs; +/// use std::old_io::fs; /// /// fs::rename(&Path::new("foo"), &Path::new("bar")); /// ``` @@ -359,7 +359,7 @@ pub fn rename(from: &Path, to: &Path) -> IoResult<()> { /// /// ```rust /// # #![allow(unused_must_use)] -/// use std::io::fs; +/// use std::old_io::fs; /// /// fs::copy(&Path::new("foo.txt"), &Path::new("bar.txt")); /// ``` @@ -386,7 +386,7 @@ pub fn copy(from: &Path, to: &Path) -> IoResult<()> { if !from.is_file() { return update_err(Err(IoError { - kind: io::MismatchedFileTypeForOperation, + kind: old_io::MismatchedFileTypeForOperation, desc: "the source path is not an existing file", detail: None }), from, to) @@ -408,12 +408,12 @@ pub fn copy(from: &Path, to: &Path) -> IoResult<()> { /// ```rust /// # #![allow(unused_must_use)] /// use std::io; -/// use std::io::fs; +/// use std::old_io::fs; /// -/// fs::chmod(&Path::new("file.txt"), io::USER_FILE); -/// fs::chmod(&Path::new("file.txt"), io::USER_READ | io::USER_WRITE); -/// fs::chmod(&Path::new("dir"), io::USER_DIR); -/// fs::chmod(&Path::new("file.exe"), io::USER_EXEC); +/// fs::chmod(&Path::new("file.txt"), old_io::USER_FILE); +/// fs::chmod(&Path::new("file.txt"), old_io::USER_READ | old_io::USER_WRITE); +/// fs::chmod(&Path::new("dir"), old_io::USER_DIR); +/// fs::chmod(&Path::new("file.exe"), old_io::USER_EXEC); /// ``` /// /// # Error @@ -421,7 +421,7 @@ pub fn copy(from: &Path, to: &Path) -> IoResult<()> { /// This function will return an error if the provided `path` doesn't exist, if /// the process lacks permissions to change the attributes of the file, or if /// some other I/O error is encountered. -pub fn chmod(path: &Path, mode: io::FilePermission) -> IoResult<()> { +pub fn chmod(path: &Path, mode: old_io::FilePermission) -> IoResult<()> { fs_imp::chmod(path, mode.bits() as uint) .update_err("couldn't chmod path", |e| format!("{}; path={}; mode={:?}", e, path.display(), mode)) @@ -470,10 +470,10 @@ pub fn readlink(path: &Path) -> IoResult { /// ```rust /// # #![allow(unused_must_use)] /// use std::io; -/// use std::io::fs; +/// use std::old_io::fs; /// /// let p = Path::new("/some/dir"); -/// fs::mkdir(&p, io::USER_RWX); +/// fs::mkdir(&p, old_io::USER_RWX); /// ``` /// /// # Error @@ -492,7 +492,7 @@ pub fn mkdir(path: &Path, mode: FilePermission) -> IoResult<()> { /// /// ```rust /// # #![allow(unused_must_use)] -/// use std::io::fs; +/// use std::old_io::fs; /// /// let p = Path::new("/some/dir"); /// fs::rmdir(&p); @@ -513,12 +513,12 @@ pub fn rmdir(path: &Path) -> IoResult<()> { /// # Example /// /// ```rust -/// use std::io::fs::PathExtensions; -/// use std::io::fs; +/// use std::old_io::fs::PathExtensions; +/// use std::old_io::fs; /// use std::io; /// /// // one possible implementation of fs::walk_dir only visiting files -/// fn visit_dirs(dir: &Path, cb: &mut F) -> io::IoResult<()> where +/// fn visit_dirs(dir: &Path, cb: &mut F) -> old_io::IoResult<()> where /// F: FnMut(&Path), /// { /// if dir.is_dir() { @@ -532,7 +532,7 @@ pub fn rmdir(path: &Path) -> IoResult<()> { /// } /// Ok(()) /// } else { -/// Err(io::standard_error(io::InvalidInput)) +/// Err(old_io::standard_error(old_io::InvalidInput)) /// } /// } /// ``` @@ -664,7 +664,7 @@ pub fn rmdir_recursive(path: &Path) -> IoResult<()> { // (eg: deleted by someone else since readdir) match update_err(unlink(&child), path) { Ok(()) => (), - Err(ref e) if e.kind == io::FileNotFound => (), + Err(ref e) if e.kind == old_io::FileNotFound => (), Err(e) => return Err(e) } } @@ -675,7 +675,7 @@ pub fn rmdir_recursive(path: &Path) -> IoResult<()> { let result = update_err(rmdir(&rm_stack.pop().unwrap()), path); match result { Ok(()) => (), - Err(ref e) if e.kind == io::FileNotFound => (), + Err(ref e) if e.kind == old_io::FileNotFound => (), Err(e) => return Err(e) } } @@ -709,7 +709,7 @@ impl Reader for File { Ok(read) => { self.last_nread = read as int; match read { - 0 => update_err(Err(standard_error(io::EndOfFile)), self), + 0 => update_err(Err(standard_error(old_io::EndOfFile)), self), _ => Ok(read as uint) } }, @@ -824,10 +824,10 @@ fn access_string(access: FileAccess) -> &'static str { #[allow(unused_mut)] mod test { use prelude::v1::*; - use io::{SeekSet, SeekCur, SeekEnd, Read, Open, ReadWrite, FileType}; + use old_io::{SeekSet, SeekCur, SeekEnd, Read, Open, ReadWrite, FileType}; use io; use str; - use io::fs::*; + use old_io::fs::*; macro_rules! check { ($e:expr) => ( match $e { @@ -863,7 +863,7 @@ mod test { // Gee, seeing how we're testing the fs module I sure hope that we // at least implement this correctly! let TempDir(ref p) = *self; - check!(io::fs::rmdir_recursive(p)); + check!(old_io::fs::rmdir_recursive(p)); } } @@ -871,7 +871,7 @@ mod test { use os; use rand; let ret = os::tmpdir().join(format!("rust-{}", rand::random::())); - check!(io::fs::mkdir(&ret, io::USER_RWX)); + check!(old_io::fs::mkdir(&ret, old_io::USER_RWX)); TempDir(ret) } @@ -1055,7 +1055,7 @@ mod test { fn file_test_stat_is_correct_on_is_dir() { let tmpdir = tmpdir(); let filename = &tmpdir.join("file_stat_correct_on_is_dir"); - check!(mkdir(filename, io::USER_RWX)); + check!(mkdir(filename, old_io::USER_RWX)); let stat_res_fn = check!(stat(filename)); assert!(stat_res_fn.kind == FileType::Directory); let stat_res_meth = check!(filename.stat()); @@ -1067,7 +1067,7 @@ mod test { fn file_test_fileinfo_false_when_checking_is_file_on_a_directory() { let tmpdir = tmpdir(); let dir = &tmpdir.join("fileinfo_false_on_dir"); - check!(mkdir(dir, io::USER_RWX)); + check!(mkdir(dir, old_io::USER_RWX)); assert!(dir.is_file() == false); check!(rmdir(dir)); } @@ -1087,7 +1087,7 @@ mod test { let tmpdir = tmpdir(); let dir = &tmpdir.join("before_and_after_dir"); assert!(!dir.exists()); - check!(mkdir(dir, io::USER_RWX)); + check!(mkdir(dir, old_io::USER_RWX)); assert!(dir.exists()); assert!(dir.is_dir()); check!(rmdir(dir)); @@ -1099,7 +1099,7 @@ mod test { use str; let tmpdir = tmpdir(); let dir = &tmpdir.join("di_readdir"); - check!(mkdir(dir, io::USER_RWX)); + check!(mkdir(dir, old_io::USER_RWX)); let prefix = "foo"; for n in range(0i,3) { let f = dir.join(format!("{}.txt", n)); @@ -1130,14 +1130,14 @@ mod test { fn file_test_walk_dir() { let tmpdir = tmpdir(); let dir = &tmpdir.join("walk_dir"); - check!(mkdir(dir, io::USER_RWX)); + check!(mkdir(dir, old_io::USER_RWX)); let dir1 = &dir.join("01/02/03"); - check!(mkdir_recursive(dir1, io::USER_RWX)); + check!(mkdir_recursive(dir1, old_io::USER_RWX)); check!(File::create(&dir1.join("04"))); let dir2 = &dir.join("11/12/13"); - check!(mkdir_recursive(dir2, io::USER_RWX)); + check!(mkdir_recursive(dir2, old_io::USER_RWX)); check!(File::create(&dir2.join("14"))); let mut files = check!(walk_dir(dir)); @@ -1155,12 +1155,12 @@ mod test { #[test] fn mkdir_path_already_exists_error() { - use io::{IoError, PathAlreadyExists}; + use old_io::{IoError, PathAlreadyExists}; let tmpdir = tmpdir(); let dir = &tmpdir.join("mkdir_error_twice"); - check!(mkdir(dir, io::USER_RWX)); - match mkdir(dir, io::USER_RWX) { + check!(mkdir(dir, old_io::USER_RWX)); + match mkdir(dir, old_io::USER_RWX) { Err(IoError{kind:PathAlreadyExists,..}) => (), _ => assert!(false) }; @@ -1170,7 +1170,7 @@ mod test { fn recursive_mkdir() { let tmpdir = tmpdir(); let dir = tmpdir.join("d1/d2"); - check!(mkdir_recursive(&dir, io::USER_RWX)); + check!(mkdir_recursive(&dir, old_io::USER_RWX)); assert!(dir.is_dir()) } @@ -1180,10 +1180,10 @@ mod test { let dir = tmpdir.join("d1"); let file = dir.join("f1"); - check!(mkdir_recursive(&dir, io::USER_RWX)); + check!(mkdir_recursive(&dir, old_io::USER_RWX)); check!(File::create(&file)); - let result = mkdir_recursive(&file, io::USER_RWX); + let result = mkdir_recursive(&file, old_io::USER_RWX); error!(result, "couldn't recursively mkdir"); error!(result, "couldn't create directory"); @@ -1193,7 +1193,7 @@ mod test { #[test] fn recursive_mkdir_slash() { - check!(mkdir_recursive(&Path::new("/"), io::USER_RWX)); + check!(mkdir_recursive(&Path::new("/"), old_io::USER_RWX)); } // FIXME(#12795) depends on lstat to work on windows @@ -1206,8 +1206,8 @@ mod test { let dtt = dt.join("t"); let d2 = tmpdir.join("d2"); let canary = d2.join("do_not_delete"); - check!(mkdir_recursive(&dtt, io::USER_RWX)); - check!(mkdir_recursive(&d2, io::USER_RWX)); + check!(mkdir_recursive(&dtt, old_io::USER_RWX)); + check!(mkdir_recursive(&d2, old_io::USER_RWX)); check!(File::create(&canary).write(b"foo")); check!(symlink(&d2, &dt.join("d2"))); check!(rmdir_recursive(&d1)); @@ -1225,7 +1225,7 @@ mod test { let mut dirpath = tmpdir.path().clone(); dirpath.push(format!("test-가一ー你好")); - check!(mkdir(&dirpath, io::USER_RWX)); + check!(mkdir(&dirpath, old_io::USER_RWX)); assert!(dirpath.is_dir()); let mut filepath = dirpath; @@ -1243,7 +1243,7 @@ mod test { let tmpdir = tmpdir(); let unicode = tmpdir.path(); let unicode = unicode.join(format!("test-각丁ー再见")); - check!(mkdir(&unicode, io::USER_RWX)); + check!(mkdir(&unicode, old_io::USER_RWX)); assert!(unicode.exists()); assert!(!Path::new("test/unicode-bogus-path-각丁ー再见").exists()); } @@ -1324,12 +1324,12 @@ mod test { let out = tmpdir.join("out.txt"); check!(File::create(&input)); - check!(chmod(&input, io::USER_READ)); + check!(chmod(&input, old_io::USER_READ)); check!(copy(&input, &out)); - assert!(!check!(out.stat()).perm.intersects(io::USER_WRITE)); + assert!(!check!(out.stat()).perm.intersects(old_io::USER_WRITE)); - check!(chmod(&input, io::USER_FILE)); - check!(chmod(&out, io::USER_FILE)); + check!(chmod(&input, old_io::USER_FILE)); + check!(chmod(&out, old_io::USER_FILE)); } #[cfg(not(windows))] // FIXME(#10264) operation not permitted? @@ -1405,16 +1405,16 @@ mod test { let file = tmpdir.join("in.txt"); check!(File::create(&file)); - assert!(check!(stat(&file)).perm.contains(io::USER_WRITE)); - check!(chmod(&file, io::USER_READ)); - assert!(!check!(stat(&file)).perm.contains(io::USER_WRITE)); + assert!(check!(stat(&file)).perm.contains(old_io::USER_WRITE)); + check!(chmod(&file, old_io::USER_READ)); + assert!(!check!(stat(&file)).perm.contains(old_io::USER_WRITE)); - match chmod(&tmpdir.join("foo"), io::USER_RWX) { + match chmod(&tmpdir.join("foo"), old_io::USER_RWX) { Ok(..) => panic!("wanted a panic"), Err(..) => {} } - check!(chmod(&file, io::USER_FILE)); + check!(chmod(&file, old_io::USER_FILE)); } #[test] @@ -1422,7 +1422,7 @@ mod test { let tmpdir = tmpdir(); let path = tmpdir.join("in.txt"); - let mut file = check!(File::open_mode(&path, io::Open, io::ReadWrite)); + let mut file = check!(File::open_mode(&path, old_io::Open, old_io::ReadWrite)); check!(file.fsync()); check!(file.datasync()); check!(file.write(b"foo")); @@ -1436,7 +1436,7 @@ mod test { let tmpdir = tmpdir(); let path = tmpdir.join("in.txt"); - let mut file = check!(File::open_mode(&path, io::Open, io::ReadWrite)); + let mut file = check!(File::open_mode(&path, old_io::Open, old_io::ReadWrite)); check!(file.write(b"foo")); check!(file.fsync()); @@ -1467,41 +1467,41 @@ mod test { fn open_flavors() { let tmpdir = tmpdir(); - match File::open_mode(&tmpdir.join("a"), io::Open, io::Read) { + match File::open_mode(&tmpdir.join("a"), old_io::Open, old_io::Read) { Ok(..) => panic!(), Err(..) => {} } // Perform each one twice to make sure that it succeeds the second time // (where the file exists) - check!(File::open_mode(&tmpdir.join("b"), io::Open, io::Write)); + check!(File::open_mode(&tmpdir.join("b"), old_io::Open, old_io::Write)); assert!(tmpdir.join("b").exists()); - check!(File::open_mode(&tmpdir.join("b"), io::Open, io::Write)); + check!(File::open_mode(&tmpdir.join("b"), old_io::Open, old_io::Write)); - check!(File::open_mode(&tmpdir.join("c"), io::Open, io::ReadWrite)); + check!(File::open_mode(&tmpdir.join("c"), old_io::Open, old_io::ReadWrite)); assert!(tmpdir.join("c").exists()); - check!(File::open_mode(&tmpdir.join("c"), io::Open, io::ReadWrite)); + check!(File::open_mode(&tmpdir.join("c"), old_io::Open, old_io::ReadWrite)); - check!(File::open_mode(&tmpdir.join("d"), io::Append, io::Write)); + check!(File::open_mode(&tmpdir.join("d"), old_io::Append, old_io::Write)); assert!(tmpdir.join("d").exists()); - check!(File::open_mode(&tmpdir.join("d"), io::Append, io::Write)); + check!(File::open_mode(&tmpdir.join("d"), old_io::Append, old_io::Write)); - check!(File::open_mode(&tmpdir.join("e"), io::Append, io::ReadWrite)); + check!(File::open_mode(&tmpdir.join("e"), old_io::Append, old_io::ReadWrite)); assert!(tmpdir.join("e").exists()); - check!(File::open_mode(&tmpdir.join("e"), io::Append, io::ReadWrite)); + check!(File::open_mode(&tmpdir.join("e"), old_io::Append, old_io::ReadWrite)); - check!(File::open_mode(&tmpdir.join("f"), io::Truncate, io::Write)); + check!(File::open_mode(&tmpdir.join("f"), old_io::Truncate, old_io::Write)); assert!(tmpdir.join("f").exists()); - check!(File::open_mode(&tmpdir.join("f"), io::Truncate, io::Write)); + check!(File::open_mode(&tmpdir.join("f"), old_io::Truncate, old_io::Write)); - check!(File::open_mode(&tmpdir.join("g"), io::Truncate, io::ReadWrite)); + check!(File::open_mode(&tmpdir.join("g"), old_io::Truncate, old_io::ReadWrite)); assert!(tmpdir.join("g").exists()); - check!(File::open_mode(&tmpdir.join("g"), io::Truncate, io::ReadWrite)); + check!(File::open_mode(&tmpdir.join("g"), old_io::Truncate, old_io::ReadWrite)); check!(File::create(&tmpdir.join("h")).write("foo".as_bytes())); - check!(File::open_mode(&tmpdir.join("h"), io::Open, io::Read)); + check!(File::open_mode(&tmpdir.join("h"), old_io::Open, old_io::Read)); { - let mut f = check!(File::open_mode(&tmpdir.join("h"), io::Open, - io::Read)); + let mut f = check!(File::open_mode(&tmpdir.join("h"), old_io::Open, + old_io::Read)); match f.write("wut".as_bytes()) { Ok(..) => panic!(), Err(..) => {} } @@ -1509,15 +1509,15 @@ mod test { assert!(check!(stat(&tmpdir.join("h"))).size == 3, "write/stat failed"); { - let mut f = check!(File::open_mode(&tmpdir.join("h"), io::Append, - io::Write)); + let mut f = check!(File::open_mode(&tmpdir.join("h"), old_io::Append, + old_io::Write)); check!(f.write("bar".as_bytes())); } assert!(check!(stat(&tmpdir.join("h"))).size == 6, "append didn't append"); { - let mut f = check!(File::open_mode(&tmpdir.join("h"), io::Truncate, - io::Write)); + let mut f = check!(File::open_mode(&tmpdir.join("h"), old_io::Truncate, + old_io::Write)); check!(f.write("bar".as_bytes())); } assert!(check!(stat(&tmpdir.join("h"))).size == 3, @@ -1529,8 +1529,9 @@ mod test { let tmpdir = tmpdir(); let path = tmpdir.join("a"); check!(File::create(&path)); - // These numbers have to be bigger than the time in the day to account for timezones - // Windows in particular will fail in certain timezones with small enough values + // These numbers have to be bigger than the time in the day to account + // for timezones Windows in particular will fail in certain timezones + // with small enough values check!(change_file_times(&path, 100000, 200000)); assert_eq!(check!(path.stat()).accessed, 100000); assert_eq!(check!(path.stat()).modified, 200000); @@ -1565,7 +1566,7 @@ mod test { let tmpdir = tmpdir(); let path = tmpdir.join("file"); check!(File::create(&path)); - check!(chmod(&path, io::USER_READ)); + check!(chmod(&path, old_io::USER_READ)); check!(unlink(&path)); } } diff --git a/src/libstd/io/mem.rs b/src/libstd/old_io/mem.rs similarity index 94% rename from src/libstd/io/mem.rs rename to src/libstd/old_io/mem.rs index ec4191297cea..3fc2a330fdec 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/old_io/mem.rs @@ -15,8 +15,8 @@ use cmp::min; use option::Option::None; use result::Result::{Err, Ok}; -use io; -use io::{Reader, Writer, Seek, Buffer, IoError, SeekStyle, IoResult}; +use old_io; +use old_io::{Reader, Writer, Seek, Buffer, IoError, SeekStyle, IoResult}; use slice::{self, AsSlice, SliceExt}; use vec::Vec; @@ -25,14 +25,14 @@ const BUF_CAPACITY: uint = 128; fn combine(seek: SeekStyle, cur: uint, end: uint, offset: i64) -> IoResult { // compute offset as signed and clamp to prevent overflow let pos = match seek { - io::SeekSet => 0, - io::SeekEnd => end, - io::SeekCur => cur, + old_io::SeekSet => 0, + old_io::SeekEnd => end, + old_io::SeekCur => cur, } as i64; if offset + pos < 0 { Err(IoError { - kind: io::InvalidInput, + kind: old_io::InvalidInput, desc: "invalid seek to a negative offset", detail: None }) @@ -55,7 +55,7 @@ impl Writer for Vec { /// /// ```rust /// # #![allow(unused_must_use)] -/// use std::io::MemWriter; +/// use std::old_io::MemWriter; /// /// let mut w = MemWriter::new(); /// w.write(&[0, 1, 2]); @@ -111,7 +111,7 @@ impl Writer for MemWriter { /// /// ```rust /// # #![allow(unused_must_use)] -/// use std::io::MemReader; +/// use std::old_io::MemReader; /// /// let mut r = MemReader::new(vec!(0, 1, 2)); /// @@ -155,7 +155,7 @@ impl MemReader { impl Reader for MemReader { #[inline] fn read(&mut self, buf: &mut [u8]) -> IoResult { - if self.eof() { return Err(io::standard_error(io::EndOfFile)) } + if self.eof() { return Err(old_io::standard_error(old_io::EndOfFile)) } let write_len = min(buf.len(), self.buf.len() - self.pos); { @@ -189,7 +189,7 @@ impl Buffer for MemReader { if self.pos < self.buf.len() { Ok(&self.buf[self.pos..]) } else { - Err(io::standard_error(io::EndOfFile)) + Err(old_io::standard_error(old_io::EndOfFile)) } } @@ -200,7 +200,7 @@ impl Buffer for MemReader { impl<'a> Reader for &'a [u8] { #[inline] fn read(&mut self, buf: &mut [u8]) -> IoResult { - if self.is_empty() { return Err(io::standard_error(io::EndOfFile)); } + if self.is_empty() { return Err(old_io::standard_error(old_io::EndOfFile)); } let write_len = min(buf.len(), self.len()); { @@ -219,7 +219,7 @@ impl<'a> Buffer for &'a [u8] { #[inline] fn fill_buf(&mut self) -> IoResult<&[u8]> { if self.is_empty() { - Err(io::standard_error(io::EndOfFile)) + Err(old_io::standard_error(old_io::EndOfFile)) } else { Ok(*self) } @@ -241,7 +241,7 @@ impl<'a> Buffer for &'a [u8] { /// /// ```rust /// # #![allow(unused_must_use)] -/// use std::io::BufWriter; +/// use std::old_io::BufWriter; /// /// let mut buf = [0; 4]; /// { @@ -274,7 +274,7 @@ impl<'a> Writer for BufWriter<'a> { let dst_len = dst.len(); if dst_len == 0 { - return Err(io::standard_error(io::EndOfFile)); + return Err(old_io::standard_error(old_io::EndOfFile)); } let src_len = src.len(); @@ -290,7 +290,7 @@ impl<'a> Writer for BufWriter<'a> { self.pos += dst_len; - Err(io::standard_error(io::ShortWrite(dst_len))) + Err(old_io::standard_error(old_io::ShortWrite(dst_len))) } } } @@ -313,7 +313,7 @@ impl<'a> Seek for BufWriter<'a> { /// /// ```rust /// # #![allow(unused_must_use)] -/// use std::io::BufReader; +/// use std::old_io::BufReader; /// /// let buf = [0, 1, 2, 3]; /// let mut r = BufReader::new(&buf); @@ -345,7 +345,7 @@ impl<'a> BufReader<'a> { impl<'a> Reader for BufReader<'a> { #[inline] fn read(&mut self, buf: &mut [u8]) -> IoResult { - if self.eof() { return Err(io::standard_error(io::EndOfFile)) } + if self.eof() { return Err(old_io::standard_error(old_io::EndOfFile)) } let write_len = min(buf.len(), self.buf.len() - self.pos); { @@ -379,7 +379,7 @@ impl<'a> Buffer for BufReader<'a> { if self.pos < self.buf.len() { Ok(&self.buf[self.pos..]) } else { - Err(io::standard_error(io::EndOfFile)) + Err(old_io::standard_error(old_io::EndOfFile)) } } @@ -390,7 +390,7 @@ impl<'a> Buffer for BufReader<'a> { #[cfg(test)] mod test { extern crate "test" as test_crate; - use io::{SeekSet, SeekCur, SeekEnd, Reader, Writer, Seek}; + use old_io::{SeekSet, SeekCur, SeekEnd, Reader, Writer, Seek}; use prelude::v1::{Ok, Err, range, Vec, Buffer, AsSlice, SliceExt}; use prelude::v1::IteratorExt; use io; @@ -432,8 +432,8 @@ mod test { writer.write(&[]).unwrap(); assert_eq!(writer.tell(), Ok(8)); - assert_eq!(writer.write(&[8, 9]).err().unwrap().kind, io::ShortWrite(1)); - assert_eq!(writer.write(&[10]).err().unwrap().kind, io::EndOfFile); + assert_eq!(writer.write(&[8, 9]).err().unwrap().kind, old_io::ShortWrite(1)); + assert_eq!(writer.write(&[10]).err().unwrap().kind, old_io::EndOfFile); } let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8]; assert_eq!(buf, b); @@ -476,7 +476,7 @@ mod test { match writer.write(&[0, 0]) { Ok(..) => panic!(), - Err(e) => assert_eq!(e.kind, io::ShortWrite(1)), + Err(e) => assert_eq!(e.kind, old_io::ShortWrite(1)), } } diff --git a/src/libstd/io/mod.rs b/src/libstd/old_io/mod.rs similarity index 97% rename from src/libstd/io/mod.rs rename to src/libstd/old_io/mod.rs index f106e9464c52..7a8ed204ca53 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/old_io/mod.rs @@ -18,6 +18,24 @@ //! I/O, including files, networking, timers, and processes //! +//! > **Warning**: This module is currently called `old_io` for a reason! The +//! > module is currently being redesigned in a number of RFCs. For more details +//! > follow the RFC repository in connection with [RFC 517][base] or follow +//! > some of these sub-RFCs +//! > +//! > * [String handling][osstr] +//! > * [Core I/O support][core] +//! > * [Deadlines][deadlines] +//! > * [std::env][env] +//! > * [std::process][process] +//! +//! [base]: https://github.com/rust-lang/rfcs/blob/master/text/0517-io-os-reform.md +//! [osstr]: https://github.com/rust-lang/rfcs/pull/575 +//! [core]: https://github.com/rust-lang/rfcs/pull/576 +//! [deadlines]: https://github.com/rust-lang/rfcs/pull/577 +//! [env]: https://github.com/rust-lang/rfcs/pull/578 +//! [process]: https://github.com/rust-lang/rfcs/pull/579 +//! //! `std::io` provides Rust's basic I/O types, //! for reading and writing to files, TCP, UDP, //! and other types of sockets and pipes, @@ -30,7 +48,7 @@ //! * Read lines from stdin //! //! ```rust -//! use std::io; +//! use std::old_io as io; //! //! for line in io::stdin().lock().lines() { //! print!("{}", line.unwrap()); @@ -40,7 +58,7 @@ //! * Read a complete file //! //! ```rust -//! use std::io::File; +//! use std::old_io::File; //! //! let contents = File::open(&Path::new("message.txt")).read_to_end(); //! ``` @@ -49,19 +67,19 @@ //! //! ```rust //! # #![allow(unused_must_use)] -//! use std::io::File; +//! use std::old_io::File; //! //! let mut file = File::create(&Path::new("message.txt")); //! file.write(b"hello, file!\n"); //! # drop(file); -//! # ::std::io::fs::unlink(&Path::new("message.txt")); +//! # ::std::old_io::fs::unlink(&Path::new("message.txt")); //! ``` //! //! * Iterate over the lines of a file //! //! ```rust,no_run -//! use std::io::BufferedReader; -//! use std::io::File; +//! use std::old_io::BufferedReader; +//! use std::old_io::File; //! //! let path = Path::new("message.txt"); //! let mut file = BufferedReader::new(File::open(&path)); @@ -73,8 +91,8 @@ //! * Pull the lines of a file into a vector of strings //! //! ```rust,no_run -//! use std::io::BufferedReader; -//! use std::io::File; +//! use std::old_io::BufferedReader; +//! use std::old_io::File; //! //! let path = Path::new("message.txt"); //! let mut file = BufferedReader::new(File::open(&path)); @@ -85,7 +103,7 @@ //! //! ```rust //! # #![allow(unused_must_use)] -//! use std::io::TcpStream; +//! use std::old_io::TcpStream; //! //! # // connection doesn't fail if a server is running on 8080 //! # // locally, we still want to be type checking this code, so lets @@ -103,8 +121,8 @@ //! # fn main() { } //! # fn foo() { //! # #![allow(dead_code)] -//! use std::io::{TcpListener, TcpStream}; -//! use std::io::{Acceptor, Listener}; +//! use std::old_io::{TcpListener, TcpStream}; +//! use std::old_io::{Acceptor, Listener}; //! use std::thread::Thread; //! //! let listener = TcpListener::bind("127.0.0.1:80"); @@ -166,14 +184,14 @@ //! //! ```rust //! # #![allow(unused_must_use)] -//! use std::io::File; +//! use std::old_io::File; //! //! match File::create(&Path::new("diary.txt")).write(b"Met a girl.\n") { //! Ok(()) => (), // succeeded //! Err(e) => println!("failed to write to my diary: {}", e), //! } //! -//! # ::std::io::fs::unlink(&Path::new("diary.txt")); +//! # ::std::old_io::fs::unlink(&Path::new("diary.txt")); //! ``` //! //! So what actually happens if `create` encounters an error? @@ -199,7 +217,7 @@ //! If you wanted to read several `u32`s from a file and return their product: //! //! ```rust -//! use std::io::{File, IoResult}; +//! use std::old_io::{File, IoResult}; //! //! fn file_product(p: &Path) -> IoResult { //! let mut f = File::open(p); @@ -925,9 +943,9 @@ unsafe fn slice_vec_capacity<'a, T>(v: &'a mut Vec, start: uint, end: uint) - /// # Examples /// /// ``` -/// use std::io; -/// use std::io::ByRefReader; -/// use std::io::util::LimitReader; +/// use std::old_io as io; +/// use std::old_io::ByRefReader; +/// use std::old_io::util::LimitReader; /// /// fn process_input(r: R) {} /// @@ -1254,8 +1272,8 @@ impl<'a> Writer for &'a mut (Writer+'a) { /// # Example /// /// ``` -/// use std::io::util::TeeReader; -/// use std::io::{stdin, ByRefWriter}; +/// use std::old_io::util::TeeReader; +/// use std::old_io::{stdin, ByRefWriter}; /// /// fn process_input(r: R) {} /// @@ -1379,7 +1397,7 @@ pub trait Buffer: Reader { /// # Example /// /// ```rust - /// use std::io::BufReader; + /// use std::old_io::BufReader; /// /// let mut reader = BufReader::new(b"hello\nworld"); /// assert_eq!("hello\n", &*reader.read_line().unwrap()); @@ -1601,7 +1619,7 @@ impl<'a, T, A: ?Sized + Acceptor> Iterator for IncomingConnections<'a, A> { /// # Example /// /// ``` -/// use std::io; +/// use std::old_io as io; /// /// let eof = io::standard_error(io::EndOfFile); /// let einval = io::standard_error(io::InvalidInput); @@ -1691,7 +1709,7 @@ pub enum FileType { /// ```no_run /// # #![allow(unstable)] /// -/// use std::io::fs::PathExtensions; +/// use std::old_io::fs::PathExtensions; /// /// let info = match Path::new("foo.txt").stat() { /// Ok(stat) => stat, diff --git a/src/libstd/io/net/addrinfo.rs b/src/libstd/old_io/net/addrinfo.rs similarity index 97% rename from src/libstd/io/net/addrinfo.rs rename to src/libstd/old_io/net/addrinfo.rs index 7825a4e16e16..9800cc6829ea 100644 --- a/src/libstd/io/net/addrinfo.rs +++ b/src/libstd/old_io/net/addrinfo.rs @@ -20,8 +20,8 @@ pub use self::Flag::*; pub use self::Protocol::*; use iter::IteratorExt; -use io::{IoResult}; -use io::net::ip::{SocketAddr, IpAddr}; +use old_io::{IoResult}; +use old_io::net::ip::{SocketAddr, IpAddr}; use option::Option; use option::Option::{Some, None}; use string::String; @@ -114,7 +114,7 @@ fn lookup(hostname: Option<&str>, servname: Option<&str>, hint: Option) mod test { use prelude::v1::*; use super::*; - use io::net::ip::*; + use old_io::net::ip::*; #[test] fn dns_smoke_test() { diff --git a/src/libstd/io/net/ip.rs b/src/libstd/old_io/net/ip.rs similarity index 98% rename from src/libstd/io/net/ip.rs rename to src/libstd/old_io/net/ip.rs index e4622781ae7e..26eb068b1518 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/old_io/net/ip.rs @@ -19,8 +19,8 @@ pub use self::IpAddr::*; use boxed::Box; use fmt; -use io::{self, IoResult, IoError}; -use io::net; +use old_io::{self, IoResult, IoError}; +use old_io::net; use iter::{Iterator, IteratorExt}; use ops::{FnOnce, FnMut}; use option::Option; @@ -406,9 +406,9 @@ impl FromStr for SocketAddr { /// ```rust,no_run /// # #![allow(unused_must_use)] /// -/// use std::io::{TcpStream, TcpListener}; -/// use std::io::net::udp::UdpSocket; -/// use std::io::net::ip::{Ipv4Addr, SocketAddr}; +/// use std::old_io::{TcpStream, TcpListener}; +/// use std::old_io::net::udp::UdpSocket; +/// use std::old_io::net::ip::{Ipv4Addr, SocketAddr}; /// /// fn main() { /// // The following lines are equivalent modulo possible "localhost" name resolution @@ -438,7 +438,7 @@ pub trait ToSocketAddr { fn to_socket_addr(&self) -> IoResult { self.to_socket_addr_all() .and_then(|v| v.into_iter().next().ok_or_else(|| IoError { - kind: io::InvalidInput, + kind: old_io::InvalidInput, desc: "no address available", detail: None })) @@ -481,7 +481,7 @@ fn parse_and_resolve_socket_addr(s: &str) -> IoResult> { match $e { Some(r) => r, None => return Err(IoError { - kind: io::InvalidInput, + kind: old_io::InvalidInput, desc: $msg, detail: None }) @@ -526,7 +526,7 @@ impl<'a> ToSocketAddr for &'a str { parse_and_resolve_socket_addr(*self) .and_then(|v| v.into_iter().next() .ok_or_else(|| IoError { - kind: io::InvalidInput, + kind: old_io::InvalidInput, desc: "no address available", detail: None }) diff --git a/src/libstd/io/net/mod.rs b/src/libstd/old_io/net/mod.rs similarity index 96% rename from src/libstd/io/net/mod.rs rename to src/libstd/old_io/net/mod.rs index 2056933e6df6..d8394aa8b6a4 100644 --- a/src/libstd/io/net/mod.rs +++ b/src/libstd/old_io/net/mod.rs @@ -10,7 +10,7 @@ //! Networking I/O -use io::{IoError, IoResult, InvalidInput}; +use old_io::{IoError, IoResult, InvalidInput}; use ops::FnMut; use option::Option::None; use result::Result::{Ok, Err}; diff --git a/src/libstd/io/net/pipe.rs b/src/libstd/old_io/net/pipe.rs similarity index 98% rename from src/libstd/io/net/pipe.rs rename to src/libstd/old_io/net/pipe.rs index 61d164d21e32..2ed6d8118d57 100644 --- a/src/libstd/io/net/pipe.rs +++ b/src/libstd/old_io/net/pipe.rs @@ -24,7 +24,7 @@ use prelude::v1::*; use ffi::CString; use path::BytesContainer; -use io::{Listener, Acceptor, IoResult, TimedOut, standard_error}; +use old_io::{Listener, Acceptor, IoResult, TimedOut, standard_error}; use sys::pipe::UnixAcceptor as UnixAcceptorImp; use sys::pipe::UnixListener as UnixListenerImp; use sys::pipe::UnixStream as UnixStreamImp; @@ -48,7 +48,7 @@ impl UnixStream { /// /// ```rust /// # #![allow(unused_must_use)] - /// use std::io::net::pipe::UnixStream; + /// use std::old_io::net::pipe::UnixStream; /// /// let server = Path::new("path/to/my/socket"); /// let mut stream = UnixStream::connect(&server); @@ -169,8 +169,8 @@ impl UnixListener { /// /// ``` /// # fn foo() { - /// use std::io::net::pipe::UnixListener; - /// use std::io::{Listener, Acceptor}; + /// use std::old_io::net::pipe::UnixListener; + /// use std::old_io::{Listener, Acceptor}; /// /// let server = Path::new("/path/to/my/socket"); /// let stream = UnixListener::bind(&server); @@ -270,11 +270,11 @@ impl sys_common::AsInner for UnixAcceptor { mod tests { use prelude::v1::*; - use io::fs::PathExtensions; - use io::{EndOfFile, TimedOut, ShortWrite, IoError, ConnectionReset}; - use io::{NotConnected, BrokenPipe, FileNotFound, InvalidInput, OtherIoError}; - use io::{PermissionDenied, Acceptor, Listener}; - use io::test::*; + use old_io::fs::PathExtensions; + use old_io::{EndOfFile, TimedOut, ShortWrite, IoError, ConnectionReset}; + use old_io::{NotConnected, BrokenPipe, FileNotFound, InvalidInput, OtherIoError}; + use old_io::{PermissionDenied, Acceptor, Listener}; + use old_io::test::*; use super::*; use sync::mpsc::channel; use thread::Thread; diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/old_io/net/tcp.rs similarity index 98% rename from src/libstd/io/net/tcp.rs rename to src/libstd/old_io/net/tcp.rs index 4978085fa4fb..62f3c02e98ff 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/old_io/net/tcp.rs @@ -18,11 +18,11 @@ //! listener (socket server) implements the `Listener` and `Acceptor` traits. use clone::Clone; -use io::IoResult; +use old_io::IoResult; use result::Result::Err; -use io::net::ip::{SocketAddr, ToSocketAddr}; -use io::{Reader, Writer, Listener, Acceptor}; -use io::{standard_error, TimedOut}; +use old_io::net::ip::{SocketAddr, ToSocketAddr}; +use old_io::{Reader, Writer, Listener, Acceptor}; +use old_io::{standard_error, TimedOut}; use option::Option; use option::Option::{None, Some}; use time::Duration; @@ -41,7 +41,7 @@ use sys_common; /// # Example /// /// ```no_run -/// use std::io::TcpStream; +/// use std::old_io::TcpStream; /// /// { /// let mut stream = TcpStream::connect("127.0.0.1:34254"); @@ -133,8 +133,8 @@ impl TcpStream { /// /// ```no_run /// # #![allow(unused_must_use)] - /// use std::io::timer; - /// use std::io::TcpStream; + /// use std::old_io::timer; + /// use std::old_io::TcpStream; /// use std::time::Duration; /// use std::thread::Thread; /// @@ -276,8 +276,8 @@ impl sys_common::AsInner for TcpStream { /// /// ``` /// # fn foo() { -/// use std::io::{TcpListener, TcpStream}; -/// use std::io::{Acceptor, Listener}; +/// use std::old_io::{TcpListener, TcpStream}; +/// use std::old_io::{Acceptor, Listener}; /// use std::thread::Thread; /// /// let listener = TcpListener::bind("127.0.0.1:80").unwrap(); @@ -373,8 +373,8 @@ impl TcpAcceptor { /// /// ```no_run /// # #![allow(unstable)] - /// use std::io::TcpListener; - /// use std::io::{Listener, Acceptor, TimedOut}; + /// use std::old_io::TcpListener; + /// use std::old_io::{Listener, Acceptor, TimedOut}; /// /// let mut a = TcpListener::bind("127.0.0.1:8482").listen().unwrap(); /// @@ -417,7 +417,7 @@ impl TcpAcceptor { /// /// ``` /// # #![allow(unstable)] - /// use std::io::{TcpListener, Listener, Acceptor, EndOfFile}; + /// use std::old_io::{TcpListener, Listener, Acceptor, EndOfFile}; /// use std::thread::Thread; /// /// let mut a = TcpListener::bind("127.0.0.1:8482").listen().unwrap(); @@ -486,13 +486,13 @@ mod test { use sync::mpsc::channel; use thread::Thread; - use io::net::tcp::*; - use io::net::ip::*; - use io::test::*; - use io::{EndOfFile, TimedOut, ShortWrite, IoError}; - use io::{ConnectionRefused, BrokenPipe, ConnectionAborted}; - use io::{ConnectionReset, NotConnected, PermissionDenied, OtherIoError}; - use io::{Acceptor, Listener}; + use old_io::net::tcp::*; + use old_io::net::ip::*; + use old_io::test::*; + use old_io::{EndOfFile, TimedOut, ShortWrite, IoError}; + use old_io::{ConnectionRefused, BrokenPipe, ConnectionAborted}; + use old_io::{ConnectionReset, NotConnected, PermissionDenied, OtherIoError}; + use old_io::{Acceptor, Listener}; // FIXME #11530 this fails on android because tests are run as root #[cfg_attr(any(windows, target_os = "android"), ignore)] diff --git a/src/libstd/io/net/udp.rs b/src/libstd/old_io/net/udp.rs similarity index 97% rename from src/libstd/io/net/udp.rs rename to src/libstd/old_io/net/udp.rs index 8cdad3f528a4..d7fc760951e8 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/old_io/net/udp.rs @@ -16,8 +16,8 @@ //! datagram protocol. use clone::Clone; -use io::net::ip::{SocketAddr, IpAddr, ToSocketAddr}; -use io::IoResult; +use old_io::net::ip::{SocketAddr, IpAddr, ToSocketAddr}; +use old_io::IoResult; use option::Option; use sys::udp::UdpSocket as UdpSocketImp; use sys_common; @@ -34,8 +34,8 @@ use sys_common; /// # #![allow(unused_must_use)] /// #![feature(slicing_syntax)] /// -/// use std::io::net::udp::UdpSocket; -/// use std::io::net::ip::{Ipv4Addr, SocketAddr}; +/// use std::old_io::net::udp::UdpSocket; +/// use std::old_io::net::ip::{Ipv4Addr, SocketAddr}; /// fn main() { /// let addr = SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 34254 }; /// let mut socket = match UdpSocket::bind(addr) { @@ -181,9 +181,9 @@ mod test { use prelude::v1::*; use sync::mpsc::channel; - use io::net::ip::*; - use io::test::*; - use io::{IoError, TimedOut, PermissionDenied, ShortWrite}; + use old_io::net::ip::*; + use old_io::test::*; + use old_io::{IoError, TimedOut, PermissionDenied, ShortWrite}; use super::*; use thread::Thread; diff --git a/src/libstd/io/pipe.rs b/src/libstd/old_io/pipe.rs similarity index 97% rename from src/libstd/io/pipe.rs rename to src/libstd/old_io/pipe.rs index 09dcafb02187..224f3bfd98c0 100644 --- a/src/libstd/io/pipe.rs +++ b/src/libstd/old_io/pipe.rs @@ -17,7 +17,7 @@ use prelude::v1::*; -use io::IoResult; +use old_io::IoResult; use libc; use sync::Arc; @@ -49,7 +49,7 @@ impl PipeStream { /// # #![allow(unused_must_use)] /// extern crate libc; /// - /// use std::io::pipe::PipeStream; + /// use std::old_io::pipe::PipeStream; /// /// fn main() { /// let mut pipe = PipeStream::open(libc::STDERR_FILENO); @@ -120,7 +120,7 @@ mod test { #[test] fn partial_read() { use os; - use io::pipe::PipeStream; + use old_io::pipe::PipeStream; let os::Pipe { reader, writer } = unsafe { os::pipe().unwrap() }; let out = PipeStream::open(writer); diff --git a/src/libstd/io/process.rs b/src/libstd/old_io/process.rs similarity index 98% rename from src/libstd/io/process.rs rename to src/libstd/old_io/process.rs index c2f52f5c8a3b..d7c263b3d1fc 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/old_io/process.rs @@ -21,9 +21,9 @@ use prelude::v1::*; use collections::HashMap; use ffi::CString; use fmt; -use io::pipe::{PipeStream, PipePair}; -use io::{IoResult, IoError}; -use io; +use old_io::pipe::{PipeStream, PipePair}; +use old_io::{IoResult, IoError}; +use old_io; use libc; use os; use path::BytesContainer; @@ -58,7 +58,7 @@ use thread::Thread; /// # Example /// /// ```should_fail -/// use std::io::Command; +/// use std::old_io::Command; /// /// let mut child = match Command::new("/bin/cat").arg("file.txt").spawn() { /// Ok(child) => child, @@ -159,7 +159,7 @@ pub type EnvMap = HashMap; /// to be changed (for example, by adding arguments) prior to spawning: /// /// ``` -/// use std::io::Command; +/// use std::old_io::Command; /// /// let mut process = match Command::new("sh").arg("-c").arg("echo hello").spawn() { /// Ok(p) => p, @@ -359,7 +359,7 @@ impl Command { /// # Example /// /// ``` - /// use std::io::Command; + /// use std::old_io::Command; /// /// let output = match Command::new("cat").arg("foot.txt").output() { /// Ok(output) => output, @@ -380,7 +380,7 @@ impl Command { /// # Example /// /// ``` - /// use std::io::Command; + /// use std::old_io::Command; /// /// let status = match Command::new("ls").status() { /// Ok(status) => status, @@ -583,7 +583,7 @@ impl Process { // newer process that happens to have the same (re-used) id if self.exit_code.is_some() { return Err(IoError { - kind: io::InvalidInput, + kind: old_io::InvalidInput, desc: "invalid argument: can't kill an exited process", detail: None, }) @@ -654,8 +654,8 @@ impl Process { /// /// ```no_run /// # #![allow(unstable)] - /// use std::io::{Command, IoResult}; - /// use std::io::process::ProcessExit; + /// use std::old_io::{Command, IoResult}; + /// use std::old_io::process::ProcessExit; /// /// fn run_gracefully(prog: &str) -> IoResult { /// let mut p = try!(Command::new("long-running-process").spawn()); @@ -698,7 +698,7 @@ impl Process { /// fail. pub fn wait_with_output(mut self) -> IoResult { drop(self.stdin.take()); - fn read(stream: Option) -> Receiver>> { + fn read(stream: Option) -> Receiver>> { let (tx, rx) = channel(); match stream { Some(stream) => { @@ -752,12 +752,12 @@ impl Drop for Process { #[cfg(test)] mod tests { - use io::{Truncate, Write, TimedOut, timer, process, FileNotFound}; + use old_io::{Truncate, Write, TimedOut, timer, process, FileNotFound}; use prelude::v1::{Ok, Err, range, drop, Some, None, Vec}; use prelude::v1::{Path, String, Reader, Writer, Clone}; use prelude::v1::{SliceExt, Str, StrExt, AsSlice, ToString, GenericPath}; - use io::fs::PathExtensions; - use io::timer::*; + use old_io::fs::PathExtensions; + use old_io::timer::*; use rt::running_on_valgrind; use str; use super::{CreatePipe}; diff --git a/src/libstd/io/result.rs b/src/libstd/old_io/result.rs similarity index 100% rename from src/libstd/io/result.rs rename to src/libstd/old_io/result.rs diff --git a/src/libstd/io/stdio.rs b/src/libstd/old_io/stdio.rs similarity index 98% rename from src/libstd/io/stdio.rs rename to src/libstd/old_io/stdio.rs index a5664b9f0137..04eedc758cd4 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/old_io/stdio.rs @@ -21,7 +21,7 @@ //! # #![allow(unused_must_use)] //! use std::io; //! -//! let mut out = io::stdout(); +//! let mut out = old_io::stdout(); //! out.write(b"Hello, world!"); //! ``` @@ -32,7 +32,7 @@ use cell::RefCell; use clone::Clone; use failure::LOCAL_STDERR; use fmt; -use io::{Reader, Writer, IoResult, IoError, OtherIoError, Buffer, +use old_io::{Reader, Writer, IoResult, IoError, OtherIoError, Buffer, standard_error, EndOfFile, LineBufferedWriter, BufferedReader}; use marker::{Sync, Send}; use libc; @@ -143,7 +143,7 @@ impl StdinReader { /// ```rust /// use std::io; /// - /// for line in io::stdin().lock().lines() { + /// for line in old_io::stdin().lock().lines() { /// println!("{}", line.unwrap()); /// } /// ``` @@ -539,7 +539,7 @@ mod tests { #[test] fn capture_stdout() { - use io::{ChanReader, ChanWriter}; + use old_io::{ChanReader, ChanWriter}; let (tx, rx) = channel(); let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx)); @@ -552,7 +552,7 @@ mod tests { #[test] fn capture_stderr() { - use io::{ChanReader, ChanWriter, Reader}; + use old_io::{ChanReader, ChanWriter, Reader}; let (tx, rx) = channel(); let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx)); diff --git a/src/libstd/io/tempfile.rs b/src/libstd/old_io/tempfile.rs similarity index 97% rename from src/libstd/io/tempfile.rs rename to src/libstd/old_io/tempfile.rs index 394686be814f..029fef7c1970 100644 --- a/src/libstd/io/tempfile.rs +++ b/src/libstd/old_io/tempfile.rs @@ -10,8 +10,8 @@ //! Temporary files and directories -use io::{fs, IoError, IoErrorKind, IoResult}; -use io; +use old_io::{fs, IoError, IoErrorKind, IoResult}; +use old_io; use iter::{IteratorExt, range}; use ops::Drop; use option::Option; @@ -29,7 +29,7 @@ use string::String; /// # Examples /// /// ```no_run -/// use std::io::TempDir; +/// use std::old_io::TempDir; /// /// { /// // create a temporary directory @@ -113,7 +113,7 @@ impl TempDir { suffix }; let path = tmpdir.join(leaf); - match fs::mkdir(&path, io::USER_RWX) { + match fs::mkdir(&path, old_io::USER_RWX) { Ok(_) => return Ok(TempDir { path: Some(path), disarmed: false }), Err(IoError{kind:IoErrorKind::PathAlreadyExists,..}) => (), Err(e) => return Err(e) diff --git a/src/libstd/io/test.rs b/src/libstd/old_io/test.rs similarity index 99% rename from src/libstd/io/test.rs rename to src/libstd/old_io/test.rs index 6de466eb20bf..f49e2397d428 100644 --- a/src/libstd/io/test.rs +++ b/src/libstd/old_io/test.rs @@ -14,7 +14,7 @@ use prelude::v1::*; use libc; use os; -use std::io::net::ip::*; +use std::old_io::net::ip::*; use sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; /// Get a port number, starting at 9600, for use in tests diff --git a/src/libstd/io/timer.rs b/src/libstd/old_io/timer.rs similarity index 98% rename from src/libstd/io/timer.rs rename to src/libstd/old_io/timer.rs index 68ae7d0ff208..7e15c9ad7fcd 100644 --- a/src/libstd/io/timer.rs +++ b/src/libstd/old_io/timer.rs @@ -17,7 +17,7 @@ use sync::mpsc::{Receiver, Sender, channel}; use time::Duration; -use io::IoResult; +use old_io::IoResult; use sys::timer::Callback; use sys::timer::Timer as TimerImp; @@ -31,7 +31,7 @@ use sys::timer::Timer as TimerImp; /// /// ``` /// # fn foo() { -/// use std::io::Timer; +/// use std::old_io::Timer; /// use std::time::Duration; /// /// let mut timer = Timer::new().unwrap(); @@ -50,11 +50,11 @@ use sys::timer::Timer as TimerImp; /// ``` /// /// If only sleeping is necessary, then a convenience API is provided through -/// the `io::timer` module. +/// the `old_io::timer` module. /// /// ``` /// # fn foo() { -/// use std::io::timer; +/// use std::old_io::timer; /// use std::time::Duration; /// /// // Put this task to sleep for 5 seconds @@ -115,7 +115,7 @@ impl Timer { /// # Example /// /// ```rust - /// use std::io::Timer; + /// use std::old_io::Timer; /// use std::time::Duration; /// /// let mut timer = Timer::new().unwrap(); @@ -128,7 +128,7 @@ impl Timer { /// ``` /// /// ```rust - /// use std::io::Timer; + /// use std::old_io::Timer; /// use std::time::Duration; /// /// // Incorrect, method chaining-style: @@ -167,7 +167,7 @@ impl Timer { /// # Example /// /// ```rust - /// use std::io::Timer; + /// use std::old_io::Timer; /// use std::time::Duration; /// /// let mut timer = Timer::new().unwrap(); @@ -186,7 +186,7 @@ impl Timer { /// ``` /// /// ```rust - /// use std::io::Timer; + /// use std::old_io::Timer; /// use std::time::Duration; /// /// // Incorrect, method chaining-style. diff --git a/src/libstd/io/util.rs b/src/libstd/old_io/util.rs similarity index 86% rename from src/libstd/io/util.rs rename to src/libstd/old_io/util.rs index e4bf38a9ef5d..f3f0b8dd6638 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/old_io/util.rs @@ -12,7 +12,7 @@ use prelude::v1::*; use cmp; -use io; +use old_io; use slice::bytes::MutableByteVector; /// Wraps a `Reader`, limiting the number of bytes that can be read from it. @@ -42,9 +42,9 @@ impl LimitReader { } impl Reader for LimitReader { - fn read(&mut self, buf: &mut [u8]) -> io::IoResult { + fn read(&mut self, buf: &mut [u8]) -> old_io::IoResult { if self.limit == 0 { - return Err(io::standard_error(io::EndOfFile)); + return Err(old_io::standard_error(old_io::EndOfFile)); } let len = cmp::min(self.limit, buf.len()); @@ -58,11 +58,11 @@ impl Reader for LimitReader { } impl Buffer for LimitReader { - fn fill_buf<'a>(&'a mut self) -> io::IoResult<&'a [u8]> { + fn fill_buf<'a>(&'a mut self) -> old_io::IoResult<&'a [u8]> { let amt = try!(self.inner.fill_buf()); let buf = &amt[..cmp::min(amt.len(), self.limit)]; if buf.len() == 0 { - Err(io::standard_error(io::EndOfFile)) + Err(old_io::standard_error(old_io::EndOfFile)) } else { Ok(buf) } @@ -83,7 +83,7 @@ pub struct NullWriter; impl Writer for NullWriter { #[inline] - fn write(&mut self, _buf: &[u8]) -> io::IoResult<()> { Ok(()) } + fn write(&mut self, _buf: &[u8]) -> old_io::IoResult<()> { Ok(()) } } /// A `Reader` which returns an infinite stream of 0 bytes, like /dev/zero. @@ -92,14 +92,14 @@ pub struct ZeroReader; impl Reader for ZeroReader { #[inline] - fn read(&mut self, buf: &mut [u8]) -> io::IoResult { + fn read(&mut self, buf: &mut [u8]) -> old_io::IoResult { buf.set_memory(0); Ok(buf.len()) } } impl Buffer for ZeroReader { - fn fill_buf<'a>(&'a mut self) -> io::IoResult<&'a [u8]> { + fn fill_buf<'a>(&'a mut self) -> old_io::IoResult<&'a [u8]> { static DATA: [u8; 64] = [0; 64]; Ok(DATA.as_slice()) } @@ -113,14 +113,14 @@ pub struct NullReader; impl Reader for NullReader { #[inline] - fn read(&mut self, _buf: &mut [u8]) -> io::IoResult { - Err(io::standard_error(io::EndOfFile)) + fn read(&mut self, _buf: &mut [u8]) -> old_io::IoResult { + Err(old_io::standard_error(old_io::EndOfFile)) } } impl Buffer for NullReader { - fn fill_buf<'a>(&'a mut self) -> io::IoResult<&'a [u8]> { - Err(io::standard_error(io::EndOfFile)) + fn fill_buf<'a>(&'a mut self) -> old_io::IoResult<&'a [u8]> { + Err(old_io::standard_error(old_io::EndOfFile)) } fn consume(&mut self, _amt: uint) {} } @@ -143,7 +143,7 @@ impl MultiWriter where W: Writer { impl Writer for MultiWriter where W: Writer { #[inline] - fn write(&mut self, buf: &[u8]) -> io::IoResult<()> { + fn write(&mut self, buf: &[u8]) -> old_io::IoResult<()> { for writer in self.writers.iter_mut() { try!(writer.write(buf)); } @@ -151,7 +151,7 @@ impl Writer for MultiWriter where W: Writer { } #[inline] - fn flush(&mut self) -> io::IoResult<()> { + fn flush(&mut self) -> old_io::IoResult<()> { for writer in self.writers.iter_mut() { try!(writer.flush()); } @@ -176,13 +176,13 @@ impl> ChainedReader { } impl> Reader for ChainedReader { - fn read(&mut self, buf: &mut [u8]) -> io::IoResult { + fn read(&mut self, buf: &mut [u8]) -> old_io::IoResult { loop { let err = match self.cur_reader { Some(ref mut r) => { match r.read(buf) { Ok(len) => return Ok(len), - Err(ref e) if e.kind == io::EndOfFile => None, + Err(ref e) if e.kind == old_io::EndOfFile => None, Err(e) => Some(e), } } @@ -194,7 +194,7 @@ impl> Reader for ChainedReader { None => {} } } - Err(io::standard_error(io::EndOfFile)) + Err(old_io::standard_error(old_io::EndOfFile)) } } @@ -221,7 +221,7 @@ impl TeeReader { } impl Reader for TeeReader { - fn read(&mut self, buf: &mut [u8]) -> io::IoResult { + fn read(&mut self, buf: &mut [u8]) -> old_io::IoResult { self.reader.read(buf).and_then(|len| { self.writer.write(&mut buf[..len]).map(|()| len) }) @@ -229,12 +229,12 @@ impl Reader for TeeReader { } /// Copies all data from a `Reader` to a `Writer`. -pub fn copy(r: &mut R, w: &mut W) -> io::IoResult<()> { +pub fn copy(r: &mut R, w: &mut W) -> old_io::IoResult<()> { let mut buf = [0; super::DEFAULT_BUF_SIZE]; loop { let len = match r.read(&mut buf) { Ok(len) => len, - Err(ref e) if e.kind == io::EndOfFile => return Ok(()), + Err(ref e) if e.kind == old_io::EndOfFile => return Ok(()), Err(e) => return Err(e), }; try!(w.write(&buf[..len])); @@ -257,14 +257,14 @@ impl> IterReader { impl> Reader for IterReader { #[inline] - fn read(&mut self, buf: &mut [u8]) -> io::IoResult { + fn read(&mut self, buf: &mut [u8]) -> old_io::IoResult { let mut len = 0; for (slot, elt) in buf.iter_mut().zip(self.iter.by_ref()) { *slot = elt; len += 1; } if len == 0 && buf.len() != 0 { - Err(io::standard_error(io::EndOfFile)) + Err(old_io::standard_error(old_io::EndOfFile)) } else { Ok(len) } @@ -275,7 +275,7 @@ impl> Reader for IterReader { mod test { use prelude::v1::*; - use io::{MemReader, ByRefReader}; + use old_io::{MemReader, ByRefReader}; use io; use super::*; @@ -347,12 +347,12 @@ mod test { struct TestWriter; impl Writer for TestWriter { - fn write(&mut self, _buf: &[u8]) -> io::IoResult<()> { + fn write(&mut self, _buf: &[u8]) -> old_io::IoResult<()> { unsafe { writes += 1 } Ok(()) } - fn flush(&mut self) -> io::IoResult<()> { + fn flush(&mut self) -> old_io::IoResult<()> { unsafe { flushes += 1 } Ok(()) } @@ -400,7 +400,7 @@ mod test { let mut r = LimitReader::new(r.by_ref(), 3); assert_eq!(r.read_line(), Ok("012".to_string())); assert_eq!(r.limit(), 0); - assert_eq!(r.read_line().err().unwrap().kind, io::EndOfFile); + assert_eq!(r.read_line().err().unwrap().kind, old_io::EndOfFile); } { let mut r = LimitReader::new(r.by_ref(), 9); @@ -432,7 +432,7 @@ mod test { assert_eq!(len, 2); assert!(buf == [6, 7, 5]); - assert_eq!(r.read(&mut buf).unwrap_err().kind, io::EndOfFile); + assert_eq!(r.read(&mut buf).unwrap_err().kind, old_io::EndOfFile); } #[test] From 3a07f859b880bfe4dd6f095c959422d7c6b53831 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 22 Jan 2015 16:31:00 -0800 Subject: [PATCH 08/15] Fallout of io => old_io --- src/compiletest/compiletest.rs | 6 +-- src/compiletest/errors.rs | 2 +- src/compiletest/header.rs | 2 +- src/compiletest/procsrv.rs | 2 +- src/compiletest/runtest.rs | 22 ++++---- src/doc/trpl/guessing-game.md | 54 +++++++++---------- src/doc/trpl/standard-input.md | 22 ++++---- src/libcore/error.rs | 2 +- src/libcore/result.rs | 16 +++--- src/libgraphviz/lib.rs | 18 +++---- src/liblog/lib.rs | 8 +-- src/librbml/io.rs | 26 ++++----- src/librbml/lib.rs | 26 ++++----- src/librustc/metadata/decoder.rs | 10 ++-- src/librustc/metadata/filesearch.rs | 4 +- src/librustc/metadata/loader.rs | 6 +-- src/librustc/middle/astencode.rs | 2 +- src/librustc/middle/dataflow.rs | 10 ++-- .../middle/infer/region_inference/graphviz.rs | 4 +- src/librustc/middle/liveness.rs | 8 +-- src/librustc_back/archive.rs | 19 +++---- src/librustc_back/fs.rs | 22 ++++---- src/librustc_back/rpath.rs | 2 +- src/librustc_back/target/apple_ios_base.rs | 2 +- src/librustc_back/target/mod.rs | 4 +- src/librustc_driver/driver.rs | 8 +-- src/librustc_driver/lib.rs | 16 +++--- src/librustc_driver/pretty.rs | 24 ++++----- src/librustc_trans/back/link.rs | 12 ++--- src/librustc_trans/back/write.rs | 10 ++-- src/librustc_trans/save/mod.rs | 4 +- src/librustdoc/externalfiles.rs | 10 ++-- src/librustdoc/html/highlight.rs | 4 +- src/librustdoc/html/layout.rs | 8 +-- src/librustdoc/html/render.rs | 32 +++++------ src/librustdoc/lib.rs | 6 +-- src/librustdoc/markdown.rs | 10 ++-- src/librustdoc/test.rs | 16 +++--- src/libserialize/json.rs | 18 +++---- src/libstd/failure.rs | 4 +- src/libstd/fmt.rs | 14 +++-- src/libstd/macros.rs | 8 +-- src/libstd/old_io/buffered.rs | 2 +- src/libstd/old_io/comm_adapters.rs | 2 +- src/libstd/old_io/extensions.rs | 2 +- src/libstd/old_io/fs.rs | 8 +-- src/libstd/old_io/mem.rs | 2 +- src/libstd/old_io/result.rs | 20 +++---- src/libstd/old_io/stdio.rs | 4 +- src/libstd/old_io/util.rs | 2 +- src/libstd/os.rs | 32 +++++------ src/libstd/path/mod.rs | 2 +- src/libstd/path/posix.rs | 2 +- src/libstd/path/windows.rs | 2 +- src/libstd/prelude/v1.rs | 2 +- src/libstd/rand/mod.rs | 2 +- src/libstd/rand/os.rs | 6 +-- src/libstd/rand/reader.rs | 6 +-- src/libstd/sync/mpsc/mod.rs | 4 +- src/libstd/sys/common/backtrace.rs | 2 +- src/libstd/sys/common/mod.rs | 10 ++-- src/libstd/sys/common/net.rs | 12 ++--- src/libstd/sys/unix/backtrace.rs | 4 +- src/libstd/sys/unix/ext.rs | 22 ++++---- src/libstd/sys/unix/fs.rs | 20 +++---- src/libstd/sys/unix/mod.rs | 40 +++++++------- src/libstd/sys/unix/os.rs | 8 +-- src/libstd/sys/unix/pipe.rs | 4 +- src/libstd/sys/unix/process.rs | 4 +- src/libstd/sys/unix/tcp.rs | 4 +- src/libstd/sys/unix/timer.rs | 2 +- src/libstd/sys/unix/tty.rs | 4 +- src/libstd/thread.rs | 4 +- src/libsyntax/ast_map/mod.rs | 2 +- src/libsyntax/diagnostic.rs | 18 +++---- src/libsyntax/ext/source_util.rs | 2 +- src/libsyntax/fold.rs | 4 +- src/libsyntax/parse/lexer/comments.rs | 4 +- src/libsyntax/parse/lexer/mod.rs | 2 +- src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/parse/parser.rs | 2 +- src/libsyntax/print/pp.rs | 44 +++++++-------- src/libsyntax/print/pprust.rs | 20 +++---- src/libterm/lib.rs | 14 ++--- src/libterm/terminfo/mod.rs | 2 +- src/libterm/terminfo/parser/compiled.rs | 6 +-- src/libterm/terminfo/searcher.rs | 4 +- src/libtest/lib.rs | 49 ++++++++--------- src/libtest/stats.rs | 4 +- src/rustbook/book.rs | 2 +- src/rustbook/build.rs | 8 +-- src/rustbook/error.rs | 2 +- src/rustbook/term.rs | 2 +- src/rustbook/test.rs | 2 +- src/test/bench/core-std.rs | 4 +- src/test/bench/shootout-fasta-redux.rs | 2 +- src/test/bench/shootout-fasta.rs | 10 ++-- src/test/bench/shootout-k-nucleotide-pipes.rs | 2 +- src/test/bench/shootout-k-nucleotide.rs | 6 +-- src/test/bench/shootout-mandelbrot.rs | 8 +-- src/test/bench/shootout-reverse-complement.rs | 4 +- src/test/bench/sudoku.rs | 12 ++--- .../cannot-mutate-captured-non-mut-var.rs | 2 +- src/test/compile-fail/issue-11374.rs | 4 +- .../compile-fail/lint-uppercase-variables.rs | 6 +-- .../debuginfo/function-arg-initialization.rs | 10 ++-- ...nction-prologue-stepping-no-stack-check.rs | 10 ++-- src/test/debuginfo/issue13213.rs | 2 +- .../create_and_compile.rs | 2 +- .../run-make/unicode-input/multiple_files.rs | 2 +- .../run-make/unicode-input/span_length.rs | 2 +- src/test/run-pass-valgrind/cleanup-stdin.rs | 2 +- src/test/run-pass/backtrace.rs | 2 +- src/test/run-pass/capturing-logging.rs | 2 +- src/test/run-pass/closure-reform.rs | 2 +- src/test/run-pass/colorful-write-macros.rs | 2 +- src/test/run-pass/core-run-destroy.rs | 6 +-- src/test/run-pass/issue-10626.rs | 2 +- src/test/run-pass/issue-11881.rs | 4 +- src/test/run-pass/issue-12684.rs | 2 +- src/test/run-pass/issue-12699.rs | 2 +- src/test/run-pass/issue-13304.rs | 6 +-- src/test/run-pass/issue-14456.rs | 12 ++--- src/test/run-pass/issue-14901.rs | 2 +- src/test/run-pass/issue-14940.rs | 2 +- src/test/run-pass/issue-15149.rs | 2 +- src/test/run-pass/issue-16272.rs | 2 +- src/test/run-pass/issue-16671.rs | 2 +- src/test/run-pass/issue-17121.rs | 8 +-- src/test/run-pass/issue-17322.rs | 4 +- src/test/run-pass/issue-18619.rs | 2 +- src/test/run-pass/issue-20091.rs | 2 +- src/test/run-pass/issue-20644.rs | 2 +- src/test/run-pass/issue-20797.rs | 6 +-- src/test/run-pass/issue-2904.rs | 6 +-- src/test/run-pass/issue-4333.rs | 4 +- src/test/run-pass/issue-4446.rs | 2 +- src/test/run-pass/issue-5988.rs | 4 +- src/test/run-pass/issue-8398.rs | 4 +- src/test/run-pass/issue-9396.rs | 2 +- src/test/run-pass/logging-separate-lines.rs | 2 +- ...thod-mut-self-modifies-mut-slice-lvalue.rs | 2 +- .../out-of-stack-new-thread-no-split.rs | 2 +- src/test/run-pass/out-of-stack.rs | 2 +- src/test/run-pass/process-remove-from-env.rs | 2 +- .../process-spawn-with-unicode-params.rs | 12 ++--- src/test/run-pass/rename-directory.rs | 12 ++--- src/test/run-pass/running-with-no-runtime.rs | 2 +- src/test/run-pass/segfault-no-out-of-stack.rs | 2 +- src/test/run-pass/signal-exit-status.rs | 2 +- .../run-pass/sigpipe-should-be-ignored.rs | 4 +- src/test/run-pass/stat.rs | 4 +- src/test/run-pass/task-stderr.rs | 2 +- src/test/run-pass/tcp-accept-stress.rs | 2 +- src/test/run-pass/tcp-connect-timeouts.rs | 8 +-- src/test/run-pass/tempfile.rs | 20 +++---- src/test/run-pass/trait-coercion.rs | 4 +- .../run-pass/wait-forked-but-failed-child.rs | 2 +- 158 files changed, 607 insertions(+), 605 deletions(-) diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 4659af4416bd..b95e956aca28 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -24,8 +24,8 @@ extern crate getopts; extern crate log; use std::os; -use std::io; -use std::io::fs; +use std::old_io; +use std::old_io::fs; use std::str::FromStr; use std::thunk::Thunk; use getopts::{optopt, optflag, reqopt}; @@ -237,7 +237,7 @@ pub fn run_tests(config: &Config) { // sadly osx needs some file descriptor limits raised for running tests in // parallel (especially when we have lots and lots of child processes). // For context, see #8904 - io::test::raise_fd_limit(); + old_io::test::raise_fd_limit(); // Prevent issue #21352 UAC blocking .exe containing 'patch' etc. on Windows // If #11207 is resolved (adding manifest to .exe) this becomes unnecessary os::setenv("__COMPAT_LAYER", "RunAsInvoker"); diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs index fc815d66a4d4..868512c7943f 100644 --- a/src/compiletest/errors.rs +++ b/src/compiletest/errors.rs @@ -9,7 +9,7 @@ // except according to those terms. use self::WhichLine::*; -use std::io::{BufferedReader, File}; +use std::old_io::{BufferedReader, File}; pub struct ExpectedError { pub line: uint, diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index d7af767688e8..8458d880d05a 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -223,7 +223,7 @@ pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool { fn iter_header(testfile: &Path, mut it: F) -> bool where F: FnMut(&str) -> bool, { - use std::io::{BufferedReader, File}; + use std::old_io::{BufferedReader, File}; let mut rdr = BufferedReader::new(File::open(testfile).unwrap()); for ln in rdr.lines() { diff --git a/src/compiletest/procsrv.rs b/src/compiletest/procsrv.rs index f3f860d470d9..60b040cd4aca 100644 --- a/src/compiletest/procsrv.rs +++ b/src/compiletest/procsrv.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::io::process::{ProcessExit, Command, Process, ProcessOutput}; +use std::old_io::process::{ProcessExit, Command, Process, ProcessOutput}; use std::dynamic_lib::DynamicLibrary; fn add_target_env(cmd: &mut Command, lib_path: &str, aux_path: Option<&str>) { diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index e5a973e7501a..b093a53eee99 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -23,14 +23,14 @@ use util; #[cfg(target_os = "windows")] use std::ascii::AsciiExt; -use std::io::File; -use std::io::fs::PathExtensions; -use std::io::fs; -use std::io::net::tcp; -use std::io::process::ProcessExit; -use std::io::process; -use std::io::timer; -use std::io; +use std::old_io::File; +use std::old_io::fs::PathExtensions; +use std::old_io::fs; +use std::old_io::net::tcp; +use std::old_io::process::ProcessExit; +use std::old_io::process; +use std::old_io::timer; +use std::old_io; use std::os; use std::iter::repeat; use std::str; @@ -619,7 +619,7 @@ fn find_rust_src_root(config: &Config) -> Option { } fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testfile: &Path) { - use std::io::process::{Command, ProcessOutput}; + use std::old_io::process::{Command, ProcessOutput}; if config.lldb_python_dir.is_none() { fatal("Can't run LLDB test because LLDB's python path is not set."); @@ -764,7 +764,7 @@ struct DebuggerCommands { fn parse_debugger_commands(file_path: &Path, debugger_prefix: &str) -> DebuggerCommands { - use std::io::{BufferedReader, File}; + use std::old_io::{BufferedReader, File}; let command_directive = format!("{}-command", debugger_prefix); let check_directive = format!("{}-check", debugger_prefix); @@ -1224,7 +1224,7 @@ fn compose_and_run_compiler( fn ensure_dir(path: &Path) { if path.is_dir() { return; } - fs::mkdir(path, io::USER_RWX).unwrap(); + fs::mkdir(path, old_io::USER_RWX).unwrap(); } fn compose_and_run(config: &Config, testfile: &Path, diff --git a/src/doc/trpl/guessing-game.md b/src/doc/trpl/guessing-game.md index 6f67c88f2c0c..f01b62223ca8 100644 --- a/src/doc/trpl/guessing-game.md +++ b/src/doc/trpl/guessing-game.md @@ -75,14 +75,14 @@ Let's get to it! The first thing we need to do for our guessing game is allow our player to input a guess. Put this in your `src/main.rs`: ```{rust,no_run} -use std::io; +use std::old_io; fn main() { println!("Guess the number!"); println!("Please input your guess."); - let input = io::stdin().read_line() + let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); @@ -121,7 +121,7 @@ explanatory text, and then an example. Let's try to modify our code to add in th `random` function and see what happens: ```{rust,ignore} -use std::io; +use std::old_io; use std::rand; fn main() { @@ -133,7 +133,7 @@ fn main() { println!("Please input your guess."); - let input = io::stdin().read_line() + let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); @@ -180,7 +180,7 @@ This says "please give me a random `i32` value." We can change our code to use this hint: ```{rust,no_run} -use std::io; +use std::old_io; use std::rand; fn main() { @@ -192,7 +192,7 @@ fn main() { println!("Please input your guess."); - let input = io::stdin().read_line() + let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); @@ -233,7 +233,7 @@ unsigned integer approach. If we want a random positive number, we should ask fo a random positive number. Our code looks like this now: ```{rust,no_run} -use std::io; +use std::old_io; use std::rand; fn main() { @@ -245,7 +245,7 @@ fn main() { println!("Please input your guess."); - let input = io::stdin().read_line() + let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); @@ -276,7 +276,7 @@ two numbers. Let's add that in, along with a `match` statement to compare our guess to the secret number: ```{rust,ignore} -use std::io; +use std::old_io; use std::rand; use std::cmp::Ordering; @@ -289,7 +289,7 @@ fn main() { println!("Please input your guess."); - let input = io::stdin().read_line() + let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); @@ -331,7 +331,7 @@ but we've given it unsigned integers. In this case, the fix is easy, because we wrote the `cmp` function! Let's change it to take `u32`s: ```{rust,ignore} -use std::io; +use std::old_io; use std::rand; use std::cmp::Ordering; @@ -344,7 +344,7 @@ fn main() { println!("Please input your guess."); - let input = io::stdin().read_line() + let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); @@ -397,7 +397,7 @@ Anyway, we have a `String`, but we need a `u32`. What to do? Well, there's a function for that: ```{rust,ignore} -let input = io::stdin().read_line() +let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); let input_num: Option = input.parse(); @@ -429,7 +429,7 @@ let input_num: Option = "5".parse(); // input_num: Option Anyway, with us now converting our input to a number, our code looks like this: ```{rust,ignore} -use std::io; +use std::old_io; use std::rand; use std::cmp::Ordering; @@ -442,7 +442,7 @@ fn main() { println!("Please input your guess."); - let input = io::stdin().read_line() + let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); let input_num: Option = input.parse(); @@ -479,7 +479,7 @@ need to unwrap the Option. If you remember from before, `match` is a great way to do that. Try this code: ```{rust,no_run} -use std::io; +use std::old_io; use std::rand; use std::cmp::Ordering; @@ -492,7 +492,7 @@ fn main() { println!("Please input your guess."); - let input = io::stdin().read_line() + let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); let input_num: Option = input.parse(); @@ -546,7 +546,7 @@ method we can use defined on them: `trim()`. One small modification, and our code looks like this: ```{rust,no_run} -use std::io; +use std::old_io; use std::rand; use std::cmp::Ordering; @@ -559,7 +559,7 @@ fn main() { println!("Please input your guess."); - let input = io::stdin().read_line() + let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); let input_num: Option = input.trim().parse(); @@ -620,7 +620,7 @@ As we already discussed, the `loop` keyword gives us an infinite loop. Let's add that in: ```{rust,no_run} -use std::io; +use std::old_io; use std::rand; use std::cmp::Ordering; @@ -635,7 +635,7 @@ fn main() { println!("Please input your guess."); - let input = io::stdin().read_line() + let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); let input_num: Option = input.trim().parse(); @@ -696,7 +696,7 @@ Ha! `quit` actually quits. As does any other non-number input. Well, this is suboptimal to say the least. First, let's actually quit when you win the game: ```{rust,no_run} -use std::io; +use std::old_io; use std::rand; use std::cmp::Ordering; @@ -711,7 +711,7 @@ fn main() { println!("Please input your guess."); - let input = io::stdin().read_line() + let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); let input_num: Option = input.trim().parse(); @@ -752,7 +752,7 @@ we don't want to quit, we just want to ignore it. Change that `return` to ```{rust,no_run} -use std::io; +use std::old_io; use std::rand; use std::cmp::Ordering; @@ -767,7 +767,7 @@ fn main() { println!("Please input your guess."); - let input = io::stdin().read_line() + let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); let input_num: Option = input.trim().parse(); @@ -831,7 +831,7 @@ think of what it is? That's right, we don't want to print out the secret number. It was good for testing, but it kind of ruins the game. Here's our final source: ```{rust,no_run} -use std::io; +use std::old_io; use std::rand; use std::cmp::Ordering; @@ -844,7 +844,7 @@ fn main() { println!("Please input your guess."); - let input = io::stdin().read_line() + let input = old_io::stdin().read_line() .ok() .expect("Failed to read line"); let input_num: Option = input.trim().parse(); diff --git a/src/doc/trpl/standard-input.md b/src/doc/trpl/standard-input.md index 7145139bba57..0c26fb2b44fa 100644 --- a/src/doc/trpl/standard-input.md +++ b/src/doc/trpl/standard-input.md @@ -8,7 +8,7 @@ and then prints it back out: fn main() { println!("Type something!"); - let input = std::io::stdin().read_line().ok().expect("Failed to read line"); + let input = std::old_io::stdin().read_line().ok().expect("Failed to read line"); println!("{}", input); } @@ -17,7 +17,7 @@ fn main() { Let's go over these chunks, one by one: ```{rust,ignore} -std::io::stdin(); +std::old_io::stdin(); ``` This calls a function, `stdin()`, that lives inside the `std::io` module. As @@ -28,7 +28,7 @@ Since writing the fully qualified name all the time is annoying, we can use the `use` statement to import it in: ```{rust} -use std::io::stdin; +use std::old_io::stdin; stdin(); ``` @@ -37,20 +37,20 @@ However, it's considered better practice to not import individual functions, but to import the module, and only use one level of qualification: ```{rust} -use std::io; +use std::old_io; -io::stdin(); +old_io::stdin(); ``` Let's update our example to use this style: ```{rust,ignore} -use std::io; +use std::old_io; fn main() { println!("Type something!"); - let input = io::stdin().read_line().ok().expect("Failed to read line"); + let input = old_io::stdin().read_line().ok().expect("Failed to read line"); println!("{}", input); } @@ -121,12 +121,12 @@ For now, this gives you enough of a basic understanding to work with. Back to the code we were working on! Here's a refresher: ```{rust,ignore} -use std::io; +use std::old_io; fn main() { println!("Type something!"); - let input = io::stdin().read_line().ok().expect("Failed to read line"); + let input = old_io::stdin().read_line().ok().expect("Failed to read line"); println!("{}", input); } @@ -136,14 +136,14 @@ With long lines like this, Rust gives you some flexibility with the whitespace. We _could_ write the example like this: ```{rust,ignore} -use std::io; +use std::old_io; fn main() { println!("Type something!"); // here, we'll show the types at each step - let input = io::stdin() // std::io::stdio::StdinReader + let input = old_io::stdin() // std::old_io::stdio::StdinReader .read_line() // IoResult .ok() // Option .expect("Failed to read line"); // String diff --git a/src/libcore/error.rs b/src/libcore/error.rs index 9ff38028df9f..7bb11fb5d927 100644 --- a/src/libcore/error.rs +++ b/src/libcore/error.rs @@ -49,7 +49,7 @@ //! //! ``` //! use std::error::FromError; -//! use std::io::{File, IoError}; +//! use std::old_io::{File, IoError}; //! use std::os::{MemoryMap, MapError}; //! use std::path::Path; //! diff --git a/src/libcore/result.rs b/src/libcore/result.rs index ab0f447f6c93..28463c0f04ca 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -95,7 +95,7 @@ //! by the [`Writer`](../io/trait.Writer.html) trait: //! //! ``` -//! use std::io::IoError; +//! use std::old_io::IoError; //! //! trait Writer { //! fn write_line(&mut self, s: &str) -> Result<(), IoError>; @@ -110,7 +110,7 @@ //! something like this: //! //! ```{.ignore} -//! use std::io::{File, Open, Write}; +//! use std::old_io::{File, Open, Write}; //! //! let mut file = File::open_mode(&Path::new("valuable_data.txt"), Open, Write); //! // If `write_line` errors, then we'll never know, because the return @@ -128,7 +128,7 @@ //! a marginally useful message indicating why: //! //! ```{.no_run} -//! use std::io::{File, Open, Write}; +//! use std::old_io::{File, Open, Write}; //! //! let mut file = File::open_mode(&Path::new("valuable_data.txt"), Open, Write); //! file.write_line("important message").ok().expect("failed to write message"); @@ -138,7 +138,7 @@ //! You might also simply assert success: //! //! ```{.no_run} -//! # use std::io::{File, Open, Write}; +//! # use std::old_io::{File, Open, Write}; //! //! # let mut file = File::open_mode(&Path::new("valuable_data.txt"), Open, Write); //! assert!(file.write_line("important message").is_ok()); @@ -148,7 +148,7 @@ //! Or propagate the error up the call stack with `try!`: //! //! ``` -//! # use std::io::{File, Open, Write, IoError}; +//! # use std::old_io::{File, Open, Write, IoError}; //! fn write_message() -> Result<(), IoError> { //! let mut file = File::open_mode(&Path::new("valuable_data.txt"), Open, Write); //! try!(file.write_line("important message")); @@ -167,7 +167,7 @@ //! It replaces this: //! //! ``` -//! use std::io::{File, Open, Write, IoError}; +//! use std::old_io::{File, Open, Write, IoError}; //! //! struct Info { //! name: String, @@ -191,7 +191,7 @@ //! With this: //! //! ``` -//! use std::io::{File, Open, Write, IoError}; +//! use std::old_io::{File, Open, Write, IoError}; //! //! struct Info { //! name: String, @@ -444,7 +444,7 @@ impl Result { /// ignoring I/O and parse errors: /// /// ``` - /// use std::io::IoResult; + /// use std::old_io::IoResult; /// /// let mut buffer = &mut b"1\n2\n3\n4\n"; /// diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index 0ed32b7bf4f3..ebe2487215a1 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -96,7 +96,7 @@ //! ```no_run //! # pub fn render_to(output: &mut W) { unimplemented!() } //! pub fn main() { -//! use std::io::File; +//! use std::old_io::File; //! let mut f = File::create(&Path::new("example1.dot")); //! render_to(&mut f) //! } @@ -188,7 +188,7 @@ //! ```no_run //! # pub fn render_to(output: &mut W) { unimplemented!() } //! pub fn main() { -//! use std::io::File; +//! use std::old_io::File; //! let mut f = File::create(&Path::new("example2.dot")); //! render_to(&mut f) //! } @@ -252,7 +252,7 @@ //! ```no_run //! # pub fn render_to(output: &mut W) { unimplemented!() } //! pub fn main() { -//! use std::io::File; +//! use std::old_io::File; //! let mut f = File::create(&Path::new("example3.dot")); //! render_to(&mut f) //! } @@ -279,7 +279,7 @@ use self::LabelText::*; use std::borrow::IntoCow; -use std::io; +use std::old_io; use std::string::CowString; use std::vec::CowVec; @@ -532,7 +532,7 @@ pub fn default_options() -> Vec { vec![] } /// (Simple wrapper around `render_opts` that passes a default set of options.) pub fn render<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, W:Writer>( g: &'a G, - w: &mut W) -> io::IoResult<()> { + w: &mut W) -> old_io::IoResult<()> { render_opts(g, w, &[]) } @@ -541,14 +541,14 @@ pub fn render<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, pub fn render_opts<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, W:Writer>( g: &'a G, w: &mut W, - options: &[RenderOption]) -> io::IoResult<()> + options: &[RenderOption]) -> old_io::IoResult<()> { - fn writeln(w: &mut W, arg: &[&str]) -> io::IoResult<()> { + fn writeln(w: &mut W, arg: &[&str]) -> old_io::IoResult<()> { for &s in arg.iter() { try!(w.write_str(s)); } w.write_char('\n') } - fn indent(w: &mut W) -> io::IoResult<()> { + fn indent(w: &mut W) -> old_io::IoResult<()> { w.write_str(" ") } @@ -590,7 +590,7 @@ mod tests { use self::NodeLabels::*; use super::{Id, Labeller, Nodes, Edges, GraphWalk, render}; use super::LabelText::{self, LabelStr, EscStr}; - use std::io::IoResult; + use std::old_io::IoResult; use std::borrow::IntoCow; use std::iter::repeat; diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index e7c5bc35f761..6712f153c095 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -174,8 +174,8 @@ use std::cell::RefCell; use std::fmt; -use std::io::LineBufferedWriter; -use std::io; +use std::old_io::LineBufferedWriter; +use std::old_io; use std::mem; use std::os; use std::ptr; @@ -232,7 +232,7 @@ pub trait Logger { } struct DefaultLogger { - handle: LineBufferedWriter, + handle: LineBufferedWriter, } /// Wraps the log level with fmt implementations. @@ -294,7 +294,7 @@ pub fn log(level: u32, loc: &'static LogLocation, args: fmt::Arguments) { let mut logger = LOCAL_LOGGER.with(|s| { s.borrow_mut().take() }).unwrap_or_else(|| { - box DefaultLogger { handle: io::stderr() } as Box + box DefaultLogger { handle: old_io::stderr() } as Box }); logger.log(&LogRecord { level: LogLevel(level), diff --git a/src/librbml/io.rs b/src/librbml/io.rs index 9c746c69baaf..d23f5c683596 100644 --- a/src/librbml/io.rs +++ b/src/librbml/io.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::io::{IoError, IoResult, SeekStyle}; -use std::io; +use std::old_io::{IoError, IoResult, SeekStyle}; +use std::old_io; use std::slice; use std::iter::repeat; @@ -18,14 +18,14 @@ static BUF_CAPACITY: uint = 128; fn combine(seek: SeekStyle, cur: uint, end: uint, offset: i64) -> IoResult { // compute offset as signed and clamp to prevent overflow let pos = match seek { - io::SeekSet => 0, - io::SeekEnd => end, - io::SeekCur => cur, + old_io::SeekSet => 0, + old_io::SeekEnd => end, + old_io::SeekCur => cur, } as i64; if offset + pos < 0 { Err(IoError { - kind: io::InvalidInput, + kind: old_io::InvalidInput, desc: "invalid seek to a negative offset", detail: None }) @@ -132,7 +132,7 @@ impl Seek for SeekableMemWriter { mod tests { extern crate test; use super::SeekableMemWriter; - use std::io; + use std::old_io; use std::iter::repeat; use test::Bencher; @@ -148,23 +148,23 @@ mod tests { let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7]; assert_eq!(writer.get_ref(), b); - writer.seek(0, io::SeekSet).unwrap(); + writer.seek(0, old_io::SeekSet).unwrap(); assert_eq!(writer.tell(), Ok(0)); writer.write(&[3, 4]).unwrap(); let b: &[_] = &[3, 4, 2, 3, 4, 5, 6, 7]; assert_eq!(writer.get_ref(), b); - writer.seek(1, io::SeekCur).unwrap(); + writer.seek(1, old_io::SeekCur).unwrap(); writer.write(&[0, 1]).unwrap(); let b: &[_] = &[3, 4, 2, 0, 1, 5, 6, 7]; assert_eq!(writer.get_ref(), b); - writer.seek(-1, io::SeekEnd).unwrap(); + writer.seek(-1, old_io::SeekEnd).unwrap(); writer.write(&[1, 2]).unwrap(); let b: &[_] = &[3, 4, 2, 0, 1, 5, 6, 1, 2]; assert_eq!(writer.get_ref(), b); - writer.seek(1, io::SeekEnd).unwrap(); + writer.seek(1, old_io::SeekEnd).unwrap(); writer.write(&[1]).unwrap(); let b: &[_] = &[3, 4, 2, 0, 1, 5, 6, 1, 2, 0, 1]; assert_eq!(writer.get_ref(), b); @@ -173,14 +173,14 @@ mod tests { #[test] fn seek_past_end() { let mut r = SeekableMemWriter::new(); - r.seek(10, io::SeekSet).unwrap(); + r.seek(10, old_io::SeekSet).unwrap(); assert!(r.write(&[3]).is_ok()); } #[test] fn seek_before_0() { let mut r = SeekableMemWriter::new(); - assert!(r.seek(-1, io::SeekSet).is_err()); + assert!(r.seek(-1, old_io::SeekSet).is_err()); } fn do_bench_seekable_mem_writer(b: &mut Bencher, times: uint, len: uint) { diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index 50fe56ff5c07..56944fac35ef 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -111,7 +111,7 @@ pub enum EbmlEncoderTag { pub enum Error { IntTooBig(uint), Expected(String), - IoError(std::io::IoError), + IoError(std::old_io::IoError), ApplicationError(String) } @@ -127,7 +127,7 @@ pub mod reader { use std::char; use std::int; - use std::io::extensions::u64_from_be_bytes; + use std::old_io::extensions::u64_from_be_bytes; use std::mem::transmute; use std::num::Int; use std::option::Option; @@ -685,9 +685,9 @@ pub mod reader { pub mod writer { use std::clone::Clone; - use std::io::extensions::u64_to_be_bytes; - use std::io::{Writer, Seek}; - use std::io; + use std::old_io::extensions::u64_to_be_bytes; + use std::old_io::{Writer, Seek}; + use std::old_io; use std::mem; use super::{ EsVec, EsMap, EsEnum, EsVecLen, EsVecElt, EsMapLen, EsMapKey, @@ -698,7 +698,7 @@ pub mod writer { use serialize; - pub type EncodeResult = io::IoResult<()>; + pub type EncodeResult = old_io::IoResult<()>; // rbml writing pub struct Encoder<'a, W:'a> { @@ -714,8 +714,8 @@ pub mod writer { n as u8]), 4u => w.write(&[0x10u8 | ((n >> 24_u) as u8), (n >> 16_u) as u8, (n >> 8_u) as u8, n as u8]), - _ => Err(io::IoError { - kind: io::OtherIoError, + _ => Err(old_io::IoError { + kind: old_io::OtherIoError, desc: "int too big", detail: Some(format!("{}", n)) }) @@ -727,8 +727,8 @@ pub mod writer { if n < 0x4000_u { return write_sized_vuint(w, n, 2u); } if n < 0x200000_u { return write_sized_vuint(w, n, 3u); } if n < 0x10000000_u { return write_sized_vuint(w, n, 4u); } - Err(io::IoError { - kind: io::OtherIoError, + Err(old_io::IoError { + kind: old_io::OtherIoError, desc: "int too big", detail: Some(format!("{}", n)) }) @@ -766,10 +766,10 @@ pub mod writer { pub fn end_tag(&mut self) -> EncodeResult { let last_size_pos = self.size_positions.pop().unwrap(); let cur_pos = try!(self.writer.tell()); - try!(self.writer.seek(last_size_pos as i64, io::SeekSet)); + try!(self.writer.seek(last_size_pos as i64, old_io::SeekSet)); let size = cur_pos as uint - last_size_pos - 4; try!(write_sized_vuint(self.writer, size, 4u)); - let r = try!(self.writer.seek(cur_pos as i64, io::SeekSet)); + let r = try!(self.writer.seek(cur_pos as i64, old_io::SeekSet)); debug!("End tag (size = {:?})", size); Ok(r) @@ -883,7 +883,7 @@ pub mod writer { } impl<'a, W: Writer + Seek> serialize::Encoder for Encoder<'a, W> { - type Error = io::IoError; + type Error = old_io::IoError; fn emit_nil(&mut self) -> EncodeResult { Ok(()) diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 1197276b9908..e6f76dedca95 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -34,8 +34,8 @@ use middle::astencode::vtable_decoder_helpers; use std::collections::HashMap; use std::hash::{self, Hash, SipHasher}; -use std::io::extensions::u64_from_be_bytes; -use std::io; +use std::old_io::extensions::u64_from_be_bytes; +use std::old_io; use std::num::FromPrimitive; use std::rc::Rc; use std::str; @@ -1178,7 +1178,7 @@ fn get_attributes(md: rbml::Doc) -> Vec { } fn list_crate_attributes(md: rbml::Doc, hash: &Svh, - out: &mut io::Writer) -> io::IoResult<()> { + out: &mut old_io::Writer) -> old_io::IoResult<()> { try!(write!(out, "=Crate Attributes ({})=\n", *hash)); let r = get_attributes(md); @@ -1223,7 +1223,7 @@ pub fn get_crate_deps(data: &[u8]) -> Vec { return deps; } -fn list_crate_deps(data: &[u8], out: &mut io::Writer) -> io::IoResult<()> { +fn list_crate_deps(data: &[u8], out: &mut old_io::Writer) -> old_io::IoResult<()> { try!(write!(out, "=External Dependencies=\n")); for dep in get_crate_deps(data).iter() { try!(write!(out, "{} {}-{}\n", dep.cnum, dep.name, dep.hash)); @@ -1262,7 +1262,7 @@ pub fn get_crate_name(data: &[u8]) -> String { maybe_get_crate_name(data).expect("no crate name in crate") } -pub fn list_crate_metadata(bytes: &[u8], out: &mut io::Writer) -> io::IoResult<()> { +pub fn list_crate_metadata(bytes: &[u8], out: &mut old_io::Writer) -> old_io::IoResult<()> { let hash = get_crate_hash(bytes); let md = rbml::Doc::new(bytes); try!(list_crate_attributes(md, &hash, out)); diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index ddee1f79d6a6..26046cfb43d8 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -13,8 +13,8 @@ pub use self::FileMatch::*; use std::collections::HashSet; -use std::io::fs::PathExtensions; -use std::io::fs; +use std::old_io::fs::PathExtensions; +use std::old_io::fs; use std::os; use util::fs as myfs; diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index b1043a4152cf..3ee4017292c4 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -231,8 +231,8 @@ use rustc_back::target::Target; use std::ffi::CString; use std::cmp; use std::collections::HashMap; -use std::io::fs::PathExtensions; -use std::io; +use std::old_io::fs::PathExtensions; +use std::old_io; use std::ptr; use std::slice; use std::time::Duration; @@ -796,7 +796,7 @@ pub fn read_meta_section_name(is_osx: bool) -> &'static str { // A diagnostic function for dumping crate metadata to an output stream pub fn list_file_metadata(is_osx: bool, path: &Path, - out: &mut io::Writer) -> io::IoResult<()> { + out: &mut old_io::Writer) -> old_io::IoResult<()> { match get_metadata_section(is_osx, path) { Ok(bytes) => decoder::list_crate_metadata(bytes.as_slice(), out), Err(msg) => { diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index fcc2be985a55..091ef9d52eb4 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -37,7 +37,7 @@ use syntax::parse::token; use syntax::ptr::P; use syntax; -use std::io::Seek; +use std::old_io::Seek; use std::rc::Rc; use rbml::io::SeekableMemWriter; diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index a17278698103..d3c843d1d50c 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -19,7 +19,7 @@ pub use self::EntryOrExit::*; use middle::cfg; use middle::cfg::CFGIndex; use middle::ty; -use std::io; +use std::old_io; use std::uint; use std::iter::repeat; use syntax::ast; @@ -105,7 +105,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> { impl<'a, 'tcx, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, 'tcx, O> { fn pre(&self, ps: &mut pprust::State, - node: pprust::AnnNode) -> io::IoResult<()> { + node: pprust::AnnNode) -> old_io::IoResult<()> { let id = match node { pprust::NodeIdent(_) | pprust::NodeName(_) => 0, pprust::NodeExpr(expr) => expr.id, @@ -457,13 +457,13 @@ impl<'a, 'tcx, O:DataFlowOperator+Clone+'static> DataFlowContext<'a, 'tcx, O> { debug!("Dataflow result for {}:", self.analysis_name); debug!("{}", { - self.pretty_print_to(box io::stderr(), blk).unwrap(); + self.pretty_print_to(box old_io::stderr(), blk).unwrap(); "" }); } - fn pretty_print_to(&self, wr: Box, - blk: &ast::Block) -> io::IoResult<()> { + fn pretty_print_to(&self, wr: Box, + blk: &ast::Block) -> old_io::IoResult<()> { let mut ps = pprust::rust_printer_annotated(wr, self); try!(ps.cbox(pprust::indent_unit)); try!(ps.ibox(0u)); diff --git a/src/librustc/middle/infer/region_inference/graphviz.rs b/src/librustc/middle/infer/region_inference/graphviz.rs index f8f962cd86d2..8803fe7cf38a 100644 --- a/src/librustc/middle/infer/region_inference/graphviz.rs +++ b/src/librustc/middle/infer/region_inference/graphviz.rs @@ -26,7 +26,7 @@ use util::nodemap::{FnvHashMap, FnvHashSet}; use util::ppaux::Repr; use std::collections::hash_map::Entry::Vacant; -use std::io::{self, File}; +use std::old_io::{self, File}; use std::os; use std::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT}; use syntax::ast; @@ -217,7 +217,7 @@ pub type ConstraintMap<'tcx> = FnvHashMap>; fn dump_region_constraints_to<'a, 'tcx:'a >(tcx: &'a ty::ctxt<'tcx>, map: &ConstraintMap<'tcx>, - path: &str) -> io::IoResult<()> { + path: &str) -> old_io::IoResult<()> { debug!("dump_region_constraints map (len: {}) path: {}", map.len(), path); let g = ConstraintGraph::new(tcx, format!("region_constraints"), map); let mut f = File::create(&Path::new(path)); diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 0131b9f1491e..00fa6546b480 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -118,7 +118,7 @@ use middle::ty::ClosureTyper; use lint; use util::nodemap::NodeMap; -use std::{fmt, io, uint}; +use std::{fmt, old_io, uint}; use std::rc::Rc; use std::iter::repeat; use syntax::ast::{self, NodeId, Expr}; @@ -693,10 +693,10 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } fn write_vars(&self, - wr: &mut io::Writer, + wr: &mut old_io::Writer, ln: LiveNode, mut test: F) - -> io::IoResult<()> where + -> old_io::IoResult<()> where F: FnMut(uint) -> LiveNode, { let node_base_idx = self.idx(ln, Variable(0)); @@ -740,7 +740,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn ln_str(&self, ln: LiveNode) -> String { let mut wr = Vec::new(); { - let wr = &mut wr as &mut io::Writer; + let wr = &mut wr as &mut old_io::Writer; write!(wr, "[ln({:?}) of kind {:?} reads", ln.get(), self.ir.lnk(ln)); self.write_vars(wr, ln, |idx| self.users[idx].reader); write!(wr, " writes"); diff --git a/src/librustc_back/archive.rs b/src/librustc_back/archive.rs index fa754b4a3018..ee8bc71668b3 100644 --- a/src/librustc_back/archive.rs +++ b/src/librustc_back/archive.rs @@ -10,10 +10,10 @@ //! A helper class for dealing with static archives -use std::io::fs::PathExtensions; -use std::io::process::{Command, ProcessOutput}; -use std::io::{fs, TempDir}; -use std::io; +use std::old_io::fs::PathExtensions; +use std::old_io::process::{Command, ProcessOutput}; +use std::old_io::{fs, TempDir}; +use std::old_io; use std::os; use std::str; use syntax::diagnostic::Handler as ErrorHandler; @@ -172,7 +172,7 @@ impl<'a> ArchiveBuilder<'a> { /// Adds all of the contents of a native library to this archive. This will /// search in the relevant locations for a library named `name`. - pub fn add_native_library(&mut self, name: &str) -> io::IoResult<()> { + pub fn add_native_library(&mut self, name: &str) -> old_io::IoResult<()> { let location = find_library(name, &self.archive.slib_prefix[], &self.archive.slib_suffix[], @@ -187,7 +187,7 @@ impl<'a> ArchiveBuilder<'a> { /// This ignores adding the bytecode from the rlib, and if LTO is enabled /// then the object file also isn't added. pub fn add_rlib(&mut self, rlib: &Path, name: &str, - lto: bool) -> io::IoResult<()> { + lto: bool) -> old_io::IoResult<()> { // Ignoring obj file starting with the crate name // as simple comparison is not enough - there // might be also an extra name suffix @@ -205,7 +205,7 @@ impl<'a> ArchiveBuilder<'a> { } /// Adds an arbitrary file to this archive - pub fn add_file(&mut self, file: &Path) -> io::IoResult<()> { + pub fn add_file(&mut self, file: &Path) -> old_io::IoResult<()> { let filename = Path::new(file.filename().unwrap()); let new_file = self.work_dir.path().join(&filename); try!(fs::copy(file, &new_file)); @@ -274,8 +274,9 @@ impl<'a> ArchiveBuilder<'a> { self.archive } - fn add_archive(&mut self, archive: &Path, name: &str, mut skip: F) -> io::IoResult<()> where - F: FnMut(&str) -> bool, + fn add_archive(&mut self, archive: &Path, name: &str, + mut skip: F) -> old_io::IoResult<()> + where F: FnMut(&str) -> bool, { let loc = TempDir::new("rsar").unwrap(); diff --git a/src/librustc_back/fs.rs b/src/librustc_back/fs.rs index d7deb09985f7..24f81b024789 100644 --- a/src/librustc_back/fs.rs +++ b/src/librustc_back/fs.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::io; -use std::io::fs; +use std::old_io; +use std::old_io::fs; use std::os; /// Returns an absolute path in the filesystem that `path` points to. The /// returned path does not contain any symlinks in its hierarchy. -pub fn realpath(original: &Path) -> io::IoResult { +pub fn realpath(original: &Path) -> old_io::IoResult { static MAX_LINKS_FOLLOWED: uint = 256; let original = os::make_absolute(original).unwrap(); @@ -32,12 +32,12 @@ pub fn realpath(original: &Path) -> io::IoResult { loop { if followed == MAX_LINKS_FOLLOWED { - return Err(io::standard_error(io::InvalidInput)) + return Err(old_io::standard_error(old_io::InvalidInput)) } match fs::lstat(&result) { Err(..) => break, - Ok(ref stat) if stat.kind != io::FileType::Symlink => break, + Ok(ref stat) if stat.kind != old_io::FileType::Symlink => break, Ok(..) => { followed += 1; let path = try!(fs::readlink(&result)); @@ -53,10 +53,10 @@ pub fn realpath(original: &Path) -> io::IoResult { #[cfg(all(not(windows), test))] mod test { - use std::io; - use std::io::fs::{File, symlink, mkdir, mkdir_recursive}; + use std::old_io; + use std::old_io::fs::{File, symlink, mkdir, mkdir_recursive}; use super::realpath; - use std::io::TempDir; + use std::old_io::TempDir; #[test] fn realpath_works() { @@ -68,7 +68,7 @@ mod test { let linkdir = tmpdir.join("test3"); File::create(&file).unwrap(); - mkdir(&dir, io::USER_RWX).unwrap(); + mkdir(&dir, old_io::USER_RWX).unwrap(); symlink(&file, &link).unwrap(); symlink(&dir, &linkdir).unwrap(); @@ -91,8 +91,8 @@ mod test { let e = d.join("e"); let f = a.join("f"); - mkdir_recursive(&b, io::USER_RWX).unwrap(); - mkdir_recursive(&d, io::USER_RWX).unwrap(); + mkdir_recursive(&b, old_io::USER_RWX).unwrap(); + mkdir_recursive(&d, old_io::USER_RWX).unwrap(); File::create(&f).unwrap(); symlink(&Path::new("../d/e"), &c).unwrap(); symlink(&Path::new("../f"), &e).unwrap(); diff --git a/src/librustc_back/rpath.rs b/src/librustc_back/rpath.rs index d24fd6a5b3f0..bafd5fbe9448 100644 --- a/src/librustc_back/rpath.rs +++ b/src/librustc_back/rpath.rs @@ -11,7 +11,7 @@ use std::collections::HashSet; use std::os; -use std::io::IoError; +use std::old_io::IoError; use syntax::ast; pub struct RPathConfig where diff --git a/src/librustc_back/target/apple_ios_base.rs b/src/librustc_back/target/apple_ios_base.rs index ac133cabc3b8..715bcc4f36dd 100644 --- a/src/librustc_back/target/apple_ios_base.rs +++ b/src/librustc_back/target/apple_ios_base.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::io::{Command, IoError, OtherIoError}; +use std::old_io::{Command, IoError, OtherIoError}; use target::TargetOptions; use self::Arch::*; diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 4626f2dc4833..36d83da725e8 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -48,7 +48,7 @@ use serialize::json::Json; use syntax::{diagnostic, abi}; use std::default::Default; -use std::io::fs::PathExtensions; +use std::old_io::fs::PathExtensions; mod windows_base; mod linux_base; @@ -302,7 +302,7 @@ impl Target { /// JSON decoding. pub fn search(target: &str) -> Result { use std::os; - use std::io::File; + use std::old_io::File; use std::path::Path; use serialize::json; diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 3fac5ba9674c..36a9c0e16f01 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -30,8 +30,8 @@ use rustc_privacy; use serialize::json; -use std::io; -use std::io::fs; +use std::old_io; +use std::old_io::fs; use std::os; use syntax::ast; use syntax::ast_map; @@ -787,14 +787,14 @@ fn write_out_deps(sess: &Session, _ => return, }; - let result = (|&:| -> io::IoResult<()> { + let result = (|&:| -> old_io::IoResult<()> { // Build a list of files used to compile the output and // write Makefile-compatible dependency rules let files: Vec = sess.codemap().files.borrow() .iter().filter(|fmap| fmap.is_real_file()) .map(|fmap| escape_dep_filename(&fmap.name[])) .collect(); - let mut file = try!(io::File::create(&deps_filename)); + let mut file = try!(old_io::File::create(&deps_filename)); for path in out_filenames.iter() { try!(write!(&mut file as &mut Writer, "{}: {}\n\n", path.display(), files.connect(" "))); diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 0e940b85bd84..fdda8e737a94 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -64,7 +64,7 @@ use rustc::metadata::creader::CrateOrString::Str; use rustc::util::common::time; use std::cmp::Ordering::Equal; -use std::io; +use std::old_io; use std::iter::repeat; use std::os; use std::sync::mpsc::channel; @@ -133,7 +133,7 @@ fn run_compiler(args: &[String]) { 1u => { let ifile = &matches.free[0][]; if ifile == "-" { - let contents = io::stdin().read_to_end().unwrap(); + let contents = old_io::stdin().read_to_end().unwrap(); let src = String::from_utf8(contents).unwrap(); (Input::Str(src), None) } else { @@ -187,7 +187,7 @@ fn run_compiler(args: &[String]) { if r.contains(&("ls".to_string())) { match input { Input::File(ref ifile) => { - let mut stdout = io::stdout(); + let mut stdout = old_io::stdout(); list_metadata(&sess, &(*ifile), &mut stdout).unwrap(); } Input::Str(_) => { @@ -590,7 +590,7 @@ fn parse_crate_attrs(sess: &Session, input: &Input) -> } pub fn list_metadata(sess: &Session, path: &Path, - out: &mut io::Writer) -> io::IoResult<()> { + out: &mut old_io::Writer) -> old_io::IoResult<()> { metadata::loader::list_file_metadata(sess.target.target.options.is_like_osx, path, out) } @@ -603,8 +603,8 @@ pub fn monitor(f: F) { static STACK_SIZE: uint = 8 * 1024 * 1024; // 8MB let (tx, rx) = channel(); - let w = io::ChanWriter::new(tx); - let mut r = io::ChanReader::new(rx); + let w = old_io::ChanWriter::new(tx); + let mut r = old_io::ChanReader::new(rx); let mut cfg = thread::Builder::new().name("rustc".to_string()); @@ -614,7 +614,7 @@ pub fn monitor(f: F) { cfg = cfg.stack_size(STACK_SIZE); } - match cfg.scoped(move || { std::io::stdio::set_stderr(box w); f() }).join() { + match cfg.scoped(move || { std::old_io::stdio::set_stderr(box w); f() }).join() { Ok(()) => { /* fallthrough */ } Err(value) => { // Thread panicked without emitting a fatal diagnostic @@ -656,7 +656,7 @@ pub fn monitor(f: F) { // Panic so the process returns a failure code, but don't pollute the // output with some unnecessary panic messages, we've already // printed everything that we needed to. - io::stdio::set_stderr(box io::util::NullWriter); + old_io::stdio::set_stderr(box old_io::util::NullWriter); panic!(); } } diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 582e10323248..b09e9f143577 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -38,7 +38,7 @@ use syntax::ptr::P; use graphviz as dot; -use std::io::{self, MemReader}; +use std::old_io::{self, MemReader}; use std::option; use std::str::FromStr; @@ -208,7 +208,7 @@ impl<'ast> PrinterSupport<'ast> for IdentifiedAnnotation<'ast> { impl<'ast> pprust::PpAnn for IdentifiedAnnotation<'ast> { fn pre(&self, s: &mut pprust::State, - node: pprust::AnnNode) -> io::IoResult<()> { + node: pprust::AnnNode) -> old_io::IoResult<()> { match node { pprust::NodeExpr(_) => s.popen(), _ => Ok(()) @@ -216,7 +216,7 @@ impl<'ast> pprust::PpAnn for IdentifiedAnnotation<'ast> { } fn post(&self, s: &mut pprust::State, - node: pprust::AnnNode) -> io::IoResult<()> { + node: pprust::AnnNode) -> old_io::IoResult<()> { match node { pprust::NodeIdent(_) | pprust::NodeName(_) => Ok(()), @@ -259,7 +259,7 @@ impl<'ast> PrinterSupport<'ast> for HygieneAnnotation<'ast> { impl<'ast> pprust::PpAnn for HygieneAnnotation<'ast> { fn post(&self, s: &mut pprust::State, - node: pprust::AnnNode) -> io::IoResult<()> { + node: pprust::AnnNode) -> old_io::IoResult<()> { match node { pprust::NodeIdent(&ast::Ident { name: ast::Name(nm), ctxt }) => { try!(pp::space(&mut s.s)); @@ -294,7 +294,7 @@ impl<'tcx> PrinterSupport<'tcx> for TypedAnnotation<'tcx> { impl<'tcx> pprust::PpAnn for TypedAnnotation<'tcx> { fn pre(&self, s: &mut pprust::State, - node: pprust::AnnNode) -> io::IoResult<()> { + node: pprust::AnnNode) -> old_io::IoResult<()> { match node { pprust::NodeExpr(_) => s.popen(), _ => Ok(()) @@ -302,7 +302,7 @@ impl<'tcx> pprust::PpAnn for TypedAnnotation<'tcx> { } fn post(&self, s: &mut pprust::State, - node: pprust::AnnNode) -> io::IoResult<()> { + node: pprust::AnnNode) -> old_io::IoResult<()> { let tcx = &self.analysis.ty_cx; match node { pprust::NodeExpr(expr) => { @@ -548,9 +548,9 @@ pub fn pretty_print_input(sess: Session, let mut rdr = MemReader::new(src); let out = match ofile { - None => box io::stdout() as Box, + None => box old_io::stdout() as Box, Some(p) => { - let r = io::File::create(&p); + let r = old_io::File::create(&p); match r { Ok(w) => box w as Box, Err(e) => panic!("print-print failed to open {} due to {}", @@ -643,11 +643,11 @@ pub fn pretty_print_input(sess: Session, }.unwrap() } -fn print_flowgraph(variants: Vec, +fn print_flowgraph(variants: Vec, analysis: ty::CrateAnalysis, code: blocks::Code, mode: PpFlowGraphMode, - mut out: W) -> io::IoResult<()> { + mut out: W) -> old_io::IoResult<()> { let ty_cx = &analysis.ty_cx; let cfg = match code { blocks::BlockCode(block) => cfg::CFG::new(ty_cx, &*block), @@ -687,11 +687,11 @@ fn print_flowgraph(variants: Vec, } } - fn expand_err_details(r: io::IoResult<()>) -> io::IoResult<()> { + fn expand_err_details(r: old_io::IoResult<()>) -> old_io::IoResult<()> { r.map_err(|ioerr| { let orig_detail = ioerr.detail.clone(); let m = "graphviz::render failed"; - io::IoError { + old_io::IoError { detail: Some(match orig_detail { None => m.to_string(), Some(d) => format!("{}: {}", m, d) diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index eedfc9407515..25fe19425796 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -27,9 +27,9 @@ use util::common::time; use util::ppaux; use util::sha2::{Digest, Sha256}; -use std::io::fs::PathExtensions; -use std::io::{fs, TempDir, Command}; -use std::io; +use std::old_io::fs::PathExtensions; +use std::old_io::{fs, TempDir, Command}; +use std::old_io; use std::mem; use std::str; use std::string::String; @@ -425,7 +425,7 @@ pub fn invalid_output_for_target(sess: &Session, fn is_writeable(p: &Path) -> bool { match p.stat() { Err(..) => true, - Ok(m) => m.perm & io::USER_WRITE == io::USER_WRITE + Ok(m) => m.perm & old_io::USER_WRITE == old_io::USER_WRITE } } @@ -671,7 +671,7 @@ fn link_rlib<'a>(sess: &'a Session, fn write_rlib_bytecode_object_v1(writer: &mut T, bc_data_deflated: &[u8]) - -> ::std::io::IoResult<()> { + -> ::std::old_io::IoResult<()> { let bc_data_deflated_size: u64 = bc_data_deflated.len() as u64; try! { writer.write(RLIB_BYTECODE_OBJECT_MAGIC) }; @@ -1201,7 +1201,7 @@ fn add_upstream_rust_crates(cmd: &mut Command, sess: &Session, // Fix up permissions of the copy, as fs::copy() preserves // permissions, but the original file may have been installed // by a package manager and may be read-only. - match fs::chmod(&dst, io::USER_READ | io::USER_WRITE) { + match fs::chmod(&dst, old_io::USER_READ | old_io::USER_WRITE) { Ok(..) => {} Err(e) => { sess.err(&format!("failed to chmod {} when preparing \ diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index 5e48ce384be5..370ea0c7b143 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -23,8 +23,8 @@ use syntax::diagnostic; use syntax::diagnostic::{Emitter, Handler, Level, mk_handler}; use std::ffi::{self, CString}; -use std::io::Command; -use std::io::fs; +use std::old_io::Command; +use std::old_io::fs; use std::iter::Unfold; use std::ptr; use std::str; @@ -728,9 +728,9 @@ pub fn run_passes(sess: &Session, println!("{:?}", &cmd); } - cmd.stdin(::std::io::process::Ignored) - .stdout(::std::io::process::InheritFd(1)) - .stderr(::std::io::process::InheritFd(2)); + cmd.stdin(::std::old_io::process::Ignored) + .stdout(::std::old_io::process::InheritFd(1)) + .stderr(::std::old_io::process::InheritFd(2)); match cmd.status() { Ok(status) => { if !status.success() { diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index 71ca6a4db03d..7e7176d661c6 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -33,7 +33,7 @@ use middle::def; use middle::ty::{self, Ty}; use std::cell::Cell; -use std::io::{self, File, fs}; +use std::old_io::{self, File, fs}; use std::os; use syntax::ast_util::{self, PostExpansionMethod}; @@ -1532,7 +1532,7 @@ pub fn process_crate(sess: &Session, }, }; - match fs::mkdir_recursive(&root_path, io::USER_RWX) { + match fs::mkdir_recursive(&root_path, old_io::USER_RWX) { Err(e) => sess.err(&format!("Could not create directory {}: {}", root_path.display(), e)[]), _ => (), diff --git a/src/librustdoc/externalfiles.rs b/src/librustdoc/externalfiles.rs index 157d2580ad97..79ca24a18d4d 100644 --- a/src/librustdoc/externalfiles.rs +++ b/src/librustdoc/externalfiles.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::{io, str}; +use std::{old_io, str}; #[derive(Clone)] pub struct ExternalHtml{ @@ -33,8 +33,8 @@ impl ExternalHtml { } } -pub fn load_string(input: &Path) -> io::IoResult> { - let mut f = try!(io::File::open(input)); +pub fn load_string(input: &Path) -> old_io::IoResult> { + let mut f = try!(old_io::File::open(input)); let d = try!(f.read_to_end()); Ok(str::from_utf8(d.as_slice()).map(|s| s.to_string()).ok()) } @@ -45,12 +45,12 @@ macro_rules! load_or_return { let input = Path::new($input); match ::externalfiles::load_string(&input) { Err(e) => { - let _ = writeln!(&mut io::stderr(), + let _ = writeln!(&mut old_io::stderr(), "error reading `{}`: {}", input.display(), e); return $cant_read; } Ok(None) => { - let _ = writeln!(&mut io::stderr(), + let _ = writeln!(&mut old_io::stderr(), "error reading `{}`: not UTF-8", input.display()); return $not_utf8; } diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 885017152de4..38b191846f19 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -15,7 +15,7 @@ use html::escape::Escape; -use std::io; +use std::old_io; use syntax::parse::lexer; use syntax::parse::token; use syntax::parse; @@ -46,7 +46,7 @@ pub fn highlight(src: &str, class: Option<&str>, id: Option<&str>) -> String { /// source. fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader, class: Option<&str>, id: Option<&str>, - out: &mut Writer) -> io::IoResult<()> { + out: &mut Writer) -> old_io::IoResult<()> { use syntax::parse::lexer::Reader; try!(write!(out, "
 {
 }
 
 pub fn render(
-    dst: &mut io::Writer, layout: &Layout, page: &Page, sidebar: &S, t: &T)
-    -> io::IoResult<()>
+    dst: &mut old_io::Writer, layout: &Layout, page: &Page, sidebar: &S, t: &T)
+    -> old_io::IoResult<()>
 {
     write!(dst,
 r##"
@@ -159,7 +159,7 @@ r##"
     )
 }
 
-pub fn redirect(dst: &mut io::Writer, url: &str) -> io::IoResult<()> {
+pub fn redirect(dst: &mut old_io::Writer, url: &str) -> old_io::IoResult<()> {
     //