Update syn to 0.15

New and faster parsers!
This commit is contained in:
Alex Crichton
2018-09-04 11:32:09 -07:00
parent e67397ec27
commit 8f9514d216
10 changed files with 123 additions and 129 deletions

View File

@ -233,6 +233,7 @@ impl ImportedTypes for syn::GenericArgument {
syn::GenericArgument::Type(ty) => ty.imported_types(f),
syn::GenericArgument::Binding(_) => {}, // TODO
syn::GenericArgument::Const(_) => {}, // TODO
syn::GenericArgument::Constraint(_) => {}, // TODO
}
}
}

View File

@ -1,5 +1,6 @@
use proc_macro2::*;
use quote::{ToTokens, TokenStreamExt};
use syn::parse::Error;
#[macro_export]
macro_rules! err_span {
@ -26,6 +27,7 @@ enum Repr {
text: String,
span: Option<(Span, Span)>,
},
SynError(Error),
Multi {
diagnostics: Vec<Diagnostic>,
}
@ -62,11 +64,20 @@ impl Diagnostic {
pub fn panic(&self) -> ! {
match &self.inner {
Repr::Single { text, .. } => panic!("{}", text),
Repr::SynError(error) => panic!("{}", error),
Repr::Multi { diagnostics } => diagnostics[0].panic(),
}
}
}
impl From<Error> for Diagnostic {
fn from(err: Error) -> Diagnostic {
Diagnostic {
inner: Repr::SynError(err),
}
}
}
fn extract_spans(node: &ToTokens) -> Option<(Span, Span)> {
let mut t = TokenStream::new();
node.to_tokens(&mut t);
@ -95,6 +106,9 @@ impl ToTokens for Diagnostic {
diagnostic.to_tokens(dst);
}
}
Repr::SynError(err) => {
err.to_compile_error().to_tokens(dst);
}
}
}
}