Skip to content

Commit 7fc3c50

Browse files
CAD97dtolnay
andcommitted
style nits
Co-authored-by: David Tolnay <dtolnay@gmail.com>
1 parent a8df928 commit 7fc3c50

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

library/alloc/src/string.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ impl String {
751751
return Err(FromUtf16Error(()));
752752
}
753753
match (cfg!(target_endian = "little"), unsafe { v.align_to::<u16>() }) {
754-
(true, (&[], v, &[])) => Self::from_utf16(v),
754+
(true, ([], v, [])) => Self::from_utf16(v),
755755
_ => decode_utf16(v.array_chunks::<2>().copied().map(u16::from_le_bytes))
756756
.collect::<Result<_, _>>()
757757
.map_err(|_| FromUtf16Error(())),
@@ -787,14 +787,18 @@ impl String {
787787
#[unstable(feature = "str_from_utf16_endian", issue = "none", reason = "recently added")]
788788
pub fn from_utf16le_lossy(v: &[u8]) -> String {
789789
match (cfg!(target_endian = "little"), unsafe { v.align_to::<u16>() }) {
790-
(true, (&[], v, &[])) => Self::from_utf16_lossy(v),
791-
(true, (&[], v, &[_remainder])) => Self::from_utf16_lossy(v) + "\u{FFFD}",
790+
(true, ([], v, [])) => Self::from_utf16_lossy(v),
791+
(true, ([], v, [_remainder])) => Self::from_utf16_lossy(v) + "\u{FFFD}",
792792
_ => {
793793
let mut iter = v.array_chunks::<2>();
794794
let string = decode_utf16(iter.by_ref().copied().map(u16::from_le_bytes))
795795
.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
796796
.collect();
797-
if iter.remainder().is_empty() { string } else { string + "\u{FFFD}" }
797+
if iter.remainder().is_empty() {
798+
string
799+
} else {
800+
string + "\u{FFFD}"
801+
}
798802
}
799803
}
800804
}
@@ -826,7 +830,7 @@ impl String {
826830
return Err(FromUtf16Error(()));
827831
}
828832
match (cfg!(target_endian = "big"), unsafe { v.align_to::<u16>() }) {
829-
(true, (&[], v, &[])) => Self::from_utf16(v),
833+
(true, ([], v, [])) => Self::from_utf16(v),
830834
_ => decode_utf16(v.array_chunks::<2>().copied().map(u16::from_be_bytes))
831835
.collect::<Result<_, _>>()
832836
.map_err(|_| FromUtf16Error(())),
@@ -862,14 +866,18 @@ impl String {
862866
#[unstable(feature = "str_from_utf16_endian", issue = "none", reason = "recently added")]
863867
pub fn from_utf16be_lossy(v: &[u8]) -> String {
864868
match (cfg!(target_endian = "big"), unsafe { v.align_to::<u16>() }) {
865-
(true, (&[], v, &[])) => Self::from_utf16_lossy(v),
866-
(true, (&[], v, &[_remainder])) => Self::from_utf16_lossy(v) + "\u{FFFD}",
869+
(true, ([], v, [])) => Self::from_utf16_lossy(v),
870+
(true, ([], v, [_remainder])) => Self::from_utf16_lossy(v) + "\u{FFFD}",
867871
_ => {
868872
let mut iter = v.array_chunks::<2>();
869873
let string = decode_utf16(iter.by_ref().copied().map(u16::from_be_bytes))
870874
.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
871875
.collect();
872-
if iter.remainder().is_empty() { string } else { string + "\u{FFFD}" }
876+
if iter.remainder().is_empty() {
877+
string
878+
} else {
879+
string + "\u{FFFD}"
880+
}
873881
}
874882
}
875883
}

0 commit comments

Comments
 (0)