rust-lang / rust-lang/rust-clippy

Warn on circular code

Open
#11,032 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

When code goes in a circular loop (fn1 calls fn 2, which then calls fn1), Clippy will emit a warning about this behavior, so the programmer won't have to wonder why their program apparently hangs.

In debug mode, it will crash with the following:

thread 'main' has overflowed its stack
fatal runtime error: stack overflow

This would be something along the lines of unconditional_recursion in rustc, unsure if these checks need to be in two separate places.

See https://github.com/rust-lang/rust-clippy/issues/428 for a previous issue.

Advantage

Circular Rust code now won't compile without the programmer knowing it's circular, but can still do so if desired.

Drawbacks

None

Example
fn output1() {
    output2();
}

fn output2() {
    output1();
}

fn main() {
    output1();
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start with the mutually recursive example, compare the proposed behavior with rustc's unconditional_recursion, and read the referenced previous issue; done means circular calls produce a warning while preserving the stated ability to compile intentionally.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.