Skip to content

Commit

Permalink
Explain why we use char_indices() instead of chars()
Browse files Browse the repository at this point in the history
  • Loading branch information
phansch committed Apr 14, 2021
1 parent 47a4865 commit cbdebd9
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clippy_lints/src/tabs_in_doc_comments.rs
Expand Up @@ -104,6 +104,9 @@ fn get_chunks_of_tabs(the_str: &str) -> Vec<(u32, u32)> {
// tracker to decide if the last group of tabs is not closed by a non-tab character
let mut is_active = false;

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

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

0 comments on commit cbdebd9

Please sign in to comment.