-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
"temporary value dropped while borrowed" occurs with let-chains #100276
Comments
This may have something to do with #99852, as there is something about let_chain drops here as well, but I don't for sure. |
The same behaviour happens with an older compiler version. Here goes an example that compiles with fn let_chains(entry: std::io::Result<std::fs::DirEntry>) {
if let Ok(entry) = entry
&& let file_name = entry.file_name()
&& let Some(s) = file_name.to_str()
&& s.contains("")
{
println!("Ok");
}
} It is not up to me to decide if this behaviour is a blocker that will revert stabilization but in case of such event, I won't have enough free time to investigate and fix stuff in the near future. |
Personally and despite the differences, I think that the |
|
cc @est31 who have been dealing with dropping stuff related to |
Some things that might be helpful to know:
|
I've locally amended fn if_let_chain_let(v: u32) {
macro_rules! if_let_chain {
($arg:pat, $exp:expr) => {
if true && let $arg = $exp && ({
print!("postfix,");
true
},).0 {
print!("body,");
} else {
print!("else,");
}
};
}
nestings!(if_let_chain, "if let chain (let)", v);
print!("\n ref &: ");
if_let_chain!(0, &Droppy(v).0);
print!("\n ref mut &mut: ");
if_let_chain!(0, &mut Droppy(v).0);
println!("");
} And this is the output:
Which actually runs counter to what I wrote above, because it predrops. It seems that it depends on whether the
So that rule that I wrote above is not correct, but the underlying behaviour is more complicated. Hmmm... |
Thanks @est31 |
@rustbot claim |
@wesleywiser pointed this out to me. It may be motivation to revert the stablization of let-chains on beta. Lets try to ensure we talk about this at Thursday triage @rustbot label I-compiler-nominated |
False alarm; @wesleywiser pointed out to me that let-chains is already been marked unstable (on beta and nightly). @rustbot label: -I-compiler-nominated |
I tried this code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=02cc60332ebe5829791b841b96fa8c5b
I expected to see this happen: both compiles successfully
Instead, this happened:
let_chains
fails to compileMeta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: