diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index f7ffbe8c65833..9a45d1bd3203b 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -469,9 +469,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { // expression to target let guard_start = self.add_dummy_node(&[pat_exit]); // Visit the guard expression - let guard_exit = match guard { - hir::Guard::If(ref e) => self.expr(e, guard_start), - }; + let guard_exit = self.expr(guard, guard_start); // #47295: We used to have very special case code // here for when a pair of arms are both formed // solely from constants, and if so, not add these diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 86c3fb9e4fcd7..bc8c2e10754d9 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -1092,10 +1092,8 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v 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); diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index d0fd5bd6844b0..603e4a17d10a9 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1130,7 +1130,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 e) => Some(P(self.lower_expr(e))), _ => None, }, body: P(self.lower_expr(&arm.body)), diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 3e7dd1432e1e3..f50b0e29421c4 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1198,15 +1198,10 @@ pub struct Local { pub struct Arm { pub attrs: HirVec, pub pats: HirVec>, - pub guard: Option, + pub guard: Option>, pub body: P, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub enum Guard { - If(P), -} - #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct Field { pub id: NodeId, diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 9b6fcf259be14..d5c5fa5191026 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -1940,14 +1940,10 @@ impl<'a> State<'a> { self.print_pat(&p)?; } self.s.space()?; - if let Some(ref g) = arm.guard { - match g { - hir::Guard::If(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/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 2b359428b1fa1..a6f344ec585a9 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -517,10 +517,6 @@ impl_stable_hash_for!(struct hir::Arm { body }); -impl_stable_hash_for!(enum hir::Guard { - If(expr), -}); - impl_stable_hash_for!(struct hir::Field { id -> _, hir_id -> _, diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 0939f07f43bb3..3569e52446d15 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -793,7 +793,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { self.walk_pat(discr_cmt.clone(), &pat, mode); } - if let Some(hir::Guard::If(ref e)) = arm.guard { + if let Some(ref e) = arm.guard { self.consume_expr(e) } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 4eb7b918dd8be..dd263a94fb956 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1085,7 +1085,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { let body_succ = self.propagate_through_expr(&arm.body, succ); let guard_succ = self.propagate_through_opt_expr( - arm.guard.as_ref().map(|hir::Guard::If(e)| &**e), + arm.guard.as_ref().map(|e| &**e), body_succ ); // only consider the first pattern; any later patterns must have diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 788d2185d6da2..93c0250ec89f7 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -815,7 +815,7 @@ fn resolve_block<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, blk: fn resolve_arm<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, arm: &'tcx hir::Arm) { visitor.terminating_scopes.insert(arm.body.hir_id.local_id); - if let Some(hir::Guard::If(ref expr)) = arm.guard { + if let Some(ref expr) = arm.guard { visitor.terminating_scopes.insert(expr.hir_id.local_id); } diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 2f1e8c03f2f7e..5fde4a045036d 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -625,7 +625,7 @@ pub struct Candidate<'pat, 'tcx: 'pat> { ascriptions: Vec>, // ...and the guard must be evaluated... - guard: Option>, + guard: Option>, // ...and then we branch to arm with this index. arm_index: usize, @@ -1242,9 +1242,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { // the block to branch to if the guard fails; if there is no // guard, this block is simply unreachable - let guard = match guard { - Guard::If(e) => self.hir.mirror(e), - }; + let guard = self.hir.mirror(guard); let source_info = self.source_info(guard.span); let cond = unpack!(block = self.as_local_operand(block, guard)); if autoref { diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 8d64c9e9ada89..5082eddf74b88 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -894,9 +894,9 @@ fn convert_arm<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, arm: &'tcx hir::Arm) Arm { patterns: arm.pats.iter().map(|p| cx.pattern_from_hir(p)).collect(), guard: match arm.guard { - Some(hir::Guard::If(ref e)) => Some(Guard::If(e.to_ref())), - _ => None, - }, + Some(ref e) => Some(e.to_ref()), + _ => None, + }, body: arm.body.to_ref(), // BUG: fix this lint_level: LintLevel::Inherited, diff --git a/src/librustc_mir/hair/mod.rs b/src/librustc_mir/hair/mod.rs index f0f8acb31df42..4b4d85770a31e 100644 --- a/src/librustc_mir/hair/mod.rs +++ b/src/librustc_mir/hair/mod.rs @@ -321,16 +321,11 @@ pub struct FruInfo<'tcx> { #[derive(Clone, Debug)] pub struct Arm<'tcx> { pub patterns: Vec>, - pub guard: Option>, + pub guard: Option>, pub body: ExprRef<'tcx>, pub lint_level: LintLevel, } -#[derive(Clone, Debug)] -pub enum Guard<'tcx> { - If(ExprRef<'tcx>), -} - #[derive(Copy, Clone, Debug)] pub enum LogicalOp { And, diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index a47d64319bdc5..ce556f2f14776 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -187,9 +187,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { } (pattern, &**pat) }).collect(), - arm.guard.as_ref().map(|g| match g { - hir::Guard::If(ref e) => &**e, - }) + arm.guard.as_ref().map(|e| &**e), )).collect(); // Bail out early if inlining failed. @@ -541,19 +539,16 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor, /// assign. /// /// FIXME: this should be done by borrowck. -fn check_for_mutation_in_guard(cx: &MatchVisitor, guard: &hir::Guard) { +fn check_for_mutation_in_guard(cx: &MatchVisitor, guard: &hir::Expr) { let mut checker = MutationChecker { cx, }; - match guard { - hir::Guard::If(expr) => - ExprUseVisitor::new(&mut checker, - cx.tcx, - cx.param_env, - cx.region_scope_tree, - cx.tables, - None).walk_expr(expr), - }; + ExprUseVisitor::new(&mut checker, + cx.tcx, + cx.param_env, + cx.region_scope_tree, + cx.tables, + None).walk_expr(guard) } struct MutationChecker<'a, 'tcx: 'a> { diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs index 739c96934e6ab..2c7036d45ad4c 100644 --- a/src/librustc_passes/rvalue_promotion.rs +++ b/src/librustc_passes/rvalue_promotion.rs @@ -524,7 +524,7 @@ fn check_expr_kind<'a, 'tcx>( let _ = v.check_expr(expr); for index in hirvec_arm.iter() { let _ = v.check_expr(&*index.body); - if let Some(hir::Guard::If(ref expr)) = index.guard { + if let Some(ref expr) = index.guard { let _ = v.check_expr(&expr); } } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 270f242419714..f505bc1755e0f 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2895,7 +2895,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 995df3802aabd..1ee02a77e5a37 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -1581,7 +1581,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc 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), + Some(ref expr) => self.visit_expr(expr), _ => {} } self.visit_expr(&arm.body); diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index a90d83f3f8be0..bcd1328f5fcca 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -690,11 +690,9 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); }; for (i, (arm, pats_diverge)) in arms.iter().zip(all_arm_pats_diverge).enumerate() { - if let Some(ref g) = arm.guard { + if let Some(ref e) = arm.guard { self.diverges.set(pats_diverge); - match g { - hir::Guard::If(e) => self.check_expr_has_type_or_error(e, tcx.types.bool), - }; + self.check_expr_has_type_or_error(e, tcx.types.bool); } self.diverges.set(pats_diverge); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 2cfe2cc896cb1..4f23baf4fe6d3 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -859,15 +859,10 @@ pub struct Local { pub struct Arm { pub attrs: Vec, pub pats: Vec>, - pub guard: Option, + pub guard: Option>, pub body: P, } -#[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 0fd8bbf100fa2..9f88486e04f6f 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); } @@ -379,16 +375,10 @@ pub fn noop_visit_use_tree(use_tree: &mut UseTree, vis: &mut T) { pub fn noop_visit_arm(Arm { attrs, pats, guard, body }: &mut Arm, vis: &mut T) { 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); } -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_binding(TypeBinding { id, ident, ty, span }: &mut TypeBinding, vis: &mut T) { vis.visit_id(id); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index cacdab980facd..b8464d9ee59e9 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1,7 +1,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}; @@ -3922,7 +3922,7 @@ impl<'a> Parser<'a> { let attrs = self.parse_outer_attributes()?; let pats = self.parse_pats()?; let guard = if self.eat_keyword(keywords::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 c7c4c4f16205b..52d0c863f5ab2 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2729,14 +2729,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 acbb58a66b6b4..a79b362251f96 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -811,10 +811,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);