Skip to content

Commit 5d817e9

Browse files
authored
Apply suggestions from code review
1 parent 0854482 commit 5d817e9

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

library/core/src/escape.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,18 @@ union MaybeEscapedCharacter<const N: usize> {
158158
}
159159

160160
/// Marker type to indicate that the character is always escaped,
161-
/// use to optimized the iterator implementation.
161+
/// used to optimize the iterator implementation.
162162
#[derive(Clone, Copy)]
163163
#[non_exhaustive]
164164
pub(crate) struct AlwaysEscaped;
165165

166166
/// Marker type to indicate that the character may be escaped,
167-
/// use to optimized the iterator implementation.
167+
/// used to optimize the iterator implementation.
168168
#[derive(Clone, Copy)]
169169
#[non_exhaustive]
170170
pub(crate) struct MaybeEscaped;
171171

172-
/// An iterator over an fixed-size array.
172+
/// An iterator over a fixed-size array.
173173
///
174174
/// This is essentially equivalent to array’s `IntoIter` except that
175175
/// indices are stored as `u8` to reduce size of the structure.
@@ -182,7 +182,7 @@ pub(crate) struct EscapeIterInner<const N: usize, ESCAPING> {
182182
data: MaybeEscapedCharacter<N>,
183183

184184
// Invariant: For non-printable characters, `alive.start <= alive.end <= N`,
185-
// for printable characters, `alive.end >= alive.start >= 128`.
185+
// for printable characters, `128 <= alive.start <= alive.end`.
186186
alive: Range<u8>,
187187

188188
escaping: PhantomData<ESCAPING>,
@@ -232,10 +232,10 @@ impl<const N: usize, ESCAPING> EscapeIterInner<N, ESCAPING> {
232232

233233
/// # Safety
234234
///
235-
/// The caller must ensure that `self` contains an unescaped `char`.
235+
/// The caller must ensure that `self` contains a literal `char`.
236236
#[inline]
237237
unsafe fn as_char(&self) -> char {
238-
// SAFETY: `self.data.unescaped` contains an unescaped `char`,
238+
// SAFETY: `self.data.unescaped` contains a literal `char`,
239239
// as is guaranteed by the caller.
240240
unsafe { self.data.unescaped }
241241
}
@@ -258,8 +258,8 @@ impl<const N: usize> EscapeIterInner<N, AlwaysEscaped> {
258258
pub(crate) fn next(&mut self) -> Option<u8> {
259259
let i = self.alive.next()?;
260260

261-
// SAFETY: We just checked that `self` contains an escape sequence, and
262-
// `i` is guaranteed to be a valid index for `self.data.escaped`.
261+
// SAFETY: The `AlwaysEscaped` marker guarantees that `self` contains an escape sequence,
262+
// and `i` is guaranteed to be a valid index for `self.data.escaped`.
263263
unsafe { Some(self.data.escaped.get_unchecked(usize::from(i)).to_u8()) }
264264
}
265265

@@ -275,7 +275,7 @@ impl<const N: usize> EscapeIterInner<N, AlwaysEscaped> {
275275
impl<const N: usize> EscapeIterInner<N, MaybeEscaped> {
276276
const CHAR_FLAG: u8 = 0b10000000;
277277

278-
// This is the only way to create an `EscapeIterInner` with an unescaped `char`, which
278+
// This is the only way to create an `EscapeIterInner` with a literal `char`, which
279279
// means the `AlwaysEscaped` marker guarantees that `self` contains an escape sequence.
280280
pub(crate) const fn printable(c: char) -> Self {
281281
Self::new(
@@ -294,7 +294,7 @@ impl<const N: usize> EscapeIterInner<N, MaybeEscaped> {
294294
let i = self.alive.next()?;
295295

296296
if self.is_unescaped() {
297-
// SAFETY: We just checked that `self` contains an unescaped `char`.
297+
// SAFETY: We just checked that `self` contains a literal `char`.
298298
return Some(unsafe { self.as_char() });
299299
}
300300

@@ -314,7 +314,7 @@ impl<const N: usize> fmt::Display for EscapeIterInner<N, AlwaysEscaped> {
314314
impl<const N: usize> fmt::Display for EscapeIterInner<N, MaybeEscaped> {
315315
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
316316
if self.is_unescaped() {
317-
// SAFETY: We just checked that `self` contains an unescaped `char`.
317+
// SAFETY: We just checked that `self` contains a literal `char`.
318318
f.write_char(unsafe { self.as_char() })
319319
} else {
320320
// SAFETY: We just checked that `self` contains an escape sequence.
@@ -336,7 +336,7 @@ impl<const N: usize> fmt::Debug for EscapeIterInner<N, MaybeEscaped> {
336336
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
337337
let mut d = f.debug_tuple("EscapeIterInner");
338338
if self.is_unescaped() {
339-
// SAFETY: We just checked that `self` contains an unescaped `char`.
339+
// SAFETY: We just checked that `self` contains a literal `char`.
340340
d.field(unsafe { &self.as_char() });
341341
} else {
342342
// SAFETY: We just checked that `self` contains an escape sequence.

0 commit comments

Comments
 (0)