-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Lint unnecessary safety comments #9851
Conversation
r? @giraffate (rust-highfive has picked a reviewer for you, use r? to override) |
95c1f0b
to
745abda
Compare
Apologies for not having added tests upfront, I forgot to add any because I was expecting to potentially get a reply for my question first. Though I think I'll just walk all statements and block tail expressions and check those, that should catch the main causes without having to check every expression. |
Okay I implemented linting on (block tail) expressions and statements as well now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I can't take the time right now, but I'll review again in a few days.
I made small comments.
The test fails because of the following:
https://github.com/rust-lang/rust-clippy/actions/runs/3489064024/jobs/5838683005#step:7:1524
error: this could be rewritten as `let...else`
--> src/undocumented_unsafe_blocks.rs:141:9
|
141 | / let expr = match stmt.kind {
142 | | hir::StmtKind::Local(&hir::Local { init: Some(expr), .. })
143 | | | hir::StmtKind::Expr(expr)
144 | | | hir::StmtKind::Semi(expr) => expr,
145 | | _ => return,
146 | | };
| |__________^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else
= note: `-D clippy::manual-let-else` implied by `-D clippy::pedantic`
help: consider writing
|
141 ~ let hir::StmtKind::Local(&hir::Local { init: Some(expr), .. })
142 + | hir::StmtKind::Expr(expr)
143 + | hir::StmtKind::Semi(expr) = stmt.kind else { return };
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, thanks!
I didn't investigate detail, but it looks like that the test may fail because #9941 was merged. So, could you try to rebase the master branch?
5721904
to
f96dd38
Compare
@bors r+ Thanks! |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
changelog: [
unnecessary_safety_comment
]: Add unnecessary safety comment lintAddresses #7954
This does not necessarily catch all occurences, as doing so would require checking all expressions in the entire source which seems rather expensive. Instead what the lint does is it checks items, statements and the tail expression of blocks for safety comments, then checks if those comments are necessary or not, then linting for the unnecessary ones.
I kept the tests in one file to check that the lints do not clash with each other.