Skip to content
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

head expression => scrutinee #59691

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,22 +1011,22 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
visitor.visit_expr(subexpression);
visitor.visit_ty(typ)
}
ExprKind::If(ref head_expression, ref if_block, ref optional_else) => {
visitor.visit_expr(head_expression);
ExprKind::If(ref scrutinee, ref if_block, ref optional_else) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

For If and While this should be condition (although I guess this code is going away soon).

visitor.visit_expr(scrutinee);
visitor.visit_expr(if_block);
walk_list!(visitor, visit_expr, optional_else);
}
ExprKind::While(ref subexpression, ref block, ref opt_label) => {
ExprKind::While(ref scrutinee, ref block, ref opt_label) => {
walk_list!(visitor, visit_label, opt_label);
visitor.visit_expr(subexpression);
visitor.visit_expr(scrutinee);
visitor.visit_block(block);
}
ExprKind::Loop(ref block, ref opt_label, _) => {
walk_list!(visitor, visit_label, opt_label);
visitor.visit_block(block);
}
ExprKind::Match(ref subexpression, ref arms, _) => {
visitor.visit_expr(subexpression);
ExprKind::Match(ref scrutinee, ref arms, _) => {
visitor.visit_expr(scrutinee);
walk_list!(visitor, visit_arm, arms);
}
ExprKind::Closure(_, ref function_declaration, body, _fn_decl_span, _gen) => {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,10 @@ impl EarlyLintPass for UnusedParens {
let (value, msg, followed_by_block) = match e.node {
If(ref cond, ..) => (cond, "`if` condition", true),
While(ref cond, ..) => (cond, "`while` condition", true),
IfLet(_, ref cond, ..) => (cond, "`if let` head expression", true),
WhileLet(_, ref cond, ..) => (cond, "`while let` head expression", true),
ForLoop(_, ref cond, ..) => (cond, "`for` head expression", true),
Match(ref head, _) => (head, "`match` head expression", true),
IfLet(_, ref cond, ..) => (cond, "`if let` scrutinee", true),
WhileLet(_, ref cond, ..) => (cond, "`while let` scrutinee", true),
ForLoop(_, ref cond, ..) => (cond, "`for` scrutinee", true),
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure "scrutinee" is correct here. The obvious "iterator expression" isn't really correct either, since it only has to implement IntoIterator. I guess this is fine for now.

Match(ref head, _) => (head, "`match` scrutinee", true),
Ret(Some(ref value)) => (value, "`return` value", false),
Assign(_, ref value) => (value, "assigned value", false),
AssignOp(.., ref value) => (value, "assigned value", false),
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/lint/lint-unnecessary-parens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ fn main() {

if (true) {} //~ ERROR unnecessary parentheses around `if` condition
while (true) {} //~ ERROR unnecessary parentheses around `while` condition
match (true) { //~ ERROR unnecessary parentheses around `match` head expression
match (true) { //~ ERROR unnecessary parentheses around `match` scrutinee
_ => {}
}
if let 1 = (1) {} //~ ERROR unnecessary parentheses around `if let` head expression
while let 1 = (2) {} //~ ERROR unnecessary parentheses around `while let` head expression
if let 1 = (1) {} //~ ERROR unnecessary parentheses around `if let` scrutinee
while let 1 = (2) {} //~ ERROR unnecessary parentheses around `while let` scrutinee
let v = X { y: false };
// struct lits needs parens, so these shouldn't warn.
if (v == X { y: true }) {}
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/lint/lint-unnecessary-parens.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ error: unnecessary parentheses around `while` condition
LL | while (true) {}
| ^^^^^^ help: remove these parentheses

error: unnecessary parentheses around `match` head expression
error: unnecessary parentheses around `match` scrutinee
--> $DIR/lint-unnecessary-parens.rs:22:11
|
LL | match (true) {
| ^^^^^^ help: remove these parentheses

error: unnecessary parentheses around `if let` head expression
error: unnecessary parentheses around `if let` scrutinee
--> $DIR/lint-unnecessary-parens.rs:25:16
|
LL | if let 1 = (1) {}
| ^^^ help: remove these parentheses

error: unnecessary parentheses around `while let` head expression
error: unnecessary parentheses around `while let` scrutinee
--> $DIR/lint-unnecessary-parens.rs:26:19
|
LL | while let 1 = (2) {}
Expand Down