diff options
| author | Adam Perry <adam.n.perry@gmail.com> | 2020-01-04 19:30:44 -0800 |
|---|---|---|
| committer | Adam Perry <adam.n.perry@gmail.com> | 2020-01-04 19:52:37 -0800 |
| commit | 2e9d573d3f6bc9808e01cef914084fac15f42cc2 (patch) | |
| tree | f8c69760319e92f9afc123d7c61996f2f98c7984 /src/libcore | |
| parent | 760ce94c69ca510d44087291c311296f6d9ccdf5 (diff) | |
Option's panics are all #[track_caller].
Also includes a simple test with a custom panic hook to ensure we don't regress.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/option.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 2066a484dac..fb534586fc6 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -341,6 +341,7 @@ impl<T> Option<T> { /// x.expect("the world is ending"); // panics with `the world is ending` /// ``` #[inline] + #[track_caller] #[stable(feature = "rust1", since = "1.0.0")] pub fn expect(self, msg: &str) -> T { match self { @@ -374,6 +375,7 @@ impl<T> Option<T> { /// assert_eq!(x.unwrap(), "air"); // fails /// ``` #[inline] + #[track_caller] #[stable(feature = "rust1", since = "1.0.0")] pub fn unwrap(self) -> T { match self { @@ -1015,6 +1017,7 @@ impl<T: fmt::Debug> Option<T> { /// } /// ``` #[inline] + #[track_caller] #[unstable(feature = "option_expect_none", reason = "newly added", issue = "62633")] pub fn expect_none(self, msg: &str) { if let Some(val) = self { @@ -1057,6 +1060,7 @@ impl<T: fmt::Debug> Option<T> { /// } /// ``` #[inline] + #[track_caller] #[unstable(feature = "option_unwrap_none", reason = "newly added", issue = "62633")] pub fn unwrap_none(self) { if let Some(val) = self { @@ -1184,6 +1188,7 @@ impl<T, E> Option<Result<T, E>> { // This is a separate function to reduce the code size of .expect() itself. #[inline(never)] #[cold] +#[track_caller] fn expect_failed(msg: &str) -> ! { panic!("{}", msg) } @@ -1191,6 +1196,7 @@ fn expect_failed(msg: &str) -> ! { // This is a separate function to reduce the code size of .expect_none() itself. #[inline(never)] #[cold] +#[track_caller] fn expect_none_failed(msg: &str, value: &dyn fmt::Debug) -> ! { panic!("{}: {:?}", msg, value) } |
