Skip to content

New lint: Manual assert #7645

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
camsteffen opened this issue Sep 8, 2021 · 3 comments · Fixed by #7669
Closed

New lint: Manual assert #7645

camsteffen opened this issue Sep 8, 2021 · 3 comments · Fixed by #7669
Assignees
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. L-style Lint: Belongs in the style lint group

Comments

@camsteffen
Copy link
Contributor

camsteffen commented Sep 8, 2021

What it does

Detects if-then-panic! that can be replaced with assert!

Categories (optional)

  • Kind: style

What is the advantage of the recommended code over the original code

It is simpler

Drawbacks

None.

Example

if !sad_people.is_empty() {
    panic!("there are sad people: {:?}", sad_people);
}

Could be written as:

assert!(sad_people.is_empty(), "there are sad people: {:?}", sad_people);

Lint name: manual_assert or if_then_panic

@camsteffen camsteffen added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. A-lint Area: New lints L-style Lint: Belongs in the style lint group labels Sep 8, 2021
@matthiaskrgr
Copy link
Member

What about its with multiple conditions?
If we have 10-5 conditions it does probably not help a lot, to use a super big assert...

@camsteffen
Copy link
Contributor Author

We could lint only if the condition expression currently fits on one line.

@Labelray
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. L-style Lint: Belongs in the style lint group
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants