mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
Use saturating_sub in more token-walking methods (#4773)
This commit is contained in:
parent
0099f9720f
commit
ab26f2dc9d
12 changed files with 49 additions and 50 deletions
|
@ -1026,7 +1026,7 @@ pub fn match_parens(start: TextSize, locator: &Locator) -> Option<TextRange> {
|
|||
|
||||
let mut fix_start = None;
|
||||
let mut fix_end = None;
|
||||
let mut count: usize = 0;
|
||||
let mut count = 0u32;
|
||||
|
||||
for (tok, range) in lexer::lex_starts_at(contents, Mode::Module, start).flatten() {
|
||||
match tok {
|
||||
|
@ -1034,10 +1034,10 @@ pub fn match_parens(start: TextSize, locator: &Locator) -> Option<TextRange> {
|
|||
if count == 0 {
|
||||
fix_start = Some(range.start());
|
||||
}
|
||||
count += 1;
|
||||
count = count.saturating_add(1);
|
||||
}
|
||||
Tok::Rpar => {
|
||||
count -= 1;
|
||||
count = count.saturating_sub(1);
|
||||
if count == 0 {
|
||||
fix_end = Some(range.end());
|
||||
break;
|
||||
|
@ -1433,16 +1433,16 @@ impl LocatedCmpop {
|
|||
pub fn locate_cmpops(contents: &str) -> Vec<LocatedCmpop> {
|
||||
let mut tok_iter = lexer::lex(contents, Mode::Module).flatten().peekable();
|
||||
let mut ops: Vec<LocatedCmpop> = vec![];
|
||||
let mut count: usize = 0;
|
||||
let mut count = 0u32;
|
||||
loop {
|
||||
let Some((tok, range)) = tok_iter.next() else {
|
||||
break;
|
||||
};
|
||||
if matches!(tok, Tok::Lpar) {
|
||||
count += 1;
|
||||
count = count.saturating_add(1);
|
||||
continue;
|
||||
} else if matches!(tok, Tok::Rpar) {
|
||||
count -= 1;
|
||||
count = count.saturating_sub(1);
|
||||
continue;
|
||||
}
|
||||
if count == 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue