Skip to content

Commit

Permalink
Auto merge of #109357 - saethlin:inline-as-deref, r=thomcc
Browse files Browse the repository at this point in the history
Add #[inline] to as_deref

While working on #109247 I found an `as_deref` call in the compiler that should have been inlined. This fixes the missing inlining (but doesn't address the perf issues I was chasing).

r? `@thomcc`
  • Loading branch information
bors committed Mar 26, 2023
2 parents 89c2e3d + d3352de commit db0cbc4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,7 @@ impl<T> Option<T> {
/// let x: Option<String> = None;
/// assert_eq!(x.as_deref(), None);
/// ```
#[inline]
#[stable(feature = "option_deref", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
pub const fn as_deref(&self) -> Option<&T::Target>
Expand All @@ -1300,6 +1301,7 @@ impl<T> Option<T> {
/// x
/// }), Some("HEY".to_owned().as_mut_str()));
/// ```
#[inline]
#[stable(feature = "option_deref", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
pub const fn as_deref_mut(&mut self) -> Option<&mut T::Target>
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ impl<T, E> Result<T, E> {
/// let y: Result<&str, &u32> = Err(&42);
/// assert_eq!(x.as_deref(), y);
/// ```
#[inline]
#[stable(feature = "inner_deref", since = "1.47.0")]
pub fn as_deref(&self) -> Result<&T::Target, &E>
where
Expand All @@ -934,6 +935,7 @@ impl<T, E> Result<T, E> {
/// let y: Result<&mut str, &mut u32> = Err(&mut i);
/// assert_eq!(x.as_deref_mut().map(|x| { x.make_ascii_uppercase(); x }), y);
/// ```
#[inline]
#[stable(feature = "inner_deref", since = "1.47.0")]
pub fn as_deref_mut(&mut self) -> Result<&mut T::Target, &mut E>
where
Expand Down

0 comments on commit db0cbc4

Please sign in to comment.