-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fix linting false positive when block used as value #141987
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
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
b7c2339
to
5fda6c1
Compare
declare_lint_pass!(UnusedBraces => [UNUSED_BRACES]); | ||
#[derive(Default)] | ||
pub(crate) struct UnusedBraces { | ||
parent_followed_by_block: Vec<bool>, |
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.
parent_followed_by_block: Vec<bool>, | |
followed_by_block: Vec<bool>, |
and please add a short comment why this is used
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.
I think this should be informative enough?
// Used for tracking parent expressions that would immediately followed
// by block. Storing false here indicates that expression itself is Block
// expression. This is meant for to prevent report false positive cases where
// expressions with stronger block bind being linted.
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.
Storing false here indicates that expression itself is Block expression.
that's for the current impl, I think storing false
should mean: while we may be inside of an expression which has a trailing block expression, there exists an expression between that one and the current which acts like a block, but may also be a function call or a try
-block
|
||
impl UnusedBraces { | ||
#[inline] | ||
fn should_mark_block(e: &ast::Expr) -> bool { |
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.
fn should_mark_block(e: &ast::Expr) -> bool { | |
fn impacts_followed_by_block(e: &ast::Expr) -> bool { |
we also need this for unused parens: #![allow(unused)]
#![warn(unused_parens)]
struct Foo;
fn main() {
loop {
if break (Foo) {}
};
} please add this as a test, also test same for |
Fix #141783.