Did you know that in Rust, 'let _ = ...' and 'let _unused = ...' are NOT the same thing?
I didn't until today!

https://gaultier.github.io/blog/rust_underscore_vars.html

#rust

In Rust, `let _ = ...` and `let _unused = ...` are not the same

@pg Funnily, I kind of knew this before reading this 🤔

Maybe the "ignore" notation of just underscore is described somewhere in the teaching materials.

@pg I guess in those cases when the deallocation order matters, it would be good practice to write an explicit `drop(foo);`, which would make the variable used.

@pg I wrote an article a few years ago with some expanded history and explanation:

https://codeandbitters.com/drop-or-not/

Fun to read the 2013 discussion where Nico first argued it’s wrong, then changed his mind.

Code and Bitters

@ericseppanen interesting article, I learned a few things !

@pg Interesting! This lead me into a short rabbithole. This is what I found:

- let _ = ... is pattern matching (https://doc.rust-lang.org/stable/reference/patterns.html#grammar-WildcardPattern states: "Unlike identifier patterns, it does not copy, move or borrow the value it matches")
- let _unused = ... assignes a variable (which is only unused by convention)

If you follow the reference carefully, it turns out that _ is not a valid identifier! It is actually a keyword (https://doc.rust-lang.org/stable/reference/keywords.html#r-lex.keywords.strict)

TIL

Patterns - The Rust Reference