You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There should be a straightforward and readable way of checking of a boolean value is false. In some situations, using ! (not) is unergonomic or less readable than alternatives.
Don't add this. You can use a closure or Not::not to achieve the same thing, but it is slightly less readable.
Links and related work
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
We think this problem seems worth solving, and the standard library might be the right place to solve it.
We think that this probably doesn't belong in the standard library.
Second, if there's a concrete solution:
We think this specific solution looks roughly right, approved, you or someone else should implement this. (Further review will still happen on the subsequent implementation PR.)
We're not sure this is the right solution, and the alternatives or other materials don't give us enough information to be sure about that. Here are some questions we have that aren't answered, or rough ideas about alternatives we'd want to see discussed.
Reacted by Chayim Refael Friedman, ptrca, kennytm and Gabriel Bjørnager Jensen
The motivation to ACP feels like there's an XY problem here. If you need to check if a file directory is accessible and the file does not exist, chances are you'll later put a new file or directory in that place, which you should just use File::create_new or fs::create_dir directly to prevent TOCTOU issue.
If it is more complicated than that I don't think std::fs::exists("some_path").is_ok_and(|exists| !exists) or matches!(std::fs::exists("some_path"), Ok(false)) is really the pain point compared with the rest of the logic.
We discussed this one in today's @rust-lang/libs-api meeting.
We had a strong consensus that the right way to write this was matches!, if let, ==, or a future is, and that if none of those suffice, a closure would be clearer than having this method.
Activity
scottmcm commentedon Feb 7, 2025
If that's a good motivating example, shouldn't there be
bool::is_truetoo for check that it does exist?Though I think that really wants
à la rust-lang/rfcs#3573, rather than
is_false.(Which can be spelled with
matches!today.)pitaj commentedon Feb 7, 2025
If this is already in a conditional, you can use
if letas wellI think
== Ok(false)would also work in this case.joseph-gio commentedon Feb 7, 2025
that requires the
Errorvariant type to also implementPartialEqkennytm commentedon Feb 7, 2025
The motivation to ACP feels like there's an XY problem here. If you need to check if a file directory is accessible and the file does not exist, chances are you'll later put a new file or directory in that place, which you should just use
File::create_neworfs::create_dirdirectly to prevent TOCTOU issue.If it is more complicated than that I don't think
std::fs::exists("some_path").is_ok_and(|exists| !exists)ormatches!(std::fs::exists("some_path"), Ok(false))is really the pain point compared with the rest of the logic.joshtriplett commentedon Feb 11, 2025
We discussed this one in today's @rust-lang/libs-api meeting.
We had a strong consensus that the right way to write this was
matches!,if let,==, or a futureis, and that if none of those suffice, a closure would be clearer than having this method.