-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documet let _ = ...
behavior saliently, or even warn about it
#40096
Comments
|
I think it should be documented. For me it was kind of obvious as it was consistent with general behavior of |
FWIW, it is somewhat documented in the book:
|
Yes, this is already described in the book, and that section is linked to from the syntax index. Not much more we can do here, I don't think. |
There are still some things you could do:
As I understand |
|
Triage: this is already documented, closing! |
Is this documented somewhere in version two of the book? I haven't been able to find it, and this caused me some frustration. At least not explicitly, maybe it would be possible to figure this out from "as a wildcard pattern that will match any value but not bind to the value", but it certainly isn't obvious and there isn't anything that calls out this potential footgun. |
|
hmm, that was hard to find, especially since it is under the section about starting a name with _ instead of the section about using just "_". Also it doesn't say anything about the behavior wrt drop. |
Hello, Basic Rust user here. My personal experience is that the issue is still relevant and not fully addressed yet. I came to #40096 and #10488 through my favorite search engine. This helped me much more than the documentation. I tried very hard to understand what a
Any chance we get this issue re-opened pleased ? |
A friend ran into an issue today with the following code:
This apparently secures a lock and then immediately drops it, cf. #10488. The following code holds onto the lock instead of dropping it:
I found this surprising and was wholly unaware of this special meaning of the
_
name, and going by the reactions of @alexcrichton and others in #10488, I'm not the only one. It's not the most Google-able topic, but I wasn't able to find documentation of this except in the issue referenced above. I have to wonder how much Rust code out there has a landmine like this buried somewhere inside, undiscovered. Not the best look for a language aiming at safety and concurrency.I suggest doing one of the following:
let _ = foo();
. One could argue that all such lines should be replaced by the more clearfoo();
.let _ = ...
or remove it from the language entirely. Not likely post-stabilization and given that the previous discussion in Fix semantics oflet _ = ...
not to drop #10488. However, I worry about Rust going the way of languages like C++ and accumulating a collection of misfeatures and "don't touch this" areas due to legacy reasons.The text was updated successfully, but these errors were encountered: