Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
![](/static/devrant/img/pipeless-devrant-banner-white.png)
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
lorentz1550042dI was also under the impression that borrow checking didn't affect behaviour at all. For this to be legal, rust has to
- save the boolean
- lift the vector out of the conditional block (into I guess a MaybeUninit?)
- add a new conditional later to deallocate the vector
That is surprisingly complex generated code from a language whose profile is minimal magic just to save me the hurdle of putting the vector in an option and then branching on it. -
lorentz1550042dI'm aware of static promotion but that's for a single lifetime. If I can rely on this for all lifetimes that will be huge.
-
lorentz1550042d@jestdotty You can certainly use the same value in an if and its corresponding else branch, that's always allowed. Other than that, I think thhere are a lot of hheuristics in the compiler that specifically target simpler cases not caught by the general algos. I wish they weren't as common, I try to think ahead and phrase my code in a way that the compiler will predictably understand before I type it, and these sometimes lead me astray. There are a lot more of them about trait solving though, this is the first piece of lifetime magic I encountered in a long time.
-
lorentz1550042d@jestdotty From what I can tell, structs with no explicit Drop implementations kind of act like a bag of values that you can remove and replace at will. Not sure though, I don't fully understand the rules around method calls on these struct either.
Related Rants
I'd had some weirder experiences with Rust where errors would surface late or in odd places so now I can't tell whether this is actually legal or the error is being discarded because it's in dead code.
When did Rust start extending the lifetime of temporaries outside enclosing blocks to match their borrows?
(in case it''s not obvious, pattern and full_pattern are both slices)
rant
compiler heuristics
rust
borrow checking