# I almost get trapped in an error

**URL:** https://internals.rust-lang.org/t/i-almost-get-trapped-in-an-error/9318
**Category:** Uncategorized
**Created:** [February 1, 2019, 11:40am UTC](https://internals.rust-lang.org/t/i-almost-get-trapped-in-an-error/9318 "2019-02-01T11:40:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![earthengine](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/earthengine/32/2577_2.png) [@earthengine](https://internals.rust-lang.org/u/earthengine)
#### Post date: [February 1, 2019, 11:40am UTC](https://internals.rust-lang.org/t/i-almost-get-trapped-in-an-error/9318/1 "2019-02-01T11:40:24Z")

</div>

I need something like

```rust
fn foo() -> std::task::Poll<Result<(),std::io::Error>>{
...
}

fn bar() -> Result<u32,std::io::Error> {
    foo()?;

   /* do something else */
}

```

I quickly wrote something like the above, and then get suppised by “what? a `Poll` is `Try`?” in review.

Then I ask my self: what does it do when `foo` is returning `Pending`? Is it returning `std::io::Error` with `ErrorKind::WouldBlock`? A few moments I assemed that but finally I get back to the document and figured out the result will be a `Pending` get ignored…

So it has to be

```rust
fn bar() -> Result<u32, std::io::Error> {
    if let Poll::Pending = foo() {
        Err(std::io::Error::from(std::io::ErrorKind::WouldBlock))
    }
    /* do something else */
}

```

Thinking how the Rust team will see from this kind of potential error…

At least, as a `Result` value will warn you if you didn’t use it, the `Poll` value should be the same, so I should be given a warning, right?

---

<div class="post-metadata">

### Author: ![Nemo157](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nemo157/32/11585_2.png) [@Nemo157](https://internals.rust-lang.org/u/Nemo157)
#### Post date: [February 1, 2019, 11:48am UTC](https://internals.rust-lang.org/t/i-almost-get-trapped-in-an-error/9318/2 "2019-02-01T11:48:07Z")

</div>

I think the issue here is just a missing `#[must_use]` on `Poll`, e.g. [a quick test with it](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=5c10b312c95e8f876c11677fe9404781) gives a decent error.

---

<div class="post-metadata">

### Author: ![withoutboats](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/withoutboats/32/4560_2.png) [@withoutboats](https://internals.rust-lang.org/u/withoutboats)
#### Post date: [February 4, 2019, 10:35am UTC](https://internals.rust-lang.org/t/i-almost-get-trapped-in-an-error/9318/3 "2019-02-04T10:35:12Z")

</div>

In addition to must\_use, should note that the futures crate provides a `ready!` macro; `ready!(foo()?)` does what you thought `foo()?` would.

---

<div class="post-metadata">

### Author: ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)
#### Post date: [May 5, 2019, 10:35am UTC](https://internals.rust-lang.org/t/i-almost-get-trapped-in-an-error/9318/4 "2019-05-05T10:35:14Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
