Skip to content

"function cannot return without recursing" should deny by default #108234

Open
@Y0h4n3s

Description

@Y0h4n3s

Code

#[derive(Default)]
struct VariantA {
    pub name: String
}

#[derive(Default)]
struct VariantB {
    pub name: String
}

enum DefaultEnum {
    A(VariantA),
    B(VariantB)
}

impl Default for DefaultEnum {
    fn default() -> Self {
        Default::default()
    }
}

fn main() {
    let default_enum: DefaultEnum = Default::default();
}

Current output

Compiling playground v0.0.1 (/playground)
warning: function cannot return without recursing
  --> src/main.rs:19:5
   |
19 |     fn default() -> Self {
   |     ^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
20 |         Default::default()
   |         ------------------ recursive call site
   |
   = help: a `loop` may express intention better if this is on purpose
   = note: `#[warn(unconditional_recursion)]` on by default

warning: `playground` (bin "playground") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.63s
     Running `target/debug/playground`

Desired output

should be an error instead of a warning

Rationale and extra context

This causes a stack overflow and should not compile

Other cases

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.L-unconditional_recursionLint: unconditional_recursionT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions