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

unsafe allowed inside #[async] functions #74

Closed
Nemo157 opened this issue Mar 19, 2018 · 3 comments
Closed

unsafe allowed inside #[async] functions #74

Nemo157 opened this issue Mar 19, 2018 · 3 comments

Comments

@Nemo157
Copy link
Contributor

Nemo157 commented Mar 19, 2018

As an example, running this will segfault without any warnings:

#![feature(proc_macro, conservative_impl_trait, generators)]

extern crate futures_await as futures;

use futures::prelude::async;

#[async]
fn glass() -> Result<u32, futures::Never> {
    Ok(*(::std::ptr::null() as *const u32))
}

fn main() {
    futures::stable::block_on_stable(glass()).unwrap();
}

while the same example with s/async/async_move/ will fail to compile:

error[E0133]: dereference of raw pointer requires unsafe function or block
 --> examples/safety.rs:9:8
  |
9 |     Ok(*(::std::ptr::null() as *const u32))
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ dereference of raw pointer

This appears to be caused by this unhygenic unsafe block, I assume this has something to do with self-referential generators, but I'm hoping there's some way to fix this to avoid accidental unsafety.

@withoutboats
Copy link
Collaborator

Ugh this is quite problematic! Once Pin stuff lands, we can make changes to generators so that this unsafe block should be going away, but until then... cc @cramertj

Nemo157 added a commit to Nemo157/futures-await that referenced this issue Mar 25, 2018
As of rust-lang/rust#49194 it's now unsafe to
resume a generator, but safe to create an immovable generator.

Fixes alexcrichton#74
@Arnavion
Copy link

Arnavion commented Apr 1, 2018

Please backport this to 0.1.x while 0.2.x is still alpha.

   Compiling futures-await v0.1.0
error[E0133]: call to unsafe function requires unsafe function or block
   --> C:\Users\Arnavion\.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
   --> C:\Users\Arnavion\.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

@Nemo157
Copy link
Contributor Author

Nemo157 commented Apr 1, 2018

See #79, this is actually about the inverse problem where you could use unsafe functions without adding an unsafe block to your code.

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

3 participants