11
11
use rustc:: hir:: def_id:: { CrateNum , DefId , DefIndex } ;
12
12
use rustc:: hir:: map:: Map ;
13
13
use rustc:: ty:: TyCtxt ;
14
- use syntax:: ast:: { self , LitKind , NodeId , StrStyle } ;
14
+ use syntax:: ast:: { self , NodeId } ;
15
15
use syntax:: codemap:: CodeMap ;
16
+ use syntax:: print:: pprust;
16
17
use syntax_pos:: Span ;
17
18
18
19
use data:: { self , Visibility , SigElement } ;
@@ -67,16 +68,22 @@ impl SpanData {
67
68
/// Represent an arbitrary attribute on a code element
68
69
#[ derive( Clone , Debug , RustcEncodable ) ]
69
70
pub struct Attribute {
70
- value : AttributeItem ,
71
+ value : String ,
71
72
span : SpanData ,
72
73
}
73
74
74
75
impl Lower for ast:: Attribute {
75
76
type Target = Attribute ;
76
77
77
- fn lower ( self , tcx : TyCtxt ) -> Attribute {
78
+ fn lower ( mut self , tcx : TyCtxt ) -> Attribute {
79
+ // strip #[] and #![] from the original attributes
80
+ self . style = ast:: AttrStyle :: Outer ;
81
+ let value = pprust:: attribute_to_string ( & self ) ;
82
+ // #[] are all ASCII which makes this slice save
83
+ let value = value[ 2 ..value. len ( ) -1 ] . to_string ( ) ;
84
+
78
85
Attribute {
79
- value : self . value . lower ( tcx ) ,
86
+ value : value,
80
87
span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
81
88
}
82
89
}
@@ -90,76 +97,6 @@ impl Lower for Vec<ast::Attribute> {
90
97
}
91
98
}
92
99
93
- /// A single item as part of an attribute
94
- #[ derive( Clone , Debug , RustcEncodable ) ]
95
- pub struct AttributeItem {
96
- name : LitKind ,
97
- kind : AttributeItemKind ,
98
- span : SpanData ,
99
- }
100
-
101
- impl Lower for ast:: MetaItem {
102
- type Target = AttributeItem ;
103
-
104
- fn lower ( self , tcx : TyCtxt ) -> AttributeItem {
105
- AttributeItem {
106
- name : LitKind :: Str ( self . name , StrStyle :: Cooked ) ,
107
- kind : self . node . lower ( tcx) ,
108
- span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
109
- }
110
- }
111
- }
112
-
113
- impl Lower for ast:: NestedMetaItem {
114
- type Target = AttributeItem ;
115
-
116
- fn lower ( self , tcx : TyCtxt ) -> AttributeItem {
117
- match self . node {
118
- ast:: NestedMetaItemKind :: MetaItem ( item) => item. lower ( tcx) ,
119
- ast:: NestedMetaItemKind :: Literal ( lit) => {
120
- AttributeItem {
121
- name : lit. node ,
122
- kind : AttributeItemKind :: Literal ,
123
- span : SpanData :: from_span ( lit. span , tcx. sess . codemap ( ) ) ,
124
- }
125
- }
126
- }
127
- }
128
- }
129
-
130
- #[ derive( Clone , Debug , RustcEncodable ) ]
131
- pub enum AttributeItemKind {
132
- /// Word meta item.
133
- ///
134
- /// E.g. `test` as in `#[test]`
135
- Literal ,
136
- /// Name value meta item.
137
- ///
138
- /// E.g. `feature = "foo"` as in `#[feature = "foo"]`
139
- NameValue ( LitKind , SpanData ) ,
140
- /// List meta item.
141
- ///
142
- /// E.g. the `derive(..)` as in `#[derive(..)]`
143
- List ( Vec < AttributeItem > ) ,
144
- }
145
-
146
- impl Lower for ast:: MetaItemKind {
147
- type Target = AttributeItemKind ;
148
-
149
- fn lower ( self , tcx : TyCtxt ) -> AttributeItemKind {
150
- match self {
151
- ast:: MetaItemKind :: Word => AttributeItemKind :: Literal ,
152
- ast:: MetaItemKind :: List ( items) => {
153
- AttributeItemKind :: List ( items. into_iter ( ) . map ( |x| x. lower ( tcx) ) . collect ( ) )
154
- }
155
- ast:: MetaItemKind :: NameValue ( lit) => {
156
- let span = SpanData :: from_span ( lit. span , tcx. sess . codemap ( ) ) ;
157
- AttributeItemKind :: NameValue ( lit. node , span)
158
- }
159
- }
160
- }
161
- }
162
-
163
100
#[ derive( Debug , RustcEncodable ) ]
164
101
pub struct CratePreludeData {
165
102
pub crate_name : String ,
0 commit comments