diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-02-26 11:55:47 +0100 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2024-02-26 17:32:38 +0000 |
commit | fa2a861457838515d3a0a4693c32b0f04cf5e29a (patch) | |
tree | 55d5ae8742afa8305f48101493acd63995ce622d | |
parent | 25839a8761ad7626cdb778304610162dfe38d91e (diff) | |
download | gcc-fa2a861457838515d3a0a4693c32b0f04cf5e29a.zip gcc-fa2a861457838515d3a0a4693c32b0f04cf5e29a.tar.gz gcc-fa2a861457838515d3a0a4693c32b0f04cf5e29a.tar.bz2 |
format-parser: Add `is_some_and` method for Option<T>
Workaround for Ubuntu 18.04, since we still use it for the GCC 4.8 CI.
The default Rust package is 1.65 (and unlikely to change I assume?),
but the generic format parser library uses `is_some_and` which was
introduced in 1.70. So this is a simple reimplementation, directly taken
from the standard library sources.
libgrust/ChangeLog:
* libformat_parser/generic_format_parser/src/lib.rs: Add IsSomeAnd<T>
trait, impl it for Option<T>.
-rw-r--r-- | libgrust/libformat_parser/generic_format_parser/src/lib.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libgrust/libformat_parser/generic_format_parser/src/lib.rs b/libgrust/libformat_parser/generic_format_parser/src/lib.rs index 6a36617..8062bf9 100644 --- a/libgrust/libformat_parser/generic_format_parser/src/lib.rs +++ b/libgrust/libformat_parser/generic_format_parser/src/lib.rs @@ -22,6 +22,22 @@ fn is_id_continue(c: char) -> bool { unicode_xid::UnicodeXID::is_xid_continue(c) } +// Workaround for Ubuntu 18.04. The default Rust package is 1.65 (and unlikely to change I assume?), but the +// generic format parser library uses `is_some_and` which was introduced in 1.70. So this is a reimplementation, +// directly taken from the standard library sources +trait IsSomeAnd<T> { + fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool; +} + +impl<T> IsSomeAnd<T> for Option<T> { + fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool { + match self { + None => false, + Some(x) => f(x), + } + } +} + // use rustc_lexer::unescape; pub use Alignment::*; pub use Count::*; |