未验证 提交 89fbed98 编写于 作者: M Mazdak Farrokhzad 提交者: GitHub

Rollup merge of #67685 - lukaslueg:const_result, r=oli-obk

Constify Result

r? @oli-obk

This is just the `Result`-part of #67494 which I'll resubmit once #66254 has landed.
......@@ -76,6 +76,7 @@
#![feature(const_fn_union)]
#![feature(const_generics)]
#![feature(const_ptr_offset_from)]
#![feature(const_result)]
#![feature(const_type_name)]
#![feature(custom_inner_attributes)]
#![feature(decl_macro)]
......
......@@ -278,9 +278,10 @@ impl<T, E> Result<T, E> {
/// assert_eq!(x.is_ok(), false);
/// ```
#[must_use = "if you intended to assert that this is ok, consider `.unwrap()` instead"]
#[rustc_const_unstable(feature = "const_result", issue = "67520")]
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_ok(&self) -> bool {
pub const fn is_ok(&self) -> bool {
match *self {
Ok(_) => true,
Err(_) => false,
......@@ -303,9 +304,10 @@ pub fn is_ok(&self) -> bool {
/// assert_eq!(x.is_err(), true);
/// ```
#[must_use = "if you intended to assert that this is err, consider `.unwrap_err()` instead"]
#[rustc_const_unstable(feature = "const_result", issue = "67520")]
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_err(&self) -> bool {
pub const fn is_err(&self) -> bool {
!self.is_ok()
}
......@@ -446,8 +448,9 @@ pub fn err(self) -> Option<E> {
/// assert_eq!(x.as_ref(), Err(&"Error"));
/// ```
#[inline]
#[rustc_const_unstable(feature = "const_result", issue = "67520")]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn as_ref(&self) -> Result<&T, &E> {
pub const fn as_ref(&self) -> Result<&T, &E> {
match *self {
Ok(ref x) => Ok(x),
Err(ref x) => Err(x),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册