Visit for hir::Expr.
This commit is contained in:
parent
2b1cfe5b5b
commit
52e9825ba8
8 changed files with 41 additions and 38 deletions
|
@ -465,7 +465,7 @@ where
|
|||
pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param<'v>) {
|
||||
visitor.visit_id(param.hir_id);
|
||||
visitor.visit_pat(¶m.pat);
|
||||
walk_list!(visitor, visit_attribute, ¶m.attrs);
|
||||
walk_list!(visitor, visit_attribute, param.attrs);
|
||||
}
|
||||
|
||||
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
|
||||
|
@ -687,14 +687,14 @@ pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V, type_binding
|
|||
pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) {
|
||||
visitor.visit_id(pattern.hir_id);
|
||||
match pattern.kind {
|
||||
PatKind::TupleStruct(ref qpath, ref children, _) => {
|
||||
PatKind::TupleStruct(ref qpath, children, _) => {
|
||||
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
|
||||
walk_list!(visitor, visit_pat, children);
|
||||
}
|
||||
PatKind::Path(ref qpath) => {
|
||||
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
|
||||
}
|
||||
PatKind::Struct(ref qpath, ref fields, _) => {
|
||||
PatKind::Struct(ref qpath, fields, _) => {
|
||||
visitor.visit_qpath(qpath, pattern.hir_id, pattern.span);
|
||||
for field in fields {
|
||||
visitor.visit_id(field.hir_id);
|
||||
|
@ -702,8 +702,8 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) {
|
|||
visitor.visit_pat(&field.pat)
|
||||
}
|
||||
}
|
||||
PatKind::Or(ref pats) => walk_list!(visitor, visit_pat, pats),
|
||||
PatKind::Tuple(ref tuple_elements, _) => {
|
||||
PatKind::Or(pats) => walk_list!(visitor, visit_pat, pats),
|
||||
PatKind::Tuple(tuple_elements, _) => {
|
||||
walk_list!(visitor, visit_pat, tuple_elements);
|
||||
}
|
||||
PatKind::Box(ref subpattern) | PatKind::Ref(ref subpattern, _) => {
|
||||
|
@ -719,7 +719,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) {
|
|||
visitor.visit_expr(upper_bound)
|
||||
}
|
||||
PatKind::Wild => (),
|
||||
PatKind::Slice(ref prepatterns, ref slice_pattern, ref postpatterns) => {
|
||||
PatKind::Slice(prepatterns, ref slice_pattern, postpatterns) => {
|
||||
walk_list!(visitor, visit_pat, prepatterns);
|
||||
walk_list!(visitor, visit_pat, slice_pattern);
|
||||
walk_list!(visitor, visit_pat, postpatterns);
|
||||
|
@ -957,7 +957,7 @@ pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, struct_field: &'v
|
|||
|
||||
pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block<'v>) {
|
||||
visitor.visit_id(block.hir_id);
|
||||
walk_list!(visitor, visit_stmt, &block.stmts);
|
||||
walk_list!(visitor, visit_stmt, block.stmts);
|
||||
walk_list!(visitor, visit_expr, &block.expr);
|
||||
}
|
||||
|
||||
|
@ -982,14 +982,14 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
|
|||
walk_list!(visitor, visit_attribute, expression.attrs.iter());
|
||||
match expression.kind {
|
||||
ExprKind::Box(ref subexpression) => visitor.visit_expr(subexpression),
|
||||
ExprKind::Array(ref subexpressions) => {
|
||||
ExprKind::Array(subexpressions) => {
|
||||
walk_list!(visitor, visit_expr, subexpressions);
|
||||
}
|
||||
ExprKind::Repeat(ref element, ref count) => {
|
||||
visitor.visit_expr(element);
|
||||
visitor.visit_anon_const(count)
|
||||
}
|
||||
ExprKind::Struct(ref qpath, ref fields, ref optional_base) => {
|
||||
ExprKind::Struct(ref qpath, fields, ref optional_base) => {
|
||||
visitor.visit_qpath(qpath, expression.hir_id, expression.span);
|
||||
for field in fields {
|
||||
visitor.visit_id(field.hir_id);
|
||||
|
@ -998,14 +998,14 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
|
|||
}
|
||||
walk_list!(visitor, visit_expr, optional_base);
|
||||
}
|
||||
ExprKind::Tup(ref subexpressions) => {
|
||||
ExprKind::Tup(subexpressions) => {
|
||||
walk_list!(visitor, visit_expr, subexpressions);
|
||||
}
|
||||
ExprKind::Call(ref callee_expression, ref arguments) => {
|
||||
ExprKind::Call(ref callee_expression, arguments) => {
|
||||
visitor.visit_expr(callee_expression);
|
||||
walk_list!(visitor, visit_expr, arguments);
|
||||
}
|
||||
ExprKind::MethodCall(ref segment, _, ref arguments) => {
|
||||
ExprKind::MethodCall(ref segment, _, arguments) => {
|
||||
visitor.visit_path_segment(expression.span, segment);
|
||||
walk_list!(visitor, visit_expr, arguments);
|
||||
}
|
||||
|
@ -1027,7 +1027,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
|
|||
walk_list!(visitor, visit_label, opt_label);
|
||||
visitor.visit_block(block);
|
||||
}
|
||||
ExprKind::Match(ref subexpression, ref arms, _) => {
|
||||
ExprKind::Match(ref subexpression, arms, _) => {
|
||||
visitor.visit_expr(subexpression);
|
||||
walk_list!(visitor, visit_arm, arms);
|
||||
}
|
||||
|
@ -1077,8 +1077,8 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
|
|||
walk_list!(visitor, visit_expr, optional_expression);
|
||||
}
|
||||
ExprKind::InlineAsm(ref asm) => {
|
||||
walk_list!(visitor, visit_expr, &asm.outputs_exprs);
|
||||
walk_list!(visitor, visit_expr, &asm.inputs_exprs);
|
||||
walk_list!(visitor, visit_expr, asm.outputs_exprs);
|
||||
walk_list!(visitor, visit_expr, asm.inputs_exprs);
|
||||
}
|
||||
ExprKind::Yield(ref subexpression, _) => {
|
||||
visitor.visit_expr(subexpression);
|
||||
|
@ -1096,7 +1096,7 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) {
|
|||
}
|
||||
}
|
||||
visitor.visit_expr(&arm.body);
|
||||
walk_list!(visitor, visit_attribute, &arm.attrs);
|
||||
walk_list!(visitor, visit_attribute, arm.attrs);
|
||||
}
|
||||
|
||||
pub fn walk_vis<'v, V: Visitor<'v>>(visitor: &mut V, vis: &'v Visibility) {
|
||||
|
|
|
@ -180,19 +180,19 @@ pub struct Map<'hir> {
|
|||
hir_to_node_id: FxHashMap<HirId, NodeId>,
|
||||
}
|
||||
|
||||
struct ParentHirIterator<'map> {
|
||||
struct ParentHirIterator<'map, 'hir> {
|
||||
current_id: HirId,
|
||||
map: &'map Map<'map>,
|
||||
map: &'map Map<'hir>,
|
||||
}
|
||||
|
||||
impl<'map> ParentHirIterator<'map> {
|
||||
fn new(current_id: HirId, map: &'map Map<'map>) -> ParentHirIterator<'map> {
|
||||
impl<'map, 'hir> ParentHirIterator<'map, 'hir> {
|
||||
fn new(current_id: HirId, map: &'map Map<'hir>) -> ParentHirIterator<'map, 'hir> {
|
||||
ParentHirIterator { current_id, map }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'map> Iterator for ParentHirIterator<'map> {
|
||||
type Item = (HirId, Node<'map>);
|
||||
impl<'map, 'hir> Iterator for ParentHirIterator<'map, 'hir> {
|
||||
type Item = (HirId, Node<'hir>);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.current_id == CRATE_HIR_ID {
|
||||
|
@ -782,7 +782,7 @@ impl<'hir> Map<'hir> {
|
|||
///
|
||||
/// Used by error reporting when there's a type error in a match arm caused by the `match`
|
||||
/// expression needing to be unit.
|
||||
pub fn get_match_if_cause(&self, hir_id: HirId) -> Option<&Expr<'hir>> {
|
||||
pub fn get_match_if_cause(&self, hir_id: HirId) -> Option<&'hir Expr<'hir>> {
|
||||
for (_, node) in ParentHirIterator::new(hir_id, &self) {
|
||||
match node {
|
||||
Node::Item(_) | Node::ForeignItem(_) | Node::TraitItem(_) | Node::ImplItem(_) => {
|
||||
|
|
|
@ -1714,7 +1714,7 @@ pub enum ExprKind<'hir> {
|
|||
Path(QPath),
|
||||
|
||||
/// A referencing operation (i.e., `&a` or `&mut a`).
|
||||
AddrOf(BorrowKind, &'hir Expr<'hir>),
|
||||
AddrOf(BorrowKind, Mutability, &'hir Expr<'hir>),
|
||||
/// A `break`, with an optional label to break.
|
||||
Break(Destination, Option<&'hir Expr<'hir>>),
|
||||
/// A `continue`, with an optional label.
|
||||
|
|
|
@ -126,7 +126,7 @@ impl hir::Pat<'_> {
|
|||
}
|
||||
|
||||
/// Checks if the pattern satisfies the given predicate on some sub-pattern.
|
||||
fn satisfies(&self, pred: impl Fn(&Self) -> bool) -> bool {
|
||||
fn satisfies(&self, pred: impl Fn(&hir::Pat<'_>) -> bool) -> bool {
|
||||
let mut satisfies = false;
|
||||
self.walk_short(|p| {
|
||||
if pred(p) {
|
||||
|
|
|
@ -10,7 +10,6 @@ use syntax::util::parser::{self, AssocOp, Fixity};
|
|||
use syntax_pos::{self, BytePos, FileName};
|
||||
|
||||
use crate::hir;
|
||||
use crate::hir::ptr::P;
|
||||
use crate::hir::{GenericArg, GenericParam, GenericParamKind};
|
||||
use crate::hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier};
|
||||
|
||||
|
@ -972,7 +971,7 @@ impl<'a> State<'a> {
|
|||
|
||||
self.print_inner_attributes(attrs);
|
||||
|
||||
for st in &blk.stmts {
|
||||
for st in blk.stmts {
|
||||
self.print_stmt(st);
|
||||
}
|
||||
if let Some(ref expr) = blk.expr {
|
||||
|
@ -1047,7 +1046,7 @@ impl<'a> State<'a> {
|
|||
&mut self,
|
||||
qpath: &hir::QPath,
|
||||
fields: &[hir::Field<'_>],
|
||||
wth: &Option<P<hir::Expr<'_>>>,
|
||||
wth: &Option<&'hir hir::Expr<'_>>,
|
||||
) {
|
||||
self.print_qpath(qpath, true);
|
||||
self.s.word("{");
|
||||
|
@ -1187,8 +1186,8 @@ impl<'a> State<'a> {
|
|||
hir::ExprKind::Repeat(ref element, ref count) => {
|
||||
self.print_expr_repeat(&element, count);
|
||||
}
|
||||
hir::ExprKind::Struct(ref qpath, ref fields, ref wth) => {
|
||||
self.print_expr_struct(qpath, &fields[..], wth);
|
||||
hir::ExprKind::Struct(ref qpath, fields, ref wth) => {
|
||||
self.print_expr_struct(qpath, fields, wth);
|
||||
}
|
||||
hir::ExprKind::Tup(ref exprs) => {
|
||||
self.print_expr_tup(exprs);
|
||||
|
@ -1251,7 +1250,7 @@ impl<'a> State<'a> {
|
|||
self.s.space();
|
||||
self.print_block(&blk);
|
||||
}
|
||||
hir::ExprKind::Match(ref expr, ref arms, _) => {
|
||||
hir::ExprKind::Match(ref expr, arms, _) => {
|
||||
self.cbox(INDENT_UNIT);
|
||||
self.ibox(INDENT_UNIT);
|
||||
self.word_nbsp("match");
|
||||
|
|
|
@ -460,7 +460,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
/// needed, suggest annotating the call, otherwise point out the resulting type of the call.
|
||||
fn annotate_method_call(
|
||||
&self,
|
||||
segment: &hir::ptr::P<hir::PathSegment>,
|
||||
segment: &hir::PathSegment,
|
||||
e: &Expr<'_>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
) {
|
||||
|
|
|
@ -1271,12 +1271,12 @@ fn resolve_local<'tcx>(
|
|||
record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id);
|
||||
record_rvalue_scope(visitor, &subexpr, blk_id);
|
||||
}
|
||||
hir::ExprKind::Struct(_, ref fields, _) => {
|
||||
hir::ExprKind::Struct(_, fields, _) => {
|
||||
for field in fields {
|
||||
record_rvalue_scope_if_borrow_expr(visitor, &field.expr, blk_id);
|
||||
}
|
||||
}
|
||||
hir::ExprKind::Array(ref subexprs) | hir::ExprKind::Tup(ref subexprs) => {
|
||||
hir::ExprKind::Array(subexprs) | hir::ExprKind::Tup(subexprs) => {
|
||||
for subexpr in subexprs {
|
||||
record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id);
|
||||
}
|
||||
|
|
|
@ -228,7 +228,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
|||
self.consume_exprs(exprs);
|
||||
}
|
||||
|
||||
hir::ExprKind::Match(ref discr, ref arms, _) => {
|
||||
hir::ExprKind::Match(ref discr, arms, _) => {
|
||||
let discr_place = return_if_err!(self.mc.cat_expr(&discr));
|
||||
self.borrow_expr(&discr, ty::ImmBorrow);
|
||||
|
||||
|
@ -251,7 +251,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
hir::ExprKind::InlineAsm(ref ia) => {
|
||||
for (o, output) in ia.inner.outputs.iter().zip(&ia.outputs_exprs) {
|
||||
for (o, output) in ia.inner.outputs.iter().zip(ia.outputs_exprs) {
|
||||
if o.is_indirect {
|
||||
self.consume_expr(output);
|
||||
} else {
|
||||
|
@ -388,7 +388,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
|||
fn walk_block(&mut self, blk: &hir::Block<'_>) {
|
||||
debug!("walk_block(blk.hir_id={})", blk.hir_id);
|
||||
|
||||
for stmt in &blk.stmts {
|
||||
for stmt in blk.stmts {
|
||||
self.walk_stmt(stmt);
|
||||
}
|
||||
|
||||
|
@ -397,7 +397,11 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn walk_struct_expr(&mut self, fields: &[hir::Field<'_>], opt_with: &Option<P<hir::Expr<'_>>>) {
|
||||
fn walk_struct_expr(
|
||||
&mut self,
|
||||
fields: &[hir::Field<'_>],
|
||||
opt_with: &Option<&'hir hir::Expr<'_>>,
|
||||
) {
|
||||
// Consume the expressions supplying values for each field.
|
||||
for field in fields {
|
||||
self.consume_expr(&field.expr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue