Skip to content

Commit

Permalink
Improve syntax errors by switching to syn 0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
antoyo committed Nov 16, 2018
1 parent 4cd718b commit 3d836d3
Show file tree
Hide file tree
Showing 9 changed files with 615 additions and 367 deletions.
1 change: 0 additions & 1 deletion examples/async/src/main.rs
Expand Up @@ -31,7 +31,6 @@ extern crate relm_derive;
use gio::{
AppInfo,
AppLaunchContext,
CancellableExt,
File,
FileExt,
};
Expand Down
5 changes: 4 additions & 1 deletion relm-attributes/Cargo.toml
Expand Up @@ -9,7 +9,10 @@ version = "0.15.0"

[dependencies]
quote = "0.6"
syn = "0.14"

[dependencies.syn]
features = ["full"]
version = "0.15"

[dependencies.relm-gen-widget]
path = "../relm-gen-widget"
Expand Down
5 changes: 4 additions & 1 deletion relm-derive-common/Cargo.toml
Expand Up @@ -9,7 +9,10 @@ version = "0.15.0"
[dependencies]
proc-macro2 = "^0.4.3"
quote = "0.6"
syn = "0.14"

[dependencies.syn]
features = ["extra-traits", "full"]
version = "0.15"

[dependencies.relm-gen-widget]
path = "../relm-gen-widget"
Expand Down
4 changes: 2 additions & 2 deletions relm-derive-common/src/lib.rs
Expand Up @@ -39,7 +39,7 @@ pub fn impl_simple_msg(ast: &Item, krate: Ident) -> TokenStream {
let typ = quote! {
#name #generics_without_bound
};
let where_clause = gen_where_clause(&generics);
let where_clause = gen_where_clause(generics);

quote! {
#display
Expand Down Expand Up @@ -143,7 +143,7 @@ fn derive_into_option(ast: &Item, krate: &Ident) -> TokenStream {
let typ = quote! {
#name #generics_without_bound
};
let where_clause = gen_where_clause(&generics);
let where_clause = gen_where_clause(generics);

quote_spanned! { krate.span() =>
impl #generics ::#krate::IntoOption<#typ> for #typ #where_clause {
Expand Down
2 changes: 1 addition & 1 deletion relm-derive-state/Cargo.toml
Expand Up @@ -10,7 +10,7 @@ version = "0.15.0"
proc-macro = true

[dependencies]
syn = "0.14"
syn = "0.15"

[dependencies.relm-derive-common]
path = "../relm-derive-common"
Expand Down
2 changes: 1 addition & 1 deletion relm-derive/Cargo.toml
Expand Up @@ -12,7 +12,7 @@ proc-macro = true

[dependencies]
quote = "0.6"
syn = "0.14"
syn = "0.15"

[dependencies.relm-derive-common]
path = "../relm-derive-common"
Expand Down
2 changes: 1 addition & 1 deletion relm-gen-widget/Cargo.toml
Expand Up @@ -14,7 +14,7 @@ quote = "0.6"

[dependencies.syn]
features = ["extra-traits", "fold", "full", "visit"]
version = "^0.14"
version = "^0.15"

[features]
unstable = ["proc-macro2/nightly"]
20 changes: 13 additions & 7 deletions relm-gen-widget/src/lib.rs
Expand Up @@ -62,8 +62,9 @@ use syn::{
};
use syn::FnArg::{self, Captured};
use syn::fold::Fold;
use syn::ImplItem::{Const, Method, Verbatim};
use syn::ImplItem::{Const, Existential, Method, Verbatim};
use syn::Item::{self, Impl};
use syn::parse::Result;
use syn::spanned::Spanned;
use syn::Type;
use syn::visit::Visit;
Expand Down Expand Up @@ -213,6 +214,7 @@ impl Driver {
let mut i = item.clone();
match item {
Const(..) => panic!("Unexpected const item"),
Existential(..) => panic!("Unexpected existential item"),
ImplItem::Macro(mac) => self.view_macro = Some(mac.mac),
Method(ImplItemMethod { sig, .. }) => {
match sig.ident.to_string().as_ref() {
Expand Down Expand Up @@ -244,7 +246,11 @@ impl Driver {
Verbatim(..) => panic!("Unexpected verbatim item"),
}
}
let view = self.get_view(&name, &self_ty);
let view =
match self.get_view(&name, &self_ty) {
Ok(view) => view,
Err(error) => return error.to_compile_error(),
};
if let Some(on_add) = gen_set_child_prop_calls(&view.widget) {
new_items.push(on_add);
}
Expand Down Expand Up @@ -366,7 +372,7 @@ impl Driver {
func
}

fn get_view(&mut self, name: &Ident, typ: &Type) -> View {
fn get_view(&mut self, name: &Ident, typ: &Type) -> Result<View> {
// This method should probably just be replaced with `impl_view` and
// `view_validation_before_impl` should be put inside `impl_view`
self.view_validation_before_impl();
Expand Down Expand Up @@ -415,9 +421,9 @@ impl Driver {
*/
}

fn impl_view(&mut self, name: &Ident, typ: &Type) -> View {
fn impl_view(&mut self, name: &Ident, typ: &Type) -> Result<View> {
let tts = self.view_macro.take().expect("view_macro in impl_view()").tts;
let mut widget = parse_widget(tts);
let mut widget = parse_widget(tts)?;
if let Gtk(ref mut widget) = widget.widget {
widget.relm_name = Some(typ.clone());
}
Expand All @@ -436,14 +442,14 @@ impl Driver {
}
};
let item = block_to_impl_item(code);
View {
Ok(View {
container_impl,
item,
msg_model_map,
properties_model_map,
relm_widgets,
widget,
}
})
}

fn update_impl(&mut self, typ: &Type, generics: &Generics, items: Vec<ImplItem>) -> TokenStream {
Expand Down

0 comments on commit 3d836d3

Please sign in to comment.