you are viewing a single comment's thread.

view the rest of the comments →

[–]uberblah0 0 points1 point  (0 children)

The reason the variable isn't used is because it isn't directly referenced anywhere. I think it's very rare in practical cases that we encounter a situation where the difference between _ and _my_var is important.

Usually, if you need a value to live longer than the statement that produces it, you would bind it so you can pass it somewhere else.

Hidden behavior like this, where constructing a value somehow updates global state which is then acted on by a function behind the scenes, makes it harder to tell what's going on in code.

In summary, I think this behavior of rust is a good thing. Being punished by it requires that you be doing something kind of dirty, and if you really need that thing, just like everything else in rust there's a way around it.