-
-
Notifications
You must be signed in to change notification settings - Fork 87
[question] Why some code compile error? #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If I use the |
I'll close this since your question is why actix-web results in non-Send futures, not anything about async-trait. You can see in the error from this code that the future is non-Send because of what's stored in HttpServer: use actix_web::{App, HttpServer};
async fn repro() {
match HttpServer::new(App::new).bind("127.0.0.1:8080") {
Ok(server) => { let _ = server.run().await; }
Err(err) => eprintln!("error: {}", err),
}
}
fn main() {
fn assert_send(_: impl Send) {}
assert_send(repro());
} error: future cannot be sent between threads safely
--> src/main.rs:12:5
|
11 | fn assert_send(_: impl Send) {}
| ---- required by this bound in `assert_send`
12 | assert_send(repro());
| ^^^^^^^^^^^ future returned by `repro` is not `Send`
|
= help: the trait `std::marker::Send` is not implemented for `(dyn std::any::Any + 'static)`
note: future is not `Send` as this value is used across an await
--> src/main.rs:5:33
|
4 | match HttpServer::new(App::new).bind("127.0.0.1:8080") {
| ------------------------- has type `HttpServer<fn() -> App<actix_web::app_service::AppEntry, actix_web::dev::Body> {App::<actix_web::app_service::AppEntry, actix_web::dev::Body>::new}, App<actix_web::app_service::AppEntry, actix_web::dev::Body>, actix_web::app_service::AppInit<actix_web::app_service::AppEntry, actix_web::dev::Body>, actix_web::dev::Body>` which is not `Send`
5 | Ok(server) => { let _ = server.run().await; }
| ^^^^^^^^^^^^^^^^^^ await occurs here, with `HttpServer::new(App::new)` maybe used later
...
8 | }
| - `HttpServer::new(App::new)` is later dropped here |
So I should use send_wrapper, right? Thank you |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had a compiler crash while compiling a piece of code #79783, after fix the bug, I found that the same piece of code failed to compile after using async-trait. Example:
Why is that? How to fix it?
The text was updated successfully, but these errors were encountered: