Created
September 17, 2023 23:59
-
-
Save tesaguri/67d6cd85b7adde59e180a267e9104f36 to your computer and use it in GitHub Desktop.
Inconsistent borrowck behavior between sync/async `fn`s when reassigning function arguments with local borrows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This doesn't compile (with good reason!): | |
#[allow(unused)] | |
fn reassign_and_return_arg(mut arg: &()) -> &() { | |
let local = (); | |
arg = &local; | |
arg | |
//~^ ERROR cannot return value referencing local variable `local` | |
} | |
// This doesn't compile either (seemingly without good reason, but consistent with the previous code): | |
#[allow(unused)] | |
fn reassign_arg(mut arg: &()) { | |
let local = (); | |
//~^ ERROR `local` does not live long enough | |
arg = &local; | |
} | |
// But this compiles (WHAT): | |
#[allow(unused)] | |
async fn reassign_arg_async(mut arg: &()) { | |
let local = (); | |
arg = &local; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment