Skip linting unused braces for FunctionArg and MethodArg context for 2024 later #154373
Skip linting unused braces for FunctionArg and MethodArg context for 2024 later #154373chenyukang wants to merge 1 commit into
Conversation
|
r? @fmease rustbot has assigned @fmease. Use Why was this reviewer chosen?The reviewer was selected based on:
|
73c892b to
e120f17
Compare
This comment has been minimized.
This comment has been minimized.
| is_kw: bool, | ||
| ); | ||
|
|
||
| fn is_expr_simple_arg(expr: &ast::Expr) -> bool { |
There was a problem hiding this comment.
This is a very generic name for a very specific use case. "Simple argument" could mean vastly different things in different contexts. I think this should be renamed to something more specific.
| ast::ExprKind::Lit(_) | ast::ExprKind::Path(..) => true, | ||
| ast::ExprKind::Type(expr, _) => Self::is_expr_simple_arg(expr), |
There was a problem hiding this comment.
Surely more kinds of expressions qualify? Like possibly as-casting other "simple" exprs, arrays & tuples of other "simple" exprs and so on.
e120f17 to
14cc286
Compare
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready |
|
r? compiler |
| ast::ExprKind::Array(exprs) | ast::ExprKind::Tup(exprs) => { | ||
| exprs.iter().all(|expr| Self::is_arg_block_without_temp_scope_change(expr)) | ||
| } | ||
| _ => false, |
There was a problem hiding this comment.
exhaustively list them all and add almost all others to the "ok" list:
- unary,unsafebindercast,includebytes
- binary, index, range,
- constblock, path,inlineasm, offsetof
- if,while,forloop,loop,match,block
- gen, closure, tryblock, try
- use, await, break, ret, continue, yield, yeet
- assign, assignop,
- struct, repeat
14cc286 to
2e43946
Compare
This comment has been minimized.
This comment has been minimized.
2e43946 to
88aa4a9
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
88aa4a9 to
8e30f04
Compare
Fixes #154247
unused_bracesis a AST level lint, but in Rust 2024 braces around function and method arguments can affect temporary drop scope.I tried to find a more complete fix for it, but seems all too heavy, which involve AST visitor or need
hirrelated stuff.Instead of teaching this lint to reason about semantics, so it's better to stop linting those argument-position braces in 2024 later edition.