1 // A signature is a string representation of an item's type signature, excluding
2 // any body. It also includes ids for any defs or refs in the signature. For
10 // The signature string is something like "fn foo(x: String) {}" and the signature
11 // will have defs for `foo` and `x` and a ref for `String`.
13 // All signature text should parse in the correct context (i.e., in a module or
14 // impl, etc.). Clients may want to trim trailing `{}` or `;`. The text of a
15 // signature is not guaranteed to be stable (it may improve or change as the
16 // syntax changes, or whitespace or punctuation may change). It is also likely
17 // not to be pretty - no attempt is made to prettify the text. It is recommended
18 // that clients run the text through Rustfmt.
20 // This module generates Signatures for items by walking the AST and looking up
23 // Signatures do not include visibility info. I'm not sure if this is a feature
24 // or an ommission (FIXME).
26 // FIXME where clauses need implementing, defs/refs in generics are mostly missing.
28 use {id_from_def_id, id_from_node_id, SaveContext};
30 use rls_data::{SigElement, Signature};
32 use rustc::hir::def::Def;
33 use syntax::ast::{self, NodeId};
34 use syntax::print::pprust;
37 pub fn item_signature(item: &ast::Item, scx: &SaveContext) -> Option<Signature> {
38 if !scx.config.signatures {
41 item.make(0, None, scx).ok()
44 pub fn foreign_item_signature(item: &ast::ForeignItem, scx: &SaveContext) -> Option<Signature> {
45 if !scx.config.signatures {
48 item.make(0, None, scx).ok()
51 /// Signature for a struct or tuple field declaration.
52 /// Does not include a trailing comma.
53 pub fn field_signature(field: &ast::StructField, scx: &SaveContext) -> Option<Signature> {
54 if !scx.config.signatures {
57 field.make(0, None, scx).ok()
60 /// Does not include a trailing comma.
61 pub fn variant_signature(variant: &ast::Variant, scx: &SaveContext) -> Option<Signature> {
62 if !scx.config.signatures {
65 variant.node.make(0, None, scx).ok()
68 pub fn method_signature(
71 generics: &ast::Generics,
74 ) -> Option<Signature> {
75 if !scx.config.signatures {
78 make_method_signature(id, ident, generics, m, scx).ok()
81 pub fn assoc_const_signature(
85 default: Option<&ast::Expr>,
87 ) -> Option<Signature> {
88 if !scx.config.signatures {
91 make_assoc_const_signature(id, ident, ty, default, scx).ok()
94 pub fn assoc_type_signature(
97 bounds: Option<&ast::GenericBounds>,
98 default: Option<&ast::Ty>,
100 ) -> Option<Signature> {
101 if !scx.config.signatures {
104 make_assoc_type_signature(id, ident, bounds, default, scx).ok()
107 type Result = ::std::result::Result<Signature, &'static str>;
110 fn make(&self, offset: usize, id: Option<NodeId>, scx: &SaveContext) -> Result;
116 defs: Vec<SigElement>,
117 refs: Vec<SigElement>,
120 sig.defs.extend(defs.into_iter());
121 sig.refs.extend(refs.into_iter());
125 fn replace_text(mut sig: Signature, text: String) -> Signature {
130 fn merge_sigs(text: String, sigs: Vec<Signature>) -> Signature {
131 let mut result = Signature {
137 let (defs, refs): (Vec<_>, Vec<_>) = sigs.into_iter().map(|s| (s.defs, s.refs)).unzip();
141 .extend(defs.into_iter().flat_map(|ds| ds.into_iter()));
144 .extend(refs.into_iter().flat_map(|rs| rs.into_iter()));
149 fn text_sig(text: String) -> Signature {
157 impl Sig for ast::Ty {
158 fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) -> Result {
159 let id = Some(self.id);
161 ast::TyKind::Slice(ref ty) => {
162 let nested = ty.make(offset + 1, id, scx)?;
163 let text = format!("[{}]", nested.text);
164 Ok(replace_text(nested, text))
166 ast::TyKind::Ptr(ref mt) => {
167 let prefix = match mt.mutbl {
168 ast::Mutability::Mutable => "*mut ",
169 ast::Mutability::Immutable => "*const ",
171 let nested = mt.ty.make(offset + prefix.len(), id, scx)?;
172 let text = format!("{}{}", prefix, nested.text);
173 Ok(replace_text(nested, text))
175 ast::TyKind::Rptr(ref lifetime, ref mt) => {
176 let mut prefix = "&".to_owned();
177 if let &Some(ref l) = lifetime {
178 prefix.push_str(&l.ident.to_string());
181 if let ast::Mutability::Mutable = mt.mutbl {
182 prefix.push_str("mut ");
185 let nested = mt.ty.make(offset + prefix.len(), id, scx)?;
186 let text = format!("{}{}", prefix, nested.text);
187 Ok(replace_text(nested, text))
189 ast::TyKind::Never => Ok(text_sig("!".to_owned())),
190 ast::TyKind::Tup(ref ts) => {
191 let mut text = "(".to_owned();
192 let mut defs = vec![];
193 let mut refs = vec![];
195 let nested = t.make(offset + text.len(), id, scx)?;
196 text.push_str(&nested.text);
198 defs.extend(nested.defs.into_iter());
199 refs.extend(nested.refs.into_iter());
202 Ok(Signature { text, defs, refs })
204 ast::TyKind::Paren(ref ty) => {
205 let nested = ty.make(offset + 1, id, scx)?;
206 let text = format!("({})", nested.text);
207 Ok(replace_text(nested, text))
209 ast::TyKind::BareFn(ref f) => {
210 let mut text = String::new();
211 if !f.generic_params.is_empty() {
212 // FIXME defs, bounds on lifetimes
213 text.push_str("for<");
214 text.push_str(&f.generic_params
216 .filter_map(|param| match param.kind {
217 ast::GenericParamKind::Lifetime { .. } => {
218 Some(param.ident.to_string())
227 if f.unsafety == ast::Unsafety::Unsafe {
228 text.push_str("unsafe ");
230 if f.abi != ::rustc_target::spec::abi::Abi::Rust {
231 text.push_str("extern");
232 text.push_str(&f.abi.to_string());
235 text.push_str("fn(");
237 let mut defs = vec![];
238 let mut refs = vec![];
239 for i in &f.decl.inputs {
240 let nested = i.ty.make(offset + text.len(), Some(i.id), scx)?;
241 text.push_str(&nested.text);
243 defs.extend(nested.defs.into_iter());
244 refs.extend(nested.refs.into_iter());
247 if let ast::FunctionRetTy::Ty(ref t) = f.decl.output {
248 text.push_str(" -> ");
249 let nested = t.make(offset + text.len(), None, scx)?;
250 text.push_str(&nested.text);
252 defs.extend(nested.defs.into_iter());
253 refs.extend(nested.refs.into_iter());
256 Ok(Signature { text, defs, refs })
258 ast::TyKind::Path(None, ref path) => path.make(offset, id, scx),
259 ast::TyKind::Path(Some(ref qself), ref path) => {
260 let nested_ty = qself.ty.make(offset + 1, id, scx)?;
261 let prefix = if qself.position == 0 {
262 format!("<{}>::", nested_ty.text)
263 } else if qself.position == 1 {
264 let first = pprust::path_segment_to_string(&path.segments[0]);
265 format!("<{} as {}>::", nested_ty.text, first)
267 // FIXME handle path instead of elipses.
268 format!("<{} as ...>::", nested_ty.text)
271 let name = pprust::path_segment_to_string(path.segments.last().ok_or("Bad path")?);
272 let def = scx.get_path_def(id.ok_or("Missing id for Path")?);
273 let id = id_from_def_id(def.def_id());
274 if path.segments.len() - qself.position == 1 {
275 let start = offset + prefix.len();
276 let end = start + name.len();
279 text: prefix + &name,
281 refs: vec![SigElement { id, start, end }],
284 let start = offset + prefix.len() + 5;
285 let end = start + name.len();
286 // FIXME should put the proper path in there, not elipses.
288 text: prefix + "...::" + &name,
290 refs: vec![SigElement { id, start, end }],
294 ast::TyKind::TraitObject(ref bounds, ..) => {
295 // FIXME recurse into bounds
296 let nested = pprust::bounds_to_string(bounds);
299 ast::TyKind::ImplTrait(_, ref bounds) => {
300 // FIXME recurse into bounds
301 let nested = pprust::bounds_to_string(bounds);
302 Ok(text_sig(format!("impl {}", nested)))
304 ast::TyKind::Array(ref ty, ref v) => {
305 let nested_ty = ty.make(offset + 1, id, scx)?;
306 let expr = pprust::expr_to_string(&v.value).replace('\n', " ");
307 let text = format!("[{}; {}]", nested_ty.text, expr);
308 Ok(replace_text(nested_ty, text))
310 ast::TyKind::Typeof(_) |
313 ast::TyKind::ImplicitSelf |
314 ast::TyKind::Mac(_) => Err("Ty"),
319 impl Sig for ast::Item {
320 fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) -> Result {
321 let id = Some(self.id);
324 ast::ItemKind::Static(ref ty, m, ref expr) => {
325 let mut text = "static ".to_owned();
326 if m == ast::Mutability::Mutable {
327 text.push_str("mut ");
329 let name = self.ident.to_string();
332 id: id_from_node_id(self.id, scx),
333 start: offset + text.len(),
334 end: offset + text.len() + name.len(),
337 text.push_str(&name);
340 let ty = ty.make(offset + text.len(), id, scx)?;
341 text.push_str(&ty.text);
342 text.push_str(" = ");
344 let expr = pprust::expr_to_string(expr).replace('\n', " ");
345 text.push_str(&expr);
348 Ok(extend_sig(ty, text, defs, vec![]))
350 ast::ItemKind::Const(ref ty, ref expr) => {
351 let mut text = "const ".to_owned();
352 let name = self.ident.to_string();
355 id: id_from_node_id(self.id, scx),
356 start: offset + text.len(),
357 end: offset + text.len() + name.len(),
360 text.push_str(&name);
363 let ty = ty.make(offset + text.len(), id, scx)?;
364 text.push_str(&ty.text);
365 text.push_str(" = ");
367 let expr = pprust::expr_to_string(expr).replace('\n', " ");
368 text.push_str(&expr);
371 Ok(extend_sig(ty, text, defs, vec![]))
373 ast::ItemKind::Fn(ref decl, header, ref generics, _) => {
374 let mut text = String::new();
375 if header.constness.node == ast::Constness::Const {
376 text.push_str("const ");
378 if header.asyncness.is_async() {
379 text.push_str("async ");
381 if header.unsafety == ast::Unsafety::Unsafe {
382 text.push_str("unsafe ");
384 if header.abi != ::rustc_target::spec::abi::Abi::Rust {
385 text.push_str("extern");
386 text.push_str(&header.abi.to_string());
389 text.push_str("fn ");
391 let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
394 for i in &decl.inputs {
395 // FIXME should descend into patterns to add defs.
396 sig.text.push_str(&pprust::pat_to_string(&i.pat));
397 sig.text.push_str(": ");
398 let nested = i.ty.make(offset + sig.text.len(), Some(i.id), scx)?;
399 sig.text.push_str(&nested.text);
401 sig.defs.extend(nested.defs.into_iter());
402 sig.refs.extend(nested.refs.into_iter());
406 if let ast::FunctionRetTy::Ty(ref t) = decl.output {
407 sig.text.push_str(" -> ");
408 let nested = t.make(offset + sig.text.len(), None, scx)?;
409 sig.text.push_str(&nested.text);
410 sig.defs.extend(nested.defs.into_iter());
411 sig.refs.extend(nested.refs.into_iter());
413 sig.text.push_str(" {}");
417 ast::ItemKind::Mod(ref _mod) => {
418 let mut text = "mod ".to_owned();
419 let name = self.ident.to_string();
422 id: id_from_node_id(self.id, scx),
423 start: offset + text.len(),
424 end: offset + text.len() + name.len(),
427 text.push_str(&name);
428 // Could be either `mod foo;` or `mod foo { ... }`, but we'll just pick one.
437 ast::ItemKind::Existential(ref bounds, ref generics) => {
438 let text = "existential type ".to_owned();
439 let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
441 if !bounds.is_empty() {
442 sig.text.push_str(": ");
443 sig.text.push_str(&pprust::bounds_to_string(bounds));
449 ast::ItemKind::Ty(ref ty, ref generics) => {
450 let text = "type ".to_owned();
451 let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
453 sig.text.push_str(" = ");
454 let ty = ty.make(offset + sig.text.len(), id, scx)?;
455 sig.text.push_str(&ty.text);
458 Ok(merge_sigs(sig.text.clone(), vec![sig, ty]))
460 ast::ItemKind::Enum(_, ref generics) => {
461 let text = "enum ".to_owned();
462 let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
463 sig.text.push_str(" {}");
466 ast::ItemKind::Struct(_, ref generics) => {
467 let text = "struct ".to_owned();
468 let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
469 sig.text.push_str(" {}");
472 ast::ItemKind::Union(_, ref generics) => {
473 let text = "union ".to_owned();
474 let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
475 sig.text.push_str(" {}");
478 ast::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, _) => {
479 let mut text = String::new();
481 if is_auto == ast::IsAuto::Yes {
482 text.push_str("auto ");
485 if unsafety == ast::Unsafety::Unsafe {
486 text.push_str("unsafe ");
488 text.push_str("trait ");
489 let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
491 if !bounds.is_empty() {
492 sig.text.push_str(": ");
493 sig.text.push_str(&pprust::bounds_to_string(bounds));
495 // FIXME where clause
496 sig.text.push_str(" {}");
500 ast::ItemKind::TraitAlias(ref generics, ref bounds) => {
501 let mut text = String::new();
502 text.push_str("trait ");
503 let mut sig = name_and_generics(text,
510 if !bounds.is_empty() {
511 sig.text.push_str(" = ");
512 sig.text.push_str(&pprust::bounds_to_string(bounds));
514 // FIXME where clause
515 sig.text.push_str(";");
528 let mut text = String::new();
529 if let ast::Defaultness::Default = defaultness {
530 text.push_str("default ");
532 if unsafety == ast::Unsafety::Unsafe {
533 text.push_str("unsafe ");
535 text.push_str("impl");
537 let generics_sig = generics.make(offset + text.len(), id, scx)?;
538 text.push_str(&generics_sig.text);
542 let trait_sig = if let Some(ref t) = *opt_trait {
543 if polarity == ast::ImplPolarity::Negative {
546 let trait_sig = t.path.make(offset + text.len(), id, scx)?;
547 text.push_str(&trait_sig.text);
548 text.push_str(" for ");
551 text_sig(String::new())
554 let ty_sig = ty.make(offset + text.len(), id, scx)?;
555 text.push_str(&ty_sig.text);
557 text.push_str(" {}");
559 Ok(merge_sigs(text, vec![generics_sig, trait_sig, ty_sig]))
561 // FIXME where clause
563 ast::ItemKind::ForeignMod(_) => Err("extern mod"),
564 ast::ItemKind::GlobalAsm(_) => Err("glboal asm"),
565 ast::ItemKind::ExternCrate(_) => Err("extern crate"),
566 // FIXME should implement this (e.g., pub use).
567 ast::ItemKind::Use(_) => Err("import"),
568 ast::ItemKind::Mac(..) | ast::ItemKind::MacroDef(_) => Err("Macro"),
573 impl Sig for ast::Path {
574 fn make(&self, offset: usize, id: Option<NodeId>, scx: &SaveContext) -> Result {
575 let def = scx.get_path_def(id.ok_or("Missing id for Path")?);
577 let (name, start, end) = match def {
578 Def::Label(..) | Def::PrimTy(..) | Def::SelfTy(..) | Def::Err => {
579 return Ok(Signature {
580 text: pprust::path_to_string(self),
585 Def::AssociatedConst(..) | Def::Variant(..) | Def::VariantCtor(..) => {
586 let len = self.segments.len();
588 return Err("Bad path");
590 // FIXME: really we should descend into the generics here and add SigElements for
592 // FIXME: would be nice to have a def for the first path segment.
593 let seg1 = pprust::path_segment_to_string(&self.segments[len - 2]);
594 let seg2 = pprust::path_segment_to_string(&self.segments[len - 1]);
595 let start = offset + seg1.len() + 2;
596 (format!("{}::{}", seg1, seg2), start, start + seg2.len())
599 let name = pprust::path_segment_to_string(self.segments.last().ok_or("Bad path")?);
600 let end = offset + name.len();
605 let id = id_from_def_id(def.def_id());
609 refs: vec![SigElement { id, start, end }],
614 // This does not cover the where clause, which must be processed separately.
615 impl Sig for ast::Generics {
616 fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) -> Result {
617 if self.params.is_empty() {
618 return Ok(text_sig(String::new()));
621 let mut text = "<".to_owned();
623 let mut defs = Vec::with_capacity(self.params.len());
624 for param in &self.params {
625 let mut param_text = param.ident.to_string();
626 defs.push(SigElement {
627 id: id_from_node_id(param.id, scx),
628 start: offset + text.len(),
629 end: offset + text.len() + param_text.len(),
631 if !param.bounds.is_empty() {
632 param_text.push_str(": ");
634 ast::GenericParamKind::Lifetime { .. } => {
635 let bounds = param.bounds.iter()
636 .map(|bound| match bound {
637 ast::GenericBound::Outlives(lt) => lt.ident.to_string(),
642 param_text.push_str(&bounds);
643 // FIXME add lifetime bounds refs.
645 ast::GenericParamKind::Type { .. } => {
646 param_text.push_str(&pprust::bounds_to_string(¶m.bounds));
647 // FIXME descend properly into bounds.
651 text.push_str(¶m_text);
664 impl Sig for ast::StructField {
665 fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) -> Result {
666 let mut text = String::new();
668 if let Some(ident) = self.ident {
669 text.push_str(&ident.to_string());
670 defs = Some(SigElement {
671 id: id_from_node_id(self.id, scx),
673 end: offset + text.len(),
678 let mut ty_sig = self.ty.make(offset + text.len(), Some(self.id), scx)?;
679 text.push_str(&ty_sig.text);
681 ty_sig.defs.extend(defs.into_iter());
687 impl Sig for ast::Variant_ {
688 fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) -> Result {
689 let mut text = self.ident.to_string();
691 ast::VariantData::Struct(ref fields, id) => {
692 let name_def = SigElement {
693 id: id_from_node_id(id, scx),
695 end: offset + text.len(),
697 text.push_str(" { ");
698 let mut defs = vec![name_def];
699 let mut refs = vec![];
701 let field_sig = f.make(offset + text.len(), Some(id), scx)?;
702 text.push_str(&field_sig.text);
704 defs.extend(field_sig.defs.into_iter());
705 refs.extend(field_sig.refs.into_iter());
708 Ok(Signature { text, defs, refs })
710 ast::VariantData::Tuple(ref fields, id) => {
711 let name_def = SigElement {
712 id: id_from_node_id(id, scx),
714 end: offset + text.len(),
717 let mut defs = vec![name_def];
718 let mut refs = vec![];
720 let field_sig = f.make(offset + text.len(), Some(id), scx)?;
721 text.push_str(&field_sig.text);
723 defs.extend(field_sig.defs.into_iter());
724 refs.extend(field_sig.refs.into_iter());
727 Ok(Signature { text, defs, refs })
729 ast::VariantData::Unit(id) => {
730 let name_def = SigElement {
731 id: id_from_node_id(id, scx),
733 end: offset + text.len(),
737 defs: vec![name_def],
745 impl Sig for ast::ForeignItem {
746 fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext) -> Result {
747 let id = Some(self.id);
749 ast::ForeignItemKind::Fn(ref decl, ref generics) => {
750 let mut text = String::new();
751 text.push_str("fn ");
753 let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
756 for i in &decl.inputs {
757 // FIXME should descend into patterns to add defs.
758 sig.text.push_str(&pprust::pat_to_string(&i.pat));
759 sig.text.push_str(": ");
760 let nested = i.ty.make(offset + sig.text.len(), Some(i.id), scx)?;
761 sig.text.push_str(&nested.text);
763 sig.defs.extend(nested.defs.into_iter());
764 sig.refs.extend(nested.refs.into_iter());
768 if let ast::FunctionRetTy::Ty(ref t) = decl.output {
769 sig.text.push_str(" -> ");
770 let nested = t.make(offset + sig.text.len(), None, scx)?;
771 sig.text.push_str(&nested.text);
772 sig.defs.extend(nested.defs.into_iter());
773 sig.refs.extend(nested.refs.into_iter());
779 ast::ForeignItemKind::Static(ref ty, m) => {
780 let mut text = "static ".to_owned();
782 text.push_str("mut ");
784 let name = self.ident.to_string();
787 id: id_from_node_id(self.id, scx),
788 start: offset + text.len(),
789 end: offset + text.len() + name.len(),
792 text.push_str(&name);
795 let ty_sig = ty.make(offset + text.len(), id, scx)?;
798 Ok(extend_sig(ty_sig, text, defs, vec![]))
800 ast::ForeignItemKind::Ty => {
801 let mut text = "type ".to_owned();
802 let name = self.ident.to_string();
805 id: id_from_node_id(self.id, scx),
806 start: offset + text.len(),
807 end: offset + text.len() + name.len(),
810 text.push_str(&name);
819 ast::ForeignItemKind::Macro(..) => Err("macro"),
824 fn name_and_generics(
827 generics: &ast::Generics,
832 let name = name.to_string();
833 let def = SigElement {
834 id: id_from_node_id(id, scx),
835 start: offset + text.len(),
836 end: offset + text.len() + name.len(),
838 text.push_str(&name);
839 let generics: Signature = generics.make(offset + text.len(), Some(id), scx)?;
840 // FIXME where clause
841 let text = format!("{}{}", text, generics.text);
842 Ok(extend_sig(generics, text, vec![def], vec![]))
846 fn make_assoc_type_signature(
849 bounds: Option<&ast::GenericBounds>,
850 default: Option<&ast::Ty>,
853 let mut text = "type ".to_owned();
854 let name = ident.to_string();
857 id: id_from_node_id(id, scx),
859 end: text.len() + name.len(),
862 let mut refs = vec![];
863 text.push_str(&name);
864 if let Some(bounds) = bounds {
866 // FIXME should descend into bounds
867 text.push_str(&pprust::bounds_to_string(bounds));
869 if let Some(default) = default {
870 text.push_str(" = ");
871 let ty_sig = default.make(text.len(), Some(id), scx)?;
872 text.push_str(&ty_sig.text);
873 defs.extend(ty_sig.defs.into_iter());
874 refs.extend(ty_sig.refs.into_iter());
877 Ok(Signature { text, defs, refs })
880 fn make_assoc_const_signature(
884 default: Option<&ast::Expr>,
887 let mut text = "const ".to_owned();
888 let name = ident.to_string();
891 id: id_from_node_id(id, scx),
893 end: text.len() + name.len(),
896 let mut refs = vec![];
897 text.push_str(&name);
900 let ty_sig = ty.make(text.len(), Some(id), scx)?;
901 text.push_str(&ty_sig.text);
902 defs.extend(ty_sig.defs.into_iter());
903 refs.extend(ty_sig.refs.into_iter());
905 if let Some(default) = default {
906 text.push_str(" = ");
907 text.push_str(&pprust::expr_to_string(default));
910 Ok(Signature { text, defs, refs })
913 fn make_method_signature(
916 generics: &ast::Generics,
920 // FIXME code dup with function signature
921 let mut text = String::new();
922 if m.header.constness.node == ast::Constness::Const {
923 text.push_str("const ");
925 if m.header.asyncness.is_async() {
926 text.push_str("async ");
928 if m.header.unsafety == ast::Unsafety::Unsafe {
929 text.push_str("unsafe ");
931 if m.header.abi != ::rustc_target::spec::abi::Abi::Rust {
932 text.push_str("extern");
933 text.push_str(&m.header.abi.to_string());
936 text.push_str("fn ");
938 let mut sig = name_and_generics(text, 0, generics, id, ident, scx)?;
941 for i in &m.decl.inputs {
942 // FIXME should descend into patterns to add defs.
943 sig.text.push_str(&pprust::pat_to_string(&i.pat));
944 sig.text.push_str(": ");
945 let nested = i.ty.make(sig.text.len(), Some(i.id), scx)?;
946 sig.text.push_str(&nested.text);
948 sig.defs.extend(nested.defs.into_iter());
949 sig.refs.extend(nested.refs.into_iter());
953 if let ast::FunctionRetTy::Ty(ref t) = m.decl.output {
954 sig.text.push_str(" -> ");
955 let nested = t.make(sig.text.len(), None, scx)?;
956 sig.text.push_str(&nested.text);
957 sig.defs.extend(nested.defs.into_iter());
958 sig.refs.extend(nested.refs.into_iter());
960 sig.text.push_str(" {}");