Skip to content

Consecutive returns dont decrease cognitive Complexity level anymore #14460

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

Merged
merged 2 commits into from
Apr 12, 2025

Conversation

cerdelen
Copy link
Contributor

@cerdelen cerdelen commented Mar 24, 2025

changelog: [cognitive_complexity]: Consecutive return calls decreased complexity level of the function by 1.

fixes #14422

@rustbot
Copy link
Collaborator

rustbot commented Mar 24, 2025

r? @y21

rustbot has assigned @y21.
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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Mar 24, 2025
@rustbot

This comment has been minimized.

@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Mar 24, 2025
@y21
Copy link
Member

y21 commented Mar 29, 2025

Do you have an example code snippet of some real code that exercises this exception here or motivation on why this change helps? It's a bit hard for me to think about when there would be two return expressions after one another

@cerdelen
Copy link
Contributor Author

cerdelen commented Mar 30, 2025

i added the id of the issue apparently it wasnt linked before

It is because you put the initial pull-request message into a code block (surrounded by three backticks). I've edited the code block markers out in the initial message, and this has now linked the issue.

Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

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

I see, thanks for referencing the issue, that gives some context. LGTM, can you add a test for this in tests/ui/cognitive_complexity.rs? (Can just copy it from the linked issue)

@y21 y21 added this pull request to the merge queue Apr 12, 2025
Merged via the queue into rust-lang:master with commit b157411 Apr 12, 2025
13 checks passed
@KonaeAkira
Copy link
Contributor

I may be mistaken here, but the bug was a false negative, and the added test tests that the lint is not triggered. Shouldn't the test added in this PR test that the lint is triggered instead?

In other words, the new test would still pass if the bugfix was reverted, which defeats the purpose of the test.

@cerdelen
Copy link
Contributor Author

You are right. I made another pull request.

#14603

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.

Extra return statements at end of function should not lower cognitive complexity
4 participants