1 // Copyright 2012-2013 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 //! This module contains the "cleaned" pieces of the AST, and the functions
18 use syntax::attr::{AttributeMethods, AttrMetaMethods};
19 use syntax::codemap::Pos;
20 use syntax::parse::token::InternedString;
21 use syntax::parse::token;
23 use rustc::back::link;
24 use rustc::driver::driver;
25 use rustc::metadata::cstore;
26 use rustc::metadata::csearch;
27 use rustc::metadata::decoder;
28 use rustc::middle::ty;
36 /// A stable identifier to the particular version of JSON output.
37 /// Increment this when the `Crate` and related structures change.
38 pub static SCHEMA_VERSION: &'static str = "0.8.2";
46 impl<T: Clean<U>, U> Clean<Vec<U>> for Vec<T> {
47 fn clean(&self) -> Vec<U> {
48 self.iter().map(|x| x.clean()).collect()
52 impl<T: Clean<U>, U> Clean<U> for @T {
53 fn clean(&self) -> U {
58 impl<T: Clean<U>, U> Clean<U> for Rc<T> {
59 fn clean(&self) -> U {
64 impl<T: Clean<U>, U> Clean<Option<U>> for Option<T> {
65 fn clean(&self) -> Option<U> {
68 &Some(ref v) => Some(v.clean())
73 impl<T: Clean<U>, U> Clean<Vec<U>> for syntax::owned_slice::OwnedSlice<T> {
74 fn clean(&self) -> Vec<U> {
75 self.iter().map(|x| x.clean()).collect()
79 #[deriving(Clone, Encodable, Decodable)]
82 pub module: Option<Item>,
83 pub externs: Vec<(ast::CrateNum, ExternalCrate)>,
86 impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
87 fn clean(&self) -> Crate {
88 let cx = super::ctxtkey.get().unwrap();
90 let mut externs = Vec::new();
91 cx.sess().cstore.iter_crate_data(|n, meta| {
92 externs.push((n, meta.clean()));
95 let input = driver::FileInput(cx.src.clone());
96 let t_outputs = driver::build_output_filenames(&input,
99 self.attrs.as_slice(),
101 let id = link::find_crate_id(self.attrs.as_slice(),
102 t_outputs.out_filestem.as_slice());
104 name: id.name.to_string(),
105 module: Some(self.module.clean()),
111 #[deriving(Clone, Encodable, Decodable)]
112 pub struct ExternalCrate {
114 pub attrs: Vec<Attribute>,
117 impl Clean<ExternalCrate> for cstore::crate_metadata {
118 fn clean(&self) -> ExternalCrate {
120 name: self.name.to_string(),
121 attrs: decoder::get_crate_attributes(self.data()).clean()
128 /// Anything with a source location and set of attributes and, optionally, a
129 /// name. That is, anything that can be documented. This doesn't correspond
130 /// directly to the AST's concept of an item; it's a strict superset.
131 #[deriving(Clone, Encodable, Decodable)]
135 /// Not everything has a name. E.g., impls
136 pub name: Option<String>,
137 pub attrs: Vec<Attribute> ,
139 pub visibility: Option<Visibility>,
140 pub def_id: ast::DefId,
144 /// Finds the `doc` attribute as a List and returns the list of attributes
146 pub fn doc_list<'a>(&'a self) -> Option<&'a [Attribute]> {
147 for attr in self.attrs.iter() {
149 List(ref x, ref list) if "doc" == x.as_slice() => {
150 return Some(list.as_slice());
158 /// Finds the `doc` attribute as a NameValue and returns the corresponding
160 pub fn doc_value<'a>(&'a self) -> Option<&'a str> {
161 for attr in self.attrs.iter() {
163 NameValue(ref x, ref v) if "doc" == x.as_slice() => {
164 return Some(v.as_slice());
172 pub fn is_hidden_from_doc(&self) -> bool {
173 match self.doc_list() {
175 for innerattr in l.iter() {
177 Word(ref s) if "hidden" == s.as_slice() => {
189 pub fn is_mod(&self) -> bool {
190 match self.inner { ModuleItem(..) => true, _ => false }
192 pub fn is_trait(&self) -> bool {
193 match self.inner { TraitItem(..) => true, _ => false }
195 pub fn is_struct(&self) -> bool {
196 match self.inner { StructItem(..) => true, _ => false }
198 pub fn is_enum(&self) -> bool {
199 match self.inner { EnumItem(..) => true, _ => false }
201 pub fn is_fn(&self) -> bool {
202 match self.inner { FunctionItem(..) => true, _ => false }
206 #[deriving(Clone, Encodable, Decodable)]
210 FunctionItem(Function),
212 TypedefItem(Typedef),
216 /// `use` and `extern crate`
217 ViewItemItem(ViewItem),
218 /// A method signature only. Used for required methods in traits (ie,
219 /// non-default-methods).
220 TyMethodItem(TyMethod),
221 /// A method with a body.
223 StructFieldItem(StructField),
224 VariantItem(Variant),
225 /// `fn`s from an extern block
226 ForeignFunctionItem(Function),
227 /// `static`s from an extern block
228 ForeignStaticItem(Static),
232 #[deriving(Clone, Encodable, Decodable)]
234 pub items: Vec<Item>,
238 impl Clean<Item> for doctree::Module {
239 fn clean(&self) -> Item {
240 let name = if self.name.is_some() {
241 self.name.unwrap().clean()
245 let mut foreigns = Vec::new();
246 for subforeigns in self.foreigns.clean().move_iter() {
247 for foreign in subforeigns.move_iter() {
248 foreigns.push(foreign)
251 let items: Vec<Vec<Item> > = vec!(
252 self.structs.clean().move_iter().collect(),
253 self.enums.clean().move_iter().collect(),
254 self.fns.clean().move_iter().collect(),
256 self.mods.clean().move_iter().collect(),
257 self.typedefs.clean().move_iter().collect(),
258 self.statics.clean().move_iter().collect(),
259 self.traits.clean().move_iter().collect(),
260 self.impls.clean().move_iter().collect(),
261 self.view_items.clean().move_iter()
262 .flat_map(|s| s.move_iter()).collect(),
263 self.macros.clean().move_iter().collect()
266 // determine if we should display the inner contents or
267 // the outer `mod` item for the source code.
269 let ctxt = super::ctxtkey.get().unwrap();
270 let cm = ctxt.sess().codemap();
271 let outer = cm.lookup_char_pos(self.where_outer.lo);
272 let inner = cm.lookup_char_pos(self.where_inner.lo);
273 if outer.file.start_pos == inner.file.start_pos {
277 // mod foo; (and a separate FileMap for the contents)
284 attrs: self.attrs.clean(),
285 source: where.clean(),
286 visibility: self.vis.clean(),
287 def_id: ast_util::local_def(self.id),
288 inner: ModuleItem(Module {
289 is_crate: self.is_crate,
291 .flat_map(|x| x.iter().map(|x| (*x).clone()))
298 #[deriving(Clone, Encodable, Decodable)]
301 List(String, Vec<Attribute> ),
302 NameValue(String, String)
305 impl Clean<Attribute> for ast::MetaItem {
306 fn clean(&self) -> Attribute {
308 ast::MetaWord(ref s) => Word(s.get().to_string()),
309 ast::MetaList(ref s, ref l) => {
310 List(s.get().to_string(), l.clean().move_iter().collect())
312 ast::MetaNameValue(ref s, ref v) => {
313 NameValue(s.get().to_string(), lit_to_str(v))
319 impl Clean<Attribute> for ast::Attribute {
320 fn clean(&self) -> Attribute {
321 self.desugar_doc().node.value.clean()
325 // This is a rough approximation that gets us what we want.
326 impl attr::AttrMetaMethods for Attribute {
327 fn name(&self) -> InternedString {
329 Word(ref n) | List(ref n, _) | NameValue(ref n, _) => {
330 token::intern_and_get_ident(n.as_slice())
335 fn value_str(&self) -> Option<InternedString> {
337 NameValue(_, ref v) => {
338 Some(token::intern_and_get_ident(v.as_slice()))
343 fn meta_item_list<'a>(&'a self) -> Option<&'a [@ast::MetaItem]> { None }
344 fn name_str_pair(&self) -> Option<(InternedString, InternedString)> {
348 impl<'a> attr::AttrMetaMethods for &'a Attribute {
349 fn name(&self) -> InternedString { (**self).name() }
350 fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
351 fn meta_item_list<'a>(&'a self) -> Option<&'a [@ast::MetaItem]> { None }
352 fn name_str_pair(&self) -> Option<(InternedString, InternedString)> {
357 #[deriving(Clone, Encodable, Decodable)]
361 pub bounds: Vec<TyParamBound>,
364 impl Clean<TyParam> for ast::TyParam {
365 fn clean(&self) -> TyParam {
367 name: self.ident.clean(),
368 did: ast::DefId { krate: ast::LOCAL_CRATE, node: self.id },
369 bounds: self.bounds.clean().move_iter().collect(),
374 impl Clean<TyParam> for ty::TypeParameterDef {
375 fn clean(&self) -> TyParam {
376 let cx = super::ctxtkey.get().unwrap();
377 cx.external_typarams.borrow_mut().get_mut_ref().insert(self.def_id,
380 name: self.ident.clean(),
382 bounds: self.bounds.clean(),
387 #[deriving(Clone, Encodable, Decodable)]
388 pub enum TyParamBound {
393 impl Clean<TyParamBound> for ast::TyParamBound {
394 fn clean(&self) -> TyParamBound {
396 ast::StaticRegionTyParamBound => RegionBound,
397 ast::OtherRegionTyParamBound(_) => RegionBound,
398 ast::TraitTyParamBound(ref t) => TraitBound(t.clean()),
403 fn external_path(name: &str, substs: &ty::substs) -> Path {
406 segments: vec![PathSegment {
407 name: name.to_string(),
408 lifetimes: match substs.regions {
409 ty::ErasedRegions => Vec::new(),
410 ty::NonerasedRegions(ref v) => {
411 v.iter().filter_map(|v| v.clean()).collect()
414 types: substs.tps.clean(),
419 impl Clean<TyParamBound> for ty::BuiltinBound {
420 fn clean(&self) -> TyParamBound {
421 let cx = super::ctxtkey.get().unwrap();
422 let tcx = match cx.maybe_typed {
423 core::Typed(ref tcx) => tcx,
424 core::NotTyped(_) => return RegionBound,
426 let empty = ty::substs::empty();
427 let (did, path) = match *self {
428 ty::BoundStatic => return RegionBound,
430 (tcx.lang_items.send_trait().unwrap(),
431 external_path("Send", &empty)),
433 (tcx.lang_items.sized_trait().unwrap(),
434 external_path("Sized", &empty)),
436 (tcx.lang_items.copy_trait().unwrap(),
437 external_path("Copy", &empty)),
439 (tcx.lang_items.share_trait().unwrap(),
440 external_path("Share", &empty)),
442 let fqn = csearch::get_item_path(tcx, did);
443 let fqn = fqn.move_iter().map(|i| i.to_str().to_string()).collect();
444 cx.external_paths.borrow_mut().get_mut_ref().insert(did,
446 TraitBound(ResolvedPath {
454 impl Clean<TyParamBound> for ty::TraitRef {
455 fn clean(&self) -> TyParamBound {
456 let cx = super::ctxtkey.get().unwrap();
457 let tcx = match cx.maybe_typed {
458 core::Typed(ref tcx) => tcx,
459 core::NotTyped(_) => return RegionBound,
461 let fqn = csearch::get_item_path(tcx, self.def_id);
462 let fqn = fqn.move_iter().map(|i| i.to_str().to_string())
463 .collect::<Vec<String>>();
464 let path = external_path(fqn.last().unwrap().as_slice(),
466 cx.external_paths.borrow_mut().get_mut_ref().insert(self.def_id,
468 TraitBound(ResolvedPath {
476 impl Clean<Vec<TyParamBound>> for ty::ParamBounds {
477 fn clean(&self) -> Vec<TyParamBound> {
478 let mut v = Vec::new();
479 for b in self.builtin_bounds.iter() {
480 if b != ty::BoundSized {
484 for t in self.trait_bounds.iter() {
491 impl Clean<Option<Vec<TyParamBound>>> for ty::substs {
492 fn clean(&self) -> Option<Vec<TyParamBound>> {
493 let mut v = Vec::new();
495 ty::NonerasedRegions(..) => v.push(RegionBound),
496 ty::ErasedRegions => {}
498 v.extend(self.tps.iter().map(|t| TraitBound(t.clean())));
500 if v.len() > 0 {Some(v)} else {None}
504 #[deriving(Clone, Encodable, Decodable, PartialEq)]
505 pub struct Lifetime(String);
508 pub fn get_ref<'a>(&'a self) -> &'a str {
509 let Lifetime(ref s) = *self;
510 let s: &'a str = s.as_slice();
515 impl Clean<Lifetime> for ast::Lifetime {
516 fn clean(&self) -> Lifetime {
517 Lifetime(token::get_name(self.name).get().to_string())
521 impl Clean<Lifetime> for ty::RegionParameterDef {
522 fn clean(&self) -> Lifetime {
523 Lifetime(token::get_name(self.name).get().to_string())
527 impl Clean<Option<Lifetime>> for ty::Region {
528 fn clean(&self) -> Option<Lifetime> {
530 ty::ReStatic => Some(Lifetime("static".to_string())),
531 ty::ReLateBound(_, ty::BrNamed(_, name)) =>
532 Some(Lifetime(token::get_name(name).get().to_string())),
533 ty::ReEarlyBound(_, _, name) => Some(Lifetime(name.clean())),
535 ty::ReLateBound(..) |
539 ty::ReEmpty(..) => None
544 // maybe use a Generic enum and use ~[Generic]?
545 #[deriving(Clone, Encodable, Decodable)]
546 pub struct Generics {
547 pub lifetimes: Vec<Lifetime>,
548 pub type_params: Vec<TyParam>,
551 impl Clean<Generics> for ast::Generics {
552 fn clean(&self) -> Generics {
554 lifetimes: self.lifetimes.clean().move_iter().collect(),
555 type_params: self.ty_params.clean().move_iter().collect(),
560 impl Clean<Generics> for ty::Generics {
561 fn clean(&self) -> Generics {
563 lifetimes: self.region_param_defs.clean(),
564 type_params: self.type_param_defs.clean(),
569 #[deriving(Clone, Encodable, Decodable)]
571 pub generics: Generics,
573 pub fn_style: ast::FnStyle,
577 impl Clean<Item> for ast::Method {
578 fn clean(&self) -> Item {
579 let inputs = match self.explicit_self.node {
580 ast::SelfStatic => self.decl.inputs.as_slice(),
581 _ => self.decl.inputs.slice_from(1)
585 values: inputs.iter().map(|x| x.clean()).collect(),
587 output: (self.decl.output.clean()),
588 cf: self.decl.cf.clean(),
592 name: Some(self.ident.clean()),
593 attrs: self.attrs.clean().move_iter().collect(),
594 source: self.span.clean(),
595 def_id: ast_util::local_def(self.id.clone()),
596 visibility: self.vis.clean(),
597 inner: MethodItem(Method {
598 generics: self.generics.clean(),
599 self_: self.explicit_self.node.clean(),
600 fn_style: self.fn_style.clone(),
607 #[deriving(Clone, Encodable, Decodable)]
608 pub struct TyMethod {
609 pub fn_style: ast::FnStyle,
611 pub generics: Generics,
615 impl Clean<Item> for ast::TypeMethod {
616 fn clean(&self) -> Item {
617 let inputs = match self.explicit_self.node {
618 ast::SelfStatic => self.decl.inputs.as_slice(),
619 _ => self.decl.inputs.slice_from(1)
623 values: inputs.iter().map(|x| x.clean()).collect(),
625 output: (self.decl.output.clean()),
626 cf: self.decl.cf.clean(),
630 name: Some(self.ident.clean()),
631 attrs: self.attrs.clean().move_iter().collect(),
632 source: self.span.clean(),
633 def_id: ast_util::local_def(self.id),
635 inner: TyMethodItem(TyMethod {
636 fn_style: self.fn_style.clone(),
638 self_: self.explicit_self.node.clean(),
639 generics: self.generics.clean(),
645 #[deriving(Clone, Encodable, Decodable, PartialEq)]
649 SelfBorrowed(Option<Lifetime>, Mutability),
653 impl Clean<SelfTy> for ast::ExplicitSelf_ {
654 fn clean(&self) -> SelfTy {
656 ast::SelfStatic => SelfStatic,
657 ast::SelfValue => SelfValue,
658 ast::SelfUniq => SelfOwned,
659 ast::SelfRegion(lt, mt) => SelfBorrowed(lt.clean(), mt.clean()),
664 #[deriving(Clone, Encodable, Decodable)]
665 pub struct Function {
667 pub generics: Generics,
668 pub fn_style: ast::FnStyle,
671 impl Clean<Item> for doctree::Function {
672 fn clean(&self) -> Item {
674 name: Some(self.name.clean()),
675 attrs: self.attrs.clean(),
676 source: self.where.clean(),
677 visibility: self.vis.clean(),
678 def_id: ast_util::local_def(self.id),
679 inner: FunctionItem(Function {
680 decl: self.decl.clean(),
681 generics: self.generics.clean(),
682 fn_style: self.fn_style,
688 #[deriving(Clone, Encodable, Decodable)]
689 pub struct ClosureDecl {
690 pub lifetimes: Vec<Lifetime>,
692 pub onceness: ast::Onceness,
693 pub fn_style: ast::FnStyle,
694 pub bounds: Vec<TyParamBound>,
697 impl Clean<ClosureDecl> for ast::ClosureTy {
698 fn clean(&self) -> ClosureDecl {
700 lifetimes: self.lifetimes.clean(),
701 decl: self.decl.clean(),
702 onceness: self.onceness,
703 fn_style: self.fn_style,
704 bounds: match self.bounds {
705 Some(ref x) => x.clean().move_iter().collect(),
712 #[deriving(Clone, Encodable, Decodable)]
714 pub inputs: Arguments,
717 pub attrs: Vec<Attribute>,
720 #[deriving(Clone, Encodable, Decodable)]
721 pub struct Arguments {
722 pub values: Vec<Argument>,
725 impl Clean<FnDecl> for ast::FnDecl {
726 fn clean(&self) -> FnDecl {
729 values: self.inputs.iter().map(|x| x.clean()).collect(),
731 output: (self.output.clean()),
738 impl<'a> Clean<FnDecl> for (ast::DefId, &'a ty::FnSig) {
739 fn clean(&self) -> FnDecl {
740 let cx = super::ctxtkey.get().unwrap();
741 let tcx = match cx.maybe_typed {
742 core::Typed(ref tcx) => tcx,
743 core::NotTyped(_) => unreachable!(),
745 let (did, sig) = *self;
746 let mut names = if did.node != 0 {
747 csearch::get_method_arg_names(&tcx.sess.cstore, did).move_iter()
749 Vec::new().move_iter()
751 if names.peek().map(|s| s.as_slice()) == Some("self") {
752 let _ = names.next();
755 output: sig.output.clean(),
759 values: sig.inputs.iter().map(|t| {
763 name: names.next().unwrap_or("".to_string()),
771 #[deriving(Clone, Encodable, Decodable)]
772 pub struct Argument {
778 impl Clean<Argument> for ast::Arg {
779 fn clean(&self) -> Argument {
781 name: name_from_pat(self.pat),
782 type_: (self.ty.clean()),
788 #[deriving(Clone, Encodable, Decodable)]
794 impl Clean<RetStyle> for ast::RetStyle {
795 fn clean(&self) -> RetStyle {
797 ast::Return => Return,
798 ast::NoReturn => NoReturn
803 #[deriving(Clone, Encodable, Decodable)]
805 pub methods: Vec<TraitMethod>,
806 pub generics: Generics,
807 pub parents: Vec<Type>,
810 impl Clean<Item> for doctree::Trait {
811 fn clean(&self) -> Item {
813 name: Some(self.name.clean()),
814 attrs: self.attrs.clean(),
815 source: self.where.clean(),
816 def_id: ast_util::local_def(self.id),
817 visibility: self.vis.clean(),
818 inner: TraitItem(Trait {
819 methods: self.methods.clean(),
820 generics: self.generics.clean(),
821 parents: self.parents.clean(),
827 impl Clean<Type> for ast::TraitRef {
828 fn clean(&self) -> Type {
829 resolve_type(self.path.clean(), None, self.ref_id)
833 #[deriving(Clone, Encodable, Decodable)]
834 pub enum TraitMethod {
840 pub fn is_req(&self) -> bool {
842 &Required(..) => true,
846 pub fn is_def(&self) -> bool {
848 &Provided(..) => true,
852 pub fn item<'a>(&'a self) -> &'a Item {
854 Required(ref item) => item,
855 Provided(ref item) => item,
860 impl Clean<TraitMethod> for ast::TraitMethod {
861 fn clean(&self) -> TraitMethod {
863 &ast::Required(ref t) => Required(t.clean()),
864 &ast::Provided(ref t) => Provided(t.clean()),
869 impl Clean<TraitMethod> for ty::Method {
870 fn clean(&self) -> TraitMethod {
871 let m = if self.provided_source.is_some() {Provided} else {Required};
872 let cx = super::ctxtkey.get().unwrap();
873 let tcx = match cx.maybe_typed {
874 core::Typed(ref tcx) => tcx,
875 core::NotTyped(_) => unreachable!(),
877 let (self_, sig) = match self.explicit_self {
878 ast::SelfStatic => (ast::SelfStatic.clean(), self.fty.sig.clone()),
880 let sig = ty::FnSig {
881 inputs: Vec::from_slice(self.fty.sig.inputs.slice_from(1)),
882 ..self.fty.sig.clone()
885 ast::SelfRegion(..) => {
886 match ty::get(*self.fty.sig.inputs.get(0)).sty {
887 ty::ty_rptr(r, mt) => {
888 SelfBorrowed(r.clean(), mt.mutbl.clean())
900 name: Some(self.ident.clean()),
901 visibility: Some(ast::Inherited),
903 attrs: inline::load_attrs(tcx, self.def_id),
904 source: Span::empty(),
905 inner: TyMethodItem(TyMethod {
906 fn_style: self.fty.fn_style,
907 generics: self.generics.clean(),
909 decl: (self.def_id, &sig).clean(),
915 /// A representation of a Type suitable for hyperlinking purposes. Ideally one can get the original
916 /// type out of the AST/ty::ctxt given one of these, if more information is needed. Most importantly
917 /// it does not preserve mutability or boxes.
918 #[deriving(Clone, Encodable, Decodable)]
920 /// structs/enums/traits (anything that'd be an ast::TyPath)
923 pub typarams: Option<Vec<TyParamBound>>,
926 // I have no idea how to usefully use this.
927 TyParamBinder(ast::NodeId),
928 /// For parameterized types, so the consumer of the JSON don't go looking
929 /// for types which don't exist anywhere.
931 /// For references to self
933 /// Primitives are just the fixed-size numeric types (plus int/uint/float), and char.
934 Primitive(ast::PrimTy),
935 Closure(Box<ClosureDecl>, Option<Lifetime>),
936 Proc(Box<ClosureDecl>),
938 BareFunction(Box<BareFunctionDecl>),
941 FixedVector(Box<Type>, String),
950 RawPointer(Mutability, Box<Type>),
952 pub lifetime: Option<Lifetime>,
953 pub mutability: Mutability,
954 pub type_: Box<Type>,
956 // region, raw, other boxes, mutable
959 #[deriving(Clone, Encodable, Decodable)]
970 impl Clean<Type> for ast::Ty {
971 fn clean(&self) -> Type {
975 TyPtr(ref m) => RawPointer(m.mutbl.clean(), box m.ty.clean()),
976 TyRptr(ref l, ref m) =>
977 BorrowedRef {lifetime: l.clean(), mutability: m.mutbl.clean(),
978 type_: box m.ty.clean()},
979 TyBox(ty) => Managed(box ty.clean()),
980 TyUniq(ty) => Unique(box ty.clean()),
981 TyVec(ty) => Vector(box ty.clean()),
982 TyFixedLengthVec(ty, ref e) => FixedVector(box ty.clean(),
984 TyTup(ref tys) => Tuple(tys.iter().map(|x| x.clean()).collect()),
985 TyPath(ref p, ref tpbs, id) => {
986 resolve_type(p.clean(),
987 tpbs.clean().map(|x| x.move_iter().collect()),
990 TyClosure(ref c, region) => Closure(box c.clean(), region.clean()),
991 TyProc(ref c) => Proc(box c.clean()),
992 TyBareFn(ref barefn) => BareFunction(box barefn.clean()),
994 ref x => fail!("Unimplemented type {:?}", x),
999 impl Clean<Type> for ty::t {
1000 fn clean(&self) -> Type {
1001 match ty::get(*self).sty {
1003 ty::ty_bot => Bottom,
1004 ty::ty_bool => Bool,
1005 ty::ty_char => Primitive(ast::TyChar),
1006 ty::ty_int(t) => Primitive(ast::TyInt(t)),
1007 ty::ty_uint(u) => Primitive(ast::TyUint(u)),
1008 ty::ty_float(f) => Primitive(ast::TyFloat(f)),
1009 ty::ty_box(t) => Managed(box t.clean()),
1010 ty::ty_uniq(t) => Unique(box t.clean()),
1011 ty::ty_str => String,
1012 ty::ty_vec(mt, None) => Vector(box mt.ty.clean()),
1013 ty::ty_vec(mt, Some(i)) => FixedVector(box mt.ty.clean(),
1015 ty::ty_ptr(mt) => RawPointer(mt.mutbl.clean(), box mt.ty.clean()),
1016 ty::ty_rptr(r, mt) => BorrowedRef {
1017 lifetime: r.clean(),
1018 mutability: mt.mutbl.clean(),
1019 type_: box mt.ty.clean(),
1021 ty::ty_bare_fn(ref fty) => BareFunction(box BareFunctionDecl {
1022 fn_style: fty.fn_style,
1023 generics: Generics {
1024 lifetimes: Vec::new(), type_params: Vec::new()
1026 decl: (ast_util::local_def(0), &fty.sig).clean(),
1027 abi: fty.abi.to_str(),
1029 ty::ty_closure(ref fty) => {
1030 let decl = box ClosureDecl {
1031 lifetimes: Vec::new(), // FIXME: this looks wrong...
1032 decl: (ast_util::local_def(0), &fty.sig).clean(),
1033 onceness: fty.onceness,
1034 fn_style: fty.fn_style,
1035 bounds: fty.bounds.iter().map(|i| i.clean()).collect(),
1038 ty::UniqTraitStore => Proc(decl),
1039 ty::RegionTraitStore(ref r, _) => Closure(decl, r.clean()),
1042 ty::ty_struct(did, ref substs) |
1043 ty::ty_enum(did, ref substs) |
1044 ty::ty_trait(box ty::TyTrait { def_id: did, ref substs, .. }) => {
1045 let cx = super::ctxtkey.get().unwrap();
1046 let tcx = match cx.maybe_typed {
1047 core::Typed(ref tycx) => tycx,
1048 core::NotTyped(_) => unreachable!(),
1050 let fqn = csearch::get_item_path(tcx, did);
1051 let fqn: Vec<String> = fqn.move_iter().map(|i| {
1052 i.to_str().to_string()
1054 let kind = match ty::get(*self).sty {
1055 ty::ty_struct(..) => TypeStruct,
1056 ty::ty_trait(..) => TypeTrait,
1059 cx.external_paths.borrow_mut().get_mut_ref().insert(did,
1062 path: external_path(fqn.last().unwrap().to_str().as_slice(),
1068 ty::ty_tup(ref t) => Tuple(t.iter().map(|t| t.clean()).collect()),
1070 ty::ty_param(ref p) => Generic(p.def_id),
1071 ty::ty_self(did) => Self(did),
1073 ty::ty_infer(..) => fail!("ty_infer"),
1074 ty::ty_err => fail!("ty_err"),
1079 #[deriving(Clone, Encodable, Decodable)]
1080 pub enum StructField {
1081 HiddenStructField, // inserted later by strip passes
1082 TypedStructField(Type),
1085 impl Clean<Item> for ast::StructField {
1086 fn clean(&self) -> Item {
1087 let (name, vis) = match self.node.kind {
1088 ast::NamedField(id, vis) => (Some(id), vis),
1089 ast::UnnamedField(vis) => (None, vis)
1093 attrs: self.node.attrs.clean().move_iter().collect(),
1094 source: self.span.clean(),
1095 visibility: Some(vis),
1096 def_id: ast_util::local_def(self.node.id),
1097 inner: StructFieldItem(TypedStructField(self.node.ty.clean())),
1102 impl Clean<Item> for ty::field_ty {
1103 fn clean(&self) -> Item {
1104 use syntax::parse::token::special_idents::unnamed_field;
1105 let name = if self.name == unnamed_field.name {
1110 let cx = super::ctxtkey.get().unwrap();
1111 let tcx = match cx.maybe_typed {
1112 core::Typed(ref tycx) => tycx,
1113 core::NotTyped(_) => unreachable!(),
1115 let ty = ty::lookup_item_type(tcx, self.id);
1118 attrs: inline::load_attrs(tcx, self.id),
1119 source: Span::empty(),
1120 visibility: Some(self.vis),
1122 inner: StructFieldItem(TypedStructField(ty.ty.clean())),
1127 pub type Visibility = ast::Visibility;
1129 impl Clean<Option<Visibility>> for ast::Visibility {
1130 fn clean(&self) -> Option<Visibility> {
1135 #[deriving(Clone, Encodable, Decodable)]
1137 pub struct_type: doctree::StructType,
1138 pub generics: Generics,
1139 pub fields: Vec<Item>,
1140 pub fields_stripped: bool,
1143 impl Clean<Item> for doctree::Struct {
1144 fn clean(&self) -> Item {
1146 name: Some(self.name.clean()),
1147 attrs: self.attrs.clean(),
1148 source: self.where.clean(),
1149 def_id: ast_util::local_def(self.id),
1150 visibility: self.vis.clean(),
1151 inner: StructItem(Struct {
1152 struct_type: self.struct_type,
1153 generics: self.generics.clean(),
1154 fields: self.fields.clean(),
1155 fields_stripped: false,
1161 /// This is a more limited form of the standard Struct, different in that
1162 /// it lacks the things most items have (name, id, parameterization). Found
1163 /// only as a variant in an enum.
1164 #[deriving(Clone, Encodable, Decodable)]
1165 pub struct VariantStruct {
1166 pub struct_type: doctree::StructType,
1167 pub fields: Vec<Item>,
1168 pub fields_stripped: bool,
1171 impl Clean<VariantStruct> for syntax::ast::StructDef {
1172 fn clean(&self) -> VariantStruct {
1174 struct_type: doctree::struct_type_from_def(self),
1175 fields: self.fields.clean().move_iter().collect(),
1176 fields_stripped: false,
1181 #[deriving(Clone, Encodable, Decodable)]
1183 pub variants: Vec<Item>,
1184 pub generics: Generics,
1185 pub variants_stripped: bool,
1188 impl Clean<Item> for doctree::Enum {
1189 fn clean(&self) -> Item {
1191 name: Some(self.name.clean()),
1192 attrs: self.attrs.clean(),
1193 source: self.where.clean(),
1194 def_id: ast_util::local_def(self.id),
1195 visibility: self.vis.clean(),
1196 inner: EnumItem(Enum {
1197 variants: self.variants.clean(),
1198 generics: self.generics.clean(),
1199 variants_stripped: false,
1205 #[deriving(Clone, Encodable, Decodable)]
1206 pub struct Variant {
1207 pub kind: VariantKind,
1210 impl Clean<Item> for doctree::Variant {
1211 fn clean(&self) -> Item {
1213 name: Some(self.name.clean()),
1214 attrs: self.attrs.clean(),
1215 source: self.where.clean(),
1216 visibility: self.vis.clean(),
1217 def_id: ast_util::local_def(self.id),
1218 inner: VariantItem(Variant {
1219 kind: self.kind.clean(),
1225 impl Clean<Item> for ty::VariantInfo {
1226 fn clean(&self) -> Item {
1227 // use syntax::parse::token::special_idents::unnamed_field;
1228 let cx = super::ctxtkey.get().unwrap();
1229 let tcx = match cx.maybe_typed {
1230 core::Typed(ref tycx) => tycx,
1231 core::NotTyped(_) => fail!("tcx not present"),
1233 let kind = match self.arg_names.as_ref().map(|s| s.as_slice()) {
1234 None | Some([]) if self.args.len() == 0 => CLikeVariant,
1235 None | Some([]) => {
1236 TupleVariant(self.args.iter().map(|t| t.clean()).collect())
1239 StructVariant(VariantStruct {
1240 struct_type: doctree::Plain,
1241 fields_stripped: false,
1242 fields: s.iter().zip(self.args.iter()).map(|(name, ty)| {
1244 source: Span::empty(),
1245 name: Some(name.clean()),
1247 visibility: Some(ast::Public),
1248 // FIXME: this is not accurate, we need an id for
1249 // the specific field but we're using the id
1250 // for the whole variant. Nothing currently
1251 // uses this so we should be good for now.
1253 inner: StructFieldItem(
1254 TypedStructField(ty.clean())
1262 name: Some(self.name.clean()),
1263 attrs: inline::load_attrs(tcx, self.id),
1264 source: Span::empty(),
1265 visibility: Some(ast::Public),
1267 inner: VariantItem(Variant { kind: kind }),
1272 #[deriving(Clone, Encodable, Decodable)]
1273 pub enum VariantKind {
1275 TupleVariant(Vec<Type>),
1276 StructVariant(VariantStruct),
1279 impl Clean<VariantKind> for ast::VariantKind {
1280 fn clean(&self) -> VariantKind {
1282 &ast::TupleVariantKind(ref args) => {
1283 if args.len() == 0 {
1286 TupleVariant(args.iter().map(|x| x.ty.clean()).collect())
1289 &ast::StructVariantKind(ref sd) => StructVariant(sd.clean()),
1294 #[deriving(Clone, Encodable, Decodable)]
1296 pub filename: String,
1304 fn empty() -> Span {
1306 filename: "".to_string(),
1307 loline: 0, locol: 0,
1308 hiline: 0, hicol: 0,
1313 impl Clean<Span> for syntax::codemap::Span {
1314 fn clean(&self) -> Span {
1315 let ctxt = super::ctxtkey.get().unwrap();
1316 let cm = ctxt.sess().codemap();
1317 let filename = cm.span_to_filename(*self);
1318 let lo = cm.lookup_char_pos(self.lo);
1319 let hi = cm.lookup_char_pos(self.hi);
1321 filename: filename.to_string(),
1323 locol: lo.col.to_uint(),
1325 hicol: hi.col.to_uint(),
1330 #[deriving(Clone, Encodable, Decodable)]
1333 pub segments: Vec<PathSegment>,
1336 impl Clean<Path> for ast::Path {
1337 fn clean(&self) -> Path {
1339 global: self.global,
1340 segments: self.segments.clean().move_iter().collect(),
1345 #[deriving(Clone, Encodable, Decodable)]
1346 pub struct PathSegment {
1348 pub lifetimes: Vec<Lifetime>,
1349 pub types: Vec<Type>,
1352 impl Clean<PathSegment> for ast::PathSegment {
1353 fn clean(&self) -> PathSegment {
1355 name: self.identifier.clean(),
1356 lifetimes: self.lifetimes.clean().move_iter().collect(),
1357 types: self.types.clean().move_iter().collect()
1362 fn path_to_str(p: &ast::Path) -> String {
1363 use syntax::parse::token;
1365 let mut s = String::new();
1366 let mut first = true;
1367 for i in p.segments.iter().map(|x| token::get_ident(x.identifier)) {
1368 if !first || p.global {
1373 s.push_str(i.get());
1378 impl Clean<String> for ast::Ident {
1379 fn clean(&self) -> String {
1380 token::get_ident(*self).get().to_string()
1384 impl Clean<String> for ast::Name {
1385 fn clean(&self) -> String {
1386 token::get_name(*self).get().to_string()
1390 #[deriving(Clone, Encodable, Decodable)]
1391 pub struct Typedef {
1393 pub generics: Generics,
1396 impl Clean<Item> for doctree::Typedef {
1397 fn clean(&self) -> Item {
1399 name: Some(self.name.clean()),
1400 attrs: self.attrs.clean(),
1401 source: self.where.clean(),
1402 def_id: ast_util::local_def(self.id.clone()),
1403 visibility: self.vis.clean(),
1404 inner: TypedefItem(Typedef {
1405 type_: self.ty.clean(),
1406 generics: self.gen.clean(),
1412 #[deriving(Clone, Encodable, Decodable)]
1413 pub struct BareFunctionDecl {
1414 pub fn_style: ast::FnStyle,
1415 pub generics: Generics,
1420 impl Clean<BareFunctionDecl> for ast::BareFnTy {
1421 fn clean(&self) -> BareFunctionDecl {
1423 fn_style: self.fn_style,
1424 generics: Generics {
1425 lifetimes: self.lifetimes.clean().move_iter().collect(),
1426 type_params: Vec::new(),
1428 decl: self.decl.clean(),
1429 abi: self.abi.to_str().to_string(),
1434 #[deriving(Clone, Encodable, Decodable)]
1437 pub mutability: Mutability,
1438 /// It's useful to have the value of a static documented, but I have no
1439 /// desire to represent expressions (that'd basically be all of the AST,
1440 /// which is huge!). So, have a string.
1444 impl Clean<Item> for doctree::Static {
1445 fn clean(&self) -> Item {
1446 debug!("claning static {}: {:?}", self.name.clean(), self);
1448 name: Some(self.name.clean()),
1449 attrs: self.attrs.clean(),
1450 source: self.where.clean(),
1451 def_id: ast_util::local_def(self.id),
1452 visibility: self.vis.clean(),
1453 inner: StaticItem(Static {
1454 type_: self.type_.clean(),
1455 mutability: self.mutability.clean(),
1456 expr: self.expr.span.to_src(),
1462 #[deriving(Show, Clone, Encodable, Decodable, PartialEq)]
1463 pub enum Mutability {
1468 impl Clean<Mutability> for ast::Mutability {
1469 fn clean(&self) -> Mutability {
1471 &ast::MutMutable => Mutable,
1472 &ast::MutImmutable => Immutable,
1477 #[deriving(Clone, Encodable, Decodable)]
1479 pub generics: Generics,
1480 pub trait_: Option<Type>,
1482 pub methods: Vec<Item>,
1486 fn detect_derived<M: AttrMetaMethods>(attrs: &[M]) -> bool {
1487 attr::contains_name(attrs, "automatically_derived")
1490 impl Clean<Item> for doctree::Impl {
1491 fn clean(&self) -> Item {
1494 attrs: self.attrs.clean(),
1495 source: self.where.clean(),
1496 def_id: ast_util::local_def(self.id),
1497 visibility: self.vis.clean(),
1498 inner: ImplItem(Impl {
1499 generics: self.generics.clean(),
1500 trait_: self.trait_.clean(),
1501 for_: self.for_.clean(),
1502 methods: self.methods.clean(),
1503 derived: detect_derived(self.attrs.as_slice()),
1509 #[deriving(Clone, Encodable, Decodable)]
1510 pub struct ViewItem {
1511 pub inner: ViewItemInner,
1514 impl Clean<Vec<Item>> for ast::ViewItem {
1515 fn clean(&self) -> Vec<Item> {
1516 // We consider inlining the documentation of `pub use` statments, but we
1517 // forcefully don't inline if this is not public or if the
1518 // #[doc(no_inline)] attribute is present.
1519 let denied = self.vis != ast::Public || self.attrs.iter().any(|a| {
1520 a.name().get() == "doc" && match a.meta_item_list() {
1521 Some(l) => attr::contains_name(l, "no_inline"),
1525 let convert = |node: &ast::ViewItem_| {
1528 attrs: self.attrs.clean().move_iter().collect(),
1529 source: self.span.clean(),
1530 def_id: ast_util::local_def(0),
1531 visibility: self.vis.clean(),
1532 inner: ViewItemItem(ViewItem { inner: node.clean() }),
1535 let mut ret = Vec::new();
1537 ast::ViewItemUse(ref path) if !denied => {
1539 ast::ViewPathGlob(..) => ret.push(convert(&self.node)),
1540 ast::ViewPathList(ref a, ref list, ref b) => {
1541 // Attempt to inline all reexported items, but be sure
1542 // to keep any non-inlineable reexports so they can be
1543 // listed in the documentation.
1544 let remaining = list.iter().filter(|path| {
1545 match inline::try_inline(path.node.id) {
1547 ret.extend(items.move_iter()); false
1551 }).map(|a| a.clone()).collect::<Vec<ast::PathListIdent>>();
1552 if remaining.len() > 0 {
1553 let path = ast::ViewPathList(a.clone(),
1556 let path = syntax::codemap::dummy_spanned(path);
1557 ret.push(convert(&ast::ViewItemUse(@path)));
1560 ast::ViewPathSimple(_, _, id) => {
1561 match inline::try_inline(id) {
1562 Some(items) => ret.extend(items.move_iter()),
1563 None => ret.push(convert(&self.node)),
1568 ref n => ret.push(convert(n)),
1574 #[deriving(Clone, Encodable, Decodable)]
1575 pub enum ViewItemInner {
1576 ExternCrate(String, Option<String>, ast::NodeId),
1580 impl Clean<ViewItemInner> for ast::ViewItem_ {
1581 fn clean(&self) -> ViewItemInner {
1583 &ast::ViewItemExternCrate(ref i, ref p, ref id) => {
1584 let string = match *p {
1586 Some((ref x, _)) => Some(x.get().to_string()),
1588 ExternCrate(i.clean(), string, *id)
1590 &ast::ViewItemUse(ref vp) => {
1597 #[deriving(Clone, Encodable, Decodable)]
1599 // use str = source;
1600 SimpleImport(String, ImportSource),
1602 GlobImport(ImportSource),
1603 // use source::{a, b, c};
1604 ImportList(ImportSource, Vec<ViewListIdent>),
1607 #[deriving(Clone, Encodable, Decodable)]
1608 pub struct ImportSource {
1610 pub did: Option<ast::DefId>,
1613 impl Clean<ViewPath> for ast::ViewPath {
1614 fn clean(&self) -> ViewPath {
1616 ast::ViewPathSimple(ref i, ref p, id) =>
1617 SimpleImport(i.clean(), resolve_use_source(p.clean(), id)),
1618 ast::ViewPathGlob(ref p, id) =>
1619 GlobImport(resolve_use_source(p.clean(), id)),
1620 ast::ViewPathList(ref p, ref pl, id) => {
1621 ImportList(resolve_use_source(p.clean(), id),
1622 pl.clean().move_iter().collect())
1628 #[deriving(Clone, Encodable, Decodable)]
1629 pub struct ViewListIdent {
1631 pub source: Option<ast::DefId>,
1634 impl Clean<ViewListIdent> for ast::PathListIdent {
1635 fn clean(&self) -> ViewListIdent {
1637 name: self.node.name.clean(),
1638 source: resolve_def(self.node.id),
1643 impl Clean<Vec<Item>> for ast::ForeignMod {
1644 fn clean(&self) -> Vec<Item> {
1649 impl Clean<Item> for ast::ForeignItem {
1650 fn clean(&self) -> Item {
1651 let inner = match self.node {
1652 ast::ForeignItemFn(ref decl, ref generics) => {
1653 ForeignFunctionItem(Function {
1655 generics: generics.clean(),
1656 fn_style: ast::UnsafeFn,
1659 ast::ForeignItemStatic(ref ty, mutbl) => {
1660 ForeignStaticItem(Static {
1662 mutability: if mutbl {Mutable} else {Immutable},
1663 expr: "".to_string(),
1668 name: Some(self.ident.clean()),
1669 attrs: self.attrs.clean().move_iter().collect(),
1670 source: self.span.clean(),
1671 def_id: ast_util::local_def(self.id),
1672 visibility: self.vis.clean(),
1681 fn to_src(&self) -> String;
1684 impl ToSource for syntax::codemap::Span {
1685 fn to_src(&self) -> String {
1686 debug!("converting span {:?} to snippet", self.clean());
1687 let ctxt = super::ctxtkey.get().unwrap();
1688 let cm = ctxt.sess().codemap().clone();
1689 let sn = match cm.span_to_snippet(*self) {
1690 Some(x) => x.to_string(),
1691 None => "".to_string()
1693 debug!("got snippet {}", sn);
1698 fn lit_to_str(lit: &ast::Lit) -> String {
1700 ast::LitStr(ref st, _) => st.get().to_string(),
1701 ast::LitBinary(ref data) => format!("{:?}", data.as_slice()),
1702 ast::LitChar(c) => format!("'{}'", c),
1703 ast::LitInt(i, _t) => i.to_str().to_string(),
1704 ast::LitUint(u, _t) => u.to_str().to_string(),
1705 ast::LitIntUnsuffixed(i) => i.to_str().to_string(),
1706 ast::LitFloat(ref f, _t) => f.get().to_string(),
1707 ast::LitFloatUnsuffixed(ref f) => f.get().to_string(),
1708 ast::LitBool(b) => b.to_str().to_string(),
1709 ast::LitNil => "".to_string(),
1713 fn name_from_pat(p: &ast::Pat) -> String {
1715 debug!("Trying to get a name from pattern: {:?}", p);
1718 PatWild => "_".to_string(),
1719 PatWildMulti => "..".to_string(),
1720 PatIdent(_, ref p, _) => path_to_str(p),
1721 PatEnum(ref p, _) => path_to_str(p),
1722 PatStruct(..) => fail!("tried to get argument name from pat_struct, \
1723 which is not allowed in function arguments"),
1724 PatTup(..) => "(tuple arg NYI)".to_string(),
1725 PatBox(p) => name_from_pat(p),
1726 PatRegion(p) => name_from_pat(p),
1728 warn!("tried to get argument name from PatLit, \
1729 which is silly in function arguments");
1732 PatRange(..) => fail!("tried to get argument name from PatRange, \
1733 which is not allowed in function arguments"),
1734 PatVec(..) => fail!("tried to get argument name from pat_vec, \
1735 which is not allowed in function arguments"),
1737 warn!("can't document the name of a function argument \
1738 produced by a pattern macro");
1739 "(argument produced by macro)".to_string()
1744 /// Given a Type, resolve it using the def_map
1745 fn resolve_type(path: Path, tpbs: Option<Vec<TyParamBound>>,
1746 id: ast::NodeId) -> Type {
1747 let cx = super::ctxtkey.get().unwrap();
1748 let tycx = match cx.maybe_typed {
1749 core::Typed(ref tycx) => tycx,
1750 // If we're extracting tests, this return value doesn't matter.
1751 core::NotTyped(_) => return Bool
1753 debug!("searching for {:?} in defmap", id);
1754 let def = match tycx.def_map.borrow().find(&id) {
1756 None => fail!("unresolved id not in defmap")
1760 ast::DefSelfTy(i) => return Self(ast_util::local_def(i)),
1761 ast::DefPrimTy(p) => match p {
1762 ast::TyStr => return String,
1763 ast::TyBool => return Bool,
1764 _ => return Primitive(p)
1766 ast::DefTyParam(i, _) => return Generic(i),
1767 ast::DefTyParamBinder(i) => return TyParamBinder(i),
1770 let did = register_def(&**cx, def);
1771 ResolvedPath { path: path, typarams: tpbs, did: did }
1774 fn register_def(cx: &core::DocContext, def: ast::Def) -> ast::DefId {
1775 let (did, kind) = match def {
1776 ast::DefFn(i, _) => (i, TypeFunction),
1777 ast::DefTy(i) => (i, TypeEnum),
1778 ast::DefTrait(i) => (i, TypeTrait),
1779 ast::DefStruct(i) => (i, TypeStruct),
1780 ast::DefMod(i) => (i, TypeModule),
1781 ast::DefStatic(i, _) => (i, TypeStatic),
1782 ast::DefVariant(i, _, _) => (i, TypeEnum),
1783 _ => return ast_util::def_id_of_def(def),
1785 if ast_util::is_local(did) { return did }
1786 let tcx = match cx.maybe_typed {
1787 core::Typed(ref t) => t,
1788 core::NotTyped(_) => return did
1790 inline::record_extern_fqn(cx, did, kind);
1793 let t = inline::build_external_trait(tcx, did);
1794 cx.external_traits.borrow_mut().get_mut_ref().insert(did, t);
1801 fn resolve_use_source(path: Path, id: ast::NodeId) -> ImportSource {
1804 did: resolve_def(id),
1808 fn resolve_def(id: ast::NodeId) -> Option<ast::DefId> {
1809 let cx = super::ctxtkey.get().unwrap();
1810 match cx.maybe_typed {
1811 core::Typed(ref tcx) => {
1812 tcx.def_map.borrow().find(&id).map(|&def| register_def(&**cx, def))
1814 core::NotTyped(_) => None
1818 #[deriving(Clone, Encodable, Decodable)]
1823 impl Clean<Item> for doctree::Macro {
1824 fn clean(&self) -> Item {
1826 name: Some(format!("{}!", self.name.clean())),
1827 attrs: self.attrs.clean(),
1828 source: self.where.clean(),
1829 visibility: ast::Public.clean(),
1830 def_id: ast_util::local_def(self.id),
1831 inner: MacroItem(Macro {
1832 source: self.where.to_src(),