]> git.lizzy.rs Git - rust.git/blobdiff - src/libsyntax_pos/lib.rs
Introduce InnerSpan abstraction
[rust.git] / src / libsyntax_pos / lib.rs
index 9bab95efd1bb7dc1e72757211a595e91002597c4..bf0ab5fae4e8734f25eea428db46b90c8a1cf12d 100644 (file)
@@ -11,7 +11,6 @@
 
 #![feature(const_fn)]
 #![feature(crate_visibility_modifier)]
-#![feature(custom_attribute)]
 #![feature(nll)]
 #![feature(non_exhaustive)]
 #![feature(optin_builtin_traits)]
@@ -505,10 +504,10 @@ pub fn until(self, end: Span) -> Span {
         )
     }
 
-    pub fn from_inner_byte_pos(self, start: usize, end: usize) -> Span {
+    pub fn from_inner(self, inner: InnerSpan) -> Span {
         let span = self.data();
-        Span::new(span.lo + BytePos::from_usize(start),
-                  span.lo + BytePos::from_usize(end),
+        Span::new(span.lo + BytePos::from_usize(inner.start),
+                  span.lo + BytePos::from_usize(inner.end),
                   span.ctxt)
     }
 
@@ -534,6 +533,14 @@ pub fn adjust(&mut self, expansion: Mark) -> Option<Mark> {
         mark
     }
 
+    #[inline]
+    pub fn modernize_and_adjust(&mut self, expansion: Mark) -> Option<Mark> {
+        let mut span = self.data();
+        let mark = span.ctxt.modernize_and_adjust(expansion);
+        *self = Span::new(span.lo, span.hi, span.ctxt);
+        mark
+    }
+
     #[inline]
     pub fn glob_adjust(&mut self, expansion: Mark, glob_span: Span) -> Option<Option<Mark>> {
         let mut span = self.data();
@@ -1388,6 +1395,18 @@ pub struct MalformedSourceMapPositions {
     pub end_pos: BytePos
 }
 
+#[derive(Copy, Clone, PartialEq, Eq, Debug)]
+pub struct InnerSpan {
+    pub start: usize,
+    pub end: usize,
+}
+
+impl InnerSpan {
+    pub fn new(start: usize, end: usize) -> InnerSpan {
+        InnerSpan { start, end }
+    }
+}
+
 // Given a slice of line start positions and a position, returns the index of
 // the line the position is on. Returns -1 if the position is located before
 // the first line.