1
1
//! Functions dealing with attributes and meta items.
2
2
3
- use crate :: ast:: { AttrArgs , AttrArgsEq , AttrId , AttrItem , AttrKind , AttrStyle , AttrVec , Attribute } ;
3
+ use crate :: ast:: {
4
+ AttrArgs , AttrArgsEq , AttrId , AttrItem , AttrKind , AttrStyle , AttrVec , Attribute , Safety ,
5
+ } ;
4
6
use crate :: ast:: { DelimArgs , Expr , ExprKind , LitKind , MetaItemLit } ;
5
7
use crate :: ast:: { MetaItem , MetaItemKind , NestedMetaItem , NormalAttr } ;
6
8
use crate :: ast:: { Path , PathSegment , DUMMY_NODE_ID } ;
@@ -238,7 +240,12 @@ impl AttrItem {
238
240
}
239
241
240
242
pub fn meta ( & self , span : Span ) -> Option < MetaItem > {
241
- Some ( MetaItem { path : self . path . clone ( ) , kind : self . meta_kind ( ) ?, span } )
243
+ Some ( MetaItem {
244
+ unsafety : Safety :: Default ,
245
+ path : self . path . clone ( ) ,
246
+ kind : self . meta_kind ( ) ?,
247
+ span,
248
+ } )
242
249
}
243
250
244
251
pub fn meta_kind ( & self ) -> Option < MetaItemKind > {
@@ -371,7 +378,10 @@ impl MetaItem {
371
378
_ => path. span . hi ( ) ,
372
379
} ;
373
380
let span = path. span . with_hi ( hi) ;
374
- Some ( MetaItem { path, kind, span } )
381
+ // FIXME: This parses `unsafe()` not as unsafe attribute syntax in `MetaItem`,
382
+ // but as a parenthesized list. This (and likely `MetaItem`) should be changed in
383
+ // such a way that builtin macros don't accept extraneous `unsafe()`.
384
+ Some ( MetaItem { unsafety : Safety :: Default , path, kind, span } )
375
385
}
376
386
}
377
387
@@ -555,11 +565,12 @@ pub fn mk_doc_comment(
555
565
pub fn mk_attr (
556
566
g : & AttrIdGenerator ,
557
567
style : AttrStyle ,
568
+ unsafety : Safety ,
558
569
path : Path ,
559
570
args : AttrArgs ,
560
571
span : Span ,
561
572
) -> Attribute {
562
- mk_attr_from_item ( g, AttrItem { path, args, tokens : None } , None , style, span)
573
+ mk_attr_from_item ( g, AttrItem { unsafety , path, args, tokens : None } , None , style, span)
563
574
}
564
575
565
576
pub fn mk_attr_from_item (
@@ -577,15 +588,22 @@ pub fn mk_attr_from_item(
577
588
}
578
589
}
579
590
580
- pub fn mk_attr_word ( g : & AttrIdGenerator , style : AttrStyle , name : Symbol , span : Span ) -> Attribute {
591
+ pub fn mk_attr_word (
592
+ g : & AttrIdGenerator ,
593
+ style : AttrStyle ,
594
+ unsafety : Safety ,
595
+ name : Symbol ,
596
+ span : Span ,
597
+ ) -> Attribute {
581
598
let path = Path :: from_ident ( Ident :: new ( name, span) ) ;
582
599
let args = AttrArgs :: Empty ;
583
- mk_attr ( g, style, path, args, span)
600
+ mk_attr ( g, style, unsafety , path, args, span)
584
601
}
585
602
586
603
pub fn mk_attr_nested_word (
587
604
g : & AttrIdGenerator ,
588
605
style : AttrStyle ,
606
+ unsafety : Safety ,
589
607
outer : Symbol ,
590
608
inner : Symbol ,
591
609
span : Span ,
@@ -601,12 +619,13 @@ pub fn mk_attr_nested_word(
601
619
delim : Delimiter :: Parenthesis ,
602
620
tokens : inner_tokens,
603
621
} ) ;
604
- mk_attr ( g, style, path, attr_args, span)
622
+ mk_attr ( g, style, unsafety , path, attr_args, span)
605
623
}
606
624
607
625
pub fn mk_attr_name_value_str (
608
626
g : & AttrIdGenerator ,
609
627
style : AttrStyle ,
628
+ unsafety : Safety ,
610
629
name : Symbol ,
611
630
val : Symbol ,
612
631
span : Span ,
@@ -621,7 +640,7 @@ pub fn mk_attr_name_value_str(
621
640
} ) ;
622
641
let path = Path :: from_ident ( Ident :: new ( name, span) ) ;
623
642
let args = AttrArgs :: Eq ( span, AttrArgsEq :: Ast ( expr) ) ;
624
- mk_attr ( g, style, path, args, span)
643
+ mk_attr ( g, style, unsafety , path, args, span)
625
644
}
626
645
627
646
pub fn filter_by_name ( attrs : & [ Attribute ] , name : Symbol ) -> impl Iterator < Item = & Attribute > {
0 commit comments