Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@praveenperera
Copy link
Collaborator

No description provided.

@praveenperera praveenperera requested a review from Copilot June 18, 2025 13:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses a Clippy lint by replacing manual index underflow checks with saturating_sub for safer subtraction.

  • Simplified boundary check to use count.saturating_sub(1) instead of a manual if count >= 1 guard.
  • Corrected indexing logic to prevent potential underflow in vec[...] lookups.

for &(count, (offset, _)) in vec.iter().rev() {
if count <= self.cursor {
if !found_word && (vec[if count >= 1 { count - 1 } else { 0 }].1).1 == " " {
if !found_word && (vec[count.saturating_sub(1)].1).1 == " " {
Copy link

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider destructuring the tuple to avoid nested .1 accesses and improve readability. For example:

let (_, (prev_offset, prev_char)) = vec[count.saturating_sub(1)];
if !found_word && prev_char == " " {
    // ...
}
Suggested change
if !found_word && (vec[count.saturating_sub(1)].1).1 == " " {
let (_, (_, prev_char)) = vec[count.saturating_sub(1)];
if !found_word && prev_char == " " {

Copilot uses AI. Check for mistakes.
@praveenperera praveenperera requested a review from cantino June 19, 2025 15:55
@praveenperera
Copy link
Collaborator Author

Hey @cantino sorry I haven't been active maintaining, but I'd like to be more active. PRs like this do you want me to wait for your review? Or just merge it?

@praveenperera praveenperera merged commit 7352ade into master Jun 22, 2025
39 checks passed
@praveenperera praveenperera deleted the fix-clippy-lints branch June 22, 2025 13:05
@cantino
Copy link
Owner

cantino commented Jun 22, 2025

Really appreciate it @praveenperera! For this kind of small change, go ahead and merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants