]> git.lizzy.rs Git - rust.git/commitdiff
Make `name` work for `MatchSource`
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Mon, 18 Nov 2019 20:58:28 +0000 (12:58 -0800)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Thu, 21 Nov 2019 22:20:00 +0000 (14:20 -0800)
src/librustc/hir/mod.rs

index 17b13dae37fdbdf04be4fc26608ee782d9590ef7..6f34b42d91c1fbccc4cc19f48b4b931b0ba42983 100644 (file)
@@ -1749,6 +1749,20 @@ pub enum MatchSource {
     AwaitDesugar,
 }
 
+impl MatchSource {
+    pub fn name(self) -> &'static str {
+        use MatchSource::*;
+        match self {
+            Normal => "match",
+            IfDesugar { .. } | IfLetDesugar { .. } => "if",
+            WhileDesugar | WhileLetDesugar => "while",
+            ForLoopDesugar => "for",
+            TryDesugar => "?",
+            AwaitDesugar => ".await",
+        }
+    }
+}
+
 /// The loop type that yielded an `ExprKind::Loop`.
 #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)]
 pub enum LoopSource {
@@ -1766,8 +1780,7 @@ impl LoopSource {
     pub fn name(self) -> &'static str {
         match self {
             LoopSource::Loop => "loop",
-            LoopSource::While => "while",
-            LoopSource::WhileLet => "while let",
+            LoopSource::While | LoopSource::WhileLet => "while",
             LoopSource::ForLoop => "for",
         }
     }