1111use rustc:: hir:: def_id:: { CrateNum , DefId , DefIndex } ;
1212use rustc:: hir:: map:: Map ;
1313use rustc:: ty:: TyCtxt ;
14- use syntax:: ast:: { self , LitKind , NodeId , StrStyle } ;
14+ use syntax:: ast:: { self , NodeId } ;
1515use syntax:: codemap:: CodeMap ;
16+ use syntax:: print:: pprust;
1617use syntax_pos:: Span ;
1718
1819use data:: { self , Visibility , SigElement } ;
@@ -67,16 +68,22 @@ impl SpanData {
6768/// Represent an arbitrary attribute on a code element
6869#[ derive( Clone , Debug , RustcEncodable ) ]
6970pub struct Attribute {
70- value : AttributeItem ,
71+ value : String ,
7172 span : SpanData ,
7273}
7374
7475impl Lower for ast:: Attribute {
7576 type Target = Attribute ;
7677
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+
7885 Attribute {
79- value : self . value . lower ( tcx ) ,
86+ value : value,
8087 span : SpanData :: from_span ( self . span , tcx. sess . codemap ( ) ) ,
8188 }
8289 }
@@ -90,76 +97,6 @@ impl Lower for Vec<ast::Attribute> {
9097 }
9198}
9299
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-
163100#[ derive( Debug , RustcEncodable ) ]
164101pub struct CratePreludeData {
165102 pub crate_name : String ,
0 commit comments