Skip to content

feat(rust): count ? try operator in complexity#701

Merged
boyter merged 5 commits intoboyter:masterfrom
daulet:daulet/rust
May 4, 2026
Merged

feat(rust): count ? try operator in complexity#701
boyter merged 5 commits intoboyter:masterfrom
daulet:daulet/rust

Conversation

@daulet
Copy link
Copy Markdown
Contributor

@daulet daulet commented Apr 23, 2026

  fn parse<T: ?Sized>(s: &str) -> Result<i32, Error> {
      let n = s.trim().parse()?;
      if n > 0 {
          Ok(n + lookup(n)?)
      } else {
          Err(Error::Negative)
      }
  }

  ┌────────┬─────────────────────────────────────┐
  │        │             Complexity              │
  ├────────┼─────────────────────────────────────┤
  │ before │ 2 — if, else                        │
  ├────────┼─────────────────────────────────────┤
  │ after  │ 4 — if, else, ? (parse), ? (lookup) │
  └────────┴─────────────────────────────────────┘

@pr-insights pr-insights Bot added M/complexity Normal or medium complexity M/size Normal or medium sized change labels Apr 23, 2026
@boyter boyter requested a review from Copilot April 23, 2026 22:20
Copy link
Copy Markdown

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

Adds support for counting Rust’s postfix ? try operator toward cyclomatic complexity by introducing a new “postfix complexity token” mechanism in the processor, and wiring it through the language definitions pipeline (JSON → generated constants → runtime token tries).

Changes:

  • Extend language definitions to support complexitychecks_postfix (JSON + generator template + Go structs/constants).
  • Add a new token type (TComplexityPostfix) and matching logic in the hot-path tokenizer/state machine.
  • Add Rust-specific tests to verify ? is counted while ?Sized is not.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
scripts/languages.tmpl Generate ComplexityChecksPostfix into languageDatabase when present.
languages.json Add Rust complexitychecks_postfix: ["?"].
processor/constants.go Generated update: Rust now includes ComplexityChecksPostfix: []string{"?"}.
processor/structs.go Add TComplexityPostfix and extend Language with ComplexityChecksPostfix.
processor/processor.go Insert postfix complexity tokens into the token trie and process mask.
processor/workers.go Implement counting logic for TComplexityPostfix and add isIdentifierStart helper.
processor/workers_test.go Add tests for Rust ? counting and ?Sized non-counting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread processor/workers.go Outdated
Comment thread processor/workers.go Outdated
Comment thread processor/workers.go Outdated
Comment thread processor/workers_test.go
Comment thread processor/workers.go Outdated
Comment thread processor/workers.go Outdated
@daulet daulet requested a review from apocelipes April 24, 2026 15:45
Comment thread processor/workers.go Outdated
@daulet daulet requested a review from apocelipes April 28, 2026 16:37
@boyter boyter merged commit cb9da67 into boyter:master May 4, 2026
4 checks passed
@boyter
Copy link
Copy Markdown
Owner

boyter commented May 4, 2026

Thanks for this. This is one of those ones I have wanted for a while but never tackled... probably because I dont do much rust.

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

Labels

M/complexity Normal or medium complexity M/size Normal or medium sized change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants