Guess what this prints without running this code. You'll be surprised. #rustlangpic.twitter.com/gWhaeDI2DT
U tweetove putem weba ili aplikacija drugih proizvođača možete dodati podatke o lokaciji, kao što su grad ili točna lokacija. Povijest lokacija tweetova uvijek možete izbrisati. Saznajte više
my guess is: temp ret oof foo ?
nope
"Temp foo oof" or "temp oof foo" I don't think "Ret"gets printed because it's not assigned and thus not dropped. I'm just not sure the order the others are dropped in...
It gets created by the bar function and returned. If this would be a heap allocated string and Rust would skip the drop logic, that would leak the string‘s memory.
Changing it to a return statement changes the behavior.
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=78ec2ec565a34dcb0e477e4d74a1fcd3 …
Yeah that‘s the surprising part of this code.
I got the first one right, but not this. Any pointers?
The locals are dropped in reverse order and then the remaining temporaries (also in reverse order). It‘s not quite clear why the temporaries of the final expression get dropped after the locals.
so if I didn't suspect there was something weird going on I'd say temp oof foo ret, but given that you're tweeting about this I bet it's oof foo temp ret, and I think I know why
temporaries live as long as the current _statement_, otherwise you'd need to pin them to a local before using references, which would be really annoying. That's more common knowledge
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.