Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Can not compile basic example on README.md #108

Open
realcr opened this issue Jul 17, 2018 · 6 comments
Open

Can not compile basic example on README.md #108

realcr opened this issue Jul 17, 2018 · 6 comments

Comments

@realcr
Copy link

realcr commented Jul 17, 2018

I can not successfully compile the basic await! example on the readme.

$ rustc --version
rustc 1.29.0-nightly (1ecf6929d 2018-07-16)

My first attempt to compile it gave me this compilation error:

error[E0658]: macro await! is unstable (see issue #50547)========>       ] 8/9: check_await                                                                                                                        
  --> src/main.rs:11:12
   |
11 |     Ok(1 + await!(bar())?)
   |            ^^^^^^^^^^^^^
   |
   = help: add #![feature(await_macro)] to the crate attributes to enable

According to the information in the error message, I added #![feature(await_macro)]. Later I also added #![feature(custom_attribute)], to obtain this source file:

main.rs

#![feature(proc_macro, generators)]
#![feature(await_macro)]
#![feature(custom_attribute)]

extern crate futures_await as futures;

use futures::prelude::{await, async};

#[async]
fn foo() -> Result<i32, i32> {
    Ok(1 + await!(bar())?)
}

#[async]
fn bar() -> Result<i32, i32> {
    Ok(2)
}

fn main() {
    assert_eq!(foo().wait(), Ok(3));
}

Cargo.toml:

[package]
name = "check_await"
version = "0.1.0"
authors = ["real"]

[dependencies]
futures-await = "0.1"

Compilation errors:

$ cargo build
   Compiling check_await v0.1.0 (file:///home/real/temp/check_await)                                                                                                                                               
error[E0432]: unresolved import `futures::prelude::await`========>       ] 8/9: check_await                                                                                                                        
 --> src/main.rs:7:24
  |
7 | use futures::prelude::{await, async};
  |                        ^^^^^ no `await` in `prelude`

error[E0432]: unresolved import `futures::prelude::async`
 --> src/main.rs:7:31
  |
7 | use futures::prelude::{await, async};
  |                               ^^^^^ no `async` in `prelude`. Did you mean to use `Async`?

warning: unused imports: `async`, `await`
 --> src/main.rs:7:24
  |
7 | use futures::prelude::{await, async};
  |                        ^^^^^  ^^^^^
  |
  = note: #[warn(unused_imports)] on by default

error[E0277]: the trait bound `std::result::Result<i32, i32>: std::future::Future` is not satisfied
  --> src/main.rs:11:12
   |
11 |     Ok(1 + await!(bar())?)
   |            ^^^^^^^^^^^^^ the trait `std::future::Future` is not implemented for `std::result::Result<i32, i32>`
   |
   = note: required by `std::future::poll_in_task_cx`
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0277]: the trait bound `std::result::Result<i32, i32>: std::future::Future` is not satisfied
  --> src/main.rs:11:12
   |
11 |     Ok(1 + await!(bar())?)
   |            ^^^^^^^^^^^^^ the trait `std::future::Future` is not implemented for `std::result::Result<i32, i32>`
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0627]: yield statement outside of generator literal
  --> src/main.rs:11:12
   |
11 |     Ok(1 + await!(bar())?)
   |            ^^^^^^^^^^^^^
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0599]: no method named `wait` found for type `std::result::Result<i32, i32>` in the current scope
  --> src/main.rs:20:22
   |
20 |     assert_eq!(foo().wait(), Ok(3));
   |                      ^^^^

error: aborting due to 6 previous errors

Some errors occurred: E0277, E0432, E0599, E0627.
For more information about an error, try `rustc --explain E0277`.
error: Could not compile `check_await`.                                                                                                                                                                            

To learn more, run the command again with --verbose.

Is there anything I can do to resolve these issues?

@Nemo157
Copy link
Contributor

Nemo157 commented Jul 17, 2018

See #106, there are compatibility issues with new nightlies because of the builtin async/await support.

@realcr
Copy link
Author

realcr commented Jul 17, 2018

@Nemo157 : Thanks!
The solution mentioned at #106 does not seem to work in this case:

error[E0432]: unresolved import `futures::prelude::await`========>       ] 8/9: check_await                                                                                                                        
 --> src/main.rs:7:24
  |
7 | use futures::prelude::{await, async};
  |                        ^^^^^ no `await` in `prelude`

What is the right thing to do right now? Is there something I should add to the example, or should I just wait until this problem is resolved? Is there a solution I could use in the meantime, because currently the build is broken for my code, and development can not be continued.

@insanitybit
Copy link

insanitybit commented Jul 27, 2018

Also running into this - is there a known-good nightly to roll back to?

@realcr
Copy link
Author

realcr commented Jul 27, 2018

@insanitybit : See: #106 (comment)

The solution that worked for me was adding:

#![feature(use_extern_macros)]

There are still some modifications required to compile the example though (As I noted above), maybe we should open a pull request to update the documentation.

@insanitybit
Copy link

Oh, you're right, that does fix it - I had tried it, but messed it up. Thank you.

@dpezely
Copy link

dpezely commented Sep 3, 2018

For compiling with a more recent nightly, a few more modifications are necessary. Use of proc_macro gets omitted from feature list, and Future gets added to use.

Using rustc 1.30.0-nightly (9395f0af7 2018-09-02)

#![feature(generators)]
#![feature(await_macro)]
#![feature(custom_attribute)]

extern crate futures_await as futures;

use futures::prelude::{await, async, Future};

#[async]
fn foo() -> Result<i32, i32> {
    Ok(1 + await!(bar())?)
}

#[async]
fn bar() -> Result<i32, i32> {
    Ok(2)
}

fn main() {
    assert_eq!(foo().wait(), Ok(3));
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants