David Tolnay | 5553501 | 2018-01-05 16:39:23 -0800 | [diff] [blame] | 1 | // Copyright 2018 Syn Developers |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 4 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 5 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 6 | // option. This file may not be copied, modified, or distributed |
| 7 | // except according to those terms. |
| 8 | |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 9 | use super::*; |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 10 | use punctuated::Punctuated; |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 11 | |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 12 | use std::iter; |
| 13 | |
David Tolnay | e303b7c | 2018-05-20 16:46:35 -0700 | [diff] [blame] | 14 | use proc_macro2::{Delimiter, Spacing, TokenStream, TokenTree}; |
David Tolnay | 9c76bcb | 2017-12-26 23:14:59 -0500 | [diff] [blame] | 15 | |
David Tolnay | 5066086 | 2018-09-01 15:42:53 -0700 | [diff] [blame] | 16 | #[cfg(feature = "parsing")] |
| 17 | use parse::{ParseStream, Result}; |
David Tolnay | 9c76bcb | 2017-12-26 23:14:59 -0500 | [diff] [blame] | 18 | #[cfg(feature = "extra-traits")] |
| 19 | use std::hash::{Hash, Hasher}; |
| 20 | #[cfg(feature = "extra-traits")] |
David Tolnay | c43b44e | 2017-12-30 23:55:54 -0500 | [diff] [blame] | 21 | use tt::TokenStreamHelper; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 22 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 23 | ast_struct! { |
David Tolnay | 2355714 | 2018-01-06 22:45:40 -0800 | [diff] [blame] | 24 | /// An attribute like `#[repr(transparent)]`. |
| 25 | /// |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 26 | /// *This type is available if Syn is built with the `"derive"` or `"full"` |
| 27 | /// feature.* |
| 28 | /// |
David Tolnay | 2355714 | 2018-01-06 22:45:40 -0800 | [diff] [blame] | 29 | /// # Syntax |
| 30 | /// |
| 31 | /// Rust has six types of attributes. |
| 32 | /// |
| 33 | /// - Outer attributes like `#[repr(transparent)]`. These appear outside or |
| 34 | /// in front of the item they describe. |
| 35 | /// - Inner attributes like `#![feature(proc_macro)]`. These appear inside |
| 36 | /// of the item they describe, usually a module. |
| 37 | /// - Outer doc comments like `/// # Example`. |
| 38 | /// - Inner doc comments like `//! Please file an issue`. |
| 39 | /// - Outer block comments `/** # Example */`. |
| 40 | /// - Inner block comments `/*! Please file an issue */`. |
| 41 | /// |
| 42 | /// The `style` field of type `AttrStyle` distinguishes whether an attribute |
| 43 | /// is outer or inner. Doc comments and block comments are promoted to |
David Tolnay | fe58330 | 2018-08-24 16:09:34 -0400 | [diff] [blame] | 44 | /// attributes, as this is how they are processed by the compiler and by |
| 45 | /// `macro_rules!` macros. |
David Tolnay | 2355714 | 2018-01-06 22:45:40 -0800 | [diff] [blame] | 46 | /// |
| 47 | /// The `path` field gives the possibly colon-delimited path against which |
| 48 | /// the attribute is resolved. It is equal to `"doc"` for desugared doc |
| 49 | /// comments. The `tts` field contains the rest of the attribute body as |
| 50 | /// tokens. |
| 51 | /// |
| 52 | /// ```text |
| 53 | /// #[derive(Copy)] #[crate::precondition x < 5] |
| 54 | /// ^^^^^^~~~~~~ ^^^^^^^^^^^^^^^^^^^ ~~~~~ |
| 55 | /// path tts path tts |
| 56 | /// ``` |
| 57 | /// |
David Tolnay | 068120a | 2018-01-06 23:17:22 -0800 | [diff] [blame] | 58 | /// Use the [`interpret_meta`] method to try parsing the tokens of an |
| 59 | /// attribute into the structured representation that is used by convention |
| 60 | /// across most Rust libraries. |
David Tolnay | 2355714 | 2018-01-06 22:45:40 -0800 | [diff] [blame] | 61 | /// |
David Tolnay | 068120a | 2018-01-06 23:17:22 -0800 | [diff] [blame] | 62 | /// [`interpret_meta`]: #method.interpret_meta |
David Tolnay | d8bd15f | 2018-09-01 16:57:39 -0700 | [diff] [blame] | 63 | /// |
| 64 | /// # Parsing |
| 65 | /// |
| 66 | /// This type does not implement the [`Parse`] trait and thus cannot be |
| 67 | /// parsed directly by [`ParseStream::parse`]. Instead use |
| 68 | /// [`ParseStream::call`] with one of the two parser functions |
| 69 | /// [`Attribute::parse_outer`] or [`Attribute::parse_inner`] depending on |
| 70 | /// which you intend to parse. |
| 71 | /// |
| 72 | /// [`Parse`]: parse/trait.Parse.html |
| 73 | /// [`ParseStream::parse`]: parse/struct.ParseBuffer.html#method.parse |
| 74 | /// [`ParseStream::call`]: parse/struct.ParseBuffer.html#method.call |
| 75 | /// [`Attribute::parse_outer`]: #method.parse_outer |
| 76 | /// [`Attribute::parse_inner`]: #method.parse_inner |
| 77 | /// |
| 78 | /// ``` |
David Tolnay | a1c9807 | 2018-09-06 08:58:10 -0700 | [diff] [blame] | 79 | /// #[macro_use] |
| 80 | /// extern crate syn; |
| 81 | /// |
| 82 | /// use syn::{Attribute, Ident}; |
David Tolnay | d8bd15f | 2018-09-01 16:57:39 -0700 | [diff] [blame] | 83 | /// use syn::parse::{Parse, ParseStream, Result}; |
| 84 | /// |
| 85 | /// // Parses a unit struct with attributes. |
| 86 | /// // |
| 87 | /// // #[path = "s.tmpl"] |
| 88 | /// // struct S; |
| 89 | /// struct UnitStruct { |
| 90 | /// attrs: Vec<Attribute>, |
| 91 | /// struct_token: Token![struct], |
| 92 | /// name: Ident, |
| 93 | /// semi_token: Token![;], |
| 94 | /// } |
| 95 | /// |
| 96 | /// impl Parse for UnitStruct { |
| 97 | /// fn parse(input: ParseStream) -> Result<Self> { |
| 98 | /// Ok(UnitStruct { |
| 99 | /// attrs: input.call(Attribute::parse_outer)?, |
| 100 | /// struct_token: input.parse()?, |
| 101 | /// name: input.parse()?, |
| 102 | /// semi_token: input.parse()?, |
| 103 | /// }) |
| 104 | /// } |
| 105 | /// } |
| 106 | /// # |
| 107 | /// # fn main() {} |
| 108 | /// ``` |
David Tolnay | 9c76bcb | 2017-12-26 23:14:59 -0500 | [diff] [blame] | 109 | pub struct Attribute #manual_extra_traits { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 110 | pub pound_token: Token![#], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 111 | pub style: AttrStyle, |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 112 | pub bracket_token: token::Bracket, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 113 | pub path: Path, |
David Tolnay | 369f0c5 | 2017-12-27 01:50:45 -0500 | [diff] [blame] | 114 | pub tts: TokenStream, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 115 | } |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 116 | } |
| 117 | |
David Tolnay | 9c76bcb | 2017-12-26 23:14:59 -0500 | [diff] [blame] | 118 | #[cfg(feature = "extra-traits")] |
| 119 | impl Eq for Attribute {} |
| 120 | |
| 121 | #[cfg(feature = "extra-traits")] |
| 122 | impl PartialEq for Attribute { |
| 123 | fn eq(&self, other: &Self) -> bool { |
David Tolnay | 65fb566 | 2018-05-20 20:02:28 -0700 | [diff] [blame] | 124 | self.style == other.style |
| 125 | && self.pound_token == other.pound_token |
| 126 | && self.bracket_token == other.bracket_token |
| 127 | && self.path == other.path |
David Tolnay | 369f0c5 | 2017-12-27 01:50:45 -0500 | [diff] [blame] | 128 | && TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts) |
David Tolnay | 9c76bcb | 2017-12-26 23:14:59 -0500 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
| 132 | #[cfg(feature = "extra-traits")] |
| 133 | impl Hash for Attribute { |
| 134 | fn hash<H>(&self, state: &mut H) |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 135 | where |
| 136 | H: Hasher, |
David Tolnay | 9c76bcb | 2017-12-26 23:14:59 -0500 | [diff] [blame] | 137 | { |
| 138 | self.style.hash(state); |
| 139 | self.pound_token.hash(state); |
| 140 | self.bracket_token.hash(state); |
| 141 | self.path.hash(state); |
David Tolnay | 369f0c5 | 2017-12-27 01:50:45 -0500 | [diff] [blame] | 142 | TokenStreamHelper(&self.tts).hash(state); |
David Tolnay | 9c76bcb | 2017-12-26 23:14:59 -0500 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
David Tolnay | 02d77cc | 2016-10-02 09:52:08 -0700 | [diff] [blame] | 146 | impl Attribute { |
David Tolnay | 068120a | 2018-01-06 23:17:22 -0800 | [diff] [blame] | 147 | /// Parses the tokens after the path as a [`Meta`](enum.Meta.html) if |
| 148 | /// possible. |
David Tolnay | aaadd78 | 2018-01-06 22:58:13 -0800 | [diff] [blame] | 149 | pub fn interpret_meta(&self) -> Option<Meta> { |
Arnavion | 95f8a7a | 2017-04-19 03:29:56 -0700 | [diff] [blame] | 150 | let name = if self.path.segments.len() == 1 { |
David Tolnay | 5608068 | 2018-01-06 14:01:52 -0800 | [diff] [blame] | 151 | &self.path.segments.first().unwrap().value().ident |
Arnavion | 95f8a7a | 2017-04-19 03:29:56 -0700 | [diff] [blame] | 152 | } else { |
| 153 | return None; |
| 154 | }; |
| 155 | |
Arnavion | bf395bf | 2017-04-15 15:35:22 -0700 | [diff] [blame] | 156 | if self.tts.is_empty() { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 157 | return Some(Meta::Word(name.clone())); |
Arnavion | bf395bf | 2017-04-15 15:35:22 -0700 | [diff] [blame] | 158 | } |
| 159 | |
David Tolnay | 369f0c5 | 2017-12-27 01:50:45 -0500 | [diff] [blame] | 160 | let tts = self.tts.clone().into_iter().collect::<Vec<_>>(); |
| 161 | |
| 162 | if tts.len() == 1 { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 163 | if let Some(meta) = Attribute::extract_meta_list(name.clone(), &tts[0]) { |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 164 | return Some(meta); |
Arnavion | bf395bf | 2017-04-15 15:35:22 -0700 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
David Tolnay | 369f0c5 | 2017-12-27 01:50:45 -0500 | [diff] [blame] | 168 | if tts.len() == 2 { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 169 | if let Some(meta) = Attribute::extract_name_value(name.clone(), &tts[0], &tts[1]) { |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 170 | return Some(meta); |
Arnavion | bf395bf | 2017-04-15 15:35:22 -0700 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | |
| 174 | None |
David Tolnay | 02d77cc | 2016-10-02 09:52:08 -0700 | [diff] [blame] | 175 | } |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 176 | |
Carl Lerche | ae0fa60 | 2018-10-12 21:46:54 -0700 | [diff] [blame] | 177 | /// Parses the tokens after the path as a [`Meta`](enum.Meta.html) if |
| 178 | /// possible. |
| 179 | #[cfg(feature = "parsing")] |
| 180 | pub fn parse_meta(&self) -> Result<Meta> { |
| 181 | use quote::ToTokens; |
| 182 | |
Carl Lerche | 22926d7 | 2018-10-12 22:29:11 -0700 | [diff] [blame] | 183 | let mut tts = TokenStream::new(); |
| 184 | |
| 185 | self.path.to_tokens(&mut tts); |
| 186 | self.tts.to_tokens(&mut tts); |
Carl Lerche | ae0fa60 | 2018-10-12 21:46:54 -0700 | [diff] [blame] | 187 | |
| 188 | ::parse2(tts) |
| 189 | } |
| 190 | |
David Tolnay | 5066086 | 2018-09-01 15:42:53 -0700 | [diff] [blame] | 191 | /// Parses zero or more outer attributes from the stream. |
David Tolnay | 206edfb | 2018-09-01 16:02:20 -0700 | [diff] [blame] | 192 | /// |
| 193 | /// *This function is available if Syn is built with the `"parsing"` |
| 194 | /// feature.* |
David Tolnay | 5066086 | 2018-09-01 15:42:53 -0700 | [diff] [blame] | 195 | #[cfg(feature = "parsing")] |
| 196 | pub fn parse_outer(input: ParseStream) -> Result<Vec<Self>> { |
| 197 | let mut attrs = Vec::new(); |
| 198 | while input.peek(Token![#]) { |
| 199 | attrs.push(input.call(parsing::single_parse_outer)?); |
| 200 | } |
| 201 | Ok(attrs) |
| 202 | } |
| 203 | |
| 204 | /// Parses zero or more inner attributes from the stream. |
David Tolnay | 206edfb | 2018-09-01 16:02:20 -0700 | [diff] [blame] | 205 | /// |
| 206 | /// *This function is available if Syn is built with the `"parsing"` |
| 207 | /// feature.* |
David Tolnay | 5066086 | 2018-09-01 15:42:53 -0700 | [diff] [blame] | 208 | #[cfg(feature = "parsing")] |
| 209 | pub fn parse_inner(input: ParseStream) -> Result<Vec<Self>> { |
| 210 | let mut attrs = Vec::new(); |
| 211 | while input.peek(Token![#]) && input.peek2(Token![!]) { |
| 212 | attrs.push(input.call(parsing::single_parse_inner)?); |
| 213 | } |
| 214 | Ok(attrs) |
| 215 | } |
| 216 | |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 217 | fn extract_meta_list(ident: Ident, tt: &TokenTree) -> Option<Meta> { |
| 218 | let g = match *tt { |
| 219 | TokenTree::Group(ref g) => g, |
| 220 | _ => return None, |
| 221 | }; |
| 222 | if g.delimiter() != Delimiter::Parenthesis { |
David Tolnay | 94d2b79 | 2018-04-29 12:26:10 -0700 | [diff] [blame] | 223 | return None; |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 224 | } |
| 225 | let tokens = g.stream().clone().into_iter().collect::<Vec<_>>(); |
| 226 | let nested = match list_of_nested_meta_items_from_tokens(&tokens) { |
| 227 | Some(n) => n, |
| 228 | None => return None, |
| 229 | }; |
| 230 | Some(Meta::List(MetaList { |
| 231 | paren_token: token::Paren(g.span()), |
| 232 | ident: ident, |
| 233 | nested: nested, |
| 234 | })) |
| 235 | } |
| 236 | |
| 237 | fn extract_name_value(ident: Ident, a: &TokenTree, b: &TokenTree) -> Option<Meta> { |
| 238 | let a = match *a { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 239 | TokenTree::Punct(ref o) => o, |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 240 | _ => return None, |
| 241 | }; |
| 242 | if a.spacing() != Spacing::Alone { |
David Tolnay | 94d2b79 | 2018-04-29 12:26:10 -0700 | [diff] [blame] | 243 | return None; |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 244 | } |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 245 | if a.as_char() != '=' { |
David Tolnay | 94d2b79 | 2018-04-29 12:26:10 -0700 | [diff] [blame] | 246 | return None; |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | match *b { |
| 250 | TokenTree::Literal(ref l) if !l.to_string().starts_with('/') => { |
| 251 | Some(Meta::NameValue(MetaNameValue { |
| 252 | ident: ident, |
| 253 | eq_token: Token]), |
| 254 | lit: Lit::new(l.clone()), |
| 255 | })) |
| 256 | } |
David Tolnay | a4319b7 | 2018-06-02 00:49:15 -0700 | [diff] [blame] | 257 | TokenTree::Ident(ref v) => match &v.to_string()[..] { |
David Tolnay | 94d2b79 | 2018-04-29 12:26:10 -0700 | [diff] [blame] | 258 | v @ "true" | v @ "false" => Some(Meta::NameValue(MetaNameValue { |
| 259 | ident: ident, |
| 260 | eq_token: Token]), |
| 261 | lit: Lit::Bool(LitBool { |
| 262 | value: v == "true", |
| 263 | span: b.span(), |
| 264 | }), |
| 265 | })), |
| 266 | _ => None, |
| 267 | }, |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 268 | _ => None, |
| 269 | } |
| 270 | } |
David Tolnay | 02d77cc | 2016-10-02 09:52:08 -0700 | [diff] [blame] | 271 | } |
| 272 | |
David Tolnay | aaadd78 | 2018-01-06 22:58:13 -0800 | [diff] [blame] | 273 | fn nested_meta_item_from_tokens(tts: &[TokenTree]) -> Option<(NestedMeta, &[TokenTree])> { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 274 | assert!(!tts.is_empty()); |
| 275 | |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 276 | match tts[0] { |
| 277 | TokenTree::Literal(ref lit) => { |
David Tolnay | 7037c9b | 2018-01-23 09:34:09 -0800 | [diff] [blame] | 278 | if lit.to_string().starts_with('/') { |
| 279 | None |
| 280 | } else { |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 281 | let lit = Lit::new(lit.clone()); |
David Tolnay | 7037c9b | 2018-01-23 09:34:09 -0800 | [diff] [blame] | 282 | Some((NestedMeta::Literal(lit), &tts[1..])) |
| 283 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 286 | TokenTree::Ident(ref ident) => { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 287 | if tts.len() >= 3 { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 288 | if let Some(meta) = Attribute::extract_name_value(ident.clone(), &tts[1], &tts[2]) { |
David Tolnay | 94d2b79 | 2018-04-29 12:26:10 -0700 | [diff] [blame] | 289 | return Some((NestedMeta::Meta(meta), &tts[3..])); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
| 293 | if tts.len() >= 2 { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 294 | if let Some(meta) = Attribute::extract_meta_list(ident.clone(), &tts[1]) { |
David Tolnay | 94d2b79 | 2018-04-29 12:26:10 -0700 | [diff] [blame] | 295 | return Some((NestedMeta::Meta(meta), &tts[2..])); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
David Tolnay | 4c51004 | 2018-09-12 00:04:51 -0700 | [diff] [blame] | 299 | let nested_meta = if ident == "true" || ident == "false" { |
| 300 | NestedMeta::Literal(Lit::Bool(LitBool { |
| 301 | value: ident == "true", |
| 302 | span: ident.span(), |
| 303 | })) |
| 304 | } else { |
| 305 | NestedMeta::Meta(Meta::Word(ident.clone())) |
| 306 | }; |
| 307 | Some((nested_meta, &tts[1..])) |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 308 | } |
| 309 | |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 310 | _ => None, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 314 | fn list_of_nested_meta_items_from_tokens( |
| 315 | mut tts: &[TokenTree], |
David Tolnay | aaadd78 | 2018-01-06 22:58:13 -0800 | [diff] [blame] | 316 | ) -> Option<Punctuated<NestedMeta, Token![,]>> { |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 317 | let mut nested_meta_items = Punctuated::new(); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 318 | let mut first = true; |
| 319 | |
| 320 | while !tts.is_empty() { |
| 321 | let prev_comma = if first { |
| 322 | first = false; |
| 323 | None |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 324 | } else if let TokenTree::Punct(ref op) = tts[0] { |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 325 | if op.spacing() != Spacing::Alone { |
David Tolnay | 94d2b79 | 2018-04-29 12:26:10 -0700 | [diff] [blame] | 326 | return None; |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 327 | } |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 328 | if op.as_char() != ',' { |
David Tolnay | 94d2b79 | 2018-04-29 12:26:10 -0700 | [diff] [blame] | 329 | return None; |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 330 | } |
| 331 | let tok = Token]); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 332 | tts = &tts[1..]; |
| 333 | if tts.is_empty() { |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 334 | break; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 335 | } |
| 336 | Some(tok) |
| 337 | } else { |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 338 | return None; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 339 | }; |
| 340 | let (nested, rest) = match nested_meta_item_from_tokens(tts) { |
| 341 | Some(pair) => pair, |
| 342 | None => return None, |
| 343 | }; |
David Tolnay | 660fd1f | 2017-12-31 01:52:57 -0500 | [diff] [blame] | 344 | if let Some(comma) = prev_comma { |
David Tolnay | a0834b4 | 2018-01-01 21:30:02 -0800 | [diff] [blame] | 345 | nested_meta_items.push_punct(comma); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 346 | } |
David Tolnay | 5608068 | 2018-01-06 14:01:52 -0800 | [diff] [blame] | 347 | nested_meta_items.push_value(nested); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 348 | tts = rest; |
| 349 | } |
| 350 | |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 351 | Some(nested_meta_items) |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 354 | ast_enum! { |
David Tolnay | 0565850 | 2018-01-07 09:56:37 -0800 | [diff] [blame] | 355 | /// Distinguishes between attributes that decorate an item and attributes |
| 356 | /// that are contained within an item. |
David Tolnay | 2355714 | 2018-01-06 22:45:40 -0800 | [diff] [blame] | 357 | /// |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 358 | /// *This type is available if Syn is built with the `"derive"` or `"full"` |
| 359 | /// feature.* |
| 360 | /// |
David Tolnay | 2355714 | 2018-01-06 22:45:40 -0800 | [diff] [blame] | 361 | /// # Outer attributes |
| 362 | /// |
| 363 | /// - `#[repr(transparent)]` |
| 364 | /// - `/// # Example` |
| 365 | /// - `/** Please file an issue */` |
| 366 | /// |
| 367 | /// # Inner attributes |
| 368 | /// |
| 369 | /// - `#![feature(proc_macro)]` |
| 370 | /// - `//! # Example` |
| 371 | /// - `/*! Please file an issue */` |
Alex Crichton | 2e0229c | 2017-05-23 09:34:50 -0700 | [diff] [blame] | 372 | #[cfg_attr(feature = "clone-impls", derive(Copy))] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 373 | pub enum AttrStyle { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 374 | Outer, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 375 | Inner(Token![!]), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 376 | } |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 379 | ast_enum_of_structs! { |
David Tolnay | 068120a | 2018-01-06 23:17:22 -0800 | [diff] [blame] | 380 | /// Content of a compile-time structured attribute. |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 381 | /// |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 382 | /// *This type is available if Syn is built with the `"derive"` or `"full"` |
| 383 | /// feature.* |
| 384 | /// |
David Tolnay | 068120a | 2018-01-06 23:17:22 -0800 | [diff] [blame] | 385 | /// ## Word |
| 386 | /// |
| 387 | /// A meta word is like the `test` in `#[test]`. |
| 388 | /// |
| 389 | /// ## List |
| 390 | /// |
| 391 | /// A meta list is like the `derive(Copy)` in `#[derive(Copy)]`. |
| 392 | /// |
| 393 | /// ## NameValue |
| 394 | /// |
| 395 | /// A name-value meta is like the `path = "..."` in `#[path = |
| 396 | /// "sys/windows.rs"]`. |
David Tolnay | 614a014 | 2018-01-07 10:25:43 -0800 | [diff] [blame] | 397 | /// |
| 398 | /// # Syntax tree enum |
| 399 | /// |
| 400 | /// This type is a [syntax tree enum]. |
| 401 | /// |
| 402 | /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums |
David Tolnay | aaadd78 | 2018-01-06 22:58:13 -0800 | [diff] [blame] | 403 | pub enum Meta { |
David Tolnay | aaadd78 | 2018-01-06 22:58:13 -0800 | [diff] [blame] | 404 | pub Word(Ident), |
David Tolnay | 068120a | 2018-01-06 23:17:22 -0800 | [diff] [blame] | 405 | /// A structured list within an attribute, like `derive(Copy, Clone)`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 406 | /// |
| 407 | /// *This type is available if Syn is built with the `"derive"` or |
| 408 | /// `"full"` feature.* |
David Tolnay | aaadd78 | 2018-01-06 22:58:13 -0800 | [diff] [blame] | 409 | pub List(MetaList { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 410 | pub ident: Ident, |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 411 | pub paren_token: token::Paren, |
David Tolnay | aaadd78 | 2018-01-06 22:58:13 -0800 | [diff] [blame] | 412 | pub nested: Punctuated<NestedMeta, Token![,]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 413 | }), |
David Tolnay | 068120a | 2018-01-06 23:17:22 -0800 | [diff] [blame] | 414 | /// A name-value pair within an attribute, like `feature = "nightly"`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 415 | /// |
| 416 | /// *This type is available if Syn is built with the `"derive"` or |
| 417 | /// `"full"` feature.* |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 418 | pub NameValue(MetaNameValue { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 419 | pub ident: Ident, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 420 | pub eq_token: Token![=], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 421 | pub lit: Lit, |
| 422 | }), |
| 423 | } |
Arnavion | 95f8a7a | 2017-04-19 03:29:56 -0700 | [diff] [blame] | 424 | } |
| 425 | |
David Tolnay | aaadd78 | 2018-01-06 22:58:13 -0800 | [diff] [blame] | 426 | impl Meta { |
David Tolnay | 068120a | 2018-01-06 23:17:22 -0800 | [diff] [blame] | 427 | /// Returns the identifier that begins this structured meta item. |
Arnavion | 95f8a7a | 2017-04-19 03:29:56 -0700 | [diff] [blame] | 428 | /// |
David Tolnay | 068120a | 2018-01-06 23:17:22 -0800 | [diff] [blame] | 429 | /// For example this would return the `test` in `#[test]`, the `derive` in |
| 430 | /// `#[derive(Copy)]`, and the `path` in `#[path = "sys/windows.rs"]`. |
| 431 | pub fn name(&self) -> Ident { |
Arnavion | 95f8a7a | 2017-04-19 03:29:56 -0700 | [diff] [blame] | 432 | match *self { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 433 | Meta::Word(ref meta) => meta.clone(), |
| 434 | Meta::List(ref meta) => meta.ident.clone(), |
| 435 | Meta::NameValue(ref meta) => meta.ident.clone(), |
Arnavion | 95f8a7a | 2017-04-19 03:29:56 -0700 | [diff] [blame] | 436 | } |
| 437 | } |
David Tolnay | 8e661e2 | 2016-09-27 00:00:04 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 440 | ast_enum_of_structs! { |
David Tolnay | 068120a | 2018-01-06 23:17:22 -0800 | [diff] [blame] | 441 | /// Element of a compile-time attribute list. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 442 | /// |
| 443 | /// *This type is available if Syn is built with the `"derive"` or `"full"` |
| 444 | /// feature.* |
David Tolnay | aaadd78 | 2018-01-06 22:58:13 -0800 | [diff] [blame] | 445 | pub enum NestedMeta { |
David Tolnay | 068120a | 2018-01-06 23:17:22 -0800 | [diff] [blame] | 446 | /// A structured meta item, like the `Copy` in `#[derive(Copy)]` which |
| 447 | /// would be a nested `Meta::Word`. |
David Tolnay | aaadd78 | 2018-01-06 22:58:13 -0800 | [diff] [blame] | 448 | pub Meta(Meta), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 449 | |
David Tolnay | 068120a | 2018-01-06 23:17:22 -0800 | [diff] [blame] | 450 | /// A Rust literal, like the `"new_name"` in `#[rename("new_name")]`. |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 451 | pub Literal(Lit), |
| 452 | } |
David Tolnay | b7fa2b6 | 2016-10-30 10:50:47 -0700 | [diff] [blame] | 453 | } |
| 454 | |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 455 | pub trait FilterAttrs<'a> { |
| 456 | type Ret: Iterator<Item = &'a Attribute>; |
| 457 | |
| 458 | fn outer(self) -> Self::Ret; |
| 459 | fn inner(self) -> Self::Ret; |
| 460 | } |
| 461 | |
David Tolnay | daaf774 | 2016-10-03 11:11:43 -0700 | [diff] [blame] | 462 | impl<'a, T> FilterAttrs<'a> for T |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 463 | where |
| 464 | T: IntoIterator<Item = &'a Attribute>, |
David Tolnay | daaf774 | 2016-10-03 11:11:43 -0700 | [diff] [blame] | 465 | { |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 466 | type Ret = iter::Filter<T::IntoIter, fn(&&Attribute) -> bool>; |
| 467 | |
| 468 | fn outer(self) -> Self::Ret { |
| 469 | fn is_outer(attr: &&Attribute) -> bool { |
Alex Crichton | 2e0229c | 2017-05-23 09:34:50 -0700 | [diff] [blame] | 470 | match attr.style { |
| 471 | AttrStyle::Outer => true, |
| 472 | _ => false, |
| 473 | } |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 474 | } |
| 475 | self.into_iter().filter(is_outer) |
| 476 | } |
| 477 | |
| 478 | fn inner(self) -> Self::Ret { |
| 479 | fn is_inner(attr: &&Attribute) -> bool { |
Alex Crichton | 2e0229c | 2017-05-23 09:34:50 -0700 | [diff] [blame] | 480 | match attr.style { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 481 | AttrStyle::Inner(_) => true, |
Alex Crichton | 2e0229c | 2017-05-23 09:34:50 -0700 | [diff] [blame] | 482 | _ => false, |
| 483 | } |
David Tolnay | 4a51dc7 | 2016-10-01 00:40:31 -0700 | [diff] [blame] | 484 | } |
| 485 | self.into_iter().filter(is_inner) |
| 486 | } |
| 487 | } |
| 488 | |
David Tolnay | 86eca75 | 2016-09-04 11:26:41 -0700 | [diff] [blame] | 489 | #[cfg(feature = "parsing")] |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 490 | pub mod parsing { |
| 491 | use super::*; |
David Tolnay | b5f6fc0 | 2018-09-01 02:18:50 -0700 | [diff] [blame] | 492 | |
David Tolnay | 5931013 | 2018-10-13 13:56:06 -0700 | [diff] [blame^] | 493 | use ext::IdentExt; |
Carl Lerche | fc96cd2 | 2018-10-12 20:45:07 -0700 | [diff] [blame] | 494 | use parse::{Parse, ParseStream, Result}; |
David Tolnay | b5f6fc0 | 2018-09-01 02:18:50 -0700 | [diff] [blame] | 495 | #[cfg(feature = "full")] |
| 496 | use private; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 497 | |
David Tolnay | d9962eb | 2018-08-30 16:23:47 -0700 | [diff] [blame] | 498 | pub fn single_parse_inner(input: ParseStream) -> Result<Attribute> { |
| 499 | let content; |
| 500 | Ok(Attribute { |
| 501 | pound_token: input.parse()?, |
| 502 | style: AttrStyle::Inner(input.parse()?), |
| 503 | bracket_token: bracketed!(content in input), |
| 504 | path: content.call(Path::parse_mod_style)?, |
| 505 | tts: content.parse()?, |
| 506 | }) |
David Tolnay | 201ef21 | 2018-01-01 00:09:14 -0500 | [diff] [blame] | 507 | } |
| 508 | |
David Tolnay | d9962eb | 2018-08-30 16:23:47 -0700 | [diff] [blame] | 509 | pub fn single_parse_outer(input: ParseStream) -> Result<Attribute> { |
| 510 | let content; |
| 511 | Ok(Attribute { |
| 512 | pound_token: input.parse()?, |
| 513 | style: AttrStyle::Outer, |
| 514 | bracket_token: bracketed!(content in input), |
| 515 | path: content.call(Path::parse_mod_style)?, |
| 516 | tts: content.parse()?, |
| 517 | }) |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 518 | } |
David Tolnay | b5f6fc0 | 2018-09-01 02:18:50 -0700 | [diff] [blame] | 519 | |
| 520 | #[cfg(feature = "full")] |
| 521 | impl private { |
| 522 | pub fn attrs(outer: Vec<Attribute>, inner: Vec<Attribute>) -> Vec<Attribute> { |
| 523 | let mut attrs = outer; |
| 524 | attrs.extend(inner); |
| 525 | attrs |
| 526 | } |
| 527 | } |
Carl Lerche | fc96cd2 | 2018-10-12 20:45:07 -0700 | [diff] [blame] | 528 | |
| 529 | impl Parse for Meta { |
| 530 | fn parse(input: ParseStream) -> Result<Self> { |
| 531 | // Detect what kind of meta this is. |
| 532 | let ahead = input.fork(); |
| 533 | |
| 534 | // The first token must be an identifier |
David Tolnay | 5931013 | 2018-10-13 13:56:06 -0700 | [diff] [blame^] | 535 | ahead.call(Ident::parse_any)?; |
Carl Lerche | fc96cd2 | 2018-10-12 20:45:07 -0700 | [diff] [blame] | 536 | |
| 537 | if ahead.peek(token::Paren) { |
David Tolnay | 5931013 | 2018-10-13 13:56:06 -0700 | [diff] [blame^] | 538 | input.parse().map(Meta::List) |
| 539 | } else if ahead.peek(Token![=]) { |
| 540 | input.parse().map(Meta::NameValue) |
Carl Lerche | fc96cd2 | 2018-10-12 20:45:07 -0700 | [diff] [blame] | 541 | } else { |
David Tolnay | 5931013 | 2018-10-13 13:56:06 -0700 | [diff] [blame^] | 542 | input.call(Ident::parse_any).map(Meta::Word) |
Carl Lerche | fc96cd2 | 2018-10-12 20:45:07 -0700 | [diff] [blame] | 543 | } |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | impl Parse for MetaList { |
| 548 | fn parse(input: ParseStream) -> Result<Self> { |
Carl Lerche | fc96cd2 | 2018-10-12 20:45:07 -0700 | [diff] [blame] | 549 | let content; |
Carl Lerche | fc96cd2 | 2018-10-12 20:45:07 -0700 | [diff] [blame] | 550 | Ok(MetaList { |
David Tolnay | 5931013 | 2018-10-13 13:56:06 -0700 | [diff] [blame^] | 551 | ident: input.call(Ident::parse_any)?, |
| 552 | paren_token: parenthesized!(content in input), |
| 553 | nested: content.parse_terminated(NestedMeta::parse)?, |
Carl Lerche | fc96cd2 | 2018-10-12 20:45:07 -0700 | [diff] [blame] | 554 | }) |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | impl Parse for MetaNameValue { |
| 559 | fn parse(input: ParseStream) -> Result<Self> { |
| 560 | Ok(MetaNameValue { |
David Tolnay | 5931013 | 2018-10-13 13:56:06 -0700 | [diff] [blame^] | 561 | ident: input.call(Ident::parse_any)?, |
Carl Lerche | fc96cd2 | 2018-10-12 20:45:07 -0700 | [diff] [blame] | 562 | eq_token: input.parse()?, |
| 563 | lit: input.parse()?, |
| 564 | }) |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | impl Parse for NestedMeta { |
| 569 | fn parse(input: ParseStream) -> Result<Self> { |
David Tolnay | 5931013 | 2018-10-13 13:56:06 -0700 | [diff] [blame^] | 570 | let ahead = input.fork(); |
| 571 | |
| 572 | if ahead.peek(Lit) { |
| 573 | input.parse().map(NestedMeta::Literal) |
| 574 | } else if ahead.call(Ident::parse_any).is_ok() { |
| 575 | input.parse().map(NestedMeta::Meta) |
Carl Lerche | fc96cd2 | 2018-10-12 20:45:07 -0700 | [diff] [blame] | 576 | } else { |
David Tolnay | 5931013 | 2018-10-13 13:56:06 -0700 | [diff] [blame^] | 577 | Err(input.error("expected identifier or literal")) |
Carl Lerche | fc96cd2 | 2018-10-12 20:45:07 -0700 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | } |
David Tolnay | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 581 | } |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 582 | |
| 583 | #[cfg(feature = "printing")] |
| 584 | mod printing { |
| 585 | use super::*; |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 586 | use proc_macro2::TokenStream; |
| 587 | use quote::ToTokens; |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 588 | |
| 589 | impl ToTokens for Attribute { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 590 | fn to_tokens(&self, tokens: &mut TokenStream) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 591 | self.pound_token.to_tokens(tokens); |
| 592 | if let AttrStyle::Inner(ref b) = self.style { |
| 593 | b.to_tokens(tokens); |
David Tolnay | 14cbdeb | 2016-10-01 12:13:59 -0700 | [diff] [blame] | 594 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 595 | self.bracket_token.surround(tokens, |tokens| { |
| 596 | self.path.to_tokens(tokens); |
David Tolnay | 360efd2 | 2018-01-04 23:35:26 -0800 | [diff] [blame] | 597 | self.tts.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 598 | }); |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | |
David Tolnay | aaadd78 | 2018-01-06 22:58:13 -0800 | [diff] [blame] | 602 | impl ToTokens for MetaList { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 603 | fn to_tokens(&self, tokens: &mut TokenStream) { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 604 | self.ident.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 605 | self.paren_token.surround(tokens, |tokens| { |
| 606 | self.nested.to_tokens(tokens); |
| 607 | }) |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 608 | } |
| 609 | } |
David Tolnay | b7fa2b6 | 2016-10-30 10:50:47 -0700 | [diff] [blame] | 610 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 611 | impl ToTokens for MetaNameValue { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 612 | fn to_tokens(&self, tokens: &mut TokenStream) { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 613 | self.ident.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 614 | self.eq_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 615 | self.lit.to_tokens(tokens); |
David Tolnay | b7fa2b6 | 2016-10-30 10:50:47 -0700 | [diff] [blame] | 616 | } |
| 617 | } |
David Tolnay | 87d0b44 | 2016-09-04 11:52:12 -0700 | [diff] [blame] | 618 | } |