X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibcore%2Foption.rs;h=cb4247d98745eb8e52af0fd9e2de8de382cd54b0;hb=94aa655a3c7a9dde612b5e65e5e8ec3c57d143a3;hp=2066a484dac8091a3a294227c15093dca5e4d403;hpb=9ae7fb3e712e6aa166a543fbf69ecb3df0b90052;p=rust.git diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 2066a484dac..cb4247d9874 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -151,6 +151,7 @@ /// The `Option` type. See [the module level documentation](index.html) for more. #[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] +#[rustc_diagnostic_item = "option_type"] #[stable(feature = "rust1", since = "1.0.0")] pub enum Option { /// No value @@ -187,10 +188,7 @@ impl Option { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_some(&self) -> bool { - match *self { - Some(_) => true, - None => false, - } + matches!(*self, Some(_)) } /// Returns `true` if the option is a [`None`] value. @@ -341,6 +339,7 @@ pub fn as_pin_mut(self: Pin<&mut Self>) -> Option> { /// 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 +373,7 @@ pub fn expect(self, msg: &str) -> 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 +1015,7 @@ impl Option { /// } /// ``` #[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 +1058,7 @@ pub fn expect_none(self, msg: &str) { /// } /// ``` #[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 +1186,7 @@ pub fn transpose(self) -> Result, 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 +1194,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) }