summaryrefslogtreecommitdiff
path: root/src/syntax/span.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/syntax/span.rs')
-rw-r--r--src/syntax/span.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/syntax/span.rs b/src/syntax/span.rs
index e9e1021c..6ba9c44a 100644
--- a/src/syntax/span.rs
+++ b/src/syntax/span.rs
@@ -40,7 +40,7 @@ impl<T> Offset for SpanVec<T> {
}
/// A value with the span it corresponds to in the source code.
-#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
+#[derive(Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
pub struct Spanned<T> {
/// The spanned value.
@@ -178,6 +178,12 @@ impl PartialEq for Span {
}
}
+impl Default for Span {
+ fn default() -> Self {
+ Span::ZERO
+ }
+}
+
impl<T> From<T> for Span
where
T: Into<Pos> + Copy,
@@ -229,6 +235,12 @@ impl From<u32> for Pos {
}
}
+impl From<i32> for Pos {
+ fn from(index: i32) -> Self {
+ Self(index as u32)
+ }
+}
+
impl From<usize> for Pos {
fn from(index: usize) -> Self {
Self(index as u32)