Skip to content

Commit 51674f8

Browse files
authored
Unrolled build for rust-lang#116481
Rollup merge of rust-lang#116481 - scottmcm:tweak-combinators, r=cuviper Reuse existing `Some`s in `Option::(x)or` LLVM still has trouble re-using discriminants sometimes when rebuilding a two-variant enum, so when we have the correct variant already built, just use it. That's shorter in the Rust code, as well as simpler in MIR and the optimized LLVM, so might as well: <https://rust.godbolt.org/z/KhdE8eToW> Thanks to `@veber-alex` for pointing out this opportunity in rust-lang#101210 (comment)
2 parents 94bc9c7 + 5432d13 commit 51674f8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

library/core/src/option.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ impl<T> Option<T> {
14751475
#[stable(feature = "rust1", since = "1.0.0")]
14761476
pub fn or(self, optb: Option<T>) -> Option<T> {
14771477
match self {
1478-
Some(x) => Some(x),
1478+
x @ Some(_) => x,
14791479
None => optb,
14801480
}
14811481
}
@@ -1500,7 +1500,7 @@ impl<T> Option<T> {
15001500
F: FnOnce() -> Option<T>,
15011501
{
15021502
match self {
1503-
Some(x) => Some(x),
1503+
x @ Some(_) => x,
15041504
None => f(),
15051505
}
15061506
}
@@ -1530,8 +1530,8 @@ impl<T> Option<T> {
15301530
#[stable(feature = "option_xor", since = "1.37.0")]
15311531
pub fn xor(self, optb: Option<T>) -> Option<T> {
15321532
match (self, optb) {
1533-
(Some(a), None) => Some(a),
1534-
(None, Some(b)) => Some(b),
1533+
(a @ Some(_), None) => a,
1534+
(None, b @ Some(_)) => b,
15351535
_ => None,
15361536
}
15371537
}

0 commit comments

Comments
 (0)