Skip to content

Commit b3ee87d

Browse files
authored
chore: use Cursor::with_position (#11627)
1 parent 9b884bd commit b3ee87d

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

crates/chisel/src/dispatcher.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,15 +528,11 @@ impl ChiselDispatcher {
528528
/// Preprocesses addresses to ensure they are correctly checksummed and returns whether the input
529529
/// only contained trivia (comments, whitespace).
530530
fn preprocess(input: &str) -> (bool, Cow<'_, str>) {
531-
let mut current_pos = 0;
532531
let mut only_trivia = true;
533532
let mut new_input = Cow::Borrowed(input);
534-
for token in solar::parse::Cursor::new(input) {
533+
for (pos, token) in solar::parse::Cursor::new(input).with_position() {
535534
use RawTokenKind::*;
536535

537-
let pos = current_pos as usize;
538-
current_pos += token.len;
539-
540536
if matches!(token.kind, Whitespace | LineComment { .. } | BlockComment { .. }) {
541537
continue;
542538
}

crates/common/src/comments/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ fn line_begin_pos(sf: &SourceFile, pos: BytePos) -> BytePos {
7070
fn gather_comments(sf: &SourceFile) -> Vec<Comment> {
7171
let text = sf.src.as_str();
7272
let start_bpos = sf.start_pos;
73-
let mut pos = 0;
7473
let mut comments: Vec<Comment> = Vec::new();
7574
let mut code_to_the_left = false;
7675

@@ -89,7 +88,7 @@ fn gather_comments(sf: &SourceFile) -> Vec<Comment> {
8988
}
9089
*/
9190

92-
for token in solar::parse::Cursor::new(&text[pos..]) {
91+
for (pos, token) in solar::parse::Cursor::new(text).with_position() {
9392
let token_range = pos..pos + token.len as usize;
9493
let span = make_span(token_range.clone());
9594
let token_text = &text[token_range];
@@ -148,7 +147,6 @@ fn gather_comments(sf: &SourceFile) -> Vec<Comment> {
148147
code_to_the_left = true;
149148
}
150149
}
151-
pos += token.len as usize;
152150
}
153151

154152
comments

0 commit comments

Comments
 (0)