-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Future non-Send although non-Send local is dropped before .await #104883
Comments
Here's a smaller repro that doesn't require a tokio dependency: fn main() {
spawn(async {
let non_send: Option<*mut ()> = None;
drop(non_send);
std::future::ready(1).await;
});
}
fn spawn(_: impl Send) {} |
I just ran into this bug too. Note that the compiler message is misleading:
The compiler states that |
This issue looks like it's solved now. |
This should be closed then. |
I get the same error |
@HashirShazad What version of Rust are you using? What example fails, exactly? |
@hniksic i am using for table in ... {
...
if scan_subfolders{
drop(table);
Box::pin(get_table(url.to_string() + href_attr, folder,
download_pdfs, download_imgs, scan_subfolders)).await?; // await here
}
} It says that Full Error error: future cannot be sent between threads safely
--> src/main.rs:197:1
|
197 | #[tauri::command(rename_all = "snake_case")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `url_entered` is not `Send`
...
214 | / tauri::generate_handler![
215 | | // all commands go here
216 | | url_entered
217 | | ]
| |_____________- in this macro invocation
|
= help: within `ego_tree::Node<Node>`, the trait `Sync` is not implemented for `std::cell::Cell<NonZero<usize>>`, which is required by `impl futures::Future<Output = Result<String, ()>>: std::marker::Send`
= note: if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock`
note: future is not `Send` as this value is used across an await
--> src/main.rs:99:93
|
43 | for table in html.select(&table_selector){ // get all tables from html
| ----- has type `ElementRef<'_>` which is not `Send`
...
99 | download_pdfs, download_imgs, scan_subfolders)).await?; // Call get_table function with new url
| ^^^^^ await occurs here, with `table` maybe used later
note: required by a bound in `ResultFutureTag::future`
--> C:\Users\DELL\.cargo\registry\src\index.crates.io-1cd66030c949c28d\tauri-1.6.8\src\command.rs:293:42
|
289 | pub fn future<T, E, F>(self, value: F) -> impl Future<Output = Result<Value, InvokeError>>
| ------ required by a bound in this associated function
...
293 | F: Future<Output = Result<T, E>> + Send,
| ^^^^ required by this bound in `ResultFutureTag::future`
= note: this error originates in the macro `__cmd__url_entered` which comes from the expansion of the macro `tauri::generate_handler` (in Nightly builds, run with -Z macro-backtrace for more info)
|
@HashirShazad Given the code shown is incomplete, it's hard to tell whether this is the same bug, or whether it is a bug at all. I recommend that you distill your code into a minimal example that reproduces the issue (ideally without external dependencies, or with those present on the Playground), and file a new issue. |
i will open a new issue tommorow. |
I think this issue should be reopen because the following simple snippets still fails: struct NonSend(*const ());
impl NonSend {
fn noop(&self) {}
}
fn main() {
assert_send(async {
let x = NonSend(core::ptr::null());
x.noop();
drop(x);
async {}.await;
});
}
fn assert_send(_: impl Send) {}
|
Please open a new issue. |
Rust 1.65 doesn't compile this code:
Playground
It complains that the future is not
Send
, reporting the following:I would expect it to compile, since the offending non-Send value is unconditionally dropped before
.await
.If I change
drop(non_send)
to a block that makes it go out of scope, then it compiles:Playground
As shown, the first example can be trivially transformed to use a scope, but in other situations it might not be as easy. This report is inspired by a post on reddit that described this issue in a slightly more complex scenario.
The text was updated successfully, but these errors were encountered: