From 4d537141835f825892e2be868620e98585b3d4a9 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sun, 23 Jun 2019 11:32:16 +0200 Subject: [PATCH] Remove redundant syntax::ast::Guard. --- src/librustc/hir/lowering.rs | 2 +- src/librustc_resolve/lib.rs | 2 +- src/librustc_save_analysis/dump_visitor.rs | 5 ++--- src/libsyntax/ast.rs | 7 +------ src/libsyntax/mut_visit.rs | 12 +----------- src/libsyntax/parse/parser.rs | 4 ++-- src/libsyntax/print/pprust.rs | 12 ++++-------- src/libsyntax/visit.rs | 6 ++---- 8 files changed, 14 insertions(+), 36 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index c87ab686937..3947327b463 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1382,7 +1382,7 @@ impl<'a> LoweringContext<'a> { attrs: self.lower_attrs(&arm.attrs), pats: arm.pats.iter().map(|x| self.lower_pat(x)).collect(), guard: match arm.guard { - Some(Guard::If(ref x)) => Some(hir::Guard::If(P(self.lower_expr(x)))), + Some(ref x) => Some(hir::Guard::If(P(self.lower_expr(x)))), _ => None, }, body: P(self.lower_expr(&arm.body)), diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 0fbd0666ad1..0b27bfdbe67 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -3065,7 +3065,7 @@ impl<'a> Resolver<'a> { // This has to happen *after* we determine which pat_idents are variants. self.check_consistent_bindings(&arm.pats); - if let Some(ast::Guard::If(ref expr)) = arm.guard { + if let Some(ref expr) = arm.guard { self.visit_expr(expr) } self.visit_expr(&arm.body); diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index f67241ef23e..fd746ef0832 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -1617,9 +1617,8 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tcx, ' fn visit_arm(&mut self, arm: &'l ast::Arm) { self.process_var_decl_multi(&arm.pats); - match arm.guard { - Some(ast::Guard::If(ref expr)) => self.visit_expr(expr), - _ => {} + if let Some(expr) = &arm.guard { + self.visit_expr(expr); } self.visit_expr(&arm.body); } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b1a62ac81d0..8a2b36e75be 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -893,16 +893,11 @@ pub struct Local { pub struct Arm { pub attrs: Vec, pub pats: Vec>, - pub guard: Option, + pub guard: Option>, pub body: P, pub span: Span, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub enum Guard { - If(P), -} - #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct Field { pub ident: Ident, diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index 5a5b633e315..076557ab11a 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -131,10 +131,6 @@ pub trait MutVisitor: Sized { noop_visit_arm(a, self); } - fn visit_guard(&mut self, g: &mut Guard) { - noop_visit_guard(g, self); - } - fn visit_pat(&mut self, p: &mut P) { noop_visit_pat(p, self); } @@ -389,17 +385,11 @@ pub fn noop_visit_arm( ) { visit_attrs(attrs, vis); visit_vec(pats, |pat| vis.visit_pat(pat)); - visit_opt(guard, |guard| vis.visit_guard(guard)); + visit_opt(guard, |guard| vis.visit_expr(guard)); vis.visit_expr(body); vis.visit_span(span); } -pub fn noop_visit_guard(g: &mut Guard, vis: &mut T) { - match g { - Guard::If(e) => vis.visit_expr(e), - } -} - pub fn noop_visit_ty_constraint( AssocTyConstraint { id, ident, kind, span }: &mut AssocTyConstraint, vis: &mut T diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index fa697e06d26..7b91ad4a0b4 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3,7 +3,7 @@ use crate::ast::{AngleBracketedArgs, ParenthesizedArgs, AttrStyle, BareFnTy}; use crate::ast::{GenericBound, TraitBoundModifier}; use crate::ast::Unsafety; -use crate::ast::{Mod, AnonConst, Arg, Arm, Guard, Attribute, BindingMode, TraitItemKind}; +use crate::ast::{Mod, AnonConst, Arg, Arm, Attribute, BindingMode, TraitItemKind}; use crate::ast::Block; use crate::ast::{BlockCheckMode, CaptureBy, Movability}; use crate::ast::{Constness, Crate}; @@ -3413,7 +3413,7 @@ impl<'a> Parser<'a> { let lo = self.token.span; let pats = self.parse_pats()?; let guard = if self.eat_keyword(kw::If) { - Some(Guard::If(self.parse_expr()?)) + Some(self.parse_expr()?) } else { None }; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 0aac4f83658..9edd09576e7 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2663,14 +2663,10 @@ impl<'a> State<'a> { self.print_outer_attributes(&arm.attrs)?; self.print_pats(&arm.pats)?; self.s.space()?; - if let Some(ref g) = arm.guard { - match g { - ast::Guard::If(ref e) => { - self.word_space("if")?; - self.print_expr(e)?; - self.s.space()?; - } - } + if let Some(ref e) = arm.guard { + self.word_space("if")?; + self.print_expr(e)?; + self.s.space()?; } self.word_space("=>")?; diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 8132024416a..e2489c16c31 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -834,10 +834,8 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) { pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) { walk_list!(visitor, visit_pat, &arm.pats); - if let Some(ref g) = &arm.guard { - match g { - Guard::If(ref e) => visitor.visit_expr(e), - } + if let Some(ref e) = &arm.guard { + visitor.visit_expr(e); } visitor.visit_expr(&arm.body); walk_list!(visitor, visit_attribute, &arm.attrs);