Skip to content

unconditional_recursion does not catch indirect infinity recursion #117541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
KisaragiEffective opened this issue Nov 3, 2023 · 3 comments
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@KisaragiEffective
Copy link
Contributor

KisaragiEffective commented Nov 3, 2023

Code

fn a() {
    b()
}

fn b() {
   a()
}

fn main() {
    let _ = a();
}

Current output

none:

Desired output

warning: function cannot return without recursing
 --> <source>:1:1
  |
1 | fn a() { 
  | ^^^^^^ cannot return without recursing
2 |     b()
  |     --- recursive call site
  |
  = help: a ​`loop​` may express intention better if this is on purpose
  = note: ​`#[warn(unconditional_recursion)]​` on by default

warning: function cannot return without recursing
 --> <source>:5:1
  |
5 | fn b() { 
  | ^^^^^^ cannot return without recursing
6 |     a()
  |     --- recursive call site
  |
  = help: a ​`loop​` may express intention better if this is on purpose
  = note: ​`#[warn(unconditional_recursion)]​` on by default

warning: 2 warnings emitted

Rationale and extra context

The compiler will not emit warning from unconditional_recursion lint if the function does mutual recursion. The above case itself is obvious, but here's a bit more complicated case:

#[derive(Default)]
struct Foo {
    #[allow(dead_code)]
    b: Box<Foo>,
}

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

The derived implementation calls Box::<Foo>::default(), and calls Foo::default() again.

Other cases

N/A

Anything else?

1.73.0 can reproduce both case. 1.74.0-beta.4 and nightly-2023-11-02 have same issue.

@KisaragiEffective KisaragiEffective added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 3, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 3, 2023
@mj10021
Copy link
Contributor

mj10021 commented Nov 3, 2023

@rustbot claim

@clubby789
Copy link
Contributor

Duplicate of #57965 I think. It would be good to look at the previous efforts to fix this to ensure any fix doesn't result in performance regressions

@clubby789 clubby789 added C-enhancement Category: An issue proposing an enhancement or a PR with one. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 3, 2023
@lcnr
Copy link
Contributor

lcnr commented Dec 8, 2023

closing this as a duplicate. #57965 has a lot of relevant info wrt to previous approaches, it's difficult to implement this in a performant way

@lcnr lcnr closed this as completed Dec 8, 2023
@clubby789 clubby789 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants