Skip to content

std: Remove generics from Option::expect #14610

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

Merged
merged 1 commit into from
Jun 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
],
vec!(("".to_string(), "".to_string())),
Some("".to_string()))
.expect(format!("failed to exec `{}`", config.adb_path));
.expect(format!("failed to exec `{}`", config.adb_path).as_slice());

procsrv::run("",
config.adb_path.as_slice(),
Expand All @@ -372,7 +372,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
],
vec!(("".to_string(), "".to_string())),
Some("".to_string()))
.expect(format!("failed to exec `{}`", config.adb_path));
.expect(format!("failed to exec `{}`", config.adb_path).as_slice());

let adb_arg = format!("export LD_LIBRARY_PATH={}; \
gdbserver :5039 {}/{}",
Expand All @@ -392,7 +392,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
vec!(("".to_string(),
"".to_string())),
Some("".to_string()))
.expect(format!("failed to exec `{}`", config.adb_path));
.expect(format!("failed to exec `{}`", config.adb_path).as_slice());
loop {
//waiting 1 second for gdbserver start
timer::sleep(1000);
Expand Down Expand Up @@ -428,7 +428,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
debugger_opts.as_slice(),
vec!(("".to_string(), "".to_string())),
None)
.expect(format!("failed to exec `{}`", gdb_path));
.expect(format!("failed to exec `{}`", gdb_path).as_slice());
let cmdline = {
let cmdline = make_cmdline("",
"arm-linux-androideabi-gdb",
Expand Down Expand Up @@ -1207,7 +1207,7 @@ fn program_output(config: &Config, testfile: &Path, lib_path: &str, prog: String
prog.as_slice(),
args.as_slice(),
env,
input).expect(format!("failed to exec `{}`", prog));
input).expect(format!("failed to exec `{}`", prog).as_slice());
dump_output(config, testfile, out.as_slice(), err.as_slice());
return ProcRes {
status: status,
Expand Down Expand Up @@ -1333,7 +1333,7 @@ fn _arm_exec_compiled_test(config: &Config,
],
vec!(("".to_string(), "".to_string())),
Some("".to_string()))
.expect(format!("failed to exec `{}`", config.adb_path));
.expect(format!("failed to exec `{}`", config.adb_path).as_slice());

if config.verbose {
println!("push ({}) {} {} {}",
Expand Down Expand Up @@ -1363,7 +1363,7 @@ fn _arm_exec_compiled_test(config: &Config,
config.adb_path.as_slice(),
runargs.as_slice(),
vec!(("".to_string(), "".to_string())), Some("".to_string()))
.expect(format!("failed to exec `{}`", config.adb_path));
.expect(format!("failed to exec `{}`", config.adb_path).as_slice());

// get exitcode of result
runargs = Vec::new();
Expand All @@ -1377,7 +1377,7 @@ fn _arm_exec_compiled_test(config: &Config,
runargs.as_slice(),
vec!(("".to_string(), "".to_string())),
Some("".to_string()))
.expect(format!("failed to exec `{}`", config.adb_path));
.expect(format!("failed to exec `{}`", config.adb_path).as_slice());

let mut exitcode: int = 0;
for c in exitcode_out.as_slice().chars() {
Expand All @@ -1400,7 +1400,7 @@ fn _arm_exec_compiled_test(config: &Config,
runargs.as_slice(),
vec!(("".to_string(), "".to_string())),
Some("".to_string()))
.expect(format!("failed to exec `{}`", config.adb_path));
.expect(format!("failed to exec `{}`", config.adb_path).as_slice());

// get stderr of result
runargs = Vec::new();
Expand All @@ -1414,7 +1414,7 @@ fn _arm_exec_compiled_test(config: &Config,
runargs.as_slice(),
vec!(("".to_string(), "".to_string())),
Some("".to_string()))
.expect(format!("failed to exec `{}`", config.adb_path));
.expect(format!("failed to exec `{}`", config.adb_path).as_slice());

dump_output(config,
testfile,
Expand Down Expand Up @@ -1448,7 +1448,7 @@ fn _arm_push_aux_shared_library(config: &Config, testfile: &Path) {
vec!(("".to_string(),
"".to_string())),
Some("".to_string()))
.expect(format!("failed to exec `{}`", config.adb_path));
.expect(format!("failed to exec `{}`", config.adb_path).as_slice());

if config.verbose {
println!("push ({}) {} {} {}",
Expand Down
14 changes: 14 additions & 0 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,20 @@ impl<T> Option<T> {
// Getting to contained values
/////////////////////////////////////////////////////////////////////////

/// Unwraps an option, yielding the content of a `Some`
///
/// # Failure
///
/// Fails if the value is a `None` with a custom failure message provided by
/// `msg`.
#[inline]
pub fn expect(self, msg: &str) -> T {
match self {
Some(val) => val,
None => fail!(msg),
}
}

/// Moves a value out of an option type and returns it, consuming the `Option`.
///
/// # Failure
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ fn parse_fn_style(c: char) -> FnStyle {
fn parse_abi_set(st: &mut PState) -> abi::Abi {
assert_eq!(next(st), '[');
scan(st, |c| c == ']', |bytes| {
let abi_str = str::from_utf8(bytes).unwrap().to_string();
let abi_str = str::from_utf8(bytes).unwrap();
abi::lookup(abi_str.as_slice()).expect(abi_str)
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<'a, 'b> Reflector<'a, 'b> {
let mth_idx = ty::method_idx(token::str_to_ident(format!(
"visit_{}", ty_name).as_slice()),
self.visitor_methods.as_slice()).expect(
format!("couldn't find visit method for {}", ty_name));
format!("couldn't find visit method for {}", ty_name).as_slice());
let mth_ty =
ty::mk_bare_fn(tcx,
self.visitor_methods[mth_idx].fty.clone());
Expand Down
1 change: 0 additions & 1 deletion src/libstd/io/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use comm::Receiver;
use io::IoResult;
use kinds::Send;
use owned::Box;
use option::Expect;
use rt::rtio::{IoFactory, LocalIo, RtioTimer};

/// A synchronous timer object
Expand Down
5 changes: 1 addition & 4 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ pub use core::simd;
pub use core::tuple;
#[cfg(not(test))] pub use core::ty;
pub use core::result;
pub use core::option;

pub use alloc::owned;
pub use alloc::rc;
Expand Down Expand Up @@ -219,10 +220,6 @@ pub mod num;
pub mod to_str;
pub mod hash;

/* Common data structures */

pub mod option;

/* Tasks and communication */

pub mod task;
Expand Down
170 changes: 0 additions & 170 deletions src/libstd/option.rs

This file was deleted.

4 changes: 1 addition & 3 deletions src/libstd/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ pub fn getcwd() -> Path {
pub fn getcwd() -> Path {
use libc::DWORD;
use libc::GetCurrentDirectoryW;
use option::Expect;

let mut buf = [0 as u16, ..BUF_BYTES];
unsafe {
Expand All @@ -101,7 +100,7 @@ pub fn getcwd() -> Path {
pub mod win32 {
use libc::types::os::arch::extra::DWORD;
use libc;
use option::{None, Option, Expect};
use option::{None, Option};
use option;
use os::TMPBUF_SZ;
use slice::{MutableVector, ImmutableVector};
Expand Down Expand Up @@ -924,7 +923,6 @@ fn real_args() -> Vec<String> {
#[cfg(windows)]
fn real_args() -> Vec<String> {
use slice;
use option::Expect;

let mut nArgs: c_int = 0;
let lpArgCount: *mut c_int = &mut nArgs;
Expand Down
1 change: 0 additions & 1 deletion src/libstd/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
#[doc(no_inline)] pub use num::{Num, NumCast, CheckedAdd, CheckedSub, CheckedMul};
#[doc(no_inline)] pub use num::{Signed, Unsigned, Primitive, Int, Float};
#[doc(no_inline)] pub use num::{FloatMath, ToPrimitive, FromPrimitive};
#[doc(no_inline)] pub use option::Expect;
#[doc(no_inline)] pub use owned::Box;
#[doc(no_inline)] pub use path::{GenericPath, Path, PosixPath, WindowsPath};
#[doc(no_inline)] pub use ptr::RawPtr;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/rt/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! Runtime environment settings

use from_str::from_str;
use option::{Some, None, Expect};
use option::{Some, None};
use os;
use str::Str;

Expand Down
1 change: 0 additions & 1 deletion src/libstd/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
fn to_owned(&self) -> ~[T] {
use RawVec = core::raw::Vec;
use num::{CheckedAdd, CheckedMul};
use option::Expect;

let len = self.len();
let data_size = len.checked_mul(&mem::size_of::<T>());
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use mem;
use num::{CheckedMul, CheckedAdd};
use num;
use ops::{Add, Drop};
use option::{None, Option, Some, Expect};
use option::{None, Option, Some};
use ptr::RawPtr;
use ptr;
use raw::Slice;
Expand Down