Skip to content

Commit

Permalink
Make sure the call span parens check only fires on the callee, not args
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Sep 11, 2021
1 parent e5c2412 commit d98892b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1842,13 +1842,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr_t
);
err.span_label(field.span, "method, not a field");
let expr_is_call = if let hir::Node::Expr(parent_expr) =
self.tcx.hir().get(self.tcx.hir().get_parent_node(expr.hir_id))
{
matches!(parent_expr.kind, ExprKind::Call(..))
} else {
false
};
let expr_is_call =
if let hir::Node::Expr(hir::Expr { kind: ExprKind::Call(callee, _args), .. }) =
self.tcx.hir().get(self.tcx.hir().get_parent_node(expr.hir_id))
{
expr.hir_id == callee.hir_id
} else {
false
};
let expr_snippet =
self.tcx.sess.source_map().span_to_snippet(expr.span).unwrap_or(String::new());
if expr_is_call && expr_snippet.starts_with("(") && expr_snippet.ends_with(")") {
Expand Down

0 comments on commit d98892b

Please sign in to comment.