Skip to content

error for functions which cannot return without recurring #613

@andrewrk

Description

@andrewrk

rust has this:

fn thing(x: i32) -> i32 {
    return thing(x) + thing(x);
}

fn main() {
    thing(0);
}
warning: function cannot return without recurring
 --> test.rs:1:1
  |
1 | / fn thing(x: i32) -> i32 {
2 | |     return thing(x) + thing(x);
3 | | }
  | |_^
  |
  = note: #[warn(unconditional_recursion)] on by default
note: recursive call site
 --> test.rs:2:12
  |
2 |     return thing(x) + thing(x);
  |            ^^^^^^^^
  = help: a `loop` may express intention better if this is on purpose

It's a pretty nice compiler error. We should have it too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.frontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    Status

    To do

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions