Skip to content

Warn on circular code #11032

Open
Open
@orowith2os

Description

@orowith2os

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 #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();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions