-
Notifications
You must be signed in to change notification settings - Fork 13k
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
must_use Option::map* #71484
Comments
Not sure about this. I've definitely seen such code in the wild. I think it's important that build-in rustc lints do not have false-positives. Even small amount of false-positives would massively diminish the value of the lint system, as you would need to think "is this a false positive?" about every other lint. Now, it might be a good idea to lint against side-effectful operations in |
Yeah, I agree that's very valid push back. However in this case I think if let is a much more readable way to accomplish what map does on Option. But maybe a crater run would help gauge the prevalence of spurious warnings - and the common reasons why. Maybe there's a pattern we can identify and not lint on. |
s/but these are so rare that it seems unlikely that we need to worry about them/but they are a bad style and should be linted against anyway/ and I will be happy :-) |
Here's an example I just noticed in the wild: let mut paths = vec![&build_targets.include];
build_targets.static_lib.as_ref().map(|p| paths.push(p));
build_targets.shared_lib.as_ref().map(|p| paths.push(p)); Using let mut paths = vec![&build_targets.include];
paths.extend(&build_targets.static_lib);
paths.extend(&build_targets.shared_lib); (not to pick on this author/crate -- it's just useful to consider a real example) |
Here are a couple examples in rust-lang/rust itself: rust/src/liballoc/tests/slice.rs Line 1311 in 3360cc3
|
These are changes that would be needed if we add `#[must_use]` to `Option::map`, per rust-lang#71484.
…imulacrum Avoid unused Option::map results These are changes that would be needed if we add `#[must_use]` to `Option::map`, per rust-lang#71484. r? @Mark-Simulacrum
I believe the Thanks |
I ran into this not being a lint today. Because the thing inside the |
We were discussing #71368 in the language team meeting today, and it came up that
Option::map
should probably be marked must_use. There are technically valid use cases which do not require using the result (i.e. side-effecting uses), but these are so rare that it seems unlikely that we need to worry about them for the purposes of such a lint.(Probably other combinators on Option should also be checked).
The text was updated successfully, but these errors were encountered: