Initial implementation of stable meaningful spans
diff --git a/src/unstable.rs b/src/unstable.rs
index 6705fb5..7d4e85c 100644
--- a/src/unstable.rs
+++ b/src/unstable.rs
@@ -159,6 +159,41 @@
}
}
+#[derive(Clone, PartialEq, Eq)]
+pub struct SourceFile(proc_macro::SourceFile);
+
+impl SourceFile {
+ /// Get the path to this source file as a string.
+ pub fn as_str(&self) -> &str {
+ self.0.as_str()
+ }
+
+ pub fn is_real(&self) -> bool {
+ self.0.is_real()
+ }
+}
+
+impl AsRef<str> for SourceFile {
+ fn as_ref(&self) -> &str {
+ self.0.as_ref()
+ }
+}
+
+impl PartialEq<str> for SourceFile {
+ fn eq(&self, other: &str) -> bool {
+ self.0.eq(other)
+ }
+}
+
+impl fmt::Debug for SourceFile {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ self.0.fmt(f)
+ }
+}
+
+// XXX(nika): We can't easily wrap LineColumn right now
+pub use proc_macro::LineColumn;
+
#[derive(Copy, Clone)]
pub struct Span(proc_macro::Span);
@@ -170,6 +205,24 @@
pub fn def_site() -> Span {
Span(proc_macro::Span::def_site())
}
+
+ pub fn source_file(&self) -> SourceFile {
+ SourceFile(self.0.source_file())
+ }
+
+ pub fn start(&self) -> LineColumn {
+ // XXX(nika): We can't easily wrap LineColumn right now
+ self.0.start()
+ }
+
+ pub fn end(&self) -> LineColumn {
+ // XXX(nika): We can't easily wrap LineColumn right now
+ self.0.end()
+ }
+
+ pub fn join(&self, other: Span) -> Option<Span> {
+ self.0.join(other.0).map(Span)
+ }
}
impl fmt::Debug for Span {