Skip to content

Commit d23eb49

Browse files
committed
Shrink unsafe block
1 parent 7cb5206 commit d23eb49

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/macros.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,22 @@ pub fn _cssparser_internal_to_lowercase<'a>(
157157
input: &'a str,
158158
first_uppercase: usize,
159159
) -> &'a str {
160-
unsafe {
160+
161161
// This cast doesn't change the pointer's validity
162162
// since `u8` has the same layout as `MaybeUninit<u8>`:
163-
let input_bytes = &*(input.as_bytes() as *const [u8] as *const [MaybeUninit<u8>]);
163+
let input_bytes = unsafe { &*(input.as_bytes() as *const [u8] as *const [MaybeUninit<u8>]) };
164164

165165
buffer.copy_from_slice(&*input_bytes);
166166

167167
// Same as above re layout, plus these bytes have been initialized:
168-
let buffer = &mut *(buffer as *mut [MaybeUninit<u8>] as *mut [u8]);
168+
let buffer = unsafe { &mut *(buffer as *mut [MaybeUninit<u8>] as *mut [u8]) };
169169

170170
buffer[first_uppercase..].make_ascii_lowercase();
171171
// `buffer` was initialized to a copy of `input`
172172
// (which is `&str` so well-formed UTF-8)
173173
// then ASCII-lowercased (which preserves UTF-8 well-formedness):
174-
::std::str::from_utf8_unchecked(buffer)
175-
}
174+
unsafe { ::std::str::from_utf8_unchecked(buffer) }
175+
176176
}
177177

178178
Some(

0 commit comments

Comments
 (0)