Add Type::Void variant
Not currently usable as a function argument or explicit return value,
but will be required when we introduce Result for the case of fallible
void functions, whose return type will be Result<()>.
diff --git a/syntax/check.rs b/syntax/check.rs
index df633de..81e1f05 100644
--- a/syntax/check.rs
+++ b/syntax/check.rs
@@ -161,6 +161,7 @@
Type::UniquePtr(_) => "unique_ptr".to_owned(),
Type::Ref(_) => "reference".to_owned(),
Type::Str(_) => "&str".to_owned(),
+ Type::Void(_) => "()".to_owned(),
}
}
diff --git a/syntax/mod.rs b/syntax/mod.rs
index c5cc1de..1acb9a5 100644
--- a/syntax/mod.rs
+++ b/syntax/mod.rs
@@ -9,9 +9,11 @@
mod impls;
mod parse;
pub mod set;
+mod span;
mod tokens;
pub mod types;
+use self::span::Span;
use proc_macro2::Ident;
use syn::{LitStr, Token};
@@ -70,6 +72,7 @@
UniquePtr(Box<Ty1>),
Ref(Box<Ref>),
Str(Box<Ref>),
+ Void(Span),
}
pub struct Ty1 {
diff --git a/syntax/span.rs b/syntax/span.rs
new file mode 100644
index 0000000..c78567e
--- /dev/null
+++ b/syntax/span.rs
@@ -0,0 +1,16 @@
+use std::hash::{Hash, Hasher};
+
+#[derive(Copy, Clone)]
+pub struct Span(pub proc_macro2::Span);
+
+impl Hash for Span {
+ fn hash<H: Hasher>(&self, _state: &mut H) {}
+}
+
+impl Eq for Span {}
+
+impl PartialEq for Span {
+ fn eq(&self, _other: &Span) -> bool {
+ true
+ }
+}
diff --git a/syntax/tokens.rs b/syntax/tokens.rs
index e97509b..4ddc1a6 100644
--- a/syntax/tokens.rs
+++ b/syntax/tokens.rs
@@ -16,6 +16,7 @@
}
Type::RustBox(ty) | Type::UniquePtr(ty) => ty.to_tokens(tokens),
Type::Ref(r) | Type::Str(r) => r.to_tokens(tokens),
+ Type::Void(span) => tokens.extend(quote_spanned!(span.0=> ())),
}
}
}
diff --git a/syntax/types.rs b/syntax/types.rs
index 50f13b1..f9f87f3 100644
--- a/syntax/types.rs
+++ b/syntax/types.rs
@@ -23,7 +23,7 @@
fn visit<'a>(all: &mut Set<'a, Type>, ty: &'a Type) {
all.insert(ty);
match ty {
- Type::Ident(_) | Type::Str(_) => {}
+ Type::Ident(_) | Type::Str(_) | Type::Void(_) => {}
Type::RustBox(ty) | Type::UniquePtr(ty) => visit(all, &ty.inner),
Type::Ref(r) => visit(all, &r.inner),
}