Skip to content

Commit

Permalink
Rollup merge of rust-lang#107987 - EFanZh:inline-poll-methods, r=Mark…
Browse files Browse the repository at this point in the history
…-Simulacrum

Inline `Poll` methods

With `opt-level="z"`, the `Poll::map*` methods are sometimes not inlined (see <https://godbolt.org/z/ca5ajKTEK>). This PR adds `#[inline]` to these methods. I have a project that can benefit from this change, but do we want to enable this behavior universally?

Fixes rust-lang#101080.
  • Loading branch information
compiler-errors committed Feb 26, 2023
2 parents d962ea5 + 4bb0a5e commit 09776a3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions library/core/src/task/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl<T> Poll<T> {
/// assert_eq!(poll_some_len, Poll::Ready(13));
/// ```
#[stable(feature = "futures_api", since = "1.36.0")]
#[inline]
pub fn map<U, F>(self, f: F) -> Poll<U>
where
F: FnOnce(T) -> U,
Expand Down Expand Up @@ -144,6 +145,7 @@ impl<T, E> Poll<Result<T, E>> {
/// assert_eq!(squared, Poll::Ready(Ok(144)));
/// ```
#[stable(feature = "futures_api", since = "1.36.0")]
#[inline]
pub fn map_ok<U, F>(self, f: F) -> Poll<Result<U, E>>
where
F: FnOnce(T) -> U,
Expand Down Expand Up @@ -171,6 +173,7 @@ impl<T, E> Poll<Result<T, E>> {
/// assert_eq!(res, Poll::Ready(Err(0)));
/// ```
#[stable(feature = "futures_api", since = "1.36.0")]
#[inline]
pub fn map_err<U, F>(self, f: F) -> Poll<Result<T, U>>
where
F: FnOnce(E) -> U,
Expand Down Expand Up @@ -199,6 +202,7 @@ impl<T, E> Poll<Option<Result<T, E>>> {
/// assert_eq!(squared, Poll::Ready(Some(Ok(144))));
/// ```
#[stable(feature = "poll_map", since = "1.51.0")]
#[inline]
pub fn map_ok<U, F>(self, f: F) -> Poll<Option<Result<U, E>>>
where
F: FnOnce(T) -> U,
Expand Down Expand Up @@ -228,6 +232,7 @@ impl<T, E> Poll<Option<Result<T, E>>> {
/// assert_eq!(res, Poll::Ready(Some(Err(0))));
/// ```
#[stable(feature = "poll_map", since = "1.51.0")]
#[inline]
pub fn map_err<U, F>(self, f: F) -> Poll<Option<Result<T, U>>>
where
F: FnOnce(E) -> U,
Expand Down

0 comments on commit 09776a3

Please sign in to comment.