Skip to content

Commit 87aece9

Browse files
committed
Auto merge of rust-lang#119878 - scottmcm:inline-always-unwrap, r=workingjubilee
Tune the inlinability of `unwrap` Fixes rust-lang#115463 cc `@thomcc` This tweaks `unwrap` on ~~`Option` &~~ `Result` to be two parts: - `#[inline(always)]` for checking the discriminant - `#[cold]` for actually panicking The idea here is that checking the discriminant on a `Result` ~~or `Option`~~ should always be trivial enough to be worth inlining, even in `opt-level=z`, especially compared to passing it to a function. As seen in the issue and codegen test, this will hopefully help particularly for things like `.try_into().unwrap()`s that are actually infallible, but in a way that's only visible with the inlining. EDIT: I've restricted this to `Result` to avoid combining effects
2 parents a4079c9 + 5953e82 commit 87aece9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

core/src/result.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ impl<T, E> Result<T, E> {
10611061
/// let x: Result<u32, &str> = Err("emergency failure");
10621062
/// x.unwrap(); // panics with `emergency failure`
10631063
/// ```
1064-
#[inline]
1064+
#[inline(always)]
10651065
#[track_caller]
10661066
#[stable(feature = "rust1", since = "1.0.0")]
10671067
pub fn unwrap(self) -> T

0 commit comments

Comments
 (0)