Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Rolling up PRs in the queue #23936

Merged
merged 56 commits into from
Apr 1, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
62645a1
Fix ICE when dividing integral SIMD types.
hirschenberger Mar 25, 2015
6370f29
std: Stabilize parts of std::os::platform::io
alexcrichton Mar 26, 2015
df65f59
replace deprecated as_slice()
demelev Mar 30, 2015
2a89d69
libcore: Ensure min and max functions are consistent for equal inputs
Ryman Mar 30, 2015
f19e763
std: Stabilize the rest of Any/BoxAny
alexcrichton Mar 30, 2015
e17f4fc
convert: remove FromError, use From<E> instead
seanmonstar Mar 31, 2015
606f50c
Lex binary and octal literals more eagerly.
huonw Mar 30, 2015
a78d383
Update lib.rs
wettowelreactor Mar 31, 2015
edc096d
Document std::borrow with examples
steveklabnik Mar 24, 2015
fe8a660
Last docs for std::env
steveklabnik Mar 31, 2015
5872ae4
Indicate select! is code-like
frewsxcv Mar 31, 2015
5d0beb7
rollup merge of #23549: aturon/stab-num
alexcrichton Mar 31, 2015
03c2f33
rollup merge of #23669: steveklabnik/doc_std_borrow
alexcrichton Mar 31, 2015
9fc51ef
Stabilize `std::convert` and related code
aturon Mar 30, 2015
cf56162
Fix up iterator documentation with regards to for loop sugar
steveklabnik Mar 31, 2015
9ba7974
book: reword timer bit
Mar 31, 2015
d9a6e86
Fixup primitive.str docs
steveklabnik Mar 31, 2015
5cf126a
std: Remove #[old_orphan_check] from PartialEq
alexcrichton Mar 11, 2015
608fff8
rustc: Remove old_orphan_check entirely
alexcrichton Mar 31, 2015
e48c7c6
Fix spelling
steveklabnik Mar 31, 2015
71982aa
std: Add a process::exit function
alexcrichton Mar 31, 2015
b9ab5fe
Stabilize a few remaining stragglers
aturon Mar 31, 2015
1829974
rollup merge of #23704: hirschenberger/simd-intdiv-ice
alexcrichton Mar 31, 2015
890f0ab
rollup merge of #23766: alexcrichton/stabilize-raw-fd
alexcrichton Mar 31, 2015
d03120a
rollup merge of #23876: alexcrichton/stabilize-any
alexcrichton Mar 31, 2015
f6bd6b4
rollup merge of #23878: Ryman/stable_extremes
alexcrichton Mar 31, 2015
095f1fb
rollup merge of #23882: wettowelreactor/patch-2
alexcrichton Mar 31, 2015
5e0bda0
rollup merge of #23885: steveklabnik/doc_std_env
alexcrichton Mar 31, 2015
6d2c640
rollup merge of #23886: demelev/remove_as_slice_usage
alexcrichton Mar 31, 2015
acdb0f9
rollup merge of #23893: frewsxcv/patch-6
alexcrichton Mar 31, 2015
d4a2c94
std: Clean out #[deprecated] APIs
alexcrichton Mar 30, 2015
e3f2d45
rollup merge of #23872: huonw/eager-lexing
alexcrichton Mar 31, 2015
94137a3
Test fixes and rebase conflicts, round 1
alexcrichton Mar 31, 2015
da04788
rollup merge of #23875: aturon/revise-convert-2
alexcrichton Mar 31, 2015
e10ee2c
rollup merge of #23879: seanmonstar/del-from-error
alexcrichton Mar 31, 2015
554946c
rollup merge of #23873: alexcrichton/remove-deprecated
alexcrichton Mar 31, 2015
3053288
Test fixes and rebase conflicts, round 2
alexcrichton Mar 31, 2015
82889f7
rollup merge of #23902: freebroccolo/master
alexcrichton Mar 31, 2015
0cac5b6
rollup merge of #23906: steveklabnik/spellin
alexcrichton Mar 31, 2015
a37311d
rollup merge of #23907: alexcrichton/impl-exit
alexcrichton Mar 31, 2015
30283d4
rollup merge of #23908: aturon/stab-more-stragglers
alexcrichton Mar 31, 2015
3422be3
rollup merge of #23288: alexcrichton/issue-19470
alexcrichton Mar 31, 2015
8da0831
Move benchmark tests to unstable section
steveklabnik Mar 31, 2015
9ab6cc9
rollup merge of #23901: steveklabnik/fix_links_str
alexcrichton Mar 31, 2015
6659865
rollup merge of #23920: steveklabnik/gh23881
alexcrichton Mar 31, 2015
ac77392
std: Stabilize last bits of io::Error
alexcrichton Mar 31, 2015
85e997a
rollup merge of #23899: steveklabnik/gh23851
alexcrichton Mar 31, 2015
50b3ecf
rollup merge of #23919: alexcrichton/stabilize-io-error
alexcrichton Mar 31, 2015
55e531d
Add test for #17746
aturon Mar 31, 2015
371ba00
Add description of + for multiple trait bounds
steveklabnik Mar 31, 2015
72f5973
Test fixes and rebase conflicts, round 3
alexcrichton Mar 31, 2015
4f643d7
rollup merge of #23863: pnkfelix/arith-oflo-const-eval
alexcrichton Apr 1, 2015
1d5ef75
rollup merge of #23921: aturon/issue-17746
alexcrichton Apr 1, 2015
6ebb6e6
rollup merge of #23923: steveklabnik/gh23688
alexcrichton Apr 1, 2015
8dff0ac
Test fixes and rebase conflicts
alexcrichton Apr 1, 2015
2b71aed
Update android tests to reflect API switch from `os::env` to `env::va…
pnkfelix Apr 1, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ use core::fmt;
use core::hash::{self, Hash};
use core::mem;
use core::ops::{Deref, DerefMut};
use core::ptr::Unique;
use core::raw::TraitObject;
use core::ptr::{self, Unique};
use core::raw::{TraitObject, Slice};

use heap;

/// A value that represents the heap. This is the default place that the `box`
/// keyword allocates into when no place is supplied.
Expand Down Expand Up @@ -313,3 +315,43 @@ impl<'a, E: Error + 'a> From<E> for Box<Error + 'a> {
Box::new(err)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, E: Error + Send + 'a> From<E> for Box<Error + Send + 'a> {
fn from(err: E) -> Box<Error + Send + 'a> {
Box::new(err)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b> From<&'b str> for Box<Error + Send + 'a> {
fn from(err: &'b str) -> Box<Error + Send + 'a> {
#[derive(Debug)]
struct StringError(Box<str>);
impl Error for StringError {
fn description(&self) -> &str { &self.0 }
}
impl fmt::Display for StringError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}

// Unfortunately `String` is located in libcollections, so we construct
// a `Box<str>` manually here.
unsafe {
let alloc = if err.len() == 0 {
0 as *mut u8
} else {
let ptr = heap::allocate(err.len(), 1);
if ptr.is_null() { ::oom(); }
ptr as *mut u8
};
ptr::copy(err.as_bytes().as_ptr(), alloc, err.len());
Box::new(StringError(mem::transmute(Slice {
data: alloc,
len: err.len(),
})))
}
}
}
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#![feature(unsafe_no_drop_flag, filling_drop)]
#![feature(core)]
#![feature(unique)]
#![feature(convert)]
#![cfg_attr(test, feature(test, alloc, rustc_private))]
#![cfg_attr(all(not(feature = "external_funcs"), not(feature = "external_crate")),
feature(libc))]
Expand Down
14 changes: 7 additions & 7 deletions src/librbml/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,8 @@ pub mod writer {
} else if 0x100 <= n && n < NUM_TAGS {
w.write_all(&[0xf0 | (n >> 8) as u8, n as u8])
} else {
Err(io::Error::new(io::ErrorKind::Other, "invalid tag",
Some(n.to_string())))
Err(io::Error::new(io::ErrorKind::Other,
&format!("invalid tag: {}", n)[..]))
}
}

Expand All @@ -876,7 +876,7 @@ pub mod writer {
4 => w.write_all(&[0x10 | ((n >> 24) as u8), (n >> 16) as u8,
(n >> 8) as u8, n as u8]),
_ => Err(io::Error::new(io::ErrorKind::Other,
"isize too big", Some(n.to_string())))
&format!("isize too big: {}", n)[..]))
}
}

Expand All @@ -885,8 +885,8 @@ pub mod writer {
if n < 0x4000 { return write_sized_vuint(w, n, 2); }
if n < 0x200000 { return write_sized_vuint(w, n, 3); }
if n < 0x10000000 { return write_sized_vuint(w, n, 4); }
Err(io::Error::new(io::ErrorKind::Other, "isize too big",
Some(n.to_string())))
Err(io::Error::new(io::ErrorKind::Other,
&format!("isize too big: {}", n)[..]))
}

impl<'a> Encoder<'a> {
Expand Down Expand Up @@ -1077,8 +1077,8 @@ pub mod writer {
self.wr_tagged_raw_u32(EsSub32 as usize, v)
} else {
Err(io::Error::new(io::ErrorKind::Other,
"length or variant id too big",
Some(v.to_string())))
&format!("length or variant id too big: {}",
v)[..]))
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/librustc_back/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ pub fn realpath(original: &Path) -> io::Result<PathBuf> {
let old = old_path::Path::new(original.to_str().unwrap());
match old_realpath(&old) {
Ok(p) => Ok(PathBuf::from(p.as_str().unwrap())),
Err(e) => Err(io::Error::new(io::ErrorKind::Other,
"realpath error",
Some(e.to_string())))
Err(e) => Err(io::Error::new(io::ErrorKind::Other, e))
}
}

Expand Down
1 change: 0 additions & 1 deletion src/librustc_back/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#![feature(collections)]
#![feature(core)]
#![feature(old_fs)]
#![feature(io)]
#![feature(old_io)]
#![feature(old_path)]
#![feature(rustc_private)]
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_back/target/apple_ios_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ pub fn get_sdk_root(sdk_name: &str) -> String {
Ok(String::from_utf8(output.stdout).unwrap())
} else {
let error = String::from_utf8(output.stderr);
let error = format!("process exit with error: {}",
error.unwrap());
Err(io::Error::new(io::ErrorKind::Other,
"process exit with error",
error.ok()))
&error[..]))
}
});

Expand Down
3 changes: 1 addition & 2 deletions src/librustc_back/tempdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ impl TempDir {
}

Err(Error::new(ErrorKind::AlreadyExists,
"too many temporary directories already exist",
None))
"too many temporary directories already exist"))
}

/// Attempts to make a temporary directory inside of `env::temp_dir()` whose
Expand Down
1 change: 0 additions & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#![feature(unsafe_destructor)]
#![feature(staged_api)]
#![feature(exit_status)]
#![feature(io)]
#![feature(set_stdio)]
#![feature(unicode)]

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,8 @@ fn print_flowgraph<W: Write>(variants: Vec<borrowck_dot::Variant>,

fn expand_err_details(r: io::Result<()>) -> io::Result<()> {
r.map_err(|ioerr| {
io::Error::new(io::ErrorKind::Other, "graphviz::render failed",
Some(ioerr.to_string()))
io::Error::new(io::ErrorKind::Other,
&format!("graphviz::render failed: {}", ioerr)[..])
})
}
}
2 changes: 1 addition & 1 deletion src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl fmt::Display for NulError {
impl From<NulError> for io::Error {
fn from(_: NulError) -> io::Error {
io::Error::new(io::ErrorKind::InvalidInput,
"data provided contains a nul byte", None)
"data provided contains a nul byte")
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,7 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
let to = to.as_ref();
if !from.is_file() {
return Err(Error::new(ErrorKind::InvalidInput,
"the source path is not an existing file",
None))
"the source path is not an existing file"))
}

let mut reader = try!(File::open(from));
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl<W: Write> BufWriter<W> {
match self.inner.as_mut().unwrap().write(&self.buf[written..]) {
Ok(0) => {
ret = Err(Error::new(ErrorKind::WriteZero,
"failed to write the buffered data", None));
"failed to write the buffered data"));
break;
}
Ok(n) => written += n,
Expand Down
3 changes: 1 addition & 2 deletions src/libstd/io/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ macro_rules! seek {

if pos < 0 {
Err(Error::new(ErrorKind::InvalidInput,
"invalid seek to a negative position",
None))
"invalid seek to a negative position"))
} else {
self.pos = pos as u64;
Ok(self.pos)
Expand Down
67 changes: 34 additions & 33 deletions src/libstd/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
// except according to those terms.

use boxed::Box;
use convert::Into;
use error;
use fmt;
use marker::Send;
use option::Option::{self, Some, None};
use result;
use string::String;
use sys;

/// A type for results generated by I/O related functions where the `Err` type
Expand All @@ -30,23 +31,22 @@ pub type Result<T> = result::Result<T, Error>;
/// Errors mostly originate from the underlying OS, but custom instances of
/// `Error` can be created with crafted error messages and a particular value of
/// `ErrorKind`.
#[derive(PartialEq, Eq, Clone, Debug)]
#[derive(Debug)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Error {
repr: Repr,
}

#[derive(PartialEq, Eq, Clone, Debug)]
#[derive(Debug)]
enum Repr {
Os(i32),
Custom(Box<Custom>),
}

#[derive(PartialEq, Eq, Clone, Debug)]
#[derive(Debug)]
struct Custom {
kind: ErrorKind,
desc: &'static str,
detail: Option<String>
error: Box<error::Error+Send>,
}

/// A list specifying general categories of I/O error.
Expand Down Expand Up @@ -124,18 +124,34 @@ pub enum ErrorKind {
}

impl Error {
/// Creates a new custom error from a specified kind/description/detail.
#[unstable(feature = "io", reason = "the exact makeup of an Error may
change to include `Box<Error>` for \
example")]
pub fn new(kind: ErrorKind,
description: &'static str,
detail: Option<String>) -> Error {
/// Creates a new I/O error from a known kind of error as well as an
/// arbitrary error payload.
///
/// This function is used to generically create I/O errors which do not
/// originate from the OS itself. The `error` argument is an arbitrary
/// payload which will be contained in this `Error`. Accessors as well as
/// downcasting will soon be added to this type as well to access the custom
/// information.
///
/// # Examples
///
/// ```
/// use std::io::{Error, ErrorKind};
///
/// // errors can be created from strings
/// let custom_error = Error::new(ErrorKind::Other, "oh no!");
///
/// // errors can also be created from other errors
/// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new<E>(kind: ErrorKind, error: E) -> Error
where E: Into<Box<error::Error+Send>>
{
Error {
repr: Repr::Custom(Box::new(Custom {
kind: kind,
desc: description,
detail: detail,
error: error.into(),
}))
}
}
Expand All @@ -161,8 +177,7 @@ impl Error {
///
/// If this `Error` was constructed via `last_os_error` then this function
/// will return `Some`, otherwise it will return `None`.
#[unstable(feature = "io", reason = "function was just added and the return \
type may become an abstract OS error")]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn raw_os_error(&self) -> Option<i32> {
match self.repr {
Repr::Os(i) => Some(i),
Expand All @@ -188,21 +203,7 @@ impl fmt::Display for Error {
let detail = sys::os::error_string(code);
write!(fmt, "{} (os error {})", detail, code)
}
Repr::Custom(ref c) => {
match **c {
Custom {
kind: ErrorKind::Other,
desc: "unknown error",
detail: Some(ref detail)
} => {
write!(fmt, "{}", detail)
}
Custom { detail: None, desc, .. } =>
write!(fmt, "{}", desc),
Custom { detail: Some(ref detail), desc, .. } =>
write!(fmt, "{} ({})", desc, detail)
}
}
Repr::Custom(ref c) => c.error.fmt(fmt),
}
}
}
Expand All @@ -212,7 +213,7 @@ impl error::Error for Error {
fn description(&self) -> &str {
match self.repr {
Repr::Os(..) => "os error",
Repr::Custom(ref c) => c.desc,
Repr::Custom(ref c) => c.error.description(),
}
}
}
2 changes: 1 addition & 1 deletion src/libstd/io/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl<'a> Write for &'a mut [u8] {
if try!(self.write(data)) == data.len() {
Ok(())
} else {
Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer", None))
Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer"))
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn append_to_string<F>(buf: &mut String, f: F) -> Result<usize>
if str::from_utf8(&g.s[g.len..]).is_err() {
ret.and_then(|_| {
Err(Error::new(ErrorKind::InvalidInput,
"stream did not contain valid UTF-8", None))
"stream did not contain valid UTF-8"))
})
} else {
g.len = g.s.len();
Expand Down Expand Up @@ -359,8 +359,7 @@ pub trait Write {
while buf.len() > 0 {
match self.write(buf) {
Ok(0) => return Err(Error::new(ErrorKind::WriteZero,
"failed to write whole buffer",
None)),
"failed to write whole buffer")),
Ok(n) => buf = &buf[n..],
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
Err(e) => return Err(e),
Expand Down Expand Up @@ -782,7 +781,7 @@ pub struct Chars<R> {

/// An enumeration of possible errors that can be generated from the `Chars`
/// adapter.
#[derive(PartialEq, Clone, Debug)]
#[derive(Debug)]
#[unstable(feature = "io", reason = "awaiting stability of Read::chars")]
pub enum CharsError {
/// Variant representing that the underlying stream was read successfully
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ impl ToSocketAddrs for str {
match $e {
Some(r) => r,
None => return Err(io::Error::new(io::ErrorKind::InvalidInput,
$msg, None)),
$msg)),
}
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn each_addr<A: ToSocketAddrs, F, T>(addr: A, mut f: F) -> io::Result<T>
}
Err(last_err.unwrap_or_else(|| {
Error::new(ErrorKind::InvalidInput,
"could not resolve to any addresses", None)
"could not resolve to any addresses")
}))
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl UdpSocket {
match try!(addr.to_socket_addrs()).next() {
Some(addr) => self.0.send_to(buf, &addr),
None => Err(Error::new(ErrorKind::InvalidInput,
"no addresses to send data to", None)),
"no addresses to send data to")),
}
}

Expand Down
Loading