Skip to content

Commit 6b15ef7

Browse files
committed
Revert unwrap const, code style
1 parent 1eaf022 commit 6b15ef7

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

library/core/src/result.rs

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@
536536
use crate::iter::{self, FusedIterator, TrustedLen};
537537
use crate::marker::Destruct;
538538
use crate::ops::{self, ControlFlow, Deref, DerefMut};
539-
use crate::panic::const_panic;
540539
use crate::{convert, fmt, hint};
541540

542541
/// `Result` is a type that represents either success ([`Ok`]) or failure ([`Err`]).
@@ -609,8 +608,9 @@ impl<T, E> Result<T, E> {
609608
#[inline]
610609
#[stable(feature = "is_some_and", since = "1.70.0")]
611610
#[rustc_const_unstable(feature = "const_result_callback_methods", issue = "67792")]
612-
pub const fn is_ok_and(self, f: impl ~const FnOnce(T) -> bool + ~const Destruct) -> bool
611+
pub const fn is_ok_and<F>(self, f: F) -> bool
613612
where
613+
F: ~const FnOnce(T) -> bool + ~const Destruct,
614614
T: ~const Destruct,
615615
E: ~const Destruct,
616616
{
@@ -663,8 +663,9 @@ impl<T, E> Result<T, E> {
663663
#[inline]
664664
#[stable(feature = "is_some_and", since = "1.70.0")]
665665
#[rustc_const_unstable(feature = "const_result_callback_methods", issue = "67792")]
666-
pub const fn is_err_and(self, f: impl ~const FnOnce(E) -> bool + ~const Destruct) -> bool
666+
pub const fn is_err_and<F>(self, f: F) -> bool
667667
where
668+
F: ~const FnOnce(E) -> bool + ~const Destruct,
668669
E: ~const Destruct,
669670
T: ~const Destruct,
670671
{
@@ -819,7 +820,10 @@ impl<T, E> Result<T, E> {
819820
#[inline]
820821
#[stable(feature = "rust1", since = "1.0.0")]
821822
#[rustc_const_unstable(feature = "const_result_callback_methods", issue = "67792")]
822-
pub const fn map<U, F: ~const FnOnce(T) -> U + ~const Destruct>(self, op: F) -> Result<U, E> {
823+
pub const fn map<U, F>(self, op: F) -> Result<U, E>
824+
where
825+
F: ~const FnOnce(T) -> U + ~const Destruct,
826+
{
823827
match self {
824828
Ok(t) => Ok(op(t)),
825829
Err(e) => Err(e),
@@ -848,8 +852,9 @@ impl<T, E> Result<T, E> {
848852
#[stable(feature = "result_map_or", since = "1.41.0")]
849853
#[rustc_const_unstable(feature = "const_result_callback_methods", issue = "67792")]
850854
#[must_use = "if you don't need the returned value, use `if let` instead"]
851-
pub const fn map_or<U, F: ~const FnOnce(T) -> U + ~const Destruct>(self, default: U, f: F) -> U
855+
pub const fn map_or<U, F>(self, default: U, f: F) -> U
852856
where
857+
F: ~const FnOnce(T) -> U + ~const Destruct,
853858
T: ~const Destruct,
854859
E: ~const Destruct,
855860
U: ~const Destruct,
@@ -881,15 +886,11 @@ impl<T, E> Result<T, E> {
881886
#[inline]
882887
#[stable(feature = "result_map_or_else", since = "1.41.0")]
883888
#[rustc_const_unstable(feature = "const_result_callback_methods", issue = "67792")]
884-
pub const fn map_or_else<
885-
U,
889+
pub const fn map_or_else<U, D, F>(self, default: D, f: F) -> U
890+
where
886891
D: ~const FnOnce(E) -> U + ~const Destruct,
887892
F: ~const FnOnce(T) -> U + ~const Destruct,
888-
>(
889-
self,
890-
default: D,
891-
f: F,
892-
) -> U {
893+
{
893894
match self {
894895
Ok(t) => f(t),
895896
Err(e) => default(e),
@@ -918,8 +919,8 @@ impl<T, E> Result<T, E> {
918919
#[rustc_const_unstable(feature = "const_result_callback_methods", issue = "67792")]
919920
pub const fn map_or_default<U, F>(self, f: F) -> U
920921
where
921-
U: ~const Default,
922922
F: ~const FnOnce(T) -> U + ~const Destruct,
923+
U: ~const Default,
923924
T: ~const Destruct,
924925
E: ~const Destruct,
925926
{
@@ -950,10 +951,10 @@ impl<T, E> Result<T, E> {
950951
#[inline]
951952
#[stable(feature = "rust1", since = "1.0.0")]
952953
#[rustc_const_unstable(feature = "const_result_callback_methods", issue = "67792")]
953-
pub const fn map_err<F, O: ~const FnOnce(E) -> F + ~const Destruct>(
954-
self,
955-
op: O,
956-
) -> Result<T, F> {
954+
pub const fn map_err<F, O>(self, op: O) -> Result<T, F>
955+
where
956+
O: ~const FnOnce(E) -> F + ~const Destruct,
957+
{
957958
match self {
958959
Ok(t) => Ok(t),
959960
Err(e) => Err(op(e)),
@@ -976,7 +977,10 @@ impl<T, E> Result<T, E> {
976977
#[inline]
977978
#[stable(feature = "result_option_inspect", since = "1.76.0")]
978979
#[rustc_const_unstable(feature = "const_result_callback_methods", issue = "67792")]
979-
pub const fn inspect<F: ~const FnOnce(&T) + ~const Destruct>(self, f: F) -> Self {
980+
pub const fn inspect<F>(self, f: F) -> Self
981+
where
982+
F: ~const FnOnce(&T) + ~const Destruct,
983+
{
980984
if let Ok(ref t) = self {
981985
f(t);
982986
}
@@ -1001,7 +1005,10 @@ impl<T, E> Result<T, E> {
10011005
#[inline]
10021006
#[stable(feature = "result_option_inspect", since = "1.76.0")]
10031007
#[rustc_const_unstable(feature = "const_result_callback_methods", issue = "67792")]
1004-
pub const fn inspect_err<F: ~const FnOnce(&E) + ~const Destruct>(self, f: F) -> Self {
1008+
pub const fn inspect_err<F>(self, f: F) -> Self
1009+
where
1010+
F: ~const FnOnce(&E) + ~const Destruct,
1011+
{
10051012
if let Err(ref e) = self {
10061013
f(e);
10071014
}
@@ -1207,8 +1214,7 @@ impl<T, E> Result<T, E> {
12071214
#[inline(always)]
12081215
#[track_caller]
12091216
#[stable(feature = "rust1", since = "1.0.0")]
1210-
#[rustc_const_unstable(feature = "const_result_callback_methods", issue = "67792")]
1211-
pub const fn unwrap(self) -> T
1217+
pub fn unwrap(self) -> T
12121218
where
12131219
E: fmt::Debug,
12141220
{
@@ -1465,10 +1471,10 @@ impl<T, E> Result<T, E> {
14651471
#[stable(feature = "rust1", since = "1.0.0")]
14661472
#[rustc_const_unstable(feature = "const_result_callback_methods", issue = "67792")]
14671473
#[rustc_confusables("flat_map", "flatmap")]
1468-
pub const fn and_then<U, F: ~const FnOnce(T) -> Result<U, E> + ~const Destruct>(
1469-
self,
1470-
op: F,
1471-
) -> Result<U, E> {
1474+
pub const fn and_then<U, F>(self, op: F) -> Result<U, E>
1475+
where
1476+
F: ~const FnOnce(T) -> Result<U, E> + ~const Destruct,
1477+
{
14721478
match self {
14731479
Ok(t) => op(t),
14741480
Err(e) => Err(e),
@@ -1536,10 +1542,10 @@ impl<T, E> Result<T, E> {
15361542
#[inline]
15371543
#[stable(feature = "rust1", since = "1.0.0")]
15381544
#[rustc_const_unstable(feature = "const_result_callback_methods", issue = "67792")]
1539-
pub const fn or_else<F, O: ~const FnOnce(E) -> Result<T, F> + ~const Destruct>(
1540-
self,
1541-
op: O,
1542-
) -> Result<T, F> {
1545+
pub const fn or_else<F, O>(self, op: O) -> Result<T, F>
1546+
where
1547+
O: ~const FnOnce(E) -> Result<T, F> + ~const Destruct,
1548+
{
15431549
match self {
15441550
Ok(t) => Ok(t),
15451551
Err(e) => op(e),
@@ -1593,7 +1599,10 @@ impl<T, E> Result<T, E> {
15931599
#[track_caller]
15941600
#[stable(feature = "rust1", since = "1.0.0")]
15951601
#[rustc_const_unstable(feature = "const_result_callback_methods", issue = "67792")]
1596-
pub const fn unwrap_or_else<F: ~const FnOnce(E) -> T + ~const Destruct>(self, op: F) -> T {
1602+
pub const fn unwrap_or_else<F>(self, op: F) -> T
1603+
where
1604+
F: ~const FnOnce(E) -> T + ~const Destruct,
1605+
{
15971606
match self {
15981607
Ok(t) => t,
15991608
Err(e) => op(e),
@@ -1835,8 +1844,8 @@ impl<T, E> Result<Result<T, E>, E> {
18351844
#[inline(never)]
18361845
#[cold]
18371846
#[track_caller]
1838-
const fn unwrap_failed(msg: &str, error: &dyn fmt::Debug) -> ! {
1839-
const_panic!("Unwrap failed", "{msg}: {error:?}", msg: &str = msg, error: &dyn fmt::Debug = error);
1847+
fn unwrap_failed(msg: &str, error: &dyn fmt::Debug) -> ! {
1848+
panic!("{msg}: {error:?}");
18401849
}
18411850

18421851
// This is a separate function to avoid constructing a `dyn Debug`

library/coretests/tests/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ const _: () = {
472472
let _inspected_ok: Result<u8, u8> = r_ok.inspect(noop_u8_ref);
473473
let _inspected_err: Result<u8, u8> = r_err.inspect_err(noop_u8_ref);
474474

475-
let _unwrapped: u8 = r_ok.unwrap();
475+
// let _unwrapped: u8 = r_ok.unwrap();
476476
let _unwrapped_default: u8 = r_err.unwrap_or_default();
477477

478478
let _and_then: Result<u8, u8> = r_ok.and_then(add1_result);

0 commit comments

Comments
 (0)