-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Omitted the walks in visit_expr() and visit_stmt() #51993
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @oli-obk (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Hmm... curious, it fails on paths. Try adding |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
hir::ExprArray(_) | | ||
hir::ExprType(..) | | ||
hir::ExprTup(..) => {} | ||
hir::ExprBlock(ref box_block, ref _option_label) => { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
||
hir::ExprArray(ref hirvec) => { | ||
for index in hirvec.iter() { | ||
match *index { |
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.
you don't need this match
, it should be fine to call v.visit_expr(index)
directly, if that fails, use v.visit_expr(&**index)
to force a deref.
That transformation can be applied to all the match
statements you used for reference conversions
@@ -293,27 +293,38 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node | |||
hir::ExprIndex(..) if v.tables.is_method_call(e) => { | |||
v.promotable = false; | |||
} | |||
hir::ExprBox(_) => { | |||
hir::ExprBox(ref expr) => { | |||
match *expr { |
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.
this match is also unnecessary
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@@ -293,27 +293,36 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node | |||
hir::ExprIndex(..) if v.tables.is_method_call(e) => { |
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.
you need to recurse into the fields of these three matches, too
v.visit_expr(expr); | ||
for index in hirvec_arm.iter() { | ||
match *index { | ||
ref arm => match arm.guard { |
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.
you also need to recurse into the other fields of arm
v.visit_expr(expr); | ||
match **box_block { | ||
ref block => { | ||
match block.expr { |
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.
you need to visit all block statements, too. it would probably be better to create a visit_block
function and call that one with the block
as an argument, because then you can reuse it below in ExprLoop
and above in ExprBlock
|
||
hir::ExprContinue(_) => {} | ||
|
||
hir::ExprRet(ref option_expr) => { |
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.
you can merge ExprBreak
and ExprRet
by making ref _destination
be _
hir::ExprAssign(..) | | ||
hir::ExprAssignOp(..) | | ||
hir::ExprInlineAsm(..) => { | ||
hir::ExprAssign(ref lhs, ref rhs) => { |
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.
you can merge this with ExprAssignOp
by making ref _binop
be _
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
hir::ExprInlineAsm(..) => { | ||
hir::ExprAssignOp(_, ref lhs, ref rhs) | hir::ExprAssign(ref lhs, ref rhs) => { | ||
v.visit_expr(lhs); | ||
v.visit_expr(rhs); |
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.
you lost the v.promotable = false;
here
|
||
// Generator expressions | ||
hir::ExprYield(_) | | ||
hir::ExprYield(ref expr) => { | ||
v.visit_expr(&expr) |
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.
v.promotable = false;
missing here
} | ||
} | ||
|
||
hir::ExprContinue(_) => {} |
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.
you lost the v.promotable = false;
here
hir::ExprBreak(..) | | ||
hir::ExprContinue(_) | | ||
hir::ExprRet(_) | | ||
hir::ExprBreak(_, ref option_expr) | hir::ExprRet(ref option_expr) => { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
} | ||
|
||
hir::ExprLoop(ref box_block, ref _option_label, ref _loop_source) => { | ||
v.visit_block(box_block); |
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.
v.promotable = false;
missing here
hir::ExprWhile(..) | | ||
hir::ExprLoop(..) | | ||
hir::ExprWhile(ref expr, ref box_block, ref _option_label) => { | ||
v.visit_expr(expr); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
match option_expr { | ||
Some(ref expr) => v.visit_expr(&expr), | ||
None => {}, | ||
} |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
None => {}, | ||
} } | ||
} | ||
} |
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.
v.promotable = false;
missing here
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
match block.expr { | ||
Some(ref box_expr) => { self.visit_expr(&*box_expr) }, | ||
None => {}, | ||
} } |
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.
can you add a line-break between those two closing bracket?
@@ -271,6 +269,19 @@ impl<'a, 'tcx> Visitor<'tcx> for CheckCrateVisitor<'a, 'tcx> { | |||
} | |||
self.promotable &= outer; | |||
} | |||
|
|||
fn visit_block(&mut self, box_block: &'tcx hir::Block) { | |||
match *box_block { |
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.
rename argument to block
and remove the match
v.promotable = false; | ||
} | ||
hir::ExprUnary(op, _) => { | ||
hir::ExprUnary(op, ref expr) => { | ||
match *expr { |
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.
still a nop-match left
|
||
v.promotable = false; | ||
} | ||
_ => {} | ||
} | ||
} | ||
hir::ExprCast(ref from, _) => { | ||
match *from { |
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.
another nop-match
@@ -379,7 +397,13 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node | |||
} | |||
} | |||
} | |||
hir::ExprCall(ref callee, _) => { | |||
hir::ExprCall(ref callee, ref hirvec) => { | |||
match **callee { |
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.
and another
hir::ExprStruct(..) => { | ||
hir::ExprStruct(ref _qpath, ref hirvec, ref option_expr) => { | ||
for index in hirvec.iter() { | ||
match *index { |
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.
also here
hir::ExprField(ref expr, _) => { | ||
hir::ExprField(ref expr, _ident) => { | ||
match *expr { | ||
ref expr => { v.visit_expr(&expr) }, |
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.
and here
hir::ExprMatch(ref expr, ref hirvec_arm, ref _match_source) => { | ||
v.visit_expr(expr); | ||
for index in hirvec_arm.iter() { | ||
match *index { |
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.
remove nop match
for index in hirvec_arm.iter() { | ||
match *index { | ||
ref arm => { | ||
match arm.body { |
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.
remove this nop-match, too. just use v.visit_expr(&arm.body)
ref expr => v.visit_expr(&*expr), | ||
} | ||
match arm.guard { | ||
Some(ref expr) => v.visit_expr(&expr), |
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.
fix indentation and newlines here
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@@ -523,6 +511,17 @@ fn check_expr<'a, 'tcx>( | |||
|
|||
// Conditional control flow (possible to implement). | |||
hir::ExprMatch(ref expr, ref hirvec_arm, ref _match_source) => { | |||
if let hir::ExprMatch(ref discr, ref arms, _) = e.node { |
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.
uh.... please don't match again, just reuse the arguments you already pattern matched (expr
and hirvec_arm
), or rename these to discr
and arms
|
||
v.promotable = false; | ||
} | ||
_ => {} | ||
} | ||
v.promotable = false; |
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.
uhm... what is this line doing here?
if op == hir::UnDeref { | ||
v.promotable = false; | ||
} | ||
v.promotable = false; |
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.
and this one?
} | ||
hir::ExprCast(ref from, _) => { | ||
match *from { |
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.
still a nop-match left
} | ||
v.visit_expr(lhs); | ||
v.visit_expr(rhs); | ||
v.promotable = false; |
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.
This v.promotable = false
is wrong
if op == hir::UnDeref { | ||
v.promotable = false; | ||
} | ||
} | ||
hir::ExprBinary(op, ref lhs, _) => { | ||
hir::ExprBinary(op, ref lhs, ref rhs) => { | ||
v.visit_expr(lhs); |
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.
Same here wrt method call
@@ -324,6 +324,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node | |||
} | |||
} | |||
hir::ExprPath(ref qpath) => { | |||
v.visit_qpath(qpath, e.id, e.span); |
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.
Not necessary
v.visit_expr(expr); | ||
} | ||
|
||
hir::ExprRepeat(ref expr, ref _anon_cast) => { |
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.
Merge with ExprAddrOf
|
||
v.visit_expr(expr); | ||
for index in hirvec_arm.iter() { | ||
match *index { |
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.
Nop match
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
NestedVisitorMap::None | ||
} | ||
|
||
impl<'a, 'tcx>CheckCrateVisitor<'a, 'tcx> { |
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.
Style nit: add a space before the Check
@bors r+ |
📌 Commit f629eb3 has been approved by |
⌛ Testing commit f629eb3 with merge 6b5e396c75db3b28c842d88d39af65afd516fb9b... |
💔 Test failed - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
1 similar comment
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Looks like a spurious network failure. |
Omitted the walks in visit_expr() and visit_stmt() @oli-obk
☀️ Test successful - status-appveyor, status-travis |
@@ -169,12 +168,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> { | |||
} | |||
} | |||
|
|||
impl<'a, 'tcx> Visitor<'tcx> for CheckCrateVisitor<'a, 'tcx> { |
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 should note that this part of the change makes no sense without #52318.
Please motivate such changes better in the future, using the PR description.
@oli-obk