about summary refs log tree commit diff
path: root/src/libsyntax_pos/lib.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-08-18 00:26:08 +0000
committerbors <bors@rust-lang.org>2017-08-18 00:26:08 +0000
commit4ac7646d3929b54678095dd349783e73f6b0b14d (patch)
tree8355a67a27c87510229c01eb480c1fd62e0e99ca /src/libsyntax_pos/lib.rs
parent59ccba995de202fb9d9a8d795d2770fb2d199db0 (diff)
parentff047a8a25738badbb88b97edf0f8108b4bc356b (diff)
downloadrust-4ac7646d3929b54678095dd349783e73f6b0b14d.tar.gz
rust-4ac7646d3929b54678095dd349783e73f6b0b14d.zip
Auto merge of #43832 - huntiep:compiler-desugaring-enum, r=nikomatsakis
Implement CompilerDesugaringKind enum

This is the first step outlined in #35946. I think that the variants of `CompilerDesugaringKind` should be changed, I didn't know what the official names for `...` and `<-` are.

I'm not to sure how tests for the compiler work, but I would imagine that tests should be added such that
`Symbol::intern(s) == CompilerDesugaringKind::from(s).as_symbol()` for valid `s`.
Diffstat (limited to 'src/libsyntax_pos/lib.rs')
-rw-r--r--src/libsyntax_pos/lib.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs
index f5449061b87..2385e3509ad 100644
--- a/src/libsyntax_pos/lib.rs
+++ b/src/libsyntax_pos/lib.rs
@@ -47,7 +47,7 @@ extern crate serialize;
 extern crate serialize as rustc_serialize; // used by deriving
 
 pub mod hygiene;
-pub use hygiene::{SyntaxContext, ExpnInfo, ExpnFormat, NameAndSpan};
+pub use hygiene::{SyntaxContext, ExpnInfo, ExpnFormat, NameAndSpan, CompilerDesugaringKind};
 
 pub mod symbol;
 
@@ -153,6 +153,17 @@ impl Span {
         }
     }
 
+    /// Check if this span arises from a compiler desugaring of kind `kind`.
+    pub fn is_compiler_desugaring(&self, kind: CompilerDesugaringKind) -> bool {
+        match self.ctxt.outer().expn_info() {
+            Some(info) => match info.callee.format {
+                ExpnFormat::CompilerDesugaring(k) => k == kind,
+                _ => false,
+            },
+            None => false,
+        }
+    }
+
     /// Check if a span is "internal" to a macro in which `unsafe`
     /// can be used without triggering the `unsafe_code` lint
     //  (that is, a macro marked with `#[allow_internal_unsafe]`).