blob: 8ffc8a4a3fd21b3c68c9d93623cad1b5752759fb [file] [log] [blame]
David Tolnay55535012018-01-05 16:39:23 -08001// 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 Tolnayf38cdf62016-09-23 19:07:09 -07009use super::*;
David Tolnayf2cfd722017-12-31 18:02:51 -050010use punctuated::Punctuated;
David Tolnayf38cdf62016-09-23 19:07:09 -070011
Alex Crichton62a0a592017-05-22 13:58:53 -070012ast_struct! {
13 /// An enum variant.
David Tolnay461d98e2018-01-07 11:07:19 -080014 ///
15 /// *This type is available if Syn is built with the `"derive"` or `"full"`
16 /// feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -070017 pub struct Variant {
Alex Crichton62a0a592017-05-22 13:58:53 -070018 /// Attributes tagged on the variant.
19 pub attrs: Vec<Attribute>,
Clar Charrd22b5702017-03-10 15:24:56 -050020
David Tolnay4a3f59a2017-12-28 21:21:12 -050021 /// Name of the variant.
22 pub ident: Ident,
23
David Tolnaye3d41b72017-12-31 15:24:00 -050024 /// Content stored in the variant.
25 pub fields: Fields,
Clar Charrd22b5702017-03-10 15:24:56 -050026
David Tolnay05658502018-01-07 09:56:37 -080027 /// Explicit discriminant: `Variant = 1`
David Tolnaye67902a2017-12-28 22:12:00 -050028 pub discriminant: Option<(Token![=], Expr)>,
Alex Crichton62a0a592017-05-22 13:58:53 -070029 }
David Tolnayf38cdf62016-09-23 19:07:09 -070030}
31
David Tolnaye3d41b72017-12-31 15:24:00 -050032ast_enum_of_structs! {
Alex Crichton62a0a592017-05-22 13:58:53 -070033 /// Data stored within an enum variant or struct.
David Tolnay614a0142018-01-07 10:25:43 -080034 ///
David Tolnay461d98e2018-01-07 11:07:19 -080035 /// *This type is available if Syn is built with the `"derive"` or `"full"`
36 /// feature.*
37 ///
David Tolnay614a0142018-01-07 10:25:43 -080038 /// # Syntax tree enum
39 ///
40 /// This type is a [syntax tree enum].
41 ///
42 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
David Tolnaye3d41b72017-12-31 15:24:00 -050043 pub enum Fields {
44 /// Named fields of a struct or struct variant such as `Point { x: f64,
45 /// y: f64 }`.
David Tolnay461d98e2018-01-07 11:07:19 -080046 ///
47 /// *This type is available if Syn is built with the `"derive"` or
48 /// `"full"` feature.*
David Tolnaye3d41b72017-12-31 15:24:00 -050049 pub Named(FieldsNamed {
50 pub brace_token: token::Brace,
David Tolnaybdafb102018-01-01 19:39:10 -080051 pub named: Punctuated<Field, Token![,]>,
David Tolnaye3d41b72017-12-31 15:24:00 -050052 }),
Clar Charrd22b5702017-03-10 15:24:56 -050053
David Tolnaye3d41b72017-12-31 15:24:00 -050054 /// Unnamed fields of a tuple struct or tuple variant such as `Some(T)`.
David Tolnay461d98e2018-01-07 11:07:19 -080055 ///
56 /// *This type is available if Syn is built with the `"derive"` or
57 /// `"full"` feature.*
David Tolnaye3d41b72017-12-31 15:24:00 -050058 pub Unnamed(FieldsUnnamed {
59 pub paren_token: token::Paren,
David Tolnaybdafb102018-01-01 19:39:10 -080060 pub unnamed: Punctuated<Field, Token![,]>,
David Tolnaye3d41b72017-12-31 15:24:00 -050061 }),
Clar Charrd22b5702017-03-10 15:24:56 -050062
David Tolnaye3d41b72017-12-31 15:24:00 -050063 /// Unit struct or unit variant such as `None`.
64 pub Unit,
Alex Crichton62a0a592017-05-22 13:58:53 -070065 }
David Tolnayf38cdf62016-09-23 19:07:09 -070066}
67
Nika Layzell5680dcc2018-01-16 15:14:27 -050068impl Fields {
Michael Bradshaw0b13ae62018-08-02 23:43:15 -060069 /// Get an iterator over the borrowed [`Field`] items in this object. This
70 /// iterator can be used to iterate over a named or unnamed struct or
71 /// variant's fields uniformly.
Nika Layzell5680dcc2018-01-16 15:14:27 -050072 ///
73 /// [`Field`]: struct.Field.html
David Tolnay8095c302018-03-31 19:34:17 +020074 pub fn iter(&self) -> punctuated::Iter<Field> {
Nika Layzell5680dcc2018-01-16 15:14:27 -050075 match *self {
David Tolnay96a09d92018-01-16 22:24:03 -080076 Fields::Unit => punctuated::Iter::private_empty(),
77 Fields::Named(ref f) => f.named.iter(),
78 Fields::Unnamed(ref f) => f.unnamed.iter(),
Nika Layzell5680dcc2018-01-16 15:14:27 -050079 }
80 }
Michael Bradshaw0b13ae62018-08-02 23:43:15 -060081
82 /// Get an iterator over the mutably borrowed [`Field`] items in this
83 /// object. This iterator can be used to iterate over a named or unnamed
84 /// struct or variant's fields uniformly.
85 ///
86 /// [`Field`]: struct.Field.html
87 pub fn iter_mut(&mut self) -> punctuated::IterMut<Field> {
88 match *self {
89 Fields::Unit => punctuated::IterMut::private_empty(),
90 Fields::Named(ref mut f) => f.named.iter_mut(),
91 Fields::Unnamed(ref mut f) => f.unnamed.iter_mut(),
92 }
93 }
Nika Layzell5680dcc2018-01-16 15:14:27 -050094}
95
96impl<'a> IntoIterator for &'a Fields {
97 type Item = &'a Field;
David Tolnay8095c302018-03-31 19:34:17 +020098 type IntoIter = punctuated::Iter<'a, Field>;
Nika Layzell5680dcc2018-01-16 15:14:27 -050099
100 fn into_iter(self) -> Self::IntoIter {
101 self.iter()
102 }
103}
104
Michael Bradshaw0b13ae62018-08-02 23:43:15 -0600105impl<'a> IntoIterator for &'a mut Fields {
106 type Item = &'a mut Field;
107 type IntoIter = punctuated::IterMut<'a, Field>;
108
109 fn into_iter(self) -> Self::IntoIter {
110 self.iter_mut()
111 }
112}
113
Alex Crichton62a0a592017-05-22 13:58:53 -0700114ast_struct! {
115 /// A field of a struct or enum variant.
David Tolnay461d98e2018-01-07 11:07:19 -0800116 ///
117 /// *This type is available if Syn is built with the `"derive"` or `"full"`
118 /// feature.*
Alex Crichton62a0a592017-05-22 13:58:53 -0700119 pub struct Field {
David Tolnay4a3f59a2017-12-28 21:21:12 -0500120 /// Attributes tagged on the field.
121 pub attrs: Vec<Attribute>,
122
123 /// Visibility of the field.
124 pub vis: Visibility,
125
Alex Crichton62a0a592017-05-22 13:58:53 -0700126 /// Name of the field, if any.
127 ///
128 /// Fields of tuple structs have no names.
129 pub ident: Option<Ident>,
Clar Charrd22b5702017-03-10 15:24:56 -0500130
David Tolnay4a3f59a2017-12-28 21:21:12 -0500131 pub colon_token: Option<Token![:]>,
Clar Charrd22b5702017-03-10 15:24:56 -0500132
Alex Crichton62a0a592017-05-22 13:58:53 -0700133 /// Type of the field.
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800134 pub ty: Type,
Alex Crichton62a0a592017-05-22 13:58:53 -0700135 }
David Tolnayf38cdf62016-09-23 19:07:09 -0700136}
137
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700138ast_enum_of_structs! {
David Tolnay05658502018-01-07 09:56:37 -0800139 /// The visibility level of an item: inherited or `pub` or
140 /// `pub(restricted)`.
David Tolnay614a0142018-01-07 10:25:43 -0800141 ///
David Tolnay461d98e2018-01-07 11:07:19 -0800142 /// *This type is available if Syn is built with the `"derive"` or `"full"`
143 /// feature.*
144 ///
David Tolnay614a0142018-01-07 10:25:43 -0800145 /// # Syntax tree enum
146 ///
147 /// This type is a [syntax tree enum].
148 ///
149 /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums
Alex Crichton62a0a592017-05-22 13:58:53 -0700150 pub enum Visibility {
David Tolnay05658502018-01-07 09:56:37 -0800151 /// A public visibility level: `pub`.
David Tolnay461d98e2018-01-07 11:07:19 -0800152 ///
153 /// *This type is available if Syn is built with the `"derive"` or
154 /// `"full"` feature.*
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700155 pub Public(VisPublic {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800156 pub pub_token: Token![pub],
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700157 }),
Clar Charrd22b5702017-03-10 15:24:56 -0500158
David Tolnayc8ecb362018-04-01 11:01:09 +0200159 /// A crate-level visibility: `crate`.
David Tolnay461d98e2018-01-07 11:07:19 -0800160 ///
161 /// *This type is available if Syn is built with the `"derive"` or
162 /// `"full"` feature.*
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700163 pub Crate(VisCrate {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800164 pub crate_token: Token![crate],
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700165 }),
Clar Charrd22b5702017-03-10 15:24:56 -0500166
David Tolnay05658502018-01-07 09:56:37 -0800167 /// A visibility level restricted to some path: `pub(self)` or
David Tolnayc8ecb362018-04-01 11:01:09 +0200168 /// `pub(super)` or `pub(crate)` or `pub(in some::module)`.
David Tolnay461d98e2018-01-07 11:07:19 -0800169 ///
170 /// *This type is available if Syn is built with the `"derive"` or
171 /// `"full"` feature.*
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700172 pub Restricted(VisRestricted {
David Tolnayf8db7ba2017-11-11 22:52:16 -0800173 pub pub_token: Token![pub],
David Tolnay32954ef2017-12-26 22:43:16 -0500174 pub paren_token: token::Paren,
David Tolnayf8db7ba2017-11-11 22:52:16 -0800175 pub in_token: Option<Token![in]>,
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700176 pub path: Box<Path>,
177 }),
Clar Charrd22b5702017-03-10 15:24:56 -0500178
David Tolnay05658502018-01-07 09:56:37 -0800179 /// An inherited visibility, which usually means private.
David Tolnayfcfb9002017-12-28 22:04:29 -0500180 pub Inherited,
Alex Crichton62a0a592017-05-22 13:58:53 -0700181 }
David Tolnayf38cdf62016-09-23 19:07:09 -0700182}
183
David Tolnayf38cdf62016-09-23 19:07:09 -0700184#[cfg(feature = "parsing")]
185pub mod parsing {
186 use super::*;
David Tolnayf38cdf62016-09-23 19:07:09 -0700187
Michael Layzell92639a52017-06-01 00:07:44 -0400188 use synom::Synom;
David Tolnayf38cdf62016-09-23 19:07:09 -0700189
David Tolnaye3d41b72017-12-31 15:24:00 -0500190 impl Synom for Variant {
191 named!(parse -> Self, do_parse!(
192 attrs: many0!(Attribute::parse_outer) >>
193 id: syn!(Ident) >>
194 fields: alt!(
195 syn!(FieldsNamed) => { Fields::Named }
196 |
197 syn!(FieldsUnnamed) => { Fields::Unnamed }
198 |
199 epsilon!() => { |_| Fields::Unit }
200 ) >>
201 disr: option!(tuple!(punct!(=), syn!(Expr))) >>
202 (Variant {
203 ident: id,
204 attrs: attrs,
205 fields: fields,
206 discriminant: disr,
207 })
208 ));
209
210 fn description() -> Option<&'static str> {
211 Some("enum variant")
212 }
213 }
214
215 impl Synom for FieldsNamed {
216 named!(parse -> Self, map!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500217 braces!(call!(Punctuated::parse_terminated_with, Field::parse_named)),
David Tolnaye3d41b72017-12-31 15:24:00 -0500218 |(brace, fields)| FieldsNamed {
219 brace_token: brace,
David Tolnaybdafb102018-01-01 19:39:10 -0800220 named: fields,
David Tolnaye3d41b72017-12-31 15:24:00 -0500221 }
222 ));
David Tolnay79777332018-01-07 10:04:42 -0800223
224 fn description() -> Option<&'static str> {
225 Some("named fields in a struct or struct variant")
226 }
David Tolnaye3d41b72017-12-31 15:24:00 -0500227 }
228
229 impl Synom for FieldsUnnamed {
230 named!(parse -> Self, map!(
David Tolnayf2cfd722017-12-31 18:02:51 -0500231 parens!(call!(Punctuated::parse_terminated_with, Field::parse_unnamed)),
David Tolnaye3d41b72017-12-31 15:24:00 -0500232 |(paren, fields)| FieldsUnnamed {
233 paren_token: paren,
David Tolnaybdafb102018-01-01 19:39:10 -0800234 unnamed: fields,
David Tolnaye3d41b72017-12-31 15:24:00 -0500235 }
236 ));
David Tolnay79777332018-01-07 10:04:42 -0800237
238 fn description() -> Option<&'static str> {
239 Some("unnamed fields in a tuple struct or tuple variant")
240 }
David Tolnaye3d41b72017-12-31 15:24:00 -0500241 }
242
Alex Crichton954046c2017-05-30 21:49:42 -0700243 impl Field {
David Tolnaye3d41b72017-12-31 15:24:00 -0500244 named!(pub parse_named -> Self, do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500245 attrs: many0!(Attribute::parse_outer) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400246 vis: syn!(Visibility) >>
247 id: syn!(Ident) >>
David Tolnayf8db7ba2017-11-11 22:52:16 -0800248 colon: punct!(:) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800249 ty: syn!(Type) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400250 (Field {
251 ident: Some(id),
252 vis: vis,
253 attrs: attrs,
254 ty: ty,
255 colon_token: Some(colon),
256 })
257 ));
David Tolnayf38cdf62016-09-23 19:07:09 -0700258
David Tolnaye3d41b72017-12-31 15:24:00 -0500259 named!(pub parse_unnamed -> Self, do_parse!(
David Tolnay2c136452017-12-27 14:13:32 -0500260 attrs: many0!(Attribute::parse_outer) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400261 vis: syn!(Visibility) >>
David Tolnayfd6bf5c2017-11-12 09:41:14 -0800262 ty: syn!(Type) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400263 (Field {
264 ident: None,
265 colon_token: None,
266 vis: vis,
267 attrs: attrs,
268 ty: ty,
269 })
270 ));
Michael Layzell416724e2017-05-24 21:12:34 -0400271 }
272
Alex Crichton954046c2017-05-30 21:49:42 -0700273 impl Synom for Visibility {
Michael Layzell92639a52017-06-01 00:07:44 -0400274 named!(parse -> Self, alt!(
275 do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800276 pub_token: keyword!(pub) >>
277 other: parens!(keyword!(crate)) >>
David Tolnayfe58b5a2018-03-31 18:20:40 +0200278 (Visibility::Restricted(VisRestricted {
Michael Layzell92639a52017-06-01 00:07:44 -0400279 pub_token: pub_token,
David Tolnay8875fca2017-12-31 13:52:37 -0500280 paren_token: other.0,
David Tolnayfe58b5a2018-03-31 18:20:40 +0200281 in_token: None,
282 path: Box::new(other.1.into()),
Michael Layzell92639a52017-06-01 00:07:44 -0400283 }))
284 )
285 |
David Tolnayf36af872018-06-30 23:07:21 -0700286 do_parse!(
287 crate_token: keyword!(crate) >>
288 not!(punct!(::)) >>
289 (Visibility::Crate(VisCrate {
290 crate_token: crate_token,
291 }))
292 )
David Tolnay36175562018-03-28 13:51:02 +0200293 |
Michael Layzell92639a52017-06-01 00:07:44 -0400294 do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800295 pub_token: keyword!(pub) >>
296 other: parens!(keyword!(self)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400297 (Visibility::Restricted(VisRestricted {
Michael Layzell92639a52017-06-01 00:07:44 -0400298 pub_token: pub_token,
David Tolnay8875fca2017-12-31 13:52:37 -0500299 paren_token: other.0,
300 in_token: None,
301 path: Box::new(other.1.into()),
Michael Layzell92639a52017-06-01 00:07:44 -0400302 }))
303 )
304 |
305 do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800306 pub_token: keyword!(pub) >>
307 other: parens!(keyword!(super)) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400308 (Visibility::Restricted(VisRestricted {
Michael Layzell92639a52017-06-01 00:07:44 -0400309 pub_token: pub_token,
David Tolnay8875fca2017-12-31 13:52:37 -0500310 paren_token: other.0,
311 in_token: None,
312 path: Box::new(other.1.into()),
Michael Layzell92639a52017-06-01 00:07:44 -0400313 }))
314 )
315 |
316 do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800317 pub_token: keyword!(pub) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400318 other: parens!(do_parse!(
David Tolnayf8db7ba2017-11-11 22:52:16 -0800319 in_tok: keyword!(in) >>
Michael Layzell92639a52017-06-01 00:07:44 -0400320 restricted: call!(Path::parse_mod_style) >>
321 (in_tok, restricted)
322 )) >>
323 (Visibility::Restricted(VisRestricted {
Michael Layzell92639a52017-06-01 00:07:44 -0400324 pub_token: pub_token,
David Tolnay8875fca2017-12-31 13:52:37 -0500325 paren_token: other.0,
326 in_token: Some((other.1).0),
327 path: Box::new((other.1).1),
Michael Layzell92639a52017-06-01 00:07:44 -0400328 }))
329 )
330 |
David Tolnayf8db7ba2017-11-11 22:52:16 -0800331 keyword!(pub) => { |tok| {
Michael Layzell92639a52017-06-01 00:07:44 -0400332 Visibility::Public(VisPublic {
333 pub_token: tok,
334 })
335 } }
336 |
David Tolnayfcfb9002017-12-28 22:04:29 -0500337 epsilon!() => { |_| Visibility::Inherited }
Michael Layzell92639a52017-06-01 00:07:44 -0400338 ));
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800339
340 fn description() -> Option<&'static str> {
David Tolnay05658502018-01-07 09:56:37 -0800341 Some("visibility qualifier such as `pub`")
Sergio Benitez5680d6a2017-12-29 11:20:29 -0800342 }
Alex Crichton954046c2017-05-30 21:49:42 -0700343 }
David Tolnayf38cdf62016-09-23 19:07:09 -0700344}
345
346#[cfg(feature = "printing")]
347mod printing {
348 use super::*;
Alex Crichtona74a1c82018-05-16 10:20:44 -0700349 use proc_macro2::TokenStream;
350 use quote::{ToTokens, TokenStreamExt};
David Tolnayf38cdf62016-09-23 19:07:09 -0700351
352 impl ToTokens for Variant {
Alex Crichtona74a1c82018-05-16 10:20:44 -0700353 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700354 tokens.append_all(&self.attrs);
David Tolnayf38cdf62016-09-23 19:07:09 -0700355 self.ident.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -0500356 self.fields.to_tokens(tokens);
David Tolnaye67902a2017-12-28 22:12:00 -0500357 if let Some((ref eq_token, ref disc)) = self.discriminant {
358 eq_token.to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -0400359 disc.to_tokens(tokens);
360 }
David Tolnayf38cdf62016-09-23 19:07:09 -0700361 }
362 }
363
David Tolnaye3d41b72017-12-31 15:24:00 -0500364 impl ToTokens for FieldsNamed {
Alex Crichtona74a1c82018-05-16 10:20:44 -0700365 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnaye3d41b72017-12-31 15:24:00 -0500366 self.brace_token.surround(tokens, |tokens| {
David Tolnaybdafb102018-01-01 19:39:10 -0800367 self.named.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -0500368 });
369 }
370 }
371
372 impl ToTokens for FieldsUnnamed {
Alex Crichtona74a1c82018-05-16 10:20:44 -0700373 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnaye3d41b72017-12-31 15:24:00 -0500374 self.paren_token.surround(tokens, |tokens| {
David Tolnaybdafb102018-01-01 19:39:10 -0800375 self.unnamed.to_tokens(tokens);
David Tolnaye3d41b72017-12-31 15:24:00 -0500376 });
David Tolnayf38cdf62016-09-23 19:07:09 -0700377 }
378 }
379
380 impl ToTokens for Field {
Alex Crichtona74a1c82018-05-16 10:20:44 -0700381 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700382 tokens.append_all(&self.attrs);
David Tolnay47a877c2016-10-01 16:50:55 -0700383 self.vis.to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -0400384 if let Some(ref ident) = self.ident {
385 ident.to_tokens(tokens);
Alex Crichton259ee532017-07-14 06:51:02 -0700386 TokensOrDefault(&self.colon_token).to_tokens(tokens);
Michael Layzell3936ceb2017-07-08 00:28:36 -0400387 }
David Tolnayf38cdf62016-09-23 19:07:09 -0700388 self.ty.to_tokens(tokens);
389 }
390 }
391
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700392 impl ToTokens for VisPublic {
Alex Crichtona74a1c82018-05-16 10:20:44 -0700393 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700394 self.pub_token.to_tokens(tokens)
395 }
396 }
Arnaviond32b2942017-04-29 17:18:02 -0700397
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700398 impl ToTokens for VisCrate {
Alex Crichtona74a1c82018-05-16 10:20:44 -0700399 fn to_tokens(&self, tokens: &mut TokenStream) {
David Tolnayfe58b5a2018-03-31 18:20:40 +0200400 self.crate_token.to_tokens(tokens);
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700401 }
402 }
Arnaviond32b2942017-04-29 17:18:02 -0700403
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700404 impl ToTokens for VisRestricted {
Alex Crichtona74a1c82018-05-16 10:20:44 -0700405 fn to_tokens(&self, tokens: &mut TokenStream) {
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700406 self.pub_token.to_tokens(tokens);
407 self.paren_token.surround(tokens, |tokens| {
David Tolnayfe58b5a2018-03-31 18:20:40 +0200408 // XXX: If we have a path which is not "self" or "super" or
409 // "crate", automatically add the "in" token.
Alex Crichtonccbb45d2017-05-23 10:58:24 -0700410 self.in_token.to_tokens(tokens);
411 self.path.to_tokens(tokens);
412 });
413 }
414 }
David Tolnayf38cdf62016-09-23 19:07:09 -0700415}