1 // Copyright 2013-2014 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 //! HTML formatting module
13 //! This module contains a large number of `fmt::Display` implementations for
14 //! various types in `rustdoc::clean`. These implementations all currently
15 //! assume that HTML output is desired, although it may be possible to redesign
16 //! them in the future to instead emit any format desired.
19 use std::iter::repeat;
21 use rustc::hir::def_id::{DefId, LOCAL_CRATE};
25 use clean::{self, PrimitiveType};
26 use core::DocAccessLevels;
27 use html::item_type::ItemType;
28 use html::escape::Escape;
30 use html::render::{cache, CURRENT_LOCATION_KEY};
32 /// Helper to render an optional visibility with a space after it (if the
33 /// visibility is preset)
34 #[derive(Copy, Clone)]
35 pub struct VisSpace<'a>(pub &'a Option<clean::Visibility>);
36 /// Similarly to VisSpace, this structure is used to render a function style with a
38 #[derive(Copy, Clone)]
39 pub struct UnsafetySpace(pub hir::Unsafety);
40 /// Similarly to VisSpace, this structure is used to render a function constness
41 /// with a space after it.
42 #[derive(Copy, Clone)]
43 pub struct ConstnessSpace(pub hir::Constness);
44 /// Wrapper struct for properly emitting a method declaration.
45 pub struct Method<'a>(pub &'a clean::FnDecl, pub usize);
46 /// Similar to VisSpace, but used for mutability
47 #[derive(Copy, Clone)]
48 pub struct MutableSpace(pub clean::Mutability);
49 /// Similar to VisSpace, but used for mutability
50 #[derive(Copy, Clone)]
51 pub struct RawMutableSpace(pub clean::Mutability);
52 /// Wrapper struct for emitting a where clause from Generics.
53 pub struct WhereClause<'a>(pub &'a clean::Generics, pub usize);
54 /// Wrapper struct for emitting type parameter bounds.
55 pub struct TyParamBounds<'a>(pub &'a [clean::TyParamBound]);
56 /// Wrapper struct for emitting a comma-separated list of items
57 pub struct CommaSep<'a, T: 'a>(pub &'a [T]);
58 pub struct AbiSpace(pub Abi);
65 impl<'a> VisSpace<'a> {
66 pub fn get(self) -> &'a Option<clean::Visibility> {
67 let VisSpace(v) = self; v
72 pub fn get(&self) -> hir::Unsafety {
73 let UnsafetySpace(v) = *self; v
78 pub fn get(&self) -> hir::Constness {
79 let ConstnessSpace(v) = *self; v
83 impl<'a, T: fmt::Display> fmt::Display for CommaSep<'a, T> {
84 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
85 for (i, item) in self.0.iter().enumerate() {
86 if i != 0 { write!(f, ", ")?; }
87 fmt::Display::fmt(item, f)?;
93 impl<'a> fmt::Display for TyParamBounds<'a> {
94 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
95 let &TyParamBounds(bounds) = self;
96 for (i, bound) in bounds.iter().enumerate() {
100 fmt::Display::fmt(bound, f)?;
106 impl fmt::Display for clean::Generics {
107 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
108 if self.lifetimes.is_empty() && self.type_params.is_empty() { return Ok(()) }
112 f.write_str("<")?;
115 for (i, life) in self.lifetimes.iter().enumerate() {
119 write!(f, "{}", *life)?;
122 if !self.type_params.is_empty() {
123 if !self.lifetimes.is_empty() {
126 for (i, tp) in self.type_params.iter().enumerate() {
130 f.write_str(&tp.name)?;
132 if !tp.bounds.is_empty() {
134 write!(f, ": {:#}", TyParamBounds(&tp.bounds))?;
136 write!(f, ": {}", TyParamBounds(&tp.bounds))?;
140 if let Some(ref ty) = tp.default {
142 write!(f, " = {:#}", ty)?;
144 write!(f, " = {}", ty)?;
152 f.write_str(">")?;
158 impl<'a> fmt::Display for WhereClause<'a> {
159 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
160 let &WhereClause(gens, pad) = self;
161 if gens.where_predicates.is_empty() {
164 let mut clause = String::new();
166 clause.push_str(" where ");
168 clause.push_str(" <span class='where'>where ");
170 for (i, pred) in gens.where_predicates.iter().enumerate() {
173 clause.push_str(", ");
175 clause.push_str(",<br>");
179 &clean::WherePredicate::BoundPredicate { ref ty, ref bounds } => {
182 clause.push_str(&format!("{:#}: {:#}", ty, TyParamBounds(bounds)));
184 clause.push_str(&format!("{}: {}", ty, TyParamBounds(bounds)));
187 &clean::WherePredicate::RegionPredicate { ref lifetime,
189 clause.push_str(&format!("{}: ", lifetime));
190 for (i, lifetime) in bounds.iter().enumerate() {
192 clause.push_str(" + ");
195 clause.push_str(&format!("{}", lifetime));
198 &clean::WherePredicate::EqPredicate { ref lhs, ref rhs } => {
200 clause.push_str(&format!("{:#} == {:#}", lhs, rhs));
202 clause.push_str(&format!("{} == {}", lhs, rhs));
208 clause.push_str("</span>");
209 let plain = format!("{:#}", self);
210 if plain.len() > 80 {
211 //break it onto its own line regardless, but make sure method impls and trait
212 //blocks keep their fixed padding (2 and 9, respectively)
213 let padding = if pad > 10 {
214 clause = clause.replace("class='where'", "class='where fmt-newline'");
215 repeat(" ").take(8).collect::<String>()
217 repeat(" ").take(pad + 6).collect::<String>()
219 clause = clause.replace("<br>", &format!("<br>{}", padding));
221 clause = clause.replace("<br>", " ");
224 write!(f, "{}", clause)
228 impl fmt::Display for clean::Lifetime {
229 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
230 f.write_str(self.get_ref())?;
235 impl fmt::Display for clean::PolyTrait {
236 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
237 if !self.lifetimes.is_empty() {
239 f.write_str("for<")?;
241 f.write_str("for<")?;
243 for (i, lt) in self.lifetimes.iter().enumerate() {
247 write!(f, "{}", lt)?;
252 f.write_str("> ")?;
256 write!(f, "{:#}", self.trait_)
258 write!(f, "{}", self.trait_)
263 impl fmt::Display for clean::TyParamBound {
264 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
266 clean::RegionBound(ref lt) => {
269 clean::TraitBound(ref ty, modifier) => {
270 let modifier_str = match modifier {
271 hir::TraitBoundModifier::None => "",
272 hir::TraitBoundModifier::Maybe => "?",
275 write!(f, "{}{:#}", modifier_str, *ty)
277 write!(f, "{}{}", modifier_str, *ty)
284 impl fmt::Display for clean::PathParameters {
285 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
287 clean::PathParameters::AngleBracketed {
288 ref lifetimes, ref types, ref bindings
290 if !lifetimes.is_empty() || !types.is_empty() || !bindings.is_empty() {
294 f.write_str("<")?;
296 let mut comma = false;
297 for lifetime in lifetimes {
302 write!(f, "{}", *lifetime)?;
310 write!(f, "{:#}", *ty)?;
312 write!(f, "{}", *ty)?;
315 for binding in bindings {
321 write!(f, "{:#}", *binding)?;
323 write!(f, "{}", *binding)?;
329 f.write_str(">")?;
333 clean::PathParameters::Parenthesized { ref inputs, ref output } => {
335 let mut comma = false;
342 write!(f, "{:#}", *ty)?;
344 write!(f, "{}", *ty)?;
348 if let Some(ref ty) = *output {
350 write!(f, " -> {:#}", ty)?;
352 write!(f, " -> {}", ty)?;
361 impl fmt::Display for clean::PathSegment {
362 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
363 f.write_str(&self.name)?;
365 write!(f, "{:#}", self.params)
367 write!(f, "{}", self.params)
372 impl fmt::Display for clean::Path {
373 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
378 for (i, seg) in self.segments.iter().enumerate() {
383 write!(f, "{:#}", seg)?;
385 write!(f, "{}", seg)?;
392 pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
394 if !did.is_local() && !cache.access_levels.is_doc_reachable(did) {
398 let loc = CURRENT_LOCATION_KEY.with(|l| l.borrow().clone());
399 let (fqp, shortty, mut url) = match cache.paths.get(&did) {
400 Some(&(ref fqp, shortty)) => {
401 (fqp, shortty, repeat("../").take(loc.len()).collect())
403 None => match cache.external_paths.get(&did) {
404 Some(&(ref fqp, shortty)) => {
405 (fqp, shortty, match cache.extern_locations[&did.krate] {
406 (_, render::Remote(ref s)) => s.to_string(),
407 (_, render::Local) => repeat("../").take(loc.len()).collect(),
408 (_, render::Unknown) => return None,
414 for component in &fqp[..fqp.len() - 1] {
415 url.push_str(component);
419 ItemType::Module => {
420 url.push_str(fqp.last().unwrap());
421 url.push_str("/index.html");
424 url.push_str(shortty.css_class());
426 url.push_str(fqp.last().unwrap());
427 url.push_str(".html");
430 Some((url, shortty, fqp.to_vec()))
433 /// Used when rendering a `ResolvedPath` structure. This invokes the `path`
434 /// rendering function with the necessary arguments for linking to a local path.
435 fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path,
436 print_all: bool) -> fmt::Result {
437 let last = path.segments.last().unwrap();
438 let rel_root = match &*path.segments[0].name {
439 "self" => Some("./".to_string()),
444 let amt = path.segments.len() - 1;
447 for seg in &path.segments[..amt] {
448 if "super" == seg.name || "self" == seg.name || w.alternate() {
449 write!(w, "{}::", seg.name)?;
451 root.push_str(&seg.name);
453 write!(w, "<a class='mod'
454 href='{}index.html'>{}</a>::",
461 for seg in &path.segments[..amt] {
462 write!(w, "{}::", seg.name)?;
468 write!(w, "{:#}{:#}", HRef::new(did, &last.name), last.params)?;
470 write!(w, "{}{}", HRef::new(did, &last.name), last.params)?;
475 fn primitive_link(f: &mut fmt::Formatter,
476 prim: clean::PrimitiveType,
477 name: &str) -> fmt::Result {
479 let mut needs_termination = false;
481 match m.primitive_locations.get(&prim) {
482 Some(&LOCAL_CRATE) => {
483 let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
484 let len = if len == 0 {0} else {len - 1};
485 write!(f, "<a class='primitive' href='{}primitive.{}.html'>",
486 repeat("../").take(len).collect::<String>(),
488 needs_termination = true;
491 let loc = match m.extern_locations[&cnum] {
492 (ref cname, render::Remote(ref s)) => Some((cname, s.to_string())),
493 (ref cname, render::Local) => {
494 let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
495 Some((cname, repeat("../").take(len).collect::<String>()))
497 (_, render::Unknown) => None,
499 if let Some((cname, root)) = loc {
500 write!(f, "<a class='primitive' href='{}{}/primitive.{}.html'>",
504 needs_termination = true;
510 write!(f, "{}", name)?;
511 if needs_termination {
517 /// Helper to render type parameters
518 fn tybounds(w: &mut fmt::Formatter,
519 typarams: &Option<Vec<clean::TyParamBound> >) -> fmt::Result {
521 Some(ref params) => {
522 for param in params {
524 fmt::Display::fmt(param, w)?;
533 pub fn new(did: DefId, text: &'a str) -> HRef<'a> {
534 HRef { did: did, text: text }
538 impl<'a> fmt::Display for HRef<'a> {
539 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
540 match href(self.did) {
541 Some((url, shortty, fqp)) => if !f.alternate() {
542 write!(f, "<a class='{}' href='{}' title='{}'>{}</a>",
543 shortty, url, fqp.join("::"), self.text)
545 write!(f, "{}", self.text)
547 _ => write!(f, "{}", self.text),
552 impl fmt::Display for clean::Type {
553 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
555 clean::Generic(ref name) => {
558 clean::ResolvedPath{ did, ref typarams, ref path, is_generic } => {
559 // Paths like T::Output and Self::Output should be rendered with all segments
560 resolved_path(f, did, path, is_generic)?;
561 tybounds(f, typarams)
563 clean::Infer => write!(f, "_"),
564 clean::Primitive(prim) => primitive_link(f, prim, prim.as_str()),
565 clean::BareFunction(ref decl) => {
567 write!(f, "{}{}fn{:#}{:#}",
568 UnsafetySpace(decl.unsafety),
573 write!(f, "{}{}fn{}{}",
574 UnsafetySpace(decl.unsafety),
580 clean::Tuple(ref typs) => {
582 &[] => primitive_link(f, PrimitiveType::Tuple, "()"),
584 primitive_link(f, PrimitiveType::Tuple, "(")?;
585 //carry f.alternate() into this display w/o branching manually
586 fmt::Display::fmt(one, f)?;
587 primitive_link(f, PrimitiveType::Tuple, ",)")
590 primitive_link(f, PrimitiveType::Tuple, "(")?;
591 fmt::Display::fmt(&CommaSep(&many), f)?;
592 primitive_link(f, PrimitiveType::Tuple, ")")
596 clean::Vector(ref t) => {
597 primitive_link(f, PrimitiveType::Slice, &format!("["))?;
598 fmt::Display::fmt(t, f)?;
599 primitive_link(f, PrimitiveType::Slice, &format!("]"))
601 clean::FixedVector(ref t, ref s) => {
602 primitive_link(f, PrimitiveType::Array, "[")?;
603 fmt::Display::fmt(t, f)?;
605 primitive_link(f, PrimitiveType::Array,
606 &format!("; {}]", s))
608 primitive_link(f, PrimitiveType::Array,
609 &format!("; {}]", Escape(s)))
612 clean::Never => f.write_str("!"),
613 clean::RawPointer(m, ref t) => {
615 clean::Generic(_) | clean::ResolvedPath {is_generic: true, ..} => {
617 primitive_link(f, clean::PrimitiveType::RawPointer,
618 &format!("*{}{:#}", RawMutableSpace(m), t))
620 primitive_link(f, clean::PrimitiveType::RawPointer,
621 &format!("*{}{}", RawMutableSpace(m), t))
625 primitive_link(f, clean::PrimitiveType::RawPointer,
626 &format!("*{}", RawMutableSpace(m)))?;
627 fmt::Display::fmt(t, f)
631 clean::BorrowedRef{ lifetime: ref l, mutability, type_: ref ty} => {
633 Some(ref l) => format!("{} ", *l),
636 let m = MutableSpace(mutability);
638 clean::Vector(ref bt) => { // BorrowedRef{ ... Vector(T) } is &[T]
642 primitive_link(f, PrimitiveType::Slice,
643 &format!("&{}{}[{:#}]", lt, m, **bt))
645 primitive_link(f, PrimitiveType::Slice,
646 &format!("&{}{}[{}]", lt, m, **bt))
650 primitive_link(f, PrimitiveType::Slice,
651 &format!("&{}{}[", lt, m))?;
652 write!(f, "{:#}", **bt)?;
654 primitive_link(f, PrimitiveType::Slice,
655 &format!("&{}{}[", lt, m))?;
656 write!(f, "{}", **bt)?;
658 primitive_link(f, PrimitiveType::Slice, "]")
664 write!(f, "&{}{}{:#}", lt, m, **ty)
666 write!(f, "&{}{}{}", lt, m, **ty)
671 clean::PolyTraitRef(ref bounds) => {
672 for (i, bound) in bounds.iter().enumerate() {
677 write!(f, "{:#}", *bound)?;
679 write!(f, "{}", *bound)?;
684 clean::ImplTrait(ref bounds) => {
686 for (i, bound) in bounds.iter().enumerate() {
691 write!(f, "{:#}", *bound)?;
693 write!(f, "{}", *bound)?;
698 // It's pretty unsightly to look at `<A as B>::C` in output, and
699 // we've got hyperlinking on our side, so try to avoid longer
700 // notation as much as possible by making `C` a hyperlink to trait
701 // `B` to disambiguate.
703 // FIXME: this is still a lossy conversion and there should probably
704 // be a better way of representing this in general? Most of
705 // the ugliness comes from inlining across crates where
706 // everything comes in as a fully resolved QPath (hard to
711 trait_: box clean::ResolvedPath { did, ref typarams, .. },
714 write!(f, "{:#}::", self_type)?;
716 write!(f, "{}::", self_type)?;
718 let path = clean::Path::singleton(name.clone());
719 resolved_path(f, did, &path, false)?;
721 // FIXME: `typarams` are not rendered, and this seems bad?
725 clean::QPath { ref name, ref self_type, ref trait_ } => {
727 write!(f, "<{:#} as {:#}>::{}", self_type, trait_, name)
729 write!(f, "<{} as {}>::{}", self_type, trait_, name)
732 clean::Unique(..) => {
733 panic!("should have been cleaned")
739 fn fmt_impl(i: &clean::Impl, f: &mut fmt::Formatter, link_trait: bool) -> fmt::Result {
740 let mut plain = String::new();
743 write!(f, "impl{:#} ", i.generics)?;
745 write!(f, "impl{} ", i.generics)?;
747 plain.push_str(&format!("impl{:#} ", i.generics));
749 if let Some(ref ty) = i.trait_ {
750 if i.polarity == Some(clean::ImplPolarity::Negative) {
756 fmt::Display::fmt(ty, f)?;
757 plain.push_str(&format!("{:#}", ty));
760 clean::ResolvedPath{ typarams: None, ref path, is_generic: false, .. } => {
761 let last = path.segments.last().unwrap();
762 fmt::Display::fmt(&last.name, f)?;
763 fmt::Display::fmt(&last.params, f)?;
764 plain.push_str(&format!("{:#}{:#}", last.name, last.params));
770 plain.push_str(" for ");
773 fmt::Display::fmt(&i.for_, f)?;
774 plain.push_str(&format!("{:#}", i.for_));
776 fmt::Display::fmt(&WhereClause(&i.generics, plain.len() + 1), f)?;
780 impl fmt::Display for clean::Impl {
781 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
782 fmt_impl(self, f, true)
786 // The difference from above is that trait is not hyperlinked.
787 pub fn fmt_impl_for_trait_page(i: &clean::Impl, f: &mut fmt::Formatter) -> fmt::Result {
788 fmt_impl(i, f, false)
791 impl fmt::Display for clean::Arguments {
792 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
793 for (i, input) in self.values.iter().enumerate() {
794 if !input.name.is_empty() {
795 write!(f, "{}: ", input.name)?;
798 write!(f, "{:#}", input.type_)?;
800 write!(f, "{}", input.type_)?;
802 if i + 1 < self.values.len() { write!(f, ", ")?; }
808 impl fmt::Display for clean::FunctionRetTy {
809 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
811 clean::Return(clean::Tuple(ref tys)) if tys.is_empty() => Ok(()),
812 clean::Return(ref ty) if f.alternate() => write!(f, " -> {:#}", ty),
813 clean::Return(ref ty) => write!(f, " -> {}", ty),
814 clean::DefaultReturn => Ok(()),
819 impl fmt::Display for clean::FnDecl {
820 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
823 write!(f, "({args:#}, ...){arrow:#}", args = self.inputs, arrow = self.output)
825 write!(f, "({args}, ...){arrow}", args = self.inputs, arrow = self.output)
829 write!(f, "({args:#}){arrow:#}", args = self.inputs, arrow = self.output)
831 write!(f, "({args}){arrow}", args = self.inputs, arrow = self.output)
837 impl<'a> fmt::Display for Method<'a> {
838 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
841 let amp = if f.alternate() { "&" } else { "&" };
842 let mut args = String::new();
843 let mut args_plain = String::new();
844 for (i, input) in decl.inputs.values.iter().enumerate() {
845 if let Some(selfty) = input.to_self() {
847 clean::SelfValue => {
848 args.push_str("self");
849 args_plain.push_str("self");
851 clean::SelfBorrowed(Some(ref lt), mtbl) => {
852 args.push_str(&format!("{}{} {}self", amp, *lt, MutableSpace(mtbl)));
853 args_plain.push_str(&format!("&{} {}self", *lt, MutableSpace(mtbl)));
855 clean::SelfBorrowed(None, mtbl) => {
856 args.push_str(&format!("{}{}self", amp, MutableSpace(mtbl)));
857 args_plain.push_str(&format!("&{}self", MutableSpace(mtbl)));
859 clean::SelfExplicit(ref typ) => {
861 args.push_str(&format!("self: {:#}", *typ));
863 args.push_str(&format!("self: {}", *typ));
865 args_plain.push_str(&format!("self: {:#}", *typ));
870 args.push_str("<br> ");
871 args_plain.push_str(" ");
873 if !input.name.is_empty() {
874 args.push_str(&format!("{}: ", input.name));
875 args_plain.push_str(&format!("{}: ", input.name));
879 args.push_str(&format!("{:#}", input.type_));
881 args.push_str(&format!("{}", input.type_));
883 args_plain.push_str(&format!("{:#}", input.type_));
885 if i + 1 < decl.inputs.values.len() {
887 args_plain.push_str(",");
892 args.push_str(",<br> ...");
893 args_plain.push_str(", ...");
896 let arrow_plain = format!("{:#}", decl.output);
897 let arrow = if f.alternate() {
898 format!("{:#}", decl.output)
900 format!("{}", decl.output)
903 let mut output: String;
905 let pad = repeat(" ").take(indent).collect::<String>();
906 if arrow.is_empty() {
907 output = format!("({})", args);
908 plain = format!("{}({})", pad, args_plain);
910 output = format!("({args})<br>{arrow}", args = args, arrow = arrow);
911 plain = format!("{pad}({args}){arrow}",
914 arrow = arrow_plain);
917 if plain.len() > 80 {
918 let pad = repeat(" ").take(indent).collect::<String>();
919 let pad = format!("<br>{}", pad);
920 output = output.replace("<br>", &pad);
922 output = output.replace("<br>", "");
925 write!(f, "{}", output.replace("<br>", "\n"))
927 write!(f, "{}", output)
932 impl<'a> fmt::Display for VisSpace<'a> {
933 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
935 Some(clean::Public) => write!(f, "pub "),
936 Some(clean::Inherited) | None => Ok(())
941 impl fmt::Display for UnsafetySpace {
942 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
944 hir::Unsafety::Unsafe => write!(f, "unsafe "),
945 hir::Unsafety::Normal => Ok(())
950 impl fmt::Display for ConstnessSpace {
951 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
953 hir::Constness::Const => write!(f, "const "),
954 hir::Constness::NotConst => Ok(())
959 impl fmt::Display for clean::Import {
960 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
962 clean::Import::Simple(ref name, ref src) => {
963 if *name == src.path.last_name() {
964 write!(f, "use {};", *src)
966 write!(f, "use {} as {};", *src, *name)
969 clean::Import::Glob(ref src) => {
970 write!(f, "use {}::*;", *src)
972 clean::Import::List(ref src, ref names) => {
973 write!(f, "use {}::{{", *src)?;
974 for (i, n) in names.iter().enumerate() {
978 write!(f, "{}", *n)?;
986 impl fmt::Display for clean::ImportSource {
987 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
989 Some(did) => resolved_path(f, did, &self.path, true),
991 for (i, seg) in self.path.segments.iter().enumerate() {
995 write!(f, "{}", seg.name)?;
1003 impl fmt::Display for clean::ViewListIdent {
1004 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1007 let path = clean::Path::singleton(self.name.clone());
1008 resolved_path(f, did, &path, false)?;
1010 _ => write!(f, "{}", self.name)?,
1013 if let Some(ref name) = self.rename {
1014 write!(f, " as {}", name)?;
1020 impl fmt::Display for clean::TypeBinding {
1021 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1023 write!(f, "{}={:#}", self.name, self.ty)
1025 write!(f, "{}={}", self.name, self.ty)
1030 impl fmt::Display for MutableSpace {
1031 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1033 MutableSpace(clean::Immutable) => Ok(()),
1034 MutableSpace(clean::Mutable) => write!(f, "mut "),
1039 impl fmt::Display for RawMutableSpace {
1040 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1042 RawMutableSpace(clean::Immutable) => write!(f, "const "),
1043 RawMutableSpace(clean::Mutable) => write!(f, "mut "),
1048 impl fmt::Display for AbiSpace {
1049 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1050 let quot = if f.alternate() { "\"" } else { """ };
1052 Abi::Rust => Ok(()),
1053 Abi::C => write!(f, "extern "),
1054 abi => write!(f, "extern {0}{1}{0} ", quot, abi.name()),