-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Be discouraging about unwrap() lints #1921
Comments
I often have used |
Yeah, I'm for making the ones that suggest expect over unwrap warn. |
@mulkieran You're probably going to get few counter arguments judging from the other issue. Do you want to open a PR changing the level from |
I personally think that |
@llogiq Currently, I unwrap() like its going out of style in test cases, so I understand where you're coming from. Maybe I should re-evaluate, though. |
As I said, once we can use |
@oli-obk I don't mind waiting for a bit more input. Part of my position is that the way @llogiq Why does not using |
Let's say I have a |
Err::<(), &str>("foobar").expect("this should not happen"); yields
|
I was surprised to not get any warnings from clippy when using Another point is that the documentation frequently overuses and misuses both
|
So, the main reason that I sometimes don't use expect is that the text still shows up in the binary, and lately I've been working on the GBA, where you get 32MB total for everything, so spare text you don't really need is just junk data. So I just unwrap with a comment in the source. |
That seems like enough of an edge case to turn off the lint, not to change the defaults. |
Oh I'm all with you. I'm shocked that "don't use unwrap you dummy, at least use expect" wasn't the first lint that clippy ever implemented. |
I don't see anything changing here. |
Please see #1300 for previous discussion.
My position is in the comments, but it essentially means that programmers should use
expect()
to communicate verbally an invariant in their code which logically implies that theunwrap()
should not fail.Thus, the use of
unwrap()
should be discouraged. Programmers can useexpect()
to indicate logical impossibility of failure and return an error to handle the failure.I would welcome suggestions about how to move this out of clippy into a more central repo like rust documentation. The examples of the use of
expect()
that I have seen in the docs are generally no more informative than a bareunwrap()
, something like:b.expect("This should work")
which is identical in information content tob.unwrap()
IMHO.The text was updated successfully, but these errors were encountered: