From 14b18111821d8e1929df149a8782e9b7c761b1ff Mon Sep 17 00:00:00 2001 From: Ferdia McKeogh Date: Thu, 7 Jun 2018 11:45:11 +0100 Subject: [PATCH] Fix "Could not find `Op` in `proc_macro`" --- Cargo.toml | 4 ++++ macros/Cargo.toml | 8 ++++---- macros/src/check.rs | 2 +- macros/src/trans.rs | 33 ++++++++++++++++----------------- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fdb1d18d65..94f81eea7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,10 @@ cortex-m = "0.4.0" cortex-m-rtfm-macros = { path = "macros", version = "0.3.1" } rtfm-core = "0.2.0" untagged-option = "0.1.1" +syn = "0.14.2" +quote = "0.6.3" +proc-macro2 = "0.4.6" +failure = "0.1.1" [target.'cfg(target_arch = "x86_64")'.dev-dependencies] compiletest_rs = "0.3.5" diff --git a/macros/Cargo.toml b/macros/Cargo.toml index d36499e4bc..5121e7f2ab 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -11,10 +11,10 @@ version = "0.3.1" [dependencies] failure = "0.1.1" -proc-macro2 = "0.3.6" -quote = "0.5.1" -rtfm-syntax = "0.3.0" -syn = "0.13.1" +proc-macro2 = "0.4.6" +quote = "0.6.3" +rtfm-syntax = {git = "https://github.com/chocol4te/rtfm-syntax.git"} +syn = "0.14.2" [lib] proc-macro = true diff --git a/macros/src/check.rs b/macros/src/check.rs index 4defb46d7d..b81fc4d435 100644 --- a/macros/src/check.rs +++ b/macros/src/check.rs @@ -61,7 +61,7 @@ pub fn app(app: check::App) -> Result { tasks: app.tasks .into_iter() .map(|(k, v)| { - let v = ::check::task(k.as_ref(), v)?; + let v = ::check::task(&k.to_string(), v)?; Ok((k, v)) }) diff --git a/macros/src/trans.rs b/macros/src/trans.rs index 964b1a3081..3da1e3ef44 100644 --- a/macros/src/trans.rs +++ b/macros/src/trans.rs @@ -1,15 +1,14 @@ -use proc_macro2::Span; -use quote::Tokens; +use proc_macro2::{TokenStream, Span}; use syn::{Ident, LitStr}; use analyze::Ownerships; use check::{App, Kind}; fn krate() -> Ident { - Ident::from("rtfm") + Ident::new("rtfm", Span::call_site()) } -pub fn app(app: &App, ownerships: &Ownerships) -> Tokens { +pub fn app(app: &App, ownerships: &Ownerships) -> TokenStream { let mut root = vec![]; let mut main = vec![quote!(#![allow(path_statements)])]; @@ -28,7 +27,7 @@ pub fn app(app: &App, ownerships: &Ownerships) -> Tokens { quote!(#(#root)*) } -fn idle(app: &App, ownerships: &Ownerships, main: &mut Vec, root: &mut Vec) { +fn idle(app: &App, ownerships: &Ownerships, main: &mut Vec, root: &mut Vec) { let krate = krate(); let mut mod_items = vec![]; @@ -54,7 +53,7 @@ fn idle(app: &App, ownerships: &Ownerships, main: &mut Vec, root: &mut V let super_ = if needs_reexport { None } else { - Some(Ident::from("super")) + Some(Ident::new("super", Span::call_site())) }; let mut rexprs = vec![]; let mut rfields = vec![]; @@ -70,7 +69,7 @@ fn idle(app: &App, ownerships: &Ownerships, main: &mut Vec, root: &mut V pub #name: &'static mut #ty, }); - let _name = Ident::from(format!("_{}", name.as_ref())); + let _name = Ident::new(&name.to_string(), Span::call_site()); rexprs.push(if resource.expr.is_some() { quote! { #name: &mut #super_::#_name, @@ -136,7 +135,7 @@ fn idle(app: &App, ownerships: &Ownerships, main: &mut Vec, root: &mut V continue; } - let _name = Ident::from(format!("_{}", name.as_ref())); + let _name = Ident::new(&name.to_string(), Span::call_site()); let resource = app.resources .get(name) .expect(&format!("BUG: resource {} has no definition", name)); @@ -224,7 +223,7 @@ fn idle(app: &App, ownerships: &Ownerships, main: &mut Vec, root: &mut V }); } -fn init(app: &App, main: &mut Vec, root: &mut Vec) { +fn init(app: &App, main: &mut Vec, root: &mut Vec) { let device = &app.device; let krate = krate(); @@ -263,7 +262,7 @@ fn init(app: &App, main: &mut Vec, root: &mut Vec) { &mut #name },)); } else { - let _name = Ident::from(format!("_{}", name.as_ref())); + let _name = Ident::new(&name.to_string(), Span::call_site()); lifetime = Some(quote!('a)); fields.push(quote! { @@ -310,7 +309,7 @@ fn init(app: &App, main: &mut Vec, root: &mut Vec) { let mut fields = vec![]; for (name, resource) in late_resources { - let _name = Ident::from(format!("_{}", name.as_ref())); + let _name = Ident::new(&name.to_string(), Span::call_site()); let ty = &resource.ty; @@ -415,11 +414,11 @@ fn init(app: &App, main: &mut Vec, root: &mut Vec) { }); } -fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec) { +fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec) { let krate = krate(); for name in ownerships.keys() { - let _name = Ident::from(format!("_{}", name.as_ref())); + let _name = Ident::new(&name.to_string(), Span::call_site()); // Declare the static that holds the resource let resource = app.resources @@ -442,7 +441,7 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec) { } } -fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec, main: &mut Vec) { +fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec, main: &mut Vec) { let device = &app.device; let krate = krate(); @@ -456,7 +455,7 @@ fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec, main: &mut if has_resources { for rname in &task.resources { let ceiling = ownerships[rname].ceiling(); - let _rname = Ident::from(format!("_{}", rname.as_ref())); + let _rname = Ident::new(&rname.to_string(), Span::call_site()); let resource = app.resources .get(rname) .expect(&format!("BUG: resource {} has no definition", rname)); @@ -594,8 +593,8 @@ fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec, main: &mut } let path = &task.path; - let _tname = Ident::from(format!("_{}", tname)); - let export_name = LitStr::new(tname.as_ref(), Span::call_site()); + let _tname = Ident::new(&tname.to_string(), Span::call_site()); + let export_name = LitStr::new(&tname.to_string(), Span::call_site()); root.push(quote! { #[allow(non_snake_case)] #[allow(unsafe_code)]