Skip to content

Add direct-recursion Lint #15006

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

felix91gr
Copy link
Contributor

@felix91gr felix91gr commented Jun 6, 2025

Checklist:

  • Followed [lint naming conventions][lint_naming]
  • Added passing UI tests (including committed .stderr file)
  • cargo test passes locally
  • Executed cargo dev update_lints
  • Added lint documentation
  • Run cargo dev fmt

changelog: new lint: [direct_recursion]

Fixes #428

After we're done with this, I'll open a follow-up issue for the indirect recursion lint

@felix91gr
Copy link
Contributor Author

@PLeVasseur WIP.

I think the implementation is correct. I'll complete the documentation later, hopefully this weekend ^^

@PLeVasseur
Copy link
Contributor

Nice! Thanks for taking on the implementation.

Copy link
Contributor

@PLeVasseur PLeVasseur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @felix91gr -- thanks for writing this up.
One thing I was unclear on: should this lint also check for recursion that's due to macros or only functions?

fn i_call_myself_in_a_bounded_way(bound: u8) {
if bound > 0 {
// "Author has audited this function and determined that its recursive call is fine."
#[allow(clippy::direct_recursion)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change this from an allow to an expect? It gives us some future proofing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly, expect makes it so Clippy checks that this "allow" is being used, right? So if I, for example, put an expect line for this lint in a file where this lint isn't being used, Clippy would issue an error because I'm telling it that I expect this lint to be active and it's not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I did add it to the documentation, btw! Thanks ❤️ )

@felix91gr
Copy link
Contributor Author

Hey @felix91gr -- thanks for writing this up. One thing I was unclear on: should this lint also check for recursion that's due to macros or only functions?

Well... since it's a LateLintPass, then I believe it should already be linting macro-generated code by default. I wonder if there's a straightforward way of testing it 🤔 I'll give it a spin.

@felix91gr felix91gr force-pushed the direct_recursion branch 4 times, most recently from d955bfc to e06510b Compare June 9, 2025 00:37
@felix91gr
Copy link
Contributor Author

Sorry for the CI churn. It took me a while to understand why it was failing the changelog check.

@felix91gr felix91gr marked this pull request as ready for review June 9, 2025 00:53
@rustbot
Copy link
Collaborator

rustbot commented Jun 9, 2025

r? @samueltardieu

rustbot has assigned @samueltardieu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 9, 2025
@rustbot

This comment has been minimized.

changelog: new lint: [`direct_recursion`]
@felix91gr
Copy link
Contributor Author

⚠️ Warning ⚠️

* There are issue links (such as `#123`) in the commit messages of the following commits.
  _Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree._
  
  * [30beb95](https://github.com/rust-lang/rust-clippy/commit/30beb9536f0d8a8c027e5ceecf207224522aa836)

I feel like this should be in the quick CI checks (like the changelog check), so that CI may do an early exit and avoid running the heavier test suites.

@felix91gr
Copy link
Contributor Author

Something that I'd like to add in a later PR, is a link to the Safety Critical Coding Guidelines where recursion is addressed.

Currently the functions section is empty, but I hope to get working on filling it as soon as I can https://coding-guidelines.arewesafetycriticalyet.org/coding-guidelines/functions.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Recursion lint
5 participants