alexcrichton / futures-await

Apache License 2.0
734 stars 55 forks source link

'call to unsafe function requires unsafe function or block' with rustc 1.26.0-nightly (f5631d9ac 2018-03-24) #79

Closed shisoft closed 6 years ago

shisoft commented 6 years ago

Hi. I use nightly rust on my project and got this compile error today after rustup update.

error[E0133]: call to unsafe function requires unsafe function or block
   --> /home/shisoft/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-await-0.1.0/src/lib.rs:123:19
    |
123 |             match self.0.resume() {
    |                   ^^^^^^^^^^^^^^^ call to unsafe function

error[E0133]: call to unsafe function requires unsafe function or block
   --> /home/shisoft/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-await-0.1.0/src/lib.rs:143:19
    |
143 |             match self.gen.resume() {
    |                   ^^^^^^^^^^^^^^^^^ call to unsafe function

error: aborting due to 2 previous errors

Is there anything need to be upgraded?

Thanks

ngg commented 6 years ago

It's caused by https://github.com/rust-lang/rust/pull/49194

@alexcrichton can you pls release a new version that fixes this but without depending on proc-macro2 0.2 nightly? (that would cause lots of other problems) The best would be a 0.1.1 version that "just" fixes this but otherwise works the same as 0.1.0?

Thanks!

ngg commented 6 years ago

I have a branch where I cherry-picked all commits that are not 0.2 specific, I use it currently until a fixed version is in cargo: https://github.com/ngg/futures-await/commits/0.1 futures-await = { git = "https://github.com/ngg/futures-await", branch = "0.1", version = "0.1" }

bbigras commented 6 years ago

@ngg for some reason I got this error while using your version:

error: custom attribute panicked
   --> src\server.rs:403:1
    |
403 | #[async]
    | ^^^^^^^^
    |
    = help: message: failed to parse tokens as a function: ParseError(Some("failed to parse item: failed to parse"))

error: aborting due to previous error
ngg commented 6 years ago

@bbigras It's strange... Did it work with the official 0.1.0 version? Can you send a file for which it fails (or a link to some crate it does not work with)?

nayato commented 6 years ago

@alexcrichton having 0.1.1 would sure be a good thing to have as it would take some time for everyone to move to futures 0.2 which is a prereq for futures-await master.

ghost commented 6 years ago

For now it would be possible to just throw the two lines that error in an unsafe block, i'm not sure why resuming generators are now unsafe or if this would have a negative impact on futures-await, but it seems like an easy fix.

Nemo157 commented 6 years ago

Resuming generators is now unsafe because the generator may or may not be an immovable generator. For futures-await 0.1 your fine though because it only creates movable generators, so just wrapping the resume calls in unsafe blocks is valid.

ghost commented 6 years ago

nice to know, thanks

golddranks commented 6 years ago

Using @ngg's branch solved this. Could you please send a pull request here and get 0.1.1 released? The current situation is no good.

seunlanlege commented 6 years ago

This change has broken a lot of crates, mine included. What's preventing this issue from being closed? happy to help out where i can.

withoutboats commented 6 years ago

Sorry about being broken for so long! Everyone involved in maintaining this crate has been pretty busy with other things.

Now that the 0.2 version has been upstreamed into rust-lang-nursery/futures-rs, I think I'm going to revert this repo to just track version 0.1. Then we can merge a fix for this in & upload an 0.1.1 version.

withoutboats commented 6 years ago

If anyone wants to take #86 over and get it passing CI, I will gladly merge it & release 0.1.1. Otherwise I will eventually get it to pass CI hopefully this week some time.

withoutboats commented 6 years ago

Uploaded futures-await 0.1.1 which should work on current nightlies :tada:

ngg commented 6 years ago

Thanks a lot, it works perfectly :)