Skip to content

unconditional_recursion lint doesn't work with struct update syntax #78474

Closed
@keiichiw

Description

@keiichiw

Code

I tried this code which causes a stack overflow due to a recursive call of Default::default() I mistakenly added.

struct S {
    x: i32,
    y: i32,
}

fn f() -> i32 {
    42
}

impl Default for S {
    fn default() -> S {
        S {
            x: f(),
            ..Default::default() // cause stack overflow
        }
    }
}

fn main() {
    let _ = S::default();
}

I expected to see the unconditional_recursion warning. However, the compiler didn't complain it.

Version it worked on

It most recently worked on: 1.43.0 showed the warning. (ref. the compiler explorer)

Version with regression

The warning isn't shown on 1.44.0 or later, including the current stable 1.47.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions