r/ProgrammingLanguages • u/jamiiecb • Apr 10 '26
Borrow-checking surprises
https://www.scattered-thoughts.net/writing/borrow-checking-surprises
52
Upvotes
r/ProgrammingLanguages • u/jamiiecb • Apr 10 '26
2
u/Express-Guest-1061 Apr 11 '26
Why does the blog post start with a link to a paywalled article. The part that is visible isnt really related to the content in the blog post.
18
u/iBPsThrowingObject Apr 10 '26
Those are less "borrow checking surprises" and more of "ergonomic accommodations that slightly break the basic mental model". In fact, the post itself points this out at the very if you unroll all the spoilers:
There's a big one with non-lexical lifetimes. The Book at first tells you that values are block-scoped, and you might be a bit surprised when this compiles:
And then you may see this work and think you got it:
and be stumped once again when this refuses to compile:
3
u/cmontella 🤖 mech-lang Apr 10 '26
lol thanks Jamii, I'm going to use these to stump my students.
3
u/nerdycatgamer Apr 10 '26
what is with the orange text on a white background? my eyes
9
u/joonazan Apr 10 '26
This is what I hate about Rust. You need to learn what you are allowed to do but then actually doing it can be trial and error even for long-time professional users.
The different rules that govern inline code and functions create friction all the time because you want to be able to extract code into a function but in Rust you can't always do that. Especially self-reference is tolerated in code blocks but not in structs.
In type-level programming it isn't even always clear what is allowed and sometimes what is allowed by the language breaks the compiler.
-1
u/R-O-B-I-N Apr 10 '26
This is the reason I don't use Rust.
I've been worn down by years of Cpp gotchas.
Here's yet another language full of "you'd think that but..." semantics.
I'm tired of language semantics having weird mindfreak moments popping up in what should be idiomatic code.