Codebase list rust-libslirp / 1649f18
Update diesel-derives kpcyrd 4 years ago
4 changed file(s) with 269 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
00 rust-diesel-derives (1.4.0-2) UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; urgency=medium
11
2 * Package diesel_derives 1.4.0 from crates.io using debcargo 2.2.10
2 * Package diesel_derives 1.4.0 from crates.io using debcargo 2.4.0
33
4 -- kpcyrd <git@rxv.cc> Thu, 11 Jul 2019 02:39:20 +0000
4 -- kpcyrd <git@rxv.cc> Wed, 28 Aug 2019 16:37:51 +0200
55
66 rust-diesel-derives (1.4.0-1) unstable; urgency=medium
77
0 diff --git a/diesel_derives/src/associations.rs b/diesel_derives/src/associations.rs
1 index dc1d0a84..14adf08c 100644
2 --- a/src/associations.rs
3 +++ b/src/associations.rs
4 @@ -115,10 +115,10 @@ impl AssociationOptions {
5 fn from_meta(meta: MetaItem) -> Result<Self, Diagnostic> {
6 let parent_struct = meta
7 .nested()?
8 - .find(|m| m.word().is_ok() || m.name() == "parent")
9 + .find(|m| m.path().is_ok() || m.name().is_ident("parent"))
10 .ok_or_else(|| meta.span())
11 .and_then(|m| {
12 - m.word()
13 + m.path()
14 .map(|i| parse_quote!(#i))
15 .or_else(|_| m.ty_value())
16 .map_err(|_| m.span())
17 @@ -136,18 +136,17 @@ impl AssociationOptions {
18 .path
19 .segments
20 .last()
21 - .expect("paths always have at least one segment")
22 - .into_value();
23 + .expect("paths always have at least one segment");
24 meta.nested_item("foreign_key")?
25 .map(|i| i.ident_value())
26 .unwrap_or_else(|| Ok(infer_foreign_key(&parent_struct_name.ident)))?
27 };
28
29 - let unrecognized_options = meta.nested()?.skip(1).filter(|n| n.name() != "foreign_key");
30 + let unrecognized_options = meta.nested()?.skip(1).filter(|n| !n.name().is_ident("foreign_key"));
31 for ignored in unrecognized_options {
32 ignored
33 .span()
34 - .warning(format!("Unrecognized option {}", ignored.name()))
35 + .warning(format!("Unrecognized option {}", path_to_string(&ignored.name())))
36 .emit();
37 }
38
39 diff --git a/diesel_derives/src/meta.rs b/diesel_derives/src/meta.rs
40 index 39830831..8c88efce 100644
41 --- a/src/meta.rs
42 +++ b/src/meta.rs
43 @@ -10,15 +10,19 @@ pub struct MetaItem {
44 meta: syn::Meta,
45 }
46
47 +pub(crate) fn path_to_string(path: &syn::Path) -> String {
48 + path.segments.iter().map(|s| s.ident.to_string()).collect::<Vec<String>>().join("::")
49 +}
50 +
51 impl MetaItem {
52 pub fn all_with_name(attrs: &[syn::Attribute], name: &str) -> Vec<Self> {
53 attrs
54 .iter()
55 .filter_map(|attr| {
56 - attr.interpret_meta()
57 + attr.parse_meta().ok()
58 .map(|m| FixSpan(attr.pound_token.spans[0]).fold_meta(m))
59 })
60 - .filter(|m| m.name() == name)
61 + .filter(|m| m.path().is_ident(name))
62 .map(|meta| Self { meta })
63 .collect()
64 }
65 @@ -30,7 +34,7 @@ impl MetaItem {
66 pub fn empty(name: &str) -> Self {
67 Self {
68 meta: syn::Meta::List(syn::MetaList {
69 - ident: Ident::new(name, Span::call_site()),
70 + path: syn::Path::from(Ident::new(name, Span::call_site())),
71 paren_token: Default::default(),
72 nested: Default::default(),
73 }),
74 @@ -38,7 +42,7 @@ impl MetaItem {
75 }
76
77 pub fn nested_item(&self, name: &str) -> Result<Option<Self>, Diagnostic> {
78 - self.nested().map(|mut i| i.find(|n| n.name() == name))
79 + self.nested().map(|mut i| i.find(|n| n.name().is_ident(name)))
80 }
81
82 pub fn required_nested_item(&self, name: &str) -> Result<Self, Diagnostic> {
83 @@ -56,7 +60,7 @@ impl MetaItem {
84 self.span()
85 .error(format!(
86 "`{0}` must be in the form `{0} = \"true\"`",
87 - self.name()
88 + path_to_string(&self.name())
89 ))
90 .emit();
91 false
92 @@ -67,22 +71,22 @@ impl MetaItem {
93 pub fn expect_ident_value(&self) -> syn::Ident {
94 self.ident_value().unwrap_or_else(|e| {
95 e.emit();
96 - self.name()
97 + self.name().segments.first().unwrap().ident.clone()
98 })
99 }
100
101 pub fn ident_value(&self) -> Result<syn::Ident, Diagnostic> {
102 let maybe_attr = self.nested().ok().and_then(|mut n| n.nth(0));
103 - let maybe_word = maybe_attr.as_ref().and_then(|m| m.word().ok());
104 - match maybe_word {
105 + let maybe_path = maybe_attr.as_ref().and_then(|m| m.path().ok());
106 + match maybe_path {
107 Some(x) => {
108 self.span()
109 .warning(format!(
110 "The form `{0}(value)` is deprecated. Use `{0} = \"value\"` instead",
111 - self.name(),
112 + path_to_string(&self.name()),
113 ))
114 .emit();
115 - Ok(x)
116 + Ok(x.segments.first().unwrap().ident.clone())
117 }
118 _ => Ok(syn::Ident::new(
119 &self.str_value()?,
120 @@ -91,23 +95,23 @@ impl MetaItem {
121 }
122 }
123
124 - pub fn expect_word(&self) -> syn::Ident {
125 - self.word().unwrap_or_else(|e| {
126 + pub fn expect_path(&self) -> syn::Path {
127 + self.path().unwrap_or_else(|e| {
128 e.emit();
129 self.name()
130 })
131 }
132
133 - pub fn word(&self) -> Result<syn::Ident, Diagnostic> {
134 + pub fn path(&self) -> Result<syn::Path, Diagnostic> {
135 use syn::Meta::*;
136
137 match self.meta {
138 - Word(ref x) => Ok(x.clone()),
139 + Path(ref x) => Ok(x.clone()),
140 _ => {
141 let meta = &self.meta;
142 Err(self.span().error(format!(
143 "Expected `{}` found `{}`",
144 - self.name(),
145 + path_to_string(&self.name()),
146 quote!(#meta)
147 )))
148 }
149 @@ -121,19 +125,19 @@ impl MetaItem {
150 List(ref list) => Ok(Nested(list.nested.iter())),
151 _ => Err(self
152 .span()
153 - .error(format!("`{0}` must be in the form `{0}(...)`", self.name()))),
154 + .error(format!("`{0}` must be in the form `{0}(...)`", path_to_string(&self.name())))),
155 }
156 }
157
158 - pub fn name(&self) -> syn::Ident {
159 - self.meta.name()
160 + pub fn name(&self) -> syn::Path {
161 + self.meta.path().clone()
162 }
163
164 pub fn has_flag(&self, flag: &str) -> bool {
165 self.nested()
166 .map(|mut n| {
167 - n.any(|m| match m.word() {
168 - Ok(word) => word == flag,
169 + n.any(|m| match m.path() {
170 + Ok(word) => word.is_ident(flag),
171 Err(_) => false,
172 })
173 })
174 @@ -152,7 +156,7 @@ impl MetaItem {
175 pub fn expect_str_value(&self) -> String {
176 self.str_value().unwrap_or_else(|e| {
177 e.emit();
178 - self.name().to_string()
179 + path_to_string(&self.name())
180 })
181 }
182
183 @@ -167,7 +171,7 @@ impl MetaItem {
184 Str(ref s) => Ok(s),
185 _ => Err(self.span().error(format!(
186 "`{0}` must be in the form `{0} = \"value\"`",
187 - self.name()
188 + path_to_string(&self.name())
189 ))),
190 }
191 }
192 @@ -183,7 +187,7 @@ impl MetaItem {
193
194 match *self.lit_value()? {
195 Str(ref s) => s.value().parse().map_err(|_| error),
196 - Int(ref i) => Ok(i.value()),
197 + Int(ref i) => i.base10_parse().map_err(|_| error),
198 _ => Err(error),
199 }
200 }
201 @@ -195,7 +199,7 @@ impl MetaItem {
202 NameValue(ref name_value) => Ok(&name_value.lit),
203 _ => Err(self.span().error(format!(
204 "`{0}` must be in the form `{0} = \"value\"`",
205 - self.name()
206 + path_to_string(&self.name())
207 ))),
208 }
209 }
210 @@ -205,11 +209,11 @@ impl MetaItem {
211 Ok(x) => x,
212 Err(_) => return,
213 };
214 - let unrecognized_options = nested.filter(|n| !options.iter().any(|&o| n.name() == o));
215 + let unrecognized_options = nested.filter(|n| !options.iter().any(|&o| n.name().is_ident(o)));
216 for ignored in unrecognized_options {
217 ignored
218 .span()
219 - .warning(format!("Option {} has no effect", ignored.name()))
220 + .warning(format!("Option {} has no effect", path_to_string(&ignored.name())))
221 .emit();
222 }
223 }
224 @@ -218,7 +222,7 @@ impl MetaItem {
225 use syn::Meta::*;
226
227 match self.meta {
228 - Word(ref ident) => ident.span(),
229 + Path(ref path) => path.span(),
230 List(ref meta) => meta.nested.span(),
231 NameValue(ref meta) => meta.lit.span(),
232 }
233 diff --git a/diesel_derives/src/model.rs b/diesel_derives/src/model.rs
234 index 25722a81..2d862f11 100644
235 --- a/src/model.rs
236 +++ b/src/model.rs
237 @@ -18,7 +18,7 @@ impl Model {
238 let table_name_from_attribute =
239 MetaItem::with_name(&item.attrs, "table_name").map(|m| m.expect_ident_value());
240 let primary_key_names = MetaItem::with_name(&item.attrs, "primary_key")
241 - .map(|m| Ok(m.nested()?.map(|m| m.expect_word()).collect()))
242 + .map(|m| Ok(m.nested()?.map(|m| m.expect_path().segments.first().unwrap().ident.clone()).collect()))
243 .unwrap_or_else(|| Ok(vec![Ident::new("id", Span::call_site())]))?;
244 let fields = fields_from_item_data(&item.data)?;
245 Ok(Self {
0 --- a/Cargo.toml
1 +++ b/Cargo.toml
2 @@ -27,13 +27,13 @@
3 [[test]]
4 name = "tests"
5 [dependencies.proc-macro2]
6 -version = "0.4.0"
7 +version = "1.0"
8
9 [dependencies.quote]
10 -version = "0.6.0"
11 +version = "1.0"
12
13 [dependencies.syn]
14 -version = "0.15.0"
15 +version = "1.0"
16 features = ["full", "fold"]
17 [dev-dependencies.cfg-if]
18 version = "0.1.0"
0 relax-deps.patch
1 patch-syn-quote-proc-macro2.patch