about summary refs log tree commit diff
path: root/src/libsyntax_pos/lib.rs
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2017-08-08 18:21:20 +0300
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2017-08-12 09:14:50 +0300
commit8a4facc3c30d9dfbbfc1ddc6d413dfb0520699c6 (patch)
treef17dec95c54f6880ef5a4705db742ecb648847ae /src/libsyntax_pos/lib.rs
parent2fa5340318111d562af2ef4897c75916731d55a2 (diff)
downloadrust-8a4facc3c30d9dfbbfc1ddc6d413dfb0520699c6.tar.gz
rust-8a4facc3c30d9dfbbfc1ddc6d413dfb0520699c6.zip
syntax: #[allow_internal_unsafe] bypasses the unsafe_code lint in macros.
Diffstat (limited to 'src/libsyntax_pos/lib.rs')
-rw-r--r--src/libsyntax_pos/lib.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs
index 7006f45455e..e162bc26412 100644
--- a/src/libsyntax_pos/lib.rs
+++ b/src/libsyntax_pos/lib.rs
@@ -153,6 +153,16 @@ impl Span {
         }
     }
 
+    /// 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]`).
+    pub fn allows_unsafe(&self) -> bool {
+        match self.ctxt.outer().expn_info() {
+            Some(info) => info.callee.allow_internal_unsafe,
+            None => false,
+        }
+    }
+
     pub fn macro_backtrace(mut self) -> Vec<MacroBacktrace> {
         let mut prev_span = DUMMY_SP;
         let mut result = vec![];