Skip to content

Commit cbdebd9

Browse files
committed
Explain why we use char_indices() instead of chars()
1 parent 47a4865 commit cbdebd9

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

clippy_lints/src/tabs_in_doc_comments.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ fn get_chunks_of_tabs(the_str: &str) -> Vec<(u32, u32)> {
104104
// tracker to decide if the last group of tabs is not closed by a non-tab character
105105
let mut is_active = false;
106106

107+
// Note that we specifically need the char _byte_ indices here, not the positional indexes
108+
// within the char array to deal with multi-byte characters properly. `char_indices` does
109+
// exactly that. It provides an iterator over tuples of the form `(byte position, char)`.
107110
let char_indices: Vec<_> = the_str.char_indices().collect();
108111

109112
if let [(_, '\t')] = char_indices.as_slice() {

0 commit comments

Comments
 (0)