Skip to content

Commit 3c1b8c4

Browse files
committed
---
yaml --- r: 274162 b: refs/heads/stable c: 257bff3 h: refs/heads/master
1 parent 2941eca commit 3c1b8c4

File tree

3 files changed

+19
-29
lines changed

3 files changed

+19
-29
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: c0221c8897db309a79990367476177b1230bb264
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 30be6a666d3918b3a149ff2c2c3242c9b1912655
32+
refs/heads/stable: 257bff3192e2c7313a4f8cfcac8839a573b42f6b
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/libcore/option.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,16 +295,10 @@ impl<T> Option<T> {
295295
pub fn expect(self, msg: &str) -> T {
296296
match self {
297297
Some(val) => val,
298-
None => Self::expect_failed(msg),
298+
None => expect_failed(msg),
299299
}
300300
}
301301

302-
#[inline(never)]
303-
#[cold]
304-
fn expect_failed(msg: &str) -> ! {
305-
panic!("{}", msg)
306-
}
307-
308302
/// Moves the value `v` out of the `Option<T>` if it is `Some(v)`.
309303
///
310304
/// # Panics
@@ -703,6 +697,14 @@ impl<T: Default> Option<T> {
703697
}
704698
}
705699

700+
// This is a separate function to reduce the code size of .expect() itself.
701+
#[inline(never)]
702+
#[cold]
703+
fn expect_failed(msg: &str) -> ! {
704+
panic!("{}", msg)
705+
}
706+
707+
706708
/////////////////////////////////////////////////////////////////////////////
707709
// Trait implementations
708710
/////////////////////////////////////////////////////////////////////////////

branches/stable/src/libcore/result.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -684,16 +684,10 @@ impl<T, E: fmt::Debug> Result<T, E> {
684684
pub fn unwrap(self) -> T {
685685
match self {
686686
Ok(t) => t,
687-
Err(e) => Self::unwrap_failed(e),
687+
Err(e) => unwrap_failed("called `Result::unwrap()` on an `Err` value", e),
688688
}
689689
}
690690

691-
#[inline(never)]
692-
#[cold]
693-
fn unwrap_failed(error: E) -> ! {
694-
panic!("called `Result::unwrap()` on an `Err` value: {:?}", error)
695-
}
696-
697691
/// Unwraps a result, yielding the content of an `Ok`.
698692
///
699693
/// # Panics
@@ -711,15 +705,9 @@ impl<T, E: fmt::Debug> Result<T, E> {
711705
pub fn expect(self, msg: &str) -> T {
712706
match self {
713707
Ok(t) => t,
714-
Err(e) => Self::expect_failed(msg, e),
708+
Err(e) => unwrap_failed(msg, e),
715709
}
716710
}
717-
718-
#[inline(never)]
719-
#[cold]
720-
fn expect_failed(msg: &str, error: E) -> ! {
721-
panic!("{}: {:?}", msg, error)
722-
}
723711
}
724712

725713
impl<T: fmt::Debug, E> Result<T, E> {
@@ -745,17 +733,17 @@ impl<T: fmt::Debug, E> Result<T, E> {
745733
#[stable(feature = "rust1", since = "1.0.0")]
746734
pub fn unwrap_err(self) -> E {
747735
match self {
748-
Ok(t) => Self::unwrap_err_failed(t),
736+
Ok(t) => unwrap_failed("called `Result::unwrap_err()` on an `Ok` value", t),
749737
Err(e) => e,
750738
}
751739
}
740+
}
752741

753-
#[inline(never)]
754-
#[cold]
755-
fn unwrap_err_failed(t: T) -> ! {
756-
panic!("called `Result::unwrap_err()` on an `Ok` value: {:?}", t)
757-
}
758-
742+
// This is a separate function to reduce the code size of the methods
743+
#[inline(never)]
744+
#[cold]
745+
fn unwrap_failed<E: fmt::Debug>(msg: &str, error: E) -> ! {
746+
panic!("{}: {:?}", msg, error)
759747
}
760748

761749
/////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)