Skip to content

Commit 6471be5

Browse files
committed
Remove the Option and bool impls for carrier and add a dummy impl
The dummy impl should ensure the same type checking behaviour as having other (real) Carrier impls.
1 parent 5f891c5 commit 6471be5

File tree

2 files changed

+7
-77
lines changed

2 files changed

+7
-77
lines changed

src/libcore/ops.rs

+7-60
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ use cmp::PartialOrd;
7171
use fmt;
7272
use marker::{Sized, Unsize};
7373
use result::Result::{self, Ok, Err};
74-
use option::Option::{self, Some, None};
7574

7675
/// The `Drop` trait is used to run some code when a value goes out of scope.
7776
/// This is sometimes called a 'destructor'.
@@ -2198,75 +2197,23 @@ impl<U, V> Carrier for Result<U, V> {
21982197
}
21992198
}
22002199

2201-
#[unstable(feature = "question_mark_carrier", issue = "31436")]
2202-
impl<U> Carrier for Option<U> {
2203-
type Success = U;
2204-
type Error = ();
2205-
2206-
fn from_success(u: U) -> Option<U> {
2207-
Some(u)
2208-
}
2200+
struct _DummyErrorType;
22092201

2210-
fn from_error(_: ()) -> Option<U> {
2211-
None
2212-
}
2213-
2214-
fn translate<T>(self) -> T
2215-
where T: Carrier<Success=U, Error=()>
2216-
{
2217-
match self {
2218-
Some(u) => T::from_success(u),
2219-
None => T::from_error(()),
2220-
}
2221-
}
2222-
}
2223-
2224-
// Implementing Carrier for bools means it's easy to write short-circuiting
2225-
// functions. E.g.,
2226-
// ```
2227-
// fn foo() -> bool {
2228-
// if !(f() || g()) {
2229-
// return false;
2230-
// }
2231-
//
2232-
// some_computation();
2233-
// if h() {
2234-
// return false;
2235-
// }
2236-
//
2237-
// more_computation();
2238-
// i()
2239-
// }
2240-
// ```
2241-
// becomes
2242-
// ```
2243-
// fn foo() -> bool {
2244-
// (f() || g())?;
2245-
// some_computation();
2246-
// (!h())?;
2247-
// more_computation();
2248-
// i()
2249-
// }
2250-
// ```
2251-
#[unstable(feature = "question_mark_carrier", issue = "31436")]
2252-
impl Carrier for bool {
2202+
impl Carrier for _DummyErrorType {
22532203
type Success = ();
22542204
type Error = ();
22552205

2256-
fn from_success(_: ()) -> bool {
2257-
true
2206+
fn from_success(_: ()) -> _DummyErrorType {
2207+
_DummyErrorType
22582208
}
22592209

2260-
fn from_error(_: ()) -> bool {
2261-
false
2210+
fn from_error(_: ()) -> _DummyErrorType {
2211+
_DummyErrorType
22622212
}
22632213

22642214
fn translate<T>(self) -> T
22652215
where T: Carrier<Success=(), Error=()>
22662216
{
2267-
match self {
2268-
true => T::from_success(()),
2269-
false => T::from_error(()),
2270-
}
2217+
T::from_success(())
22712218
}
22722219
}

src/test/run-pass/try-operator.rs

-17
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,6 @@ fn merge_error() -> Result<i32, Error> {
144144
Ok(s.parse::<i32>()? + 1)
145145
}
146146

147-
fn option() -> Option<i32> {
148-
let x = Some(42);
149-
let y = x?;
150-
Some(y + 2)
151-
}
152-
153-
fn bool() -> bool {
154-
let x = true;
155-
let y = false;
156-
let z = true;
157-
158-
(x || y)?;
159-
let a: () = z?;
160-
x?;
161-
true
162-
}
163-
164147
fn main() {
165148
assert_eq!(Ok(3), on_method());
166149

0 commit comments

Comments
 (0)