use fmt;
use marker::{Sized, Unsize};
use result::Result::{self, Ok, Err};
-use option::Option::{self, Some, None};
/// The `Drop` trait is used to run some code when a value goes out of scope.
/// This is sometimes called a 'destructor'.
}
}
-#[unstable(feature = "question_mark_carrier", issue = "31436")]
-impl<U> Carrier for Option<U> {
- type Success = U;
- type Error = ();
-
- fn from_success(u: U) -> Option<U> {
- Some(u)
- }
+struct _DummyErrorType;
- fn from_error(_: ()) -> Option<U> {
- None
- }
-
- fn translate<T>(self) -> T
- where T: Carrier<Success=U, Error=()>
- {
- match self {
- Some(u) => T::from_success(u),
- None => T::from_error(()),
- }
- }
-}
-
-// Implementing Carrier for bools means it's easy to write short-circuiting
-// functions. E.g.,
-// ```
-// fn foo() -> bool {
-// if !(f() || g()) {
-// return false;
-// }
-//
-// some_computation();
-// if h() {
-// return false;
-// }
-//
-// more_computation();
-// i()
-// }
-// ```
-// becomes
-// ```
-// fn foo() -> bool {
-// (f() || g())?;
-// some_computation();
-// (!h())?;
-// more_computation();
-// i()
-// }
-// ```
-#[unstable(feature = "question_mark_carrier", issue = "31436")]
-impl Carrier for bool {
+impl Carrier for _DummyErrorType {
type Success = ();
type Error = ();
- fn from_success(_: ()) -> bool {
- true
+ fn from_success(_: ()) -> _DummyErrorType {
+ _DummyErrorType
}
- fn from_error(_: ()) -> bool {
- false
+ fn from_error(_: ()) -> _DummyErrorType {
+ _DummyErrorType
}
fn translate<T>(self) -> T
where T: Carrier<Success=(), Error=()>
{
- match self {
- true => T::from_success(()),
- false => T::from_error(()),
- }
+ T::from_success(())
}
}
--- /dev/null
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(question_mark, question_mark_carrier)]
+
+// Test that type inference fails where there are multiple possible return types
+// for the `?` operator.
+
+fn f(x: &i32) -> Result<i32, ()> {
+ Ok(*x)
+}
+
+fn g() -> Result<Vec<i32>, ()> {
+ let l = [1, 2, 3, 4];
+ l.iter().map(f).collect()? //~ ERROR type annotations required: cannot resolve
+}
+
+fn main() {
+ g();
+}