-
Notifications
You must be signed in to change notification settings - Fork 24
Closed as not planned
Labels
T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard librariesA proposal to add or alter unstable APIs in the standard libraries
Description
Proposal
Problem statement
There’s no clean way to express boolean implication: you need to resort to something like !a || b.
Motivation, use-cases
Happens kind of a lot, but it may be unclear whether a.implies(b) or !a || b is more clear in each concrete use case.
Some examples from rustc:
if !expected.is_box() || found.is_box()attrs.iter().all(|attr| !is_cfg(attr) || self.cfg_true(attr))!clone_or_copy_needed || is_copy(cx, in_ty)Solution sketches
impl bool {
fn implies(self, other: Self) -> Self {
!self || other
}
fn implied_by(self, other: Self) -> Self {
self || !other
}
// Or maybe (to preserve laziness)
fn implies(self, other: impl FnOnce() -> Self) -> Self {
!self || other()
}
fn implied_by(self, other: impl FnOnce() -> Self) -> Self {
self || !other()
}
}Links and related work
Some languages have implication function or operator, e.g. Racket.
Rust has <=, which works like boolean implication but looks like implication backwards, which is kinda confusing.
What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.
CryZe and VeykrilWaffleLapkin
Metadata
Metadata
Assignees
Labels
T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard librariesA proposal to add or alter unstable APIs in the standard libraries