2019-09-06 03:56:45 +01:00
|
|
|
//! Functions dealing with attributes and meta items.
|
2011-06-28 15:25:20 -07:00
|
|
|
|
2018-06-30 12:19:18 -04:00
|
|
|
mod builtin;
|
|
|
|
|
2019-06-30 01:12:04 +03:00
|
|
|
pub use builtin::*;
|
2019-02-07 02:33:01 +09:00
|
|
|
pub use IntType::*;
|
|
|
|
pub use ReprAttr::*;
|
|
|
|
pub use StabilityLevel::*;
|
2019-07-30 13:50:22 -04:00
|
|
|
pub use crate::ast::Attribute;
|
2014-11-06 00:05:53 -08:00
|
|
|
|
2019-02-07 02:33:01 +09:00
|
|
|
use crate::ast;
|
2019-10-24 06:33:12 +11:00
|
|
|
use crate::ast::{AttrItem, AttrId, AttrKind, AttrStyle, Name, Ident, Path, PathSegment};
|
2019-03-03 20:56:24 +03:00
|
|
|
use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem};
|
2019-05-10 03:00:51 +03:00
|
|
|
use crate::ast::{Lit, LitKind, Expr, Item, Local, Stmt, StmtKind, GenericParam};
|
2019-02-07 02:33:01 +09:00
|
|
|
use crate::mut_visit::visit_clobber;
|
2019-10-11 14:01:02 +02:00
|
|
|
use crate::source_map::{BytePos, Spanned};
|
2019-10-11 12:46:32 +02:00
|
|
|
use crate::token::{self, Token};
|
2019-02-07 02:33:01 +09:00
|
|
|
use crate::ptr::P;
|
2019-05-13 22:46:20 +03:00
|
|
|
use crate::symbol::{sym, Symbol};
|
2019-02-07 02:33:01 +09:00
|
|
|
use crate::ThinVec;
|
2019-10-14 14:06:00 +11:00
|
|
|
use crate::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndJoint};
|
2019-02-07 02:33:01 +09:00
|
|
|
use crate::GLOBALS;
|
|
|
|
|
|
|
|
use log::debug;
|
2019-09-06 23:41:54 +03:00
|
|
|
use syntax_pos::Span;
|
2012-12-23 17:41:37 -05:00
|
|
|
|
2017-03-03 09:23:59 +00:00
|
|
|
use std::iter;
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
use std::ops::DerefMut;
|
2012-03-02 13:14:10 -08:00
|
|
|
|
2014-05-20 00:07:24 -07:00
|
|
|
pub fn mark_used(attr: &Attribute) {
|
2019-07-23 20:03:20 +02:00
|
|
|
debug!("marking {:?} as used", attr);
|
2018-03-07 02:44:10 +01:00
|
|
|
GLOBALS.with(|globals| {
|
2018-07-30 08:39:03 -06:00
|
|
|
globals.used_attrs.lock().insert(attr.id);
|
2015-08-11 17:27:05 -07:00
|
|
|
});
|
2014-05-20 00:07:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_used(attr: &Attribute) -> bool {
|
2018-03-07 02:44:10 +01:00
|
|
|
GLOBALS.with(|globals| {
|
2018-07-30 08:39:03 -06:00
|
|
|
globals.used_attrs.lock().contains(attr.id)
|
2015-08-11 17:27:05 -07:00
|
|
|
})
|
2014-05-20 00:07:24 -07:00
|
|
|
}
|
|
|
|
|
2016-11-08 08:30:26 +10:30
|
|
|
pub fn mark_known(attr: &Attribute) {
|
2019-07-23 20:03:20 +02:00
|
|
|
debug!("marking {:?} as known", attr);
|
2018-03-07 02:44:10 +01:00
|
|
|
GLOBALS.with(|globals| {
|
2018-07-30 08:39:03 -06:00
|
|
|
globals.known_attrs.lock().insert(attr.id);
|
2016-11-08 08:30:26 +10:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_known(attr: &Attribute) -> bool {
|
2018-03-07 02:44:10 +01:00
|
|
|
GLOBALS.with(|globals| {
|
2018-07-30 08:39:03 -06:00
|
|
|
globals.known_attrs.lock().contains(attr.id)
|
2016-11-08 08:30:26 +10:30
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-07-04 14:25:33 +02:00
|
|
|
pub fn is_known_lint_tool(m_item: Ident) -> bool {
|
2019-06-24 18:14:04 +02:00
|
|
|
[sym::clippy, sym::rustc].contains(&m_item.name)
|
2018-07-03 13:50:48 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 03:21:17 +00:00
|
|
|
impl NestedMetaItem {
|
2019-09-06 03:56:45 +01:00
|
|
|
/// Returns the `MetaItem` if `self` is a `NestedMetaItem::MetaItem`.
|
2016-11-15 10:17:24 +00:00
|
|
|
pub fn meta_item(&self) -> Option<&MetaItem> {
|
2019-03-03 20:56:24 +03:00
|
|
|
match *self {
|
|
|
|
NestedMetaItem::MetaItem(ref item) => Some(item),
|
2016-08-23 03:21:17 +00:00
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:56:45 +01:00
|
|
|
/// Returns the `Lit` if `self` is a `NestedMetaItem::Literal`s.
|
2016-08-23 03:21:17 +00:00
|
|
|
pub fn literal(&self) -> Option<&Lit> {
|
2019-03-03 20:56:24 +03:00
|
|
|
match *self {
|
|
|
|
NestedMetaItem::Literal(ref lit) => Some(lit),
|
2016-08-23 03:21:17 +00:00
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Returns `true` if this list item is a MetaItem with a name of `name`.
|
2019-05-08 13:21:18 +10:00
|
|
|
pub fn check_name(&self, name: Symbol) -> bool {
|
2016-08-19 18:58:14 -07:00
|
|
|
self.meta_item().map_or(false, |meta_item| meta_item.check_name(name))
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:56:45 +01:00
|
|
|
/// For a single-segment meta item, returns its name; otherwise, returns `None`.
|
2019-02-28 09:17:24 +03:00
|
|
|
pub fn ident(&self) -> Option<Ident> {
|
|
|
|
self.meta_item().and_then(|meta_item| meta_item.ident())
|
|
|
|
}
|
2019-05-08 14:33:06 +10:00
|
|
|
pub fn name_or_empty(&self) -> Symbol {
|
2019-05-11 17:41:37 +03:00
|
|
|
self.ident().unwrap_or(Ident::invalid()).name
|
2016-08-19 18:58:14 -07:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:56:45 +01:00
|
|
|
/// Gets the string value if `self` is a `MetaItem` and the `MetaItem` is a
|
|
|
|
/// `MetaItemKind::NameValue` variant containing a string, otherwise `None`.
|
2016-11-16 10:52:37 +00:00
|
|
|
pub fn value_str(&self) -> Option<Symbol> {
|
2016-08-19 18:58:14 -07:00
|
|
|
self.meta_item().and_then(|meta_item| meta_item.value_str())
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:56:45 +01:00
|
|
|
/// Returns a name and single literal value tuple of the `MetaItem`.
|
2017-01-15 09:49:29 +11:00
|
|
|
pub fn name_value_literal(&self) -> Option<(Name, &Lit)> {
|
|
|
|
self.meta_item().and_then(
|
|
|
|
|meta_item| meta_item.meta_item_list().and_then(
|
|
|
|
|meta_item_list| {
|
|
|
|
if meta_item_list.len() == 1 {
|
2019-02-28 09:17:24 +03:00
|
|
|
if let Some(ident) = meta_item.ident() {
|
|
|
|
if let Some(lit) = meta_item_list[0].literal() {
|
|
|
|
return Some((ident.name, lit));
|
|
|
|
}
|
2017-01-15 09:49:29 +11:00
|
|
|
}
|
|
|
|
}
|
2019-02-28 09:17:24 +03:00
|
|
|
None
|
|
|
|
}))
|
2016-08-19 18:58:14 -07:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:56:45 +01:00
|
|
|
/// Gets a list of inner meta items from a list `MetaItem` type.
|
2016-08-23 03:21:17 +00:00
|
|
|
pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
|
2016-08-19 18:58:14 -07:00
|
|
|
self.meta_item().and_then(|meta_item| meta_item.meta_item_list())
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:56:45 +01:00
|
|
|
/// Returns `true` if the variant is `MetaItem`.
|
2016-08-23 03:21:17 +00:00
|
|
|
pub fn is_meta_item(&self) -> bool {
|
2016-08-19 18:58:14 -07:00
|
|
|
self.meta_item().is_some()
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:56:45 +01:00
|
|
|
/// Returns `true` if the variant is `Literal`.
|
2016-08-23 03:21:17 +00:00
|
|
|
pub fn is_literal(&self) -> bool {
|
2016-08-19 18:58:14 -07:00
|
|
|
self.literal().is_some()
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:56:45 +01:00
|
|
|
/// Returns `true` if `self` is a `MetaItem` and the meta item is a word.
|
2016-08-23 03:21:17 +00:00
|
|
|
pub fn is_word(&self) -> bool {
|
2019-02-28 09:17:24 +03:00
|
|
|
self.meta_item().map_or(false, |meta_item| meta_item.is_word())
|
2016-08-19 18:58:14 -07:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:56:45 +01:00
|
|
|
/// Returns `true` if `self` is a `MetaItem` and the meta item is a `ValueString`.
|
2016-08-23 03:21:17 +00:00
|
|
|
pub fn is_value_str(&self) -> bool {
|
2016-08-19 18:58:14 -07:00
|
|
|
self.value_str().is_some()
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:56:45 +01:00
|
|
|
/// Returns `true` if `self` is a `MetaItem` and the meta item is a list.
|
2016-08-23 03:21:17 +00:00
|
|
|
pub fn is_meta_item_list(&self) -> bool {
|
2016-08-19 18:58:14 -07:00
|
|
|
self.meta_item_list().is_some()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-23 03:54:53 +00:00
|
|
|
impl Attribute {
|
2019-10-24 06:33:12 +11:00
|
|
|
pub fn has_name(&self, name: Symbol) -> bool {
|
|
|
|
match self.kind {
|
|
|
|
AttrKind::Normal(ref item) => item.path == name,
|
|
|
|
AttrKind::DocComment(_) => name == sym::doc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-04 12:41:01 -05:00
|
|
|
/// Returns `true` if the attribute's path matches the argument. If it matches, then the
|
|
|
|
/// attribute is marked as used.
|
2019-05-08 13:21:18 +10:00
|
|
|
pub fn check_name(&self, name: Symbol) -> bool {
|
2019-10-24 06:33:12 +11:00
|
|
|
let matches = self.has_name(name);
|
2019-04-03 02:43:49 +02:00
|
|
|
if matches {
|
|
|
|
mark_used(self);
|
|
|
|
}
|
|
|
|
matches
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:56:45 +01:00
|
|
|
/// For a single-segment attribute, returns its name; otherwise, returns `None`.
|
2019-02-28 09:17:24 +03:00
|
|
|
pub fn ident(&self) -> Option<Ident> {
|
2019-10-24 06:33:12 +11:00
|
|
|
match self.kind {
|
|
|
|
AttrKind::Normal(ref item) => {
|
|
|
|
if item.path.segments.len() == 1 {
|
|
|
|
Some(item.path.segments[0].ident)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AttrKind::DocComment(_) => Some(Ident::new(sym::doc, self.span)),
|
2019-02-28 09:17:24 +03:00
|
|
|
}
|
|
|
|
}
|
2019-05-08 14:33:06 +10:00
|
|
|
pub fn name_or_empty(&self) -> Symbol {
|
2019-05-11 17:41:37 +03:00
|
|
|
self.ident().unwrap_or(Ident::invalid()).name
|
2017-03-03 09:23:59 +00:00
|
|
|
}
|
2016-08-19 18:58:14 -07:00
|
|
|
|
2016-11-16 10:52:37 +00:00
|
|
|
pub fn value_str(&self) -> Option<Symbol> {
|
2019-10-24 06:33:12 +11:00
|
|
|
match self.kind {
|
|
|
|
AttrKind::Normal(ref item) => {
|
|
|
|
item.meta(self.span).and_then(|meta| meta.value_str())
|
|
|
|
}
|
|
|
|
AttrKind::DocComment(comment) => Some(comment),
|
|
|
|
}
|
2014-01-10 14:02:36 -08:00
|
|
|
}
|
2016-08-19 18:58:14 -07:00
|
|
|
|
2017-03-03 09:23:59 +00:00
|
|
|
pub fn meta_item_list(&self) -> Option<Vec<NestedMetaItem>> {
|
2019-10-24 06:33:12 +11:00
|
|
|
match self.kind {
|
|
|
|
AttrKind::Normal(ref item) => {
|
|
|
|
match item.meta(self.span) {
|
|
|
|
Some(MetaItem { kind: MetaItemKind::List(list), .. }) => Some(list),
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AttrKind::DocComment(_) => None,
|
2017-03-03 09:23:59 +00:00
|
|
|
}
|
2013-07-19 21:51:37 +10:00
|
|
|
}
|
2016-07-15 13:13:17 -07:00
|
|
|
|
2017-03-03 09:23:59 +00:00
|
|
|
pub fn is_word(&self) -> bool {
|
2019-10-24 06:33:12 +11:00
|
|
|
if let AttrKind::Normal(item) = &self.kind {
|
|
|
|
item.tokens.is_empty()
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
2017-03-03 09:23:59 +00:00
|
|
|
}
|
2016-08-23 03:54:53 +00:00
|
|
|
|
|
|
|
pub fn is_meta_item_list(&self) -> bool {
|
|
|
|
self.meta_item_list().is_some()
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:56:45 +01:00
|
|
|
/// Indicates if the attribute is a `ValueString`.
|
2016-08-23 03:54:53 +00:00
|
|
|
pub fn is_value_str(&self) -> bool {
|
|
|
|
self.value_str().is_some()
|
|
|
|
}
|
2011-06-28 11:24:24 -07:00
|
|
|
}
|
|
|
|
|
2016-08-23 03:54:53 +00:00
|
|
|
impl MetaItem {
|
2019-09-06 03:56:45 +01:00
|
|
|
/// For a single-segment meta item, returns its name; otherwise, returns `None`.
|
2019-02-28 09:17:24 +03:00
|
|
|
pub fn ident(&self) -> Option<Ident> {
|
2019-03-02 19:15:26 +03:00
|
|
|
if self.path.segments.len() == 1 {
|
|
|
|
Some(self.path.segments[0].ident)
|
2019-02-28 09:17:24 +03:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
2019-05-08 14:33:06 +10:00
|
|
|
pub fn name_or_empty(&self) -> Symbol {
|
2019-05-13 22:46:20 +03:00
|
|
|
self.ident().unwrap_or(Ident::invalid()).name
|
2018-01-30 14:30:39 +09:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:56:45 +01:00
|
|
|
// Example:
|
|
|
|
// #[attribute(name = "value")]
|
|
|
|
// ^^^^^^^^^^^^^^
|
2018-10-09 22:54:47 +08:00
|
|
|
pub fn name_value_literal(&self) -> Option<&Lit> {
|
2019-09-26 18:04:05 +01:00
|
|
|
match &self.kind {
|
2018-10-09 22:54:47 +08:00
|
|
|
MetaItemKind::NameValue(v) => Some(v),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 10:52:37 +00:00
|
|
|
pub fn value_str(&self) -> Option<Symbol> {
|
2019-09-26 18:04:05 +01:00
|
|
|
match self.kind {
|
2016-11-15 07:37:10 +00:00
|
|
|
MetaItemKind::NameValue(ref v) => {
|
2019-09-26 16:56:53 +01:00
|
|
|
match v.kind {
|
2017-05-12 20:05:39 +02:00
|
|
|
LitKind::Str(ref s, _) => Some(*s),
|
2013-07-19 21:51:37 +10:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
2012-04-15 01:07:47 -07:00
|
|
|
|
2016-08-23 03:54:53 +00:00
|
|
|
pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
|
2019-09-26 18:04:05 +01:00
|
|
|
match self.kind {
|
2016-11-15 07:37:10 +00:00
|
|
|
MetaItemKind::List(ref l) => Some(&l[..]),
|
2013-07-19 21:51:37 +10:00
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
2016-07-15 13:13:17 -07:00
|
|
|
|
2016-08-23 03:54:53 +00:00
|
|
|
pub fn is_word(&self) -> bool {
|
2019-09-26 18:04:05 +01:00
|
|
|
match self.kind {
|
2016-11-15 07:37:10 +00:00
|
|
|
MetaItemKind::Word => true,
|
2016-07-15 13:13:17 -07:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-08 13:21:18 +10:00
|
|
|
pub fn check_name(&self, name: Symbol) -> bool {
|
2019-04-03 02:43:49 +02:00
|
|
|
self.path == name
|
|
|
|
}
|
|
|
|
|
2016-08-23 03:54:53 +00:00
|
|
|
pub fn is_value_str(&self) -> bool {
|
|
|
|
self.value_str().is_some()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_meta_item_list(&self) -> bool {
|
|
|
|
self.meta_item_list().is_some()
|
2012-06-30 11:54:54 +01:00
|
|
|
}
|
|
|
|
}
|
2012-04-15 01:07:47 -07:00
|
|
|
|
2019-08-18 01:10:56 +03:00
|
|
|
impl AttrItem {
|
2019-10-15 22:48:13 +02:00
|
|
|
pub fn meta(&self, span: Span) -> Option<MetaItem> {
|
2017-03-03 09:23:59 +00:00
|
|
|
let mut tokens = self.tokens.trees().peekable();
|
|
|
|
Some(MetaItem {
|
2019-03-02 19:15:26 +03:00
|
|
|
path: self.path.clone(),
|
2019-09-26 18:04:05 +01:00
|
|
|
kind: if let Some(kind) = MetaItemKind::from_tokens(&mut tokens) {
|
2017-03-03 09:23:59 +00:00
|
|
|
if tokens.peek().is_some() {
|
|
|
|
return None;
|
|
|
|
}
|
2019-09-26 18:04:05 +01:00
|
|
|
kind
|
2017-03-03 09:23:59 +00:00
|
|
|
} else {
|
|
|
|
return None;
|
|
|
|
},
|
2019-08-18 01:10:56 +03:00
|
|
|
span,
|
2017-03-03 09:23:59 +00:00
|
|
|
})
|
|
|
|
}
|
2019-08-18 01:10:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Attribute {
|
2019-10-24 06:33:12 +11:00
|
|
|
pub fn is_doc_comment(&self) -> bool {
|
|
|
|
match self.kind {
|
|
|
|
AttrKind::Normal(_) => false,
|
|
|
|
AttrKind::DocComment(_) => true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_normal_item(&self) -> &AttrItem {
|
|
|
|
match self.kind {
|
|
|
|
AttrKind::Normal(ref item) => item,
|
|
|
|
AttrKind::DocComment(_) => panic!("unexpected sugared doc"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn unwrap_normal_item(self) -> AttrItem {
|
|
|
|
match self.kind {
|
|
|
|
AttrKind::Normal(item) => item,
|
|
|
|
AttrKind::DocComment(_) => panic!("unexpected sugared doc"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-18 01:10:56 +03:00
|
|
|
/// Extracts the MetaItem from inside this Attribute.
|
|
|
|
pub fn meta(&self) -> Option<MetaItem> {
|
2019-10-24 06:33:12 +11:00
|
|
|
match self.kind {
|
|
|
|
AttrKind::Normal(ref item) => item.meta(self.span),
|
|
|
|
AttrKind::DocComment(comment) =>
|
|
|
|
Some(mk_name_value_item_str(Ident::new(sym::doc, self.span), comment, self.span)),
|
|
|
|
}
|
2019-08-18 01:10:56 +03:00
|
|
|
}
|
2011-07-05 17:01:23 -07:00
|
|
|
}
|
|
|
|
|
2013-07-19 21:51:37 +10:00
|
|
|
/* Constructors */
|
2011-10-29 17:35:45 -07:00
|
|
|
|
2019-08-15 01:56:44 +03:00
|
|
|
pub fn mk_name_value_item_str(ident: Ident, str: Symbol, str_span: Span) -> MetaItem {
|
|
|
|
let lit_kind = LitKind::Str(str, ast::StrStyle::Cooked);
|
|
|
|
mk_name_value_item(ident, lit_kind, str_span)
|
2012-04-15 01:07:47 -07:00
|
|
|
}
|
2011-06-28 12:53:59 -07:00
|
|
|
|
2019-08-04 18:03:34 -04:00
|
|
|
pub fn mk_name_value_item(ident: Ident, lit_kind: LitKind, lit_span: Span) -> MetaItem {
|
2019-05-10 03:00:51 +03:00
|
|
|
let lit = Lit::from_lit_kind(lit_kind, lit_span);
|
2019-08-04 18:03:34 -04:00
|
|
|
let span = ident.span.to(lit_span);
|
2019-09-26 18:04:05 +01:00
|
|
|
MetaItem { path: Path::from_ident(ident), span, kind: MetaItemKind::NameValue(lit) }
|
2012-04-15 01:07:47 -07:00
|
|
|
}
|
|
|
|
|
2019-08-04 17:59:06 -04:00
|
|
|
pub fn mk_list_item(ident: Ident, items: Vec<NestedMetaItem>) -> MetaItem {
|
2019-09-26 18:04:05 +01:00
|
|
|
MetaItem { path: Path::from_ident(ident), span: ident.span, kind: MetaItemKind::List(items) }
|
2012-04-15 01:07:47 -07:00
|
|
|
}
|
|
|
|
|
2018-03-24 21:17:27 +03:00
|
|
|
pub fn mk_word_item(ident: Ident) -> MetaItem {
|
2019-09-26 18:04:05 +01:00
|
|
|
MetaItem { path: Path::from_ident(ident), span: ident.span, kind: MetaItemKind::Word }
|
2016-08-19 18:58:14 -07:00
|
|
|
}
|
2018-01-30 14:30:39 +09:00
|
|
|
|
2018-03-24 21:17:27 +03:00
|
|
|
pub fn mk_nested_word_item(ident: Ident) -> NestedMetaItem {
|
2019-03-03 20:56:24 +03:00
|
|
|
NestedMetaItem::MetaItem(mk_word_item(ident))
|
2016-07-15 13:13:17 -07:00
|
|
|
}
|
|
|
|
|
2019-08-04 19:35:29 -04:00
|
|
|
crate fn mk_attr_id() -> AttrId {
|
2017-12-03 14:03:28 +01:00
|
|
|
use std::sync::atomic::AtomicUsize;
|
|
|
|
use std::sync::atomic::Ordering;
|
2016-07-15 13:13:17 -07:00
|
|
|
|
2017-12-03 14:03:28 +01:00
|
|
|
static NEXT_ATTR_ID: AtomicUsize = AtomicUsize::new(0);
|
2016-07-15 13:13:17 -07:00
|
|
|
|
2017-12-03 14:03:28 +01:00
|
|
|
let id = NEXT_ATTR_ID.fetch_add(1, Ordering::SeqCst);
|
|
|
|
assert!(id != ::std::usize::MAX);
|
2014-05-20 00:07:24 -07:00
|
|
|
AttrId(id)
|
|
|
|
}
|
|
|
|
|
2019-09-06 23:41:54 +03:00
|
|
|
pub fn mk_attr(style: AttrStyle, path: Path, tokens: TokenStream, span: Span) -> Attribute {
|
2019-10-10 10:26:10 +02:00
|
|
|
mk_attr_from_item(style, AttrItem { path, tokens }, span)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn mk_attr_from_item(style: AttrStyle, item: AttrItem, span: Span) -> Attribute {
|
2016-11-14 12:00:25 +00:00
|
|
|
Attribute {
|
2019-10-10 10:26:10 +02:00
|
|
|
kind: AttrKind::Normal(item),
|
2019-07-30 13:50:22 -04:00
|
|
|
id: mk_attr_id(),
|
2019-09-06 23:41:54 +03:00
|
|
|
style,
|
|
|
|
span,
|
2016-11-14 12:00:25 +00:00
|
|
|
}
|
2016-07-15 13:13:17 -07:00
|
|
|
}
|
|
|
|
|
2019-09-06 23:41:54 +03:00
|
|
|
/// Returns an inner attribute with the given value and span.
|
|
|
|
pub fn mk_attr_inner(item: MetaItem) -> Attribute {
|
2019-09-26 18:04:05 +01:00
|
|
|
mk_attr(AttrStyle::Inner, item.path, item.kind.tokens(item.span), item.span)
|
2019-09-06 23:41:54 +03:00
|
|
|
}
|
|
|
|
|
2016-07-15 13:13:17 -07:00
|
|
|
/// Returns an outer attribute with the given value and span.
|
2019-07-30 14:18:19 -04:00
|
|
|
pub fn mk_attr_outer(item: MetaItem) -> Attribute {
|
2019-09-26 18:04:05 +01:00
|
|
|
mk_attr(AttrStyle::Outer, item.path, item.kind.tokens(item.span), item.span)
|
2016-07-15 13:13:17 -07:00
|
|
|
}
|
|
|
|
|
2019-10-11 14:14:30 +02:00
|
|
|
pub fn mk_doc_comment(style: AttrStyle, comment: Symbol, span: Span) -> Attribute {
|
2016-11-14 12:00:25 +00:00
|
|
|
Attribute {
|
2019-10-24 06:33:12 +11:00
|
|
|
kind: AttrKind::DocComment(comment),
|
2019-07-30 13:50:22 -04:00
|
|
|
id: mk_attr_id(),
|
2019-10-11 14:14:30 +02:00
|
|
|
style,
|
2017-08-06 22:54:09 -07:00
|
|
|
span,
|
2016-11-14 12:00:25 +00:00
|
|
|
}
|
2011-07-13 18:13:19 -07:00
|
|
|
}
|
|
|
|
|
2019-05-08 13:21:18 +10:00
|
|
|
pub fn list_contains_name(items: &[NestedMetaItem], name: Symbol) -> bool {
|
2016-08-19 18:58:14 -07:00
|
|
|
items.iter().any(|item| {
|
|
|
|
item.check_name(name)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-05-08 13:21:18 +10:00
|
|
|
pub fn contains_name(attrs: &[Attribute], name: Symbol) -> bool {
|
2016-08-23 03:54:53 +00:00
|
|
|
attrs.iter().any(|item| {
|
2014-05-21 00:05:45 -07:00
|
|
|
item.check_name(name)
|
2013-11-20 16:23:04 -08:00
|
|
|
})
|
2012-04-15 01:07:47 -07:00
|
|
|
}
|
|
|
|
|
2019-06-21 17:46:41 +02:00
|
|
|
pub fn find_by_name(attrs: &[Attribute], name: Symbol) -> Option<&Attribute> {
|
2017-08-26 18:00:33 -07:00
|
|
|
attrs.iter().find(|attr| attr.check_name(name))
|
|
|
|
}
|
|
|
|
|
2019-08-21 02:23:46 +02:00
|
|
|
pub fn allow_internal_unstable<'a>(
|
|
|
|
attrs: &[Attribute],
|
|
|
|
span_diagnostic: &'a errors::Handler,
|
|
|
|
) -> Option<impl Iterator<Item = Symbol> + 'a> {
|
|
|
|
find_by_name(attrs, sym::allow_internal_unstable).and_then(|attr| {
|
|
|
|
attr.meta_item_list().or_else(|| {
|
|
|
|
span_diagnostic.span_err(
|
|
|
|
attr.span,
|
|
|
|
"allow_internal_unstable expects list of feature names"
|
|
|
|
);
|
|
|
|
None
|
|
|
|
}).map(|features| features.into_iter().filter_map(move |it| {
|
|
|
|
let name = it.ident().map(|ident| ident.name);
|
|
|
|
if name.is_none() {
|
|
|
|
span_diagnostic.span_err(
|
|
|
|
it.span(),
|
|
|
|
"`allow_internal_unstable` expects feature names",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
name
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-21 17:46:41 +02:00
|
|
|
pub fn filter_by_name(attrs: &[Attribute], name: Symbol)
|
|
|
|
-> impl Iterator<Item=&Attribute> {
|
2018-10-31 02:54:56 +11:00
|
|
|
attrs.iter().filter(move |attr| attr.check_name(name))
|
|
|
|
}
|
|
|
|
|
2019-05-08 13:21:18 +10:00
|
|
|
pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: Symbol) -> Option<Symbol> {
|
2013-07-19 21:51:37 +10:00
|
|
|
attrs.iter()
|
2014-05-21 00:05:45 -07:00
|
|
|
.find(|at| at.check_name(name))
|
2013-09-11 12:52:17 -07:00
|
|
|
.and_then(|at| at.value_str())
|
2012-04-15 01:07:47 -07:00
|
|
|
}
|
|
|
|
|
2017-03-03 09:23:59 +00:00
|
|
|
impl MetaItem {
|
2019-10-14 14:06:00 +11:00
|
|
|
fn token_trees_and_joints(&self) -> Vec<TreeAndJoint> {
|
2018-01-30 14:30:39 +09:00
|
|
|
let mut idents = vec![];
|
|
|
|
let mut last_pos = BytePos(0 as u32);
|
2019-03-02 19:15:26 +03:00
|
|
|
for (i, segment) in self.path.segments.iter().enumerate() {
|
2018-01-30 14:30:39 +09:00
|
|
|
let is_first = i == 0;
|
|
|
|
if !is_first {
|
2018-04-17 15:33:39 +02:00
|
|
|
let mod_sep_span = Span::new(last_pos,
|
|
|
|
segment.ident.span.lo(),
|
|
|
|
segment.ident.span.ctxt());
|
2019-06-05 13:25:26 +03:00
|
|
|
idents.push(TokenTree::token(token::ModSep, mod_sep_span).into());
|
2018-01-30 14:30:39 +09:00
|
|
|
}
|
2019-06-08 19:45:12 +03:00
|
|
|
idents.push(TokenTree::Token(Token::from_ast_ident(segment.ident)).into());
|
2018-04-17 15:33:39 +02:00
|
|
|
last_pos = segment.ident.span.hi();
|
2018-01-30 14:30:39 +09:00
|
|
|
}
|
2019-10-14 14:06:00 +11:00
|
|
|
idents.extend(self.kind.token_trees_and_joints(self.span));
|
|
|
|
idents
|
2017-03-03 09:23:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn from_tokens<I>(tokens: &mut iter::Peekable<I>) -> Option<MetaItem>
|
|
|
|
where I: Iterator<Item = TokenTree>,
|
|
|
|
{
|
2018-04-24 16:57:41 +02:00
|
|
|
// FIXME: Share code with `parse_path`.
|
2019-03-02 19:15:26 +03:00
|
|
|
let path = match tokens.next() {
|
2019-06-04 20:42:43 +03:00
|
|
|
Some(TokenTree::Token(Token { kind: kind @ token::Ident(..), span })) |
|
|
|
|
Some(TokenTree::Token(Token { kind: kind @ token::ModSep, span })) => 'arm: {
|
2019-06-05 11:56:06 +03:00
|
|
|
let mut segments = if let token::Ident(name, _) = kind {
|
2019-06-05 14:17:56 +03:00
|
|
|
if let Some(TokenTree::Token(Token { kind: token::ModSep, .. }))
|
|
|
|
= tokens.peek() {
|
2019-01-02 02:21:05 +03:00
|
|
|
tokens.next();
|
2019-06-05 11:56:06 +03:00
|
|
|
vec![PathSegment::from_ident(Ident::new(name, span))]
|
2019-01-02 02:21:05 +03:00
|
|
|
} else {
|
2019-06-05 11:56:06 +03:00
|
|
|
break 'arm Path::from_ident(Ident::new(name, span));
|
2018-01-30 14:30:39 +09:00
|
|
|
}
|
|
|
|
} else {
|
2019-01-02 02:21:05 +03:00
|
|
|
vec![PathSegment::path_root(span)]
|
|
|
|
};
|
|
|
|
loop {
|
2019-06-05 14:17:56 +03:00
|
|
|
if let Some(TokenTree::Token(Token { kind: token::Ident(name, _), span }))
|
|
|
|
= tokens.next() {
|
2019-06-05 11:56:06 +03:00
|
|
|
segments.push(PathSegment::from_ident(Ident::new(name, span)));
|
2019-01-02 02:21:05 +03:00
|
|
|
} else {
|
|
|
|
return None;
|
|
|
|
}
|
2019-06-05 14:17:56 +03:00
|
|
|
if let Some(TokenTree::Token(Token { kind: token::ModSep, .. }))
|
|
|
|
= tokens.peek() {
|
2019-01-02 02:21:05 +03:00
|
|
|
tokens.next();
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2018-01-30 14:30:39 +09:00
|
|
|
}
|
2019-01-02 02:21:05 +03:00
|
|
|
let span = span.with_hi(segments.last().unwrap().ident.span.hi());
|
|
|
|
Path { span, segments }
|
2018-01-30 14:30:39 +09:00
|
|
|
}
|
2019-06-04 20:42:43 +03:00
|
|
|
Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. })) => match *nt {
|
2018-04-24 16:57:41 +02:00
|
|
|
token::Nonterminal::NtIdent(ident, _) => Path::from_ident(ident),
|
2019-08-18 01:10:56 +03:00
|
|
|
token::Nonterminal::NtMeta(ref item) => return item.meta(item.path.span),
|
2018-01-30 14:30:39 +09:00
|
|
|
token::Nonterminal::NtPath(ref path) => path.clone(),
|
2017-03-29 07:17:18 +00:00
|
|
|
_ => return None,
|
2017-03-08 23:13:35 +00:00
|
|
|
},
|
2017-03-03 09:23:59 +00:00
|
|
|
_ => return None,
|
|
|
|
};
|
2017-07-31 23:04:34 +03:00
|
|
|
let list_closing_paren_pos = tokens.peek().map(|tt| tt.span().hi());
|
2019-09-26 18:04:05 +01:00
|
|
|
let kind = MetaItemKind::from_tokens(tokens)?;
|
|
|
|
let hi = match kind {
|
2017-07-31 23:04:34 +03:00
|
|
|
MetaItemKind::NameValue(ref lit) => lit.span.hi(),
|
2019-03-02 19:15:26 +03:00
|
|
|
MetaItemKind::List(..) => list_closing_paren_pos.unwrap_or(path.span.hi()),
|
|
|
|
_ => path.span.hi(),
|
2017-08-17 21:58:01 +09:00
|
|
|
};
|
2019-03-02 19:15:26 +03:00
|
|
|
let span = path.span.with_hi(hi);
|
2019-09-26 18:04:05 +01:00
|
|
|
Some(MetaItem { path, kind, span })
|
2017-03-03 09:23:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MetaItemKind {
|
2019-10-14 14:06:00 +11:00
|
|
|
pub fn token_trees_and_joints(&self, span: Span) -> Vec<TreeAndJoint> {
|
2017-03-03 09:23:59 +00:00
|
|
|
match *self {
|
2019-10-14 14:06:00 +11:00
|
|
|
MetaItemKind::Word => vec![],
|
2017-03-03 09:23:59 +00:00
|
|
|
MetaItemKind::NameValue(ref lit) => {
|
2019-10-14 14:06:00 +11:00
|
|
|
vec![
|
2019-10-14 11:24:46 +11:00
|
|
|
TokenTree::token(token::Eq, span).into(),
|
|
|
|
lit.token_tree().into(),
|
2019-10-14 14:06:00 +11:00
|
|
|
]
|
2017-03-03 09:23:59 +00:00
|
|
|
}
|
|
|
|
MetaItemKind::List(ref list) => {
|
|
|
|
let mut tokens = Vec::new();
|
|
|
|
for (i, item) in list.iter().enumerate() {
|
|
|
|
if i > 0 {
|
2019-06-05 13:25:26 +03:00
|
|
|
tokens.push(TokenTree::token(token::Comma, span).into());
|
2017-03-03 09:23:59 +00:00
|
|
|
}
|
2019-10-14 14:06:00 +11:00
|
|
|
tokens.extend(item.token_trees_and_joints())
|
2017-03-03 09:23:59 +00:00
|
|
|
}
|
2019-10-14 14:06:00 +11:00
|
|
|
vec![
|
|
|
|
TokenTree::Delimited(
|
|
|
|
DelimSpan::from_single(span),
|
|
|
|
token::Paren,
|
|
|
|
TokenStream::new(tokens).into(),
|
|
|
|
).into()
|
|
|
|
]
|
2017-03-03 09:23:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-14 14:06:00 +11:00
|
|
|
// Premature conversions of `TokenTree`s to `TokenStream`s can hurt
|
|
|
|
// performance. Do not use this function if `token_trees_and_joints()` can
|
|
|
|
// be used instead.
|
|
|
|
pub fn tokens(&self, span: Span) -> TokenStream {
|
|
|
|
TokenStream::new(self.token_trees_and_joints(span))
|
|
|
|
}
|
|
|
|
|
2017-03-03 09:23:59 +00:00
|
|
|
fn from_tokens<I>(tokens: &mut iter::Peekable<I>) -> Option<MetaItemKind>
|
|
|
|
where I: Iterator<Item = TokenTree>,
|
|
|
|
{
|
|
|
|
let delimited = match tokens.peek().cloned() {
|
2019-06-04 20:42:43 +03:00
|
|
|
Some(TokenTree::Token(token)) if token == token::Eq => {
|
2017-03-03 09:23:59 +00:00
|
|
|
tokens.next();
|
2019-06-04 20:42:43 +03:00
|
|
|
return if let Some(TokenTree::Token(token)) = tokens.next() {
|
2019-06-05 13:24:54 +03:00
|
|
|
Lit::from_token(&token).ok().map(MetaItemKind::NameValue)
|
2017-03-03 09:23:59 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
}
|
2018-11-30 10:02:04 +11:00
|
|
|
Some(TokenTree::Delimited(_, delim, ref tts)) if delim == token::Paren => {
|
2017-03-03 09:23:59 +00:00
|
|
|
tokens.next();
|
2019-01-09 16:53:14 +11:00
|
|
|
tts.clone()
|
2017-03-03 09:23:59 +00:00
|
|
|
}
|
|
|
|
_ => return Some(MetaItemKind::Word),
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut tokens = delimited.into_trees().peekable();
|
|
|
|
let mut result = Vec::new();
|
|
|
|
while let Some(..) = tokens.peek() {
|
2019-03-03 20:56:24 +03:00
|
|
|
let item = NestedMetaItem::from_tokens(&mut tokens)?;
|
|
|
|
result.push(item);
|
2017-03-03 09:23:59 +00:00
|
|
|
match tokens.next() {
|
2019-06-04 20:42:43 +03:00
|
|
|
None | Some(TokenTree::Token(Token { kind: token::Comma, .. })) => {}
|
2017-03-03 09:23:59 +00:00
|
|
|
_ => return None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(MetaItemKind::List(result))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 20:56:24 +03:00
|
|
|
impl NestedMetaItem {
|
|
|
|
pub fn span(&self) -> Span {
|
2017-03-03 09:23:59 +00:00
|
|
|
match *self {
|
2019-03-03 20:56:24 +03:00
|
|
|
NestedMetaItem::MetaItem(ref item) => item.span,
|
|
|
|
NestedMetaItem::Literal(ref lit) => lit.span,
|
2017-03-03 09:23:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-14 14:06:00 +11:00
|
|
|
fn token_trees_and_joints(&self) -> Vec<TreeAndJoint> {
|
2017-03-03 09:23:59 +00:00
|
|
|
match *self {
|
2019-10-14 14:06:00 +11:00
|
|
|
NestedMetaItem::MetaItem(ref item) => item.token_trees_and_joints(),
|
|
|
|
NestedMetaItem::Literal(ref lit) => vec![lit.token_tree().into()],
|
2017-03-03 09:23:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 20:56:24 +03:00
|
|
|
fn from_tokens<I>(tokens: &mut iter::Peekable<I>) -> Option<NestedMetaItem>
|
2017-03-03 09:23:59 +00:00
|
|
|
where I: Iterator<Item = TokenTree>,
|
|
|
|
{
|
2019-06-05 09:39:34 +03:00
|
|
|
if let Some(TokenTree::Token(token)) = tokens.peek() {
|
2019-06-05 13:24:54 +03:00
|
|
|
if let Ok(lit) = Lit::from_token(token) {
|
2017-03-03 09:23:59 +00:00
|
|
|
tokens.next();
|
2019-05-10 03:00:51 +03:00
|
|
|
return Some(NestedMetaItem::Literal(lit));
|
2017-03-03 09:23:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 20:56:24 +03:00
|
|
|
MetaItem::from_tokens(tokens).map(NestedMetaItem::MetaItem)
|
2017-03-03 09:23:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-18 07:25:44 +00:00
|
|
|
pub trait HasAttrs: Sized {
|
|
|
|
fn attrs(&self) -> &[ast::Attribute];
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
fn visit_attrs<F: FnOnce(&mut Vec<ast::Attribute>)>(&mut self, f: F);
|
2016-05-18 07:25:44 +00:00
|
|
|
}
|
|
|
|
|
2017-01-03 19:13:01 -08:00
|
|
|
impl<T: HasAttrs> HasAttrs for Spanned<T> {
|
|
|
|
fn attrs(&self) -> &[ast::Attribute] { self.node.attrs() }
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
fn visit_attrs<F: FnOnce(&mut Vec<ast::Attribute>)>(&mut self, f: F) {
|
|
|
|
self.node.visit_attrs(f);
|
2017-01-03 19:13:01 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-18 07:25:44 +00:00
|
|
|
impl HasAttrs for Vec<Attribute> {
|
|
|
|
fn attrs(&self) -> &[Attribute] {
|
2017-05-12 20:05:39 +02:00
|
|
|
self
|
2016-05-18 07:25:44 +00:00
|
|
|
}
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
fn visit_attrs<F: FnOnce(&mut Vec<Attribute>)>(&mut self, f: F) {
|
2016-05-18 07:25:44 +00:00
|
|
|
f(self)
|
2015-11-03 17:39:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-18 04:01:57 +00:00
|
|
|
impl HasAttrs for ThinVec<Attribute> {
|
2016-05-18 07:25:44 +00:00
|
|
|
fn attrs(&self) -> &[Attribute] {
|
2017-05-12 20:05:39 +02:00
|
|
|
self
|
2016-05-18 07:25:44 +00:00
|
|
|
}
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
fn visit_attrs<F: FnOnce(&mut Vec<Attribute>)>(&mut self, f: F) {
|
|
|
|
visit_clobber(self, |this| {
|
|
|
|
let mut vec = this.into();
|
|
|
|
f(&mut vec);
|
|
|
|
vec.into()
|
|
|
|
});
|
2015-11-03 17:39:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-18 07:25:44 +00:00
|
|
|
impl<T: HasAttrs + 'static> HasAttrs for P<T> {
|
|
|
|
fn attrs(&self) -> &[Attribute] {
|
|
|
|
(**self).attrs()
|
|
|
|
}
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
fn visit_attrs<F: FnOnce(&mut Vec<Attribute>)>(&mut self, f: F) {
|
|
|
|
(**self).visit_attrs(f);
|
2015-11-03 17:39:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-18 07:25:44 +00:00
|
|
|
impl HasAttrs for StmtKind {
|
|
|
|
fn attrs(&self) -> &[Attribute] {
|
|
|
|
match *self {
|
2016-06-17 02:30:01 +00:00
|
|
|
StmtKind::Local(ref local) => local.attrs(),
|
2016-06-14 06:48:24 +00:00
|
|
|
StmtKind::Item(..) => &[],
|
2016-06-17 02:30:01 +00:00
|
|
|
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => expr.attrs(),
|
|
|
|
StmtKind::Mac(ref mac) => {
|
|
|
|
let (_, _, ref attrs) = **mac;
|
|
|
|
attrs.attrs()
|
|
|
|
}
|
2016-05-18 07:25:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
fn visit_attrs<F: FnOnce(&mut Vec<Attribute>)>(&mut self, f: F) {
|
2016-05-18 07:25:44 +00:00
|
|
|
match self {
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
StmtKind::Local(local) => local.visit_attrs(f),
|
|
|
|
StmtKind::Item(..) => {}
|
|
|
|
StmtKind::Expr(expr) => expr.visit_attrs(f),
|
|
|
|
StmtKind::Semi(expr) => expr.visit_attrs(f),
|
|
|
|
StmtKind::Mac(mac) => {
|
|
|
|
let (_mac, _style, attrs) = mac.deref_mut();
|
|
|
|
attrs.visit_attrs(f);
|
|
|
|
}
|
2016-05-18 07:25:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-03 19:13:01 -08:00
|
|
|
impl HasAttrs for Stmt {
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
fn attrs(&self) -> &[ast::Attribute] {
|
2019-09-26 17:34:50 +01:00
|
|
|
self.kind.attrs()
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_attrs<F: FnOnce(&mut Vec<ast::Attribute>)>(&mut self, f: F) {
|
2019-09-26 17:34:50 +01:00
|
|
|
self.kind.visit_attrs(f);
|
2017-01-03 19:13:01 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-02 05:10:29 +08:00
|
|
|
impl HasAttrs for GenericParam {
|
|
|
|
fn attrs(&self) -> &[ast::Attribute] {
|
2018-06-13 13:29:40 +01:00
|
|
|
&self.attrs
|
2018-06-02 05:10:29 +08:00
|
|
|
}
|
|
|
|
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
fn visit_attrs<F: FnOnce(&mut Vec<Attribute>)>(&mut self, f: F) {
|
|
|
|
self.attrs.visit_attrs(f);
|
2018-06-02 05:10:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-03 19:13:01 -08:00
|
|
|
macro_rules! derive_has_attrs {
|
|
|
|
($($ty:path),*) => { $(
|
2016-05-18 07:25:44 +00:00
|
|
|
impl HasAttrs for $ty {
|
|
|
|
fn attrs(&self) -> &[Attribute] {
|
2017-01-03 19:13:01 -08:00
|
|
|
&self.attrs
|
2016-05-18 07:25:44 +00:00
|
|
|
}
|
|
|
|
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
fn visit_attrs<F: FnOnce(&mut Vec<Attribute>)>(&mut self, f: F) {
|
|
|
|
self.attrs.visit_attrs(f);
|
2016-05-18 07:25:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)* }
|
|
|
|
}
|
|
|
|
|
2017-01-03 19:13:01 -08:00
|
|
|
derive_has_attrs! {
|
|
|
|
Item, Expr, Local, ast::ForeignItem, ast::StructField, ast::ImplItem, ast::TraitItem, ast::Arm,
|
2019-08-27 13:24:32 +02:00
|
|
|
ast::Field, ast::FieldPat, ast::Variant, ast::Param
|
2016-05-18 07:25:44 +00:00
|
|
|
}
|