about summary refs log tree commit diff
path: root/src/librustc_save_analysis/external_data.rs
diff options
context:
space:
mode:
authorJonas Bushart <jonas@bushart.org>2017-03-02 22:38:57 +0100
committerAlex Crichton <alex@alexcrichton.com>2017-03-10 08:02:24 -0800
commitdb35604792fb64efa0a3deaebc0ea0842e19c67a (patch)
tree0bd9403c77684ab24200a71210e00ebed36dff5f /src/librustc_save_analysis/external_data.rs
parent203d22762ddb215af583108d79a521a8441693c2 (diff)
Move remove_docs_from_attrs into lowering step
Diffstat (limited to 'src/librustc_save_analysis/external_data.rs')
-rw-r--r--src/librustc_save_analysis/external_data.rs38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/librustc_save_analysis/external_data.rs b/src/librustc_save_analysis/external_data.rs
index 38d1df2abb8..41658dc5b1b 100644
--- a/src/librustc_save_analysis/external_data.rs
+++ b/src/librustc_save_analysis/external_data.rs
@@ -14,6 +14,7 @@ use rustc::ty::TyCtxt;
 use syntax::ast::{self, NodeId};
 use syntax::codemap::CodeMap;
 use syntax::print::pprust;
+use syntax::symbol::Symbol;
 use syntax_pos::Span;
 
 use data::{self, Visibility, SigElement};
@@ -72,28 +73,29 @@ pub struct Attribute {
     span: SpanData,
 }
 
-impl Lower for ast::Attribute {
-    type Target = Attribute;
-
-    fn lower(mut self, tcx: TyCtxt) -> Attribute {
-        // strip #[] and #![] from the original attributes
-        self.style = ast::AttrStyle::Outer;
-        let value = pprust::attribute_to_string(&self);
-        // #[] are all ASCII which makes this slice save
-        let value = value[2..value.len()-1].to_string();
-
-        Attribute {
-            value: value,
-            span: SpanData::from_span(self.span, tcx.sess.codemap()),
-        }
-    }
-}
-
 impl Lower for Vec<ast::Attribute> {
     type Target = Vec<Attribute>;
 
     fn lower(self, tcx: TyCtxt) -> Vec<Attribute> {
-        self.into_iter().map(|x| x.lower(tcx)).collect()
+        let doc = Symbol::intern("doc");
+        self.into_iter()
+        // Only retain real attributes. Doc comments are lowered separately.
+        .filter(|attr| attr.name() != doc)
+        .map(|mut attr| {
+            // Remove the surrounding '#[..]' or '#![..]' of the pretty printed
+            // attribute. First normalize all inner attribute (#![..]) to outer
+            // ones (#[..]), then remove the two leading and the one trailing character.
+            attr.style = ast::AttrStyle::Outer;
+            let value = pprust::attribute_to_string(&attr);
+            // This str slicing works correctly, because the leading and trailing characters
+            // are in the ASCII range and thus exactly one byte each.
+            let value = value[2..value.len()-1].to_string();
+
+            Attribute {
+                value: value,
+                span: SpanData::from_span(attr.span, tcx.sess.codemap()),
+            }
+        }).collect()
     }
 }