about summary refs log tree commit diff
path: root/src/librustc
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-12-14 23:43:21 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2019-12-23 14:47:19 +0100
commitb9aba749cfc192422d879b12c7a5c3674f5ad110 (patch)
treeeaeb3f4a300e3118ca479117127055ff51b75a48 /src/librustc
parent5a8baa28763a706ff7a338b1492ca31cf8c615c1 (diff)
downloadrust-b9aba749cfc192422d879b12c7a5c3674f5ad110.tar.gz
rust-b9aba749cfc192422d879b12c7a5c3674f5ad110.zip
improve robustness of pat walkers
Diffstat (limited to 'src/librustc')
-rw-r--r--src/librustc/hir/mod.rs10
-rw-r--r--src/librustc/hir/pat_util.rs3
2 files changed, 11 insertions, 2 deletions
diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs
index 4aa8c12a219..a85685caf7d 100644
--- a/src/librustc/hir/mod.rs
+++ b/src/librustc/hir/mod.rs
@@ -921,6 +921,16 @@ impl Pat {
     pub fn walk(&self, mut it: impl FnMut(&Pat) -> bool) {
         self.walk_(&mut it)
     }
+
+    /// Walk the pattern in left-to-right order.
+    ///
+    /// If you always want to recurse, prefer this method over `walk`.
+    pub fn walk_always(&self, mut it: impl FnMut(&Pat)) {
+        self.walk(|p| {
+            it(p);
+            true
+        })
+    }
 }
 
 /// A single field in a struct pattern.
diff --git a/src/librustc/hir/pat_util.rs b/src/librustc/hir/pat_util.rs
index c0aa54beac2..8d3b464a8ff 100644
--- a/src/librustc/hir/pat_util.rs
+++ b/src/librustc/hir/pat_util.rs
@@ -79,11 +79,10 @@ impl hir::Pat {
     /// Call `f` on every "binding" in a pattern, e.g., on `a` in
     /// `match foo() { Some(a) => (), None => () }`
     pub fn each_binding(&self, mut f: impl FnMut(hir::BindingAnnotation, HirId, Span, ast::Ident)) {
-        self.walk(|p| {
+        self.walk_always(|p| {
             if let PatKind::Binding(binding_mode, _, ident, _) = p.kind {
                 f(binding_mode, p.hir_id, p.span, ident);
             }
-            true
         });
     }