[internal] ComparableExpr (f)strings and bytes made invariant under concatenation (#13301)

This commit is contained in:
Dylan 2024-09-25 09:58:57 -05:00 committed by GitHub
parent ca0ae0a484
commit f27a8b8c7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 173 additions and 38 deletions

View file

@ -1,5 +1,6 @@
#![allow(clippy::derive_partial_eq_without_eq)]
use std::borrow::Cow;
use std::fmt;
use std::fmt::Debug;
use std::iter::FusedIterator;
@ -2186,6 +2187,22 @@ impl PartialEq<[u8]> for BytesLiteralValue {
}
}
impl<'a> From<&'a BytesLiteralValue> for Cow<'a, [u8]> {
fn from(value: &'a BytesLiteralValue) -> Self {
match &value.inner {
BytesLiteralValueInner::Single(BytesLiteral {
value: bytes_value, ..
}) => Cow::from(bytes_value.as_ref()),
BytesLiteralValueInner::Concatenated(bytes_literal_vec) => Cow::Owned(
bytes_literal_vec
.iter()
.flat_map(|bytes_literal| bytes_literal.value.to_vec())
.collect::<Vec<u8>>(),
),
}
}
}
/// An internal representation of [`BytesLiteralValue`].
#[derive(Clone, Debug, PartialEq)]
enum BytesLiteralValueInner {