Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Result's panics have #[track_caller].
  • Loading branch information
anp committed Jan 5, 2020
commit 7a6af7eb0ef685c2dfd907f7e76a876174c9f665
5 changes: 5 additions & 0 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@ impl<T, E: fmt::Debug> Result<T, E> {
/// x.unwrap(); // panics with `emergency failure`
/// ```
#[inline]
#[track_caller]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap(self) -> T {
match self {
Expand Down Expand Up @@ -984,6 +985,7 @@ impl<T, E: fmt::Debug> Result<T, E> {
/// x.expect("Testing expect"); // panics with `Testing expect: emergency failure`
/// ```
#[inline]
#[track_caller]
#[stable(feature = "result_expect", since = "1.4.0")]
pub fn expect(self, msg: &str) -> T {
match self {
Expand Down Expand Up @@ -1017,6 +1019,7 @@ impl<T: fmt::Debug, E> Result<T, E> {
/// assert_eq!(x.unwrap_err(), "emergency failure");
/// ```
#[inline]
#[track_caller]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap_err(self) -> E {
match self {
Expand Down Expand Up @@ -1044,6 +1047,7 @@ impl<T: fmt::Debug, E> Result<T, E> {
/// x.expect_err("Testing expect_err"); // panics with `Testing expect_err: 10`
/// ```
#[inline]
#[track_caller]
#[stable(feature = "result_expect_err", since = "1.17.0")]
pub fn expect_err(self, msg: &str) -> E {
match self {
Expand Down Expand Up @@ -1188,6 +1192,7 @@ impl<T, E> Result<Option<T>, E> {
// This is a separate function to reduce the code size of the methods
#[inline(never)]
#[cold]
#[track_caller]
fn unwrap_failed(msg: &str, error: &dyn fmt::Debug) -> ! {
panic!("{}: {:?}", msg, error)
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/rfc-2091-track-caller/std-panic-locations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ fn main() {
let yep: Option<()> = Some(());
assert_panicked(|| yep.unwrap_none());
assert_panicked(|| yep.expect_none(""));

let oops: Result<(), ()> = Err(());
assert_panicked(|| oops.unwrap());
assert_panicked(|| oops.expect(""));

let fine: Result<(), ()> = Ok(());
assert_panicked(|| fine.unwrap_err());
assert_panicked(|| fine.expect_err(""));
}