Skip to content

Commit 285519d

Browse files
committed
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
2 parents 8ab82b8 + b851591 commit 285519d

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -4013,7 +4013,6 @@ dependencies = [
40134013
"log",
40144014
"rustc_ast",
40154015
"rustc_ast_pretty",
4016-
"rustc_attr",
40174016
"rustc_data_structures",
40184017
"rustc_errors",
40194018
"rustc_feature",

src/libcore/result.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@
230230
231231
#![stable(feature = "rust1", since = "1.0.0")]
232232

233-
use crate::fmt;
234233
use crate::iter::{self, FromIterator, FusedIterator, TrustedLen};
235234
use crate::ops::{self, Deref, DerefMut};
235+
use crate::{convert, fmt};
236236

237237
/// `Result` is a type that represents either success ([`Ok`]) or failure ([`Err`]).
238238
///
@@ -1214,6 +1214,38 @@ impl<T, E> Result<Option<T>, E> {
12141214
}
12151215
}
12161216

1217+
impl<T, E> Result<Result<T, E>, E> {
1218+
/// Converts from `Result<Result<T, E>, E>` to `Result<T, E>`
1219+
///
1220+
/// # Examples
1221+
/// Basic usage:
1222+
/// ```
1223+
/// #![feature(result_flattening)]
1224+
/// let x: Result<Result<&'static str, u32>, u32> = Ok(Ok("hello"));
1225+
/// assert_eq!(Ok("hello"), x.flatten());
1226+
///
1227+
/// let x: Result<Result<&'static str, u32>, u32> = Ok(Err(6));
1228+
/// assert_eq!(Err(6), x.flatten());
1229+
///
1230+
/// let x: Result<Result<&'static str, u32>, u32> = Err(6);
1231+
/// assert_eq!(Err(6), x.flatten());
1232+
/// ```
1233+
///
1234+
/// Flattening once only removes one level of nesting:
1235+
///
1236+
/// ```
1237+
/// #![feature(result_flattening)]
1238+
/// let x: Result<Result<Result<&'static str, u32>, u32>, u32> = Ok(Ok(Ok("hello")));
1239+
/// assert_eq!(Ok(Ok("hello")), x.flatten());
1240+
/// assert_eq!(Ok("hello"), x.flatten().flatten());
1241+
/// ```
1242+
#[inline]
1243+
#[unstable(feature = "result_flattening", issue = "70142")]
1244+
pub fn flatten(self) -> Result<T, E> {
1245+
self.and_then(convert::identity)
1246+
}
1247+
}
1248+
12171249
// This is a separate function to reduce the code size of the methods
12181250
#[inline(never)]
12191251
#[cold]

src/librustc_codegen_llvm/attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::attributes;
2121
use crate::llvm::AttributePlace::Function;
2222
use crate::llvm::{self, Attribute};
2323
use crate::llvm_util;
24-
pub use rustc_attr::{self as attr, InlineAttr, OptimizeAttr};
24+
pub use rustc_attr::{InlineAttr, OptimizeAttr};
2525

2626
use crate::context::CodegenCx;
2727
use crate::value::Value;

src/librustc_parse/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ doctest = false
1313
bitflags = "1.0"
1414
log = "0.4"
1515
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
16-
rustc_attr = { path = "../librustc_attr" }
1716
rustc_data_structures = { path = "../librustc_data_structures" }
1817
rustc_feature = { path = "../librustc_feature" }
1918
rustc_lexer = { path = "../librustc_lexer" }

0 commit comments

Comments
 (0)