-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Select macro incorrectly binds expression result as shared reference #4076
Comments
This update diff --git a/tokio/src/macros/select.rs b/tokio/src/macros/select.rs
index a90ee9eb..88c26adb 100644
--- a/tokio/src/macros/select.rs
+++ b/tokio/src/macros/select.rs
@@ -502,7 +502,7 @@ macro_rules! select {
let mut fut = unsafe { Pin::new_unchecked(fut) };
// Try polling it
- let out = match fut.poll(cx) {
+ let mut out = match fut.poll(cx) {
Ready(out) => out,
Pending => {
// Track that at least one future is
@@ -519,8 +519,8 @@ macro_rules! select {
// the specified pattern.
#[allow(unused_variables)]
#[allow(unused_mut)]
- match &out {
- $bind => {}
+ match &mut out {
+ $bind => {},
_ => continue,
}
allows me to do the following: Some(ref mut req) = rx.recv() => {...} However, I still cannot get the following pattern: Some(mut req) = rx.recv() => {...} |
Try using the |
Do you mean if !matches!(&mut out, $bind) {continue} same result |
Hmm, yeah I tried a few things. It doesn't seem like we can get it to work. We probably have to change the macro to not require this check in the first place. |
Any suggestions? I tried playing around and couldn't find an easy way. |
I don't think there's an easy way. |
Version
tokio 1.10.1
Description
When using
select!
and taking advantage of the built-in pattern matching i.e.Some(foo) = fut_here()
, the macro incorrectly binds the result as a shared reference, which turns into confusing errors like this:The full code can be seen here, but
rx
isReceiver<S3Request>
, so clearly the returned value is/should be owned. @Darksonn pointed out that the code in the macro responsible for this issue is here.Note to whoever is interested in fixing it: @Darksonn also pointed out that changing from
match &out {
tomatch &mut out {
would likely be a suitable fix.The text was updated successfully, but these errors were encountered: