Skip to content

Commit f471a93

Browse files
committed
Auto merge of #124737 - alion02:litter-less, r=<try>
[Experiment] Replace `unreachable_unchecked()` with `uninit().assume_init()` in `unwrap_unchecked()` [Relevant ACP.](rust-lang/libs-team#378) [Relevant godbolt.](https://godbolt.org/z/WqfcT7Ys9) Attempt to clean up the LLVM IR we generate based on the assumption that we usually don't want to `assume` the value of the discriminant (because it sticks around in the IR and randomly inhibits optimizations).
2 parents 69ffc0d + fd98988 commit f471a93

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

library/core/src/option.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ use crate::iter::{self, FusedIterator, TrustedLen};
557557
use crate::panicking::{panic, panic_display};
558558
use crate::pin::Pin;
559559
use crate::{
560-
cmp, convert, hint, mem,
560+
cmp, convert, mem,
561561
ops::{self, ControlFlow, Deref, DerefMut},
562562
slice,
563563
};
@@ -1037,7 +1037,7 @@ impl<T> Option<T> {
10371037
match self {
10381038
Some(val) => val,
10391039
// SAFETY: the safety contract must be upheld by the caller.
1040-
None => unsafe { hint::unreachable_unchecked() },
1040+
None => unsafe { mem::MaybeUninit::uninit().assume_init() },
10411041
}
10421042
}
10431043

library/core/src/result.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@
490490

491491
use crate::iter::{self, FusedIterator, TrustedLen};
492492
use crate::ops::{self, ControlFlow, Deref, DerefMut};
493-
use crate::{convert, fmt, hint};
493+
use crate::{convert, fmt, mem};
494494

495495
/// `Result` is a type that represents either success ([`Ok`]) or failure ([`Err`]).
496496
///
@@ -1460,7 +1460,7 @@ impl<T, E> Result<T, E> {
14601460
match self {
14611461
Ok(t) => t,
14621462
// SAFETY: the safety contract must be upheld by the caller.
1463-
Err(_) => unsafe { hint::unreachable_unchecked() },
1463+
Err(_) => unsafe { mem::MaybeUninit::uninit().assume_init() },
14641464
}
14651465
}
14661466

@@ -1491,7 +1491,7 @@ impl<T, E> Result<T, E> {
14911491
debug_assert!(self.is_err());
14921492
match self {
14931493
// SAFETY: the safety contract must be upheld by the caller.
1494-
Ok(_) => unsafe { hint::unreachable_unchecked() },
1494+
Ok(_) => unsafe { mem::MaybeUninit::uninit().assume_init() },
14951495
Err(e) => e,
14961496
}
14971497
}

0 commit comments

Comments
 (0)