Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make Result::copied unstably const #130090

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,7 @@ impl<T> Option<&T> {
where
T: Copy,
{
// FIXME: this implementation, which sidesteps using `Option::map` since it's not const
// FIXME(const-hack): this implementation, which sidesteps using `Option::map` since it's not const
// ready yet, should be reverted when possible to avoid code repetition
match self {
Some(&v) => Some(v),
Expand Down Expand Up @@ -1942,7 +1942,7 @@ impl<T> Option<&mut T> {
/// ```
#[must_use = "`self` will be dropped if the result is not used"]
#[stable(feature = "copied", since = "1.35.0")]
#[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
pub const fn copied(self) -> Option<T>
where
T: Copy,
Expand Down
20 changes: 16 additions & 4 deletions library/core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1535,11 +1535,17 @@ impl<T, E> Result<&T, E> {
/// ```
#[inline]
#[stable(feature = "result_copied", since = "1.59.0")]
pub fn copied(self) -> Result<T, E>
#[rustc_const_unstable(feature = "const_result", issue = "82814")]
pub const fn copied(self) -> Result<T, E>
where
T: Copy,
{
self.map(|&t| t)
// FIXME(const-hack): this implementation, which sidesteps using `Result::map` since it's not const
// ready yet, should be reverted when possible to avoid code repetition
match self {
Ok(&v) => Ok(v),
Err(e) => Err(e),
}
}

/// Maps a `Result<&T, E>` to a `Result<T, E>` by cloning the contents of the
Expand Down Expand Up @@ -1579,11 +1585,17 @@ impl<T, E> Result<&mut T, E> {
/// ```
#[inline]
#[stable(feature = "result_copied", since = "1.59.0")]
pub fn copied(self) -> Result<T, E>
#[rustc_const_unstable(feature = "const_result", issue = "82814")]
pub const fn copied(self) -> Result<T, E>
where
T: Copy,
{
self.map(|&mut t| t)
// FIXME(const-hack): this implementation, which sidesteps using `Result::map` since it's not const
// ready yet, should be reverted when possible to avoid code repetition
match self {
Ok(&mut v) => Ok(v),
Err(e) => Err(e),
}
}

/// Maps a `Result<&mut T, E>` to a `Result<T, E>` by cloning the contents of the
Expand Down
Loading