diff options
| author | bors <bors@rust-lang.org> | 2020-03-29 14:48:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-03-29 14:48:58 +0000 |
| commit | 285519d412ef9c65df3bcd2de2b1a3d6ca16a255 (patch) | |
| tree | 27bae9b4daff1595d72f320e89353f4aa817391c | |
| parent | 8ab82b87af4f20b6c0a481e050517103d50263e9 (diff) | |
| parent | b851591731ef4e8017672e1e94ea55a44396d593 (diff) | |
| download | rust-285519d412ef9c65df3bcd2de2b1a3d6ca16a255.tar.gz rust-285519d412ef9c65df3bcd2de2b1a3d6ca16a255.zip | |
Auto merge of #70534 - Centril:rollup-t59tcx2, r=Centril
Rollup of 3 pull requests Successful merges: - #70140 (Add Result<Result<T, E>, E>::flatten -> Result<T, E>) - #70526 (reduce `rustc_attr` usage in places) - #70527 (Update LLVM submodule) Failed merges: r? @ghost
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | src/libcore/result.rs | 34 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/attributes.rs | 2 | ||||
| -rw-r--r-- | src/librustc_parse/Cargo.toml | 1 | ||||
| m--------- | src/llvm-project | 0 |
5 files changed, 34 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock index 3237b90a7c0..fdc84e53d12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4013,7 +4013,6 @@ dependencies = [ "log", "rustc_ast", "rustc_ast_pretty", - "rustc_attr", "rustc_data_structures", "rustc_errors", "rustc_feature", diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 0bc29e1bc66..0087b92f1f2 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -230,9 +230,9 @@ #![stable(feature = "rust1", since = "1.0.0")] -use crate::fmt; use crate::iter::{self, FromIterator, FusedIterator, TrustedLen}; use crate::ops::{self, Deref, DerefMut}; +use crate::{convert, fmt}; /// `Result` is a type that represents either success ([`Ok`]) or failure ([`Err`]). /// @@ -1214,6 +1214,38 @@ impl<T, E> Result<Option<T>, E> { } } +impl<T, E> Result<Result<T, E>, E> { + /// Converts from `Result<Result<T, E>, E>` to `Result<T, E>` + /// + /// # Examples + /// Basic usage: + /// ``` + /// #![feature(result_flattening)] + /// let x: Result<Result<&'static str, u32>, u32> = Ok(Ok("hello")); + /// assert_eq!(Ok("hello"), x.flatten()); + /// + /// let x: Result<Result<&'static str, u32>, u32> = Ok(Err(6)); + /// assert_eq!(Err(6), x.flatten()); + /// + /// let x: Result<Result<&'static str, u32>, u32> = Err(6); + /// assert_eq!(Err(6), x.flatten()); + /// ``` + /// + /// Flattening once only removes one level of nesting: + /// + /// ``` + /// #![feature(result_flattening)] + /// let x: Result<Result<Result<&'static str, u32>, u32>, u32> = Ok(Ok(Ok("hello"))); + /// assert_eq!(Ok(Ok("hello")), x.flatten()); + /// assert_eq!(Ok("hello"), x.flatten().flatten()); + /// ``` + #[inline] + #[unstable(feature = "result_flattening", issue = "70142")] + pub fn flatten(self) -> Result<T, E> { + self.and_then(convert::identity) + } +} + // This is a separate function to reduce the code size of the methods #[inline(never)] #[cold] diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs index 072607fff85..a7417685c5c 100644 --- a/src/librustc_codegen_llvm/attributes.rs +++ b/src/librustc_codegen_llvm/attributes.rs @@ -21,7 +21,7 @@ use crate::attributes; use crate::llvm::AttributePlace::Function; use crate::llvm::{self, Attribute}; use crate::llvm_util; -pub use rustc_attr::{self as attr, InlineAttr, OptimizeAttr}; +pub use rustc_attr::{InlineAttr, OptimizeAttr}; use crate::context::CodegenCx; use crate::value::Value; diff --git a/src/librustc_parse/Cargo.toml b/src/librustc_parse/Cargo.toml index b02cabab0a8..a73d30e860b 100644 --- a/src/librustc_parse/Cargo.toml +++ b/src/librustc_parse/Cargo.toml @@ -13,7 +13,6 @@ doctest = false bitflags = "1.0" log = "0.4" rustc_ast_pretty = { path = "../librustc_ast_pretty" } -rustc_attr = { path = "../librustc_attr" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_feature = { path = "../librustc_feature" } rustc_lexer = { path = "../librustc_lexer" } diff --git a/src/llvm-project b/src/llvm-project -Subproject 9f65ad057357b307180955831968f79e74090a9 +Subproject 992e608cfc5d1c126a23c640222fd396a3bdeb9 |
