1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Functions dealing with attributes and meta items
13 pub use self::StabilityLevel::*;
14 pub use self::ReprAttr::*;
15 pub use self::IntType::*;
18 use ast::{AttrId, Attribute, Attribute_, MetaItem, MetaWord, MetaNameValue, MetaList};
19 use ast::{Stmt, StmtDecl, StmtExpr, StmtMac, StmtSemi, DeclItem, DeclLocal};
20 use ast::{Expr, Item, Local, Decl};
21 use codemap::{Span, Spanned, spanned, dummy_spanned};
24 use diagnostic::SpanHandler;
25 use feature_gate::{GatedCfg, GatedCfgAttr};
26 use parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
27 use parse::token::InternedString;
31 use std::cell::{RefCell, Cell};
32 use std::collections::HashSet;
35 static USED_ATTRS: RefCell<Vec<u64>> = RefCell::new(Vec::new())
38 pub fn mark_used(attr: &Attribute) {
39 let AttrId(id) = attr.node.id;
40 USED_ATTRS.with(|slot| {
41 let idx = (id / 64) as usize;
43 if slot.borrow().len() <= idx {
44 slot.borrow_mut().resize(idx + 1, 0);
46 slot.borrow_mut()[idx] |= 1 << shift;
50 pub fn is_used(attr: &Attribute) -> bool {
51 let AttrId(id) = attr.node.id;
52 USED_ATTRS.with(|slot| {
53 let idx = (id / 64) as usize;
55 slot.borrow().get(idx).map(|bits| bits & (1 << shift) != 0)
60 pub trait AttrMetaMethods {
61 fn check_name(&self, name: &str) -> bool {
62 name == &self.name()[..]
65 /// Retrieve the name of the meta item, e.g. `foo` in `#[foo]`,
66 /// `#[foo="bar"]` and `#[foo(bar)]`
67 fn name(&self) -> InternedString;
69 /// Gets the string value if self is a MetaNameValue variant
70 /// containing a string, otherwise None.
71 fn value_str(&self) -> Option<InternedString>;
72 /// Gets a list of inner meta items from a list MetaItem type.
73 fn meta_item_list(&self) -> Option<&[P<MetaItem>]>;
75 fn span(&self) -> Span;
78 impl AttrMetaMethods for Attribute {
79 fn check_name(&self, name: &str) -> bool {
80 let matches = name == &self.name()[..];
86 fn name(&self) -> InternedString { self.meta().name() }
87 fn value_str(&self) -> Option<InternedString> {
88 self.meta().value_str()
90 fn meta_item_list(&self) -> Option<&[P<MetaItem>]> {
91 self.node.value.meta_item_list()
93 fn span(&self) -> Span { self.meta().span }
96 impl AttrMetaMethods for MetaItem {
97 fn name(&self) -> InternedString {
99 MetaWord(ref n) => (*n).clone(),
100 MetaNameValue(ref n, _) => (*n).clone(),
101 MetaList(ref n, _) => (*n).clone(),
105 fn value_str(&self) -> Option<InternedString> {
107 MetaNameValue(_, ref v) => {
109 ast::LitStr(ref s, _) => Some((*s).clone()),
117 fn meta_item_list(&self) -> Option<&[P<MetaItem>]> {
119 MetaList(_, ref l) => Some(&l[..]),
123 fn span(&self) -> Span { self.span }
126 // Annoying, but required to get test_cfg to work
127 impl AttrMetaMethods for P<MetaItem> {
128 fn name(&self) -> InternedString { (**self).name() }
129 fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
130 fn meta_item_list(&self) -> Option<&[P<MetaItem>]> {
131 (**self).meta_item_list()
133 fn span(&self) -> Span { (**self).span() }
137 pub trait AttributeMethods {
138 fn meta(&self) -> &MetaItem;
139 fn with_desugared_doc<T, F>(&self, f: F) -> T where
140 F: FnOnce(&Attribute) -> T;
143 impl AttributeMethods for Attribute {
144 /// Extract the MetaItem from inside this Attribute.
145 fn meta(&self) -> &MetaItem {
149 /// Convert self to a normal #[doc="foo"] comment, if it is a
150 /// comment like `///` or `/** */`. (Returns self unchanged for
151 /// non-sugared doc attributes.)
152 fn with_desugared_doc<T, F>(&self, f: F) -> T where
153 F: FnOnce(&Attribute) -> T,
155 if self.node.is_sugared_doc {
156 let comment = self.value_str().unwrap();
157 let meta = mk_name_value_item_str(
158 InternedString::new("doc"),
159 token::intern_and_get_ident(&strip_doc_comment_decoration(
161 if self.node.style == ast::AttrStyle::Outer {
162 f(&mk_attr_outer(self.node.id, meta))
164 f(&mk_attr_inner(self.node.id, meta))
174 pub fn mk_name_value_item_str(name: InternedString, value: InternedString)
176 let value_lit = dummy_spanned(ast::LitStr(value, ast::CookedStr));
177 mk_name_value_item(name, value_lit)
180 pub fn mk_name_value_item(name: InternedString, value: ast::Lit)
182 P(dummy_spanned(MetaNameValue(name, value)))
185 pub fn mk_list_item(name: InternedString, items: Vec<P<MetaItem>>) -> P<MetaItem> {
186 P(dummy_spanned(MetaList(name, items)))
189 pub fn mk_word_item(name: InternedString) -> P<MetaItem> {
190 P(dummy_spanned(MetaWord(name)))
193 thread_local! { static NEXT_ATTR_ID: Cell<usize> = Cell::new(0) }
195 pub fn mk_attr_id() -> AttrId {
196 let id = NEXT_ATTR_ID.with(|slot| {
204 /// Returns an inner attribute with the given value.
205 pub fn mk_attr_inner(id: AttrId, item: P<MetaItem>) -> Attribute {
206 dummy_spanned(Attribute_ {
208 style: ast::AttrStyle::Inner,
210 is_sugared_doc: false,
214 /// Returns an outer attribute with the given value.
215 pub fn mk_attr_outer(id: AttrId, item: P<MetaItem>) -> Attribute {
216 dummy_spanned(Attribute_ {
218 style: ast::AttrStyle::Outer,
220 is_sugared_doc: false,
224 pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos,
227 let style = doc_comment_style(&text);
228 let lit = spanned(lo, hi, ast::LitStr(text, ast::CookedStr));
229 let attr = Attribute_ {
232 value: P(spanned(lo, hi, MetaNameValue(InternedString::new("doc"),
236 spanned(lo, hi, attr)
240 /// Check if `needle` occurs in `haystack` by a structural
241 /// comparison. This is slightly subtle, and relies on ignoring the
242 /// span included in the `==` comparison a plain MetaItem.
243 pub fn contains(haystack: &[P<MetaItem>], needle: &MetaItem) -> bool {
244 debug!("attr::contains (name={})", needle.name());
245 haystack.iter().any(|item| {
246 debug!(" testing: {}", item.name());
247 item.node == needle.node
251 pub fn contains_name<AM: AttrMetaMethods>(metas: &[AM], name: &str) -> bool {
252 debug!("attr::contains_name (name={})", name);
253 metas.iter().any(|item| {
254 debug!(" testing: {}", item.name());
255 item.check_name(name)
259 pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: &str)
260 -> Option<InternedString> {
262 .find(|at| at.check_name(name))
263 .and_then(|at| at.value_str())
266 pub fn last_meta_item_value_str_by_name(items: &[P<MetaItem>], name: &str)
267 -> Option<InternedString> {
270 .find(|mi| mi.check_name(name))
271 .and_then(|i| i.value_str())
274 /* Higher-level applications */
276 pub fn sort_meta_items(items: Vec<P<MetaItem>>) -> Vec<P<MetaItem>> {
277 // This is sort of stupid here, but we need to sort by
278 // human-readable strings.
279 let mut v = items.into_iter()
280 .map(|mi| (mi.name(), mi))
281 .collect::<Vec<(InternedString, P<MetaItem>)>>();
283 v.sort_by(|&(ref a, _), &(ref b, _)| a.cmp(b));
285 // There doesn't seem to be a more optimal way to do this
286 v.into_iter().map(|(_, m)| m.map(|Spanned {node, span}| {
289 MetaList(n, mis) => MetaList(n, sort_meta_items(mis)),
297 pub fn find_crate_name(attrs: &[Attribute]) -> Option<InternedString> {
298 first_attr_value_str_by_name(attrs, "crate_name")
301 /// Find the value of #[export_name=*] attribute and check its validity.
302 pub fn find_export_name_attr(diag: &SpanHandler, attrs: &[Attribute]) -> Option<InternedString> {
303 attrs.iter().fold(None, |ia,attr| {
304 if attr.check_name("export_name") {
305 if let s@Some(_) = attr.value_str() {
308 diag.span_err(attr.span, "export_name attribute has invalid format");
309 diag.handler.help("use #[export_name=\"*\"]");
318 #[derive(Copy, Clone, PartialEq)]
319 pub enum InlineAttr {
326 /// Determine what `#[inline]` attribute is present in `attrs`, if any.
327 pub fn find_inline_attr(diagnostic: Option<&SpanHandler>, attrs: &[Attribute]) -> InlineAttr {
328 attrs.iter().fold(InlineAttr::None, |ia,attr| {
329 match attr.node.value.node {
330 MetaWord(ref n) if *n == "inline" => {
334 MetaList(ref n, ref items) if *n == "inline" => {
336 if items.len() != 1 {
337 diagnostic.map(|d|{ d.span_err(attr.span, "expected one argument"); });
339 } else if contains_name(&items[..], "always") {
341 } else if contains_name(&items[..], "never") {
344 diagnostic.map(|d|{ d.span_err((*items[0]).span, "invalid argument"); });
353 /// True if `#[inline]` or `#[inline(always)]` is present in `attrs`.
354 pub fn requests_inline(attrs: &[Attribute]) -> bool {
355 match find_inline_attr(None, attrs) {
356 InlineAttr::Hint | InlineAttr::Always => true,
357 InlineAttr::None | InlineAttr::Never => false,
361 /// Tests if a cfg-pattern matches the cfg set
362 pub fn cfg_matches<T: CfgDiag>(cfgs: &[P<MetaItem>],
364 diag: &mut T) -> bool {
366 ast::MetaList(ref pred, ref mis) if &pred[..] == "any" =>
367 mis.iter().any(|mi| cfg_matches(cfgs, &**mi, diag)),
368 ast::MetaList(ref pred, ref mis) if &pred[..] == "all" =>
369 mis.iter().all(|mi| cfg_matches(cfgs, &**mi, diag)),
370 ast::MetaList(ref pred, ref mis) if &pred[..] == "not" => {
372 diag.emit_error(|diagnostic| {
373 diagnostic.span_err(cfg.span, "expected 1 cfg-pattern");
377 !cfg_matches(cfgs, &*mis[0], diag)
379 ast::MetaList(ref pred, _) => {
380 diag.emit_error(|diagnostic| {
381 diagnostic.span_err(cfg.span,
382 &format!("invalid predicate `{}`", pred));
386 ast::MetaWord(_) | ast::MetaNameValue(..) => {
387 diag.flag_gated(|feature_gated_cfgs| {
388 feature_gated_cfgs.extend(
389 GatedCfg::gate(cfg).map(GatedCfgAttr::GatedCfg));
396 /// Represents the #[stable], #[unstable] and #[rustc_deprecated] attributes.
397 #[derive(RustcEncodable, RustcDecodable, Clone, Debug, PartialEq, Eq, Hash)]
398 pub struct Stability {
399 pub level: StabilityLevel,
400 pub feature: InternedString,
401 pub rustc_depr: Option<RustcDeprecation>,
404 /// The available stability levels.
405 #[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Clone, Debug, Eq, Hash)]
406 pub enum StabilityLevel {
407 // Reason for the current stability level and the relevant rust-lang issue
408 Unstable { reason: Option<InternedString>, issue: u32 },
409 Stable { since: InternedString },
412 #[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Clone, Debug, Eq, Hash)]
413 pub struct RustcDeprecation {
414 pub since: InternedString,
415 pub reason: InternedString,
418 #[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Clone, Debug, Eq, Hash)]
419 pub struct Deprecation {
420 pub since: Option<InternedString>,
421 pub note: Option<InternedString>,
424 impl StabilityLevel {
425 pub fn is_unstable(&self) -> bool { if let Unstable {..} = *self { true } else { false }}
426 pub fn is_stable(&self) -> bool { if let Stable {..} = *self { true } else { false }}
429 fn find_stability_generic<'a, I>(diagnostic: &SpanHandler,
433 where I: Iterator<Item = &'a Attribute>
435 let mut stab: Option<Stability> = None;
436 let mut rustc_depr: Option<RustcDeprecation> = None;
438 'outer: for attr in attrs_iter {
439 let tag = attr.name();
441 if tag != "rustc_deprecated" && tag != "unstable" && tag != "stable" {
442 continue // not a stability level
447 if let Some(metas) = attr.meta_item_list() {
448 let get = |meta: &MetaItem, item: &mut Option<InternedString>| {
450 diagnostic.span_err(meta.span, &format!("multiple '{}' items",
454 if let Some(v) = meta.value_str() {
458 diagnostic.span_err(meta.span, "incorrect meta item");
464 "rustc_deprecated" => {
465 if rustc_depr.is_some() {
466 diagnostic.span_err(item_sp, "multiple rustc_deprecated attributes");
470 let mut since = None;
471 let mut reason = None;
473 match &*meta.name() {
474 "since" => if !get(meta, &mut since) { continue 'outer },
475 "reason" => if !get(meta, &mut reason) { continue 'outer },
477 diagnostic.span_err(meta.span, &format!("unknown meta item '{}'",
484 match (since, reason) {
485 (Some(since), Some(reason)) => {
486 rustc_depr = Some(RustcDeprecation {
492 diagnostic.span_err(attr.span(), "missing 'since'");
496 diagnostic.span_err(attr.span(), "missing 'reason'");
503 diagnostic.span_err(item_sp, "multiple stability levels");
507 let mut feature = None;
508 let mut reason = None;
509 let mut issue = None;
511 match &*meta.name() {
512 "feature" => if !get(meta, &mut feature) { continue 'outer },
513 "reason" => if !get(meta, &mut reason) { continue 'outer },
514 "issue" => if !get(meta, &mut issue) { continue 'outer },
516 diagnostic.span_err(meta.span, &format!("unknown meta item '{}'",
523 match (feature, reason, issue) {
524 (Some(feature), reason, Some(issue)) => {
525 stab = Some(Stability {
529 if let Ok(issue) = issue.parse() {
532 diagnostic.span_err(attr.span(), "incorrect 'issue'");
542 diagnostic.span_err(attr.span(), "missing 'feature'");
546 diagnostic.span_err(attr.span(), "missing 'issue'");
553 diagnostic.span_err(item_sp, "multiple stability levels");
557 let mut feature = None;
558 let mut since = None;
560 match &*meta.name() {
561 "feature" => if !get(meta, &mut feature) { continue 'outer },
562 "since" => if !get(meta, &mut since) { continue 'outer },
564 diagnostic.span_err(meta.span, &format!("unknown meta item '{}'",
571 match (feature, since) {
572 (Some(feature), Some(since)) => {
573 stab = Some(Stability {
582 diagnostic.span_err(attr.span(), "missing 'feature'");
586 diagnostic.span_err(attr.span(), "missing 'since'");
594 diagnostic.span_err(attr.span(), "incorrect stability attribute type");
599 // Merge the deprecation info into the stability info
600 if let Some(rustc_depr) = rustc_depr {
601 if let Some(ref mut stab) = stab {
602 if let Unstable {reason: ref mut reason @ None, ..} = stab.level {
603 *reason = Some(rustc_depr.reason.clone())
605 stab.rustc_depr = Some(rustc_depr);
607 diagnostic.span_err(item_sp, "rustc_deprecated attribute must be paired with \
608 either stable or unstable attribute");
615 fn find_deprecation_generic<'a, I>(diagnostic: &SpanHandler,
618 -> Option<Deprecation>
619 where I: Iterator<Item = &'a Attribute>
621 let mut depr: Option<Deprecation> = None;
623 'outer: for attr in attrs_iter {
624 if attr.name() != "deprecated" {
631 diagnostic.span_err(item_sp, "multiple deprecated attributes");
635 depr = if let Some(metas) = attr.meta_item_list() {
636 let get = |meta: &MetaItem, item: &mut Option<InternedString>| {
638 diagnostic.span_err(meta.span, &format!("multiple '{}' items",
642 if let Some(v) = meta.value_str() {
646 diagnostic.span_err(meta.span, "incorrect meta item");
651 let mut since = None;
654 match &*meta.name() {
655 "since" => if !get(meta, &mut since) { continue 'outer },
656 "note" => if !get(meta, &mut note) { continue 'outer },
658 diagnostic.span_err(meta.span, &format!("unknown meta item '{}'",
665 Some(Deprecation {since: since, note: note})
667 Some(Deprecation{since: None, note: None})
674 /// Find the first stability attribute. `None` if none exists.
675 pub fn find_stability(diagnostic: &SpanHandler, attrs: &[Attribute],
676 item_sp: Span) -> Option<Stability> {
677 find_stability_generic(diagnostic, attrs.iter(), item_sp)
680 /// Find the deprecation attribute. `None` if none exists.
681 pub fn find_deprecation(diagnostic: &SpanHandler, attrs: &[Attribute],
682 item_sp: Span) -> Option<Deprecation> {
683 find_deprecation_generic(diagnostic, attrs.iter(), item_sp)
686 pub fn require_unique_names(diagnostic: &SpanHandler, metas: &[P<MetaItem>]) {
687 let mut set = HashSet::new();
689 let name = meta.name();
691 if !set.insert(name.clone()) {
692 panic!(diagnostic.span_fatal(meta.span,
693 &format!("duplicate meta item `{}`", name)));
699 /// Parse #[repr(...)] forms.
701 /// Valid repr contents: any of the primitive integral type names (see
702 /// `int_type_of_word`, below) to specify enum discriminant type; `C`, to use
703 /// the same discriminant size that the corresponding C enum would or C
704 /// structure layout, and `packed` to remove padding.
705 pub fn find_repr_attrs(diagnostic: &SpanHandler, attr: &Attribute) -> Vec<ReprAttr> {
706 let mut acc = Vec::new();
707 match attr.node.value.node {
708 ast::MetaList(ref s, ref items) if *s == "repr" => {
712 ast::MetaWord(ref word) => {
713 let hint = match &word[..] {
714 // Can't use "extern" because it's not a lexical identifier.
715 "C" => Some(ReprExtern),
716 "packed" => Some(ReprPacked),
717 "simd" => Some(ReprSimd),
718 _ => match int_type_of_word(&word) {
719 Some(ity) => Some(ReprInt(item.span, ity)),
721 // Not a word we recognize
722 diagnostic.span_err(item.span,
723 "unrecognized representation hint");
730 Some(h) => acc.push(h),
735 _ => diagnostic.span_err(item.span, "unrecognized enum representation hint")
739 // Not a "repr" hint: ignore.
745 fn int_type_of_word(s: &str) -> Option<IntType> {
747 "i8" => Some(SignedInt(ast::TyI8)),
748 "u8" => Some(UnsignedInt(ast::TyU8)),
749 "i16" => Some(SignedInt(ast::TyI16)),
750 "u16" => Some(UnsignedInt(ast::TyU16)),
751 "i32" => Some(SignedInt(ast::TyI32)),
752 "u32" => Some(UnsignedInt(ast::TyU32)),
753 "i64" => Some(SignedInt(ast::TyI64)),
754 "u64" => Some(UnsignedInt(ast::TyU64)),
755 "isize" => Some(SignedInt(ast::TyIs)),
756 "usize" => Some(UnsignedInt(ast::TyUs)),
761 #[derive(PartialEq, Debug, RustcEncodable, RustcDecodable, Copy, Clone)]
764 ReprInt(Span, IntType),
771 pub fn is_ffi_safe(&self) -> bool {
774 ReprInt(_sp, ity) => ity.is_ffi_safe(),
782 #[derive(Eq, Hash, PartialEq, Debug, RustcEncodable, RustcDecodable, Copy, Clone)]
784 SignedInt(ast::IntTy),
785 UnsignedInt(ast::UintTy)
790 pub fn is_signed(self) -> bool {
792 SignedInt(..) => true,
793 UnsignedInt(..) => false
796 fn is_ffi_safe(self) -> bool {
798 SignedInt(ast::TyI8) | UnsignedInt(ast::TyU8) |
799 SignedInt(ast::TyI16) | UnsignedInt(ast::TyU16) |
800 SignedInt(ast::TyI32) | UnsignedInt(ast::TyU32) |
801 SignedInt(ast::TyI64) | UnsignedInt(ast::TyU64) => true,
802 SignedInt(ast::TyIs) | UnsignedInt(ast::TyUs) => false
807 /// A list of attributes, behind a optional box as
808 /// a space optimization.
809 pub type ThinAttributes = Option<Box<Vec<Attribute>>>;
811 pub trait ThinAttributesExt {
812 fn map_thin_attrs<F>(self, f: F) -> Self
813 where F: FnOnce(Vec<Attribute>) -> Vec<Attribute>;
814 fn prepend(mut self, attrs: Self) -> Self;
815 fn append(mut self, attrs: Self) -> Self;
816 fn update<F>(&mut self, f: F)
818 F: FnOnce(Self) -> Self;
819 fn as_attr_slice(&self) -> &[Attribute];
820 fn into_attr_vec(self) -> Vec<Attribute>;
823 impl ThinAttributesExt for ThinAttributes {
824 fn map_thin_attrs<F>(self, f: F) -> Self
825 where F: FnOnce(Vec<Attribute>) -> Vec<Attribute>
827 f(self.map(|b| *b).unwrap_or(Vec::new())).into_thin_attrs()
830 fn prepend(self, attrs: ThinAttributes) -> Self {
831 attrs.map_thin_attrs(|mut attrs| {
832 attrs.extend(self.into_attr_vec());
837 fn append(self, attrs: ThinAttributes) -> Self {
838 self.map_thin_attrs(|mut self_| {
839 self_.extend(attrs.into_attr_vec());
844 fn update<F>(&mut self, f: F)
846 F: FnOnce(ThinAttributes) -> ThinAttributes
848 let self_ = f(self.take());
852 fn as_attr_slice(&self) -> &[Attribute] {
859 fn into_attr_vec(self) -> Vec<Attribute> {
867 pub trait AttributesExt {
868 fn into_thin_attrs(self) -> ThinAttributes;
871 impl AttributesExt for Vec<Attribute> {
872 fn into_thin_attrs(self) -> ThinAttributes {
881 /// A cheap way to add Attributes to an AST node.
882 pub trait WithAttrs {
883 // FIXME: Could be extended to anything IntoIter<Item=Attribute>
884 fn with_attrs(self, attrs: ThinAttributes) -> Self;
887 impl WithAttrs for P<Expr> {
888 fn with_attrs(self, attrs: ThinAttributes) -> Self {
890 e.attrs.update(|a| a.append(attrs));
896 impl WithAttrs for P<Item> {
897 fn with_attrs(self, attrs: ThinAttributes) -> Self {
898 self.map(|Item { ident, attrs: mut ats, id, node, vis, span }| {
899 ats.extend(attrs.into_attr_vec());
912 impl WithAttrs for P<Local> {
913 fn with_attrs(self, attrs: ThinAttributes) -> Self {
914 self.map(|Local { pat, ty, init, id, span, attrs: mut ats }| {
915 ats.update(|a| a.append(attrs));
928 impl WithAttrs for P<Decl> {
929 fn with_attrs(self, attrs: ThinAttributes) -> Self {
930 self.map(|Spanned { span, node }| {
934 DeclLocal(local) => DeclLocal(local.with_attrs(attrs)),
935 DeclItem(item) => DeclItem(item.with_attrs(attrs)),
942 impl WithAttrs for P<Stmt> {
943 fn with_attrs(self, attrs: ThinAttributes) -> Self {
944 self.map(|Spanned { span, node }| {
948 StmtDecl(decl, id) => StmtDecl(decl.with_attrs(attrs), id),
949 StmtExpr(expr, id) => StmtExpr(expr.with_attrs(attrs), id),
950 StmtSemi(expr, id) => StmtSemi(expr.with_attrs(attrs), id),
951 StmtMac(mac, style, mut ats) => {
952 ats.update(|a| a.append(attrs));
953 StmtMac(mac, style, ats)