0 | |
diff --git a/diesel_migrations/migrations_macros/src/embed_migrations.rs b/diesel_migrations/migrations_macros/src/embed_migrations.rs
|
1 | |
index 82541361..4dc2a7f9 100644
|
2 | |
--- a/src/embed_migrations.rs
|
3 | |
+++ b/src/embed_migrations.rs
|
4 | |
@@ -1,4 +1,4 @@
|
5 | |
-use quote;
|
6 | |
+use proc_macro2;
|
7 | |
use syn;
|
8 | |
|
9 | |
use migrations::migration_directory_from_given_path;
|
10 | |
@@ -8,7 +8,7 @@ use std::path::Path;
|
11 | |
|
12 | |
use util::{get_option, get_options_from_input};
|
13 | |
|
14 | |
-pub fn derive_embed_migrations(input: &syn::DeriveInput) -> quote::Tokens {
|
15 | |
+pub fn derive_embed_migrations(input: &syn::DeriveInput) -> proc_macro2::TokenStream {
|
16 | |
fn bug() -> ! {
|
17 | |
panic!(
|
18 | |
"This is a bug. Please open a Github issue \
|
19 | |
@@ -16,12 +16,14 @@ pub fn derive_embed_migrations(input: &syn::DeriveInput) -> quote::Tokens {
|
20 | |
);
|
21 | |
}
|
22 | |
|
23 | |
- let options = get_options_from_input("embed_migrations_options", &input.attrs, bug);
|
24 | |
+ let options =
|
25 | |
+ get_options_from_input(&parse_quote!(embed_migrations_options), &input.attrs, bug);
|
26 | |
let migrations_path_opt = options
|
27 | |
.as_ref()
|
28 | |
.map(|o| get_option(o, "migrations_path", bug));
|
29 | |
- let migrations_expr = migration_directory_from_given_path(migrations_path_opt)
|
30 | |
- .and_then(|path| migration_literals_from_path(&path));
|
31 | |
+ let migrations_expr =
|
32 | |
+ migration_directory_from_given_path(migrations_path_opt.as_ref().map(String::as_str))
|
33 | |
+ .and_then(|path| migration_literals_from_path(&path));
|
34 | |
let migrations_expr = match migrations_expr {
|
35 | |
Ok(v) => v,
|
36 | |
Err(e) => panic!("Error reading migrations: {}", e),
|
37 | |
@@ -78,7 +80,7 @@ pub fn derive_embed_migrations(input: &syn::DeriveInput) -> quote::Tokens {
|
38 | |
}
|
39 | |
}
|
40 | |
|
41 | |
-fn migration_literals_from_path(path: &Path) -> Result<Vec<quote::Tokens>, Box<Error>> {
|
42 | |
+fn migration_literals_from_path(path: &Path) -> Result<Vec<proc_macro2::TokenStream>, Box<Error>> {
|
43 | |
let mut migrations = migration_paths_in_directory(path)?;
|
44 | |
|
45 | |
migrations.sort_by_key(|a| a.path());
|
46 | |
@@ -89,7 +91,7 @@ fn migration_literals_from_path(path: &Path) -> Result<Vec<quote::Tokens>, Box<E
|
47 | |
.collect()
|
48 | |
}
|
49 | |
|
50 | |
-fn migration_literal_from_path(path: &Path) -> Result<quote::Tokens, Box<Error>> {
|
51 | |
+fn migration_literal_from_path(path: &Path) -> Result<proc_macro2::TokenStream, Box<Error>> {
|
52 | |
let version = version_from_path(path)?;
|
53 | |
let sql_file = path.join("up.sql");
|
54 | |
let sql_file_path = sql_file.to_str();
|
55 | |
diff --git a/diesel_migrations/migrations_macros/src/lib.rs b/diesel_migrations/migrations_macros/src/lib.rs
|
56 | |
index 0a83234e..b8f3bfc9 100644
|
57 | |
--- a/src/lib.rs
|
58 | |
+++ b/src/lib.rs
|
59 | |
@@ -1,5 +1,5 @@
|
60 | |
// Built-in Lints
|
61 | |
-#![deny(warnings, missing_debug_implementations, missing_copy_implementations)]
|
62 | |
+#![deny(missing_debug_implementations, missing_copy_implementations)]
|
63 | |
// Clippy lints
|
64 | |
#![allow(
|
65 | |
clippy::option_map_unwrap_or_else,
|
66 | |
diff --git a/diesel_migrations/migrations_macros/src/lib.rs b/diesel_migrations/migrations_macros/src/lib.rs
|
67 | |
index 0a83234e..b8f3bfc9 100644
|
68 | |
--- a/src/lib.rs
|
69 | |
+++ b/src/lib.rs
|
70 | |
@@ -23,8 +23,10 @@
|
71 | |
#![cfg_attr(test, allow(clippy::option_unwrap_used, clippy::result_unwrap_used))]
|
72 | |
extern crate migrations_internals;
|
73 | |
extern crate proc_macro;
|
74 | |
+extern crate proc_macro2;
|
75 | |
#[macro_use]
|
76 | |
extern crate quote;
|
77 | |
+#[macro_use]
|
78 | |
extern crate syn;
|
79 | |
|
80 | |
mod embed_migrations;
|
81 | |
@@ -32,11 +34,11 @@ mod migrations;
|
82 | |
mod util;
|
83 | |
|
84 | |
use proc_macro::TokenStream;
|
85 | |
-use syn::parse_derive_input;
|
86 | |
+use syn::DeriveInput;
|
87 | |
|
88 | |
#[proc_macro_derive(EmbedMigrations, attributes(embed_migrations_options))]
|
89 | |
pub fn derive_embed_migrations(input: TokenStream) -> TokenStream {
|
90 | |
- let item = parse_derive_input(&input.to_string()).unwrap();
|
91 | |
+ let item = parse_macro_input!(input as DeriveInput);
|
92 | |
embed_migrations::derive_embed_migrations(&item)
|
93 | |
.to_string()
|
94 | |
.parse()
|
95 | |
diff --git a/diesel_migrations/migrations_macros/src/util.rs b/diesel_migrations/migrations_macros/src/util.rs
|
96 | |
index 8c502bef..9aa095f4 100644
|
97 | |
--- a/src/util.rs
|
98 | |
+++ b/src/util.rs
|
99 | |
@@ -1,8 +1,11 @@
|
100 | |
use syn::*;
|
101 | |
|
102 | |
-pub fn str_value_of_meta_item<'a>(item: &'a MetaItem, name: &str) -> &'a str {
|
103 | |
+pub fn str_value_of_meta_item(item: &Meta, name: &str) -> String {
|
104 | |
match *item {
|
105 | |
- MetaItem::NameValue(_, Lit::Str(ref value, _)) => &*value,
|
106 | |
+ Meta::NameValue(MetaNameValue {
|
107 | |
+ lit: Lit::Str(ref value),
|
108 | |
+ ..
|
109 | |
+ }) => value.value(),
|
110 | |
_ => panic!(
|
111 | |
r#"`{}` must be in the form `#[{}="something"]`"#,
|
112 | |
name, name
|
113 | |
@@ -11,17 +14,20 @@ pub fn str_value_of_meta_item<'a>(item: &'a MetaItem, name: &str) -> &'a str {
|
114 | |
}
|
115 | |
|
116 | |
pub fn get_options_from_input(
|
117 | |
- name: &str,
|
118 | |
+ name: &Path,
|
119 | |
attrs: &[Attribute],
|
120 | |
on_bug: fn() -> !,
|
121 | |
-) -> Option<Vec<MetaItem>> {
|
122 | |
- let options = attrs.iter().find(|a| a.name() == name).map(|a| &a.value);
|
123 | |
+) -> Option<Vec<Meta>> {
|
124 | |
+ let options = attrs
|
125 | |
+ .iter()
|
126 | |
+ .find(|a| &a.path == name)
|
127 | |
+ .map(|a| a.parse_meta());
|
128 | |
match options {
|
129 | |
- Some(&MetaItem::List(_, ref options)) => Some(
|
130 | |
- options
|
131 | |
+ Some(Ok(Meta::List(MetaList { ref nested, .. }))) => Some(
|
132 | |
+ nested
|
133 | |
.iter()
|
134 | |
.map(|o| match *o {
|
135 | |
- NestedMetaItem::MetaItem(ref m) => m.clone(),
|
136 | |
+ NestedMeta::Meta(ref m) => m.clone(),
|
137 | |
_ => on_bug(),
|
138 | |
})
|
139 | |
.collect(),
|
140 | |
@@ -31,13 +37,13 @@ pub fn get_options_from_input(
|
141 | |
}
|
142 | |
}
|
143 | |
|
144 | |
-pub fn get_option<'a>(options: &'a [MetaItem], option_name: &str, on_bug: fn() -> !) -> &'a str {
|
145 | |
+pub fn get_option(options: &[Meta], option_name: &str, on_bug: fn() -> !) -> String {
|
146 | |
get_optional_option(options, option_name).unwrap_or_else(|| on_bug())
|
147 | |
}
|
148 | |
|
149 | |
-pub fn get_optional_option<'a>(options: &'a [MetaItem], option_name: &str) -> Option<&'a str> {
|
150 | |
+pub fn get_optional_option(options: &[Meta], option_name: &str) -> Option<String> {
|
151 | |
options
|
152 | |
.iter()
|
153 | |
- .find(|a| a.name() == option_name)
|
154 | |
+ .find(|a| a.path().is_ident(option_name))
|
155 | |
.map(|a| str_value_of_meta_item(a, option_name))
|
156 | |
}
|