Skip to content

Commit

Permalink
Auto merge of #70534 - Centril:rollup-t59tcx2, r=Centril
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Mar 29, 2020
2 parents 8ab82b8 + b851591 commit 285519d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4013,7 +4013,6 @@ dependencies = [
"log",
"rustc_ast",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
Expand Down
34 changes: 33 additions & 1 deletion src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`]).
///
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/librustc_parse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion src/llvm-project

0 comments on commit 285519d

Please sign in to comment.