Skip to content

Commit 422d54b

Browse files
committed
auto merge of #14610 : alexcrichton/rust/issue-14008, r=brson
This commit removes the <M: Any + Send> type parameter from Option::expect in favor of just taking a hard-coded `&str` argument. This allows this function to move into libcore. Previous code using strings with `expect` will continue to work, but code using this implicitly to transmit task failure will need to unwrap manually with a `match` statement. [breaking-change] Closes #14008
2 parents 193574a + 896cfcc commit 422d54b

File tree

12 files changed

+31
-195
lines changed

12 files changed

+31
-195
lines changed

src/compiletest/runtest.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
361361
],
362362
vec!(("".to_string(), "".to_string())),
363363
Some("".to_string()))
364-
.expect(format!("failed to exec `{}`", config.adb_path));
364+
.expect(format!("failed to exec `{}`", config.adb_path).as_slice());
365365

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

377377
let adb_arg = format!("export LD_LIBRARY_PATH={}; \
378378
gdbserver :5039 {}/{}",
@@ -392,7 +392,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
392392
vec!(("".to_string(),
393393
"".to_string())),
394394
Some("".to_string()))
395-
.expect(format!("failed to exec `{}`", config.adb_path));
395+
.expect(format!("failed to exec `{}`", config.adb_path).as_slice());
396396
loop {
397397
//waiting 1 second for gdbserver start
398398
timer::sleep(1000);
@@ -428,7 +428,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
428428
debugger_opts.as_slice(),
429429
vec!(("".to_string(), "".to_string())),
430430
None)
431-
.expect(format!("failed to exec `{}`", gdb_path));
431+
.expect(format!("failed to exec `{}`", gdb_path).as_slice());
432432
let cmdline = {
433433
let cmdline = make_cmdline("",
434434
"arm-linux-androideabi-gdb",
@@ -1207,7 +1207,7 @@ fn program_output(config: &Config, testfile: &Path, lib_path: &str, prog: String
12071207
prog.as_slice(),
12081208
args.as_slice(),
12091209
env,
1210-
input).expect(format!("failed to exec `{}`", prog));
1210+
input).expect(format!("failed to exec `{}`", prog).as_slice());
12111211
dump_output(config, testfile, out.as_slice(), err.as_slice());
12121212
return ProcRes {
12131213
status: status,
@@ -1333,7 +1333,7 @@ fn _arm_exec_compiled_test(config: &Config,
13331333
],
13341334
vec!(("".to_string(), "".to_string())),
13351335
Some("".to_string()))
1336-
.expect(format!("failed to exec `{}`", config.adb_path));
1336+
.expect(format!("failed to exec `{}`", config.adb_path).as_slice());
13371337

13381338
if config.verbose {
13391339
println!("push ({}) {} {} {}",
@@ -1363,7 +1363,7 @@ fn _arm_exec_compiled_test(config: &Config,
13631363
config.adb_path.as_slice(),
13641364
runargs.as_slice(),
13651365
vec!(("".to_string(), "".to_string())), Some("".to_string()))
1366-
.expect(format!("failed to exec `{}`", config.adb_path));
1366+
.expect(format!("failed to exec `{}`", config.adb_path).as_slice());
13671367

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

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

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

14191419
dump_output(config,
14201420
testfile,
@@ -1448,7 +1448,7 @@ fn _arm_push_aux_shared_library(config: &Config, testfile: &Path) {
14481448
vec!(("".to_string(),
14491449
"".to_string())),
14501450
Some("".to_string()))
1451-
.expect(format!("failed to exec `{}`", config.adb_path));
1451+
.expect(format!("failed to exec `{}`", config.adb_path).as_slice());
14521452

14531453
if config.verbose {
14541454
println!("push ({}) {} {} {}",

src/libcore/option.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,20 @@ impl<T> Option<T> {
233233
// Getting to contained values
234234
/////////////////////////////////////////////////////////////////////////
235235

236+
/// Unwraps an option, yielding the content of a `Some`
237+
///
238+
/// # Failure
239+
///
240+
/// Fails if the value is a `None` with a custom failure message provided by
241+
/// `msg`.
242+
#[inline]
243+
pub fn expect(self, msg: &str) -> T {
244+
match self {
245+
Some(val) => val,
246+
None => fail!(msg),
247+
}
248+
}
249+
236250
/// Moves a value out of an option type and returns it, consuming the `Option`.
237251
///
238252
/// # Failure

src/librustc/metadata/tydecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ fn parse_fn_style(c: char) -> FnStyle {
451451
fn parse_abi_set(st: &mut PState) -> abi::Abi {
452452
assert_eq!(next(st), '[');
453453
scan(st, |c| c == ']', |bytes| {
454-
let abi_str = str::from_utf8(bytes).unwrap().to_string();
454+
let abi_str = str::from_utf8(bytes).unwrap();
455455
abi::lookup(abi_str.as_slice()).expect(abi_str)
456456
})
457457
}

src/librustc/middle/trans/reflect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<'a, 'b> Reflector<'a, 'b> {
9090
let mth_idx = ty::method_idx(token::str_to_ident(format!(
9191
"visit_{}", ty_name).as_slice()),
9292
self.visitor_methods.as_slice()).expect(
93-
format!("couldn't find visit method for {}", ty_name));
93+
format!("couldn't find visit method for {}", ty_name).as_slice());
9494
let mth_ty =
9595
ty::mk_bare_fn(tcx,
9696
self.visitor_methods[mth_idx].fty.clone());

src/libstd/io/timer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use comm::Receiver;
2121
use io::IoResult;
2222
use kinds::Send;
2323
use owned::Box;
24-
use option::Expect;
2524
use rt::rtio::{IoFactory, LocalIo, RtioTimer};
2625

2726
/// A synchronous timer object

src/libstd/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ pub use core::simd;
155155
pub use core::tuple;
156156
#[cfg(not(test))] pub use core::ty;
157157
pub use core::result;
158+
pub use core::option;
158159

159160
pub use alloc::owned;
160161
pub use alloc::rc;
@@ -219,10 +220,6 @@ pub mod num;
219220
pub mod to_str;
220221
pub mod hash;
221222

222-
/* Common data structures */
223-
224-
pub mod option;
225-
226223
/* Tasks and communication */
227224

228225
pub mod task;

src/libstd/option.rs

Lines changed: 0 additions & 170 deletions
This file was deleted.

src/libstd/os.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ pub fn getcwd() -> Path {
8585
pub fn getcwd() -> Path {
8686
use libc::DWORD;
8787
use libc::GetCurrentDirectoryW;
88-
use option::Expect;
8988

9089
let mut buf = [0 as u16, ..BUF_BYTES];
9190
unsafe {
@@ -101,7 +100,7 @@ pub fn getcwd() -> Path {
101100
pub mod win32 {
102101
use libc::types::os::arch::extra::DWORD;
103102
use libc;
104-
use option::{None, Option, Expect};
103+
use option::{None, Option};
105104
use option;
106105
use os::TMPBUF_SZ;
107106
use slice::{MutableVector, ImmutableVector};
@@ -924,7 +923,6 @@ fn real_args() -> Vec<String> {
924923
#[cfg(windows)]
925924
fn real_args() -> Vec<String> {
926925
use slice;
927-
use option::Expect;
928926

929927
let mut nArgs: c_int = 0;
930928
let lpArgCount: *mut c_int = &mut nArgs;

src/libstd/prelude.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
#[doc(no_inline)] pub use num::{Num, NumCast, CheckedAdd, CheckedSub, CheckedMul};
7070
#[doc(no_inline)] pub use num::{Signed, Unsigned, Primitive, Int, Float};
7171
#[doc(no_inline)] pub use num::{FloatMath, ToPrimitive, FromPrimitive};
72-
#[doc(no_inline)] pub use option::Expect;
7372
#[doc(no_inline)] pub use owned::Box;
7473
#[doc(no_inline)] pub use path::{GenericPath, Path, PosixPath, WindowsPath};
7574
#[doc(no_inline)] pub use ptr::RawPtr;

src/libstd/rt/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! Runtime environment settings
1212
1313
use from_str::from_str;
14-
use option::{Some, None, Expect};
14+
use option::{Some, None};
1515
use os;
1616
use str::Str;
1717

src/libstd/slice.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
296296
fn to_owned(&self) -> ~[T] {
297297
use RawVec = core::raw::Vec;
298298
use num::{CheckedAdd, CheckedMul};
299-
use option::Expect;
300299

301300
let len = self.len();
302301
let data_size = len.checked_mul(&mem::size_of::<T>());

src/libstd/vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use mem;
2121
use num::{CheckedMul, CheckedAdd};
2222
use num;
2323
use ops::{Add, Drop};
24-
use option::{None, Option, Some, Expect};
24+
use option::{None, Option, Some};
2525
use ptr::RawPtr;
2626
use ptr;
2727
use raw::Slice;

0 commit comments

Comments
 (0)