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;
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 fmt-newline'>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() + pad > 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 repeat(" ").take(8).collect::<String>()
216 repeat(" ").take(pad + 6).collect::<String>()
218 clause = clause.replace("<br>", &format!("<br>{}", padding));
220 clause = clause.replace("<br>", " ");
223 write!(f, "{}", clause)
227 impl fmt::Display for clean::Lifetime {
228 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
229 f.write_str(self.get_ref())?;
234 impl fmt::Display for clean::PolyTrait {
235 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
236 if !self.lifetimes.is_empty() {
238 f.write_str("for<")?;
240 f.write_str("for<")?;
242 for (i, lt) in self.lifetimes.iter().enumerate() {
246 write!(f, "{}", lt)?;
251 f.write_str("> ")?;
255 write!(f, "{:#}", self.trait_)
257 write!(f, "{}", self.trait_)
262 impl fmt::Display for clean::TyParamBound {
263 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
265 clean::RegionBound(ref lt) => {
268 clean::TraitBound(ref ty, modifier) => {
269 let modifier_str = match modifier {
270 hir::TraitBoundModifier::None => "",
271 hir::TraitBoundModifier::Maybe => "?",
274 write!(f, "{}{:#}", modifier_str, *ty)
276 write!(f, "{}{}", modifier_str, *ty)
283 impl fmt::Display for clean::PathParameters {
284 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
286 clean::PathParameters::AngleBracketed {
287 ref lifetimes, ref types, ref bindings
289 if !lifetimes.is_empty() || !types.is_empty() || !bindings.is_empty() {
293 f.write_str("<")?;
295 let mut comma = false;
296 for lifetime in lifetimes {
301 write!(f, "{}", *lifetime)?;
309 write!(f, "{:#}", *ty)?;
311 write!(f, "{}", *ty)?;
314 for binding in bindings {
320 write!(f, "{:#}", *binding)?;
322 write!(f, "{}", *binding)?;
328 f.write_str(">")?;
332 clean::PathParameters::Parenthesized { ref inputs, ref output } => {
334 let mut comma = false;
341 write!(f, "{:#}", *ty)?;
343 write!(f, "{}", *ty)?;
347 if let Some(ref ty) = *output {
349 write!(f, " -> {:#}", ty)?;
351 write!(f, " -> {}", ty)?;
360 impl fmt::Display for clean::PathSegment {
361 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
362 f.write_str(&self.name)?;
364 write!(f, "{:#}", self.params)
366 write!(f, "{}", self.params)
371 impl fmt::Display for clean::Path {
372 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
377 for (i, seg) in self.segments.iter().enumerate() {
382 write!(f, "{:#}", seg)?;
384 write!(f, "{}", seg)?;
391 pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
393 if !did.is_local() && !cache.access_levels.is_doc_reachable(did) {
397 let loc = CURRENT_LOCATION_KEY.with(|l| l.borrow().clone());
398 let (fqp, shortty, mut url) = match cache.paths.get(&did) {
399 Some(&(ref fqp, shortty)) => {
400 (fqp, shortty, repeat("../").take(loc.len()).collect())
402 None => match cache.external_paths.get(&did) {
403 Some(&(ref fqp, shortty)) => {
404 (fqp, shortty, match cache.extern_locations[&did.krate] {
405 (.., render::Remote(ref s)) => s.to_string(),
406 (.., render::Local) => repeat("../").take(loc.len()).collect(),
407 (.., render::Unknown) => return None,
413 for component in &fqp[..fqp.len() - 1] {
414 url.push_str(component);
418 ItemType::Module => {
419 url.push_str(fqp.last().unwrap());
420 url.push_str("/index.html");
423 url.push_str(shortty.css_class());
425 url.push_str(fqp.last().unwrap());
426 url.push_str(".html");
429 Some((url, shortty, fqp.to_vec()))
432 /// Used when rendering a `ResolvedPath` structure. This invokes the `path`
433 /// rendering function with the necessary arguments for linking to a local path.
434 fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path,
435 print_all: bool, use_absolute: bool) -> fmt::Result {
436 let last = path.segments.last().unwrap();
437 let rel_root = match &*path.segments[0].name {
438 "self" => Some("./".to_string()),
443 let amt = path.segments.len() - 1;
446 for seg in &path.segments[..amt] {
447 if "super" == seg.name || "self" == seg.name || w.alternate() {
448 write!(w, "{}::", seg.name)?;
450 root.push_str(&seg.name);
452 write!(w, "<a class='mod'
453 href='{}index.html'>{}</a>::",
460 for seg in &path.segments[..amt] {
461 write!(w, "{}::", seg.name)?;
467 write!(w, "{:#}{:#}", HRef::new(did, &last.name), last.params)?;
469 let path = if use_absolute {
471 Some((_, _, fqp)) => format!("{}::{}",
472 fqp[..fqp.len()-1].join("::"),
473 HRef::new(did, fqp.last().unwrap())),
474 None => format!("{}", HRef::new(did, &last.name)),
477 format!("{}", HRef::new(did, &last.name))
479 write!(w, "{}{}", path, last.params)?;
484 fn primitive_link(f: &mut fmt::Formatter,
485 prim: clean::PrimitiveType,
486 name: &str) -> fmt::Result {
488 let mut needs_termination = false;
490 match m.primitive_locations.get(&prim) {
491 Some(&def_id) if def_id.is_local() => {
492 let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
493 let len = if len == 0 {0} else {len - 1};
494 write!(f, "<a class='primitive' href='{}primitive.{}.html'>",
495 repeat("../").take(len).collect::<String>(),
497 needs_termination = true;
500 let loc = match m.extern_locations[&def_id.krate] {
501 (ref cname, _, render::Remote(ref s)) => {
502 Some((cname, s.to_string()))
504 (ref cname, _, render::Local) => {
505 let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
506 Some((cname, repeat("../").take(len).collect::<String>()))
508 (.., render::Unknown) => None,
510 if let Some((cname, root)) = loc {
511 write!(f, "<a class='primitive' href='{}{}/primitive.{}.html'>",
515 needs_termination = true;
521 write!(f, "{}", name)?;
522 if needs_termination {
528 /// Helper to render type parameters
529 fn tybounds(w: &mut fmt::Formatter,
530 typarams: &Option<Vec<clean::TyParamBound> >) -> fmt::Result {
532 Some(ref params) => {
533 for param in params {
535 fmt::Display::fmt(param, w)?;
544 pub fn new(did: DefId, text: &'a str) -> HRef<'a> {
545 HRef { did: did, text: text }
549 impl<'a> fmt::Display for HRef<'a> {
550 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
551 match href(self.did) {
552 Some((url, shortty, fqp)) => if !f.alternate() {
553 write!(f, "<a class='{}' href='{}' title='{}'>{}</a>",
554 shortty, url, fqp.join("::"), self.text)
556 write!(f, "{}", self.text)
558 _ => write!(f, "{}", self.text),
563 fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt::Result {
565 clean::Generic(ref name) => {
568 clean::ResolvedPath{ did, ref typarams, ref path, is_generic } => {
569 // Paths like T::Output and Self::Output should be rendered with all segments
570 resolved_path(f, did, path, is_generic, use_absolute)?;
571 tybounds(f, typarams)
573 clean::Infer => write!(f, "_"),
574 clean::Primitive(prim) => primitive_link(f, prim, prim.as_str()),
575 clean::BareFunction(ref decl) => {
577 write!(f, "{}{}fn{:#}{:#}",
578 UnsafetySpace(decl.unsafety),
583 write!(f, "{}{}fn{}{}",
584 UnsafetySpace(decl.unsafety),
590 clean::Tuple(ref typs) => {
592 &[] => primitive_link(f, PrimitiveType::Tuple, "()"),
594 primitive_link(f, PrimitiveType::Tuple, "(")?;
595 //carry f.alternate() into this display w/o branching manually
596 fmt::Display::fmt(one, f)?;
597 primitive_link(f, PrimitiveType::Tuple, ",)")
600 primitive_link(f, PrimitiveType::Tuple, "(")?;
601 fmt::Display::fmt(&CommaSep(&many), f)?;
602 primitive_link(f, PrimitiveType::Tuple, ")")
606 clean::Vector(ref t) => {
607 primitive_link(f, PrimitiveType::Slice, &format!("["))?;
608 fmt::Display::fmt(t, f)?;
609 primitive_link(f, PrimitiveType::Slice, &format!("]"))
611 clean::FixedVector(ref t, ref s) => {
612 primitive_link(f, PrimitiveType::Array, "[")?;
613 fmt::Display::fmt(t, f)?;
615 primitive_link(f, PrimitiveType::Array,
616 &format!("; {}]", s))
618 primitive_link(f, PrimitiveType::Array,
619 &format!("; {}]", Escape(s)))
622 clean::Never => f.write_str("!"),
623 clean::RawPointer(m, ref t) => {
625 clean::Generic(_) | clean::ResolvedPath {is_generic: true, ..} => {
627 primitive_link(f, clean::PrimitiveType::RawPointer,
628 &format!("*{}{:#}", RawMutableSpace(m), t))
630 primitive_link(f, clean::PrimitiveType::RawPointer,
631 &format!("*{}{}", RawMutableSpace(m), t))
635 primitive_link(f, clean::PrimitiveType::RawPointer,
636 &format!("*{}", RawMutableSpace(m)))?;
637 fmt::Display::fmt(t, f)
641 clean::BorrowedRef{ lifetime: ref l, mutability, type_: ref ty} => {
643 Some(ref l) => format!("{} ", *l),
646 let m = MutableSpace(mutability);
648 clean::Vector(ref bt) => { // BorrowedRef{ ... Vector(T) } is &[T]
652 primitive_link(f, PrimitiveType::Slice,
653 &format!("&{}{}[{:#}]", lt, m, **bt))
655 primitive_link(f, PrimitiveType::Slice,
656 &format!("&{}{}[{}]", lt, m, **bt))
660 primitive_link(f, PrimitiveType::Slice,
661 &format!("&{}{}[", lt, m))?;
662 write!(f, "{:#}", **bt)?;
664 primitive_link(f, PrimitiveType::Slice,
665 &format!("&{}{}[", lt, m))?;
666 write!(f, "{}", **bt)?;
668 primitive_link(f, PrimitiveType::Slice, "]")
674 write!(f, "&{}{}", lt, m)?;
675 fmt_type(&ty, f, use_absolute)
677 write!(f, "&{}{}", lt, m)?;
678 fmt_type(&ty, f, use_absolute)
683 clean::ImplTrait(ref bounds) => {
685 for (i, bound) in bounds.iter().enumerate() {
690 write!(f, "{:#}", *bound)?;
692 write!(f, "{}", *bound)?;
697 // It's pretty unsightly to look at `<A as B>::C` in output, and
698 // we've got hyperlinking on our side, so try to avoid longer
699 // notation as much as possible by making `C` a hyperlink to trait
700 // `B` to disambiguate.
702 // FIXME: this is still a lossy conversion and there should probably
703 // be a better way of representing this in general? Most of
704 // the ugliness comes from inlining across crates where
705 // everything comes in as a fully resolved QPath (hard to
710 trait_: box clean::ResolvedPath { did, ref typarams, .. },
713 write!(f, "{:#}::", self_type)?;
715 write!(f, "{}::", self_type)?;
717 let path = clean::Path::singleton(name.clone());
718 resolved_path(f, did, &path, true, use_absolute)?;
720 // FIXME: `typarams` are not rendered, and this seems bad?
724 clean::QPath { ref name, ref self_type, ref trait_ } => {
726 write!(f, "<{:#} as {:#}>::{}", self_type, trait_, name)
728 write!(f, "<{} as {}>::{}", self_type, trait_, name)
731 clean::Unique(..) => {
732 panic!("should have been cleaned")
737 impl fmt::Display for clean::Type {
738 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
739 fmt_type(self, f, false)
743 fn fmt_impl(i: &clean::Impl,
744 f: &mut fmt::Formatter,
746 use_absolute: bool) -> fmt::Result {
747 let mut plain = String::new();
750 write!(f, "impl{:#} ", i.generics)?;
752 write!(f, "impl{} ", i.generics)?;
754 plain.push_str(&format!("impl{:#} ", i.generics));
756 if let Some(ref ty) = i.trait_ {
757 if i.polarity == Some(clean::ImplPolarity::Negative) {
763 fmt::Display::fmt(ty, f)?;
764 plain.push_str(&format!("{:#}", ty));
767 clean::ResolvedPath { typarams: None, ref path, is_generic: false, .. } => {
768 let last = path.segments.last().unwrap();
769 fmt::Display::fmt(&last.name, f)?;
770 fmt::Display::fmt(&last.params, f)?;
771 plain.push_str(&format!("{:#}{:#}", last.name, last.params));
777 plain.push_str(" for ");
780 fmt_type(&i.for_, f, use_absolute)?;
781 plain.push_str(&format!("{:#}", i.for_));
783 fmt::Display::fmt(&WhereClause(&i.generics, plain.len() + 1), f)?;
787 impl fmt::Display for clean::Impl {
788 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
789 fmt_impl(self, f, true, false)
793 // The difference from above is that trait is not hyperlinked.
794 pub fn fmt_impl_for_trait_page(i: &clean::Impl,
795 f: &mut fmt::Formatter,
796 use_absolute: bool) -> fmt::Result {
797 fmt_impl(i, f, false, use_absolute)
800 impl fmt::Display for clean::Arguments {
801 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
802 for (i, input) in self.values.iter().enumerate() {
803 if !input.name.is_empty() {
804 write!(f, "{}: ", input.name)?;
807 write!(f, "{:#}", input.type_)?;
809 write!(f, "{}", input.type_)?;
811 if i + 1 < self.values.len() { write!(f, ", ")?; }
817 impl fmt::Display for clean::FunctionRetTy {
818 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
820 clean::Return(clean::Tuple(ref tys)) if tys.is_empty() => Ok(()),
821 clean::Return(ref ty) if f.alternate() => write!(f, " -> {:#}", ty),
822 clean::Return(ref ty) => write!(f, " -> {}", ty),
823 clean::DefaultReturn => Ok(()),
828 impl fmt::Display for clean::FnDecl {
829 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
832 write!(f, "({args:#}, ...){arrow:#}", args = self.inputs, arrow = self.output)
834 write!(f, "({args}, ...){arrow}", args = self.inputs, arrow = self.output)
838 write!(f, "({args:#}){arrow:#}", args = self.inputs, arrow = self.output)
840 write!(f, "({args}){arrow}", args = self.inputs, arrow = self.output)
846 impl<'a> fmt::Display for Method<'a> {
847 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
850 let amp = if f.alternate() { "&" } else { "&" };
851 let mut args = String::new();
852 let mut args_plain = String::new();
853 for (i, input) in decl.inputs.values.iter().enumerate() {
854 if let Some(selfty) = input.to_self() {
856 clean::SelfValue => {
857 args.push_str("self");
858 args_plain.push_str("self");
860 clean::SelfBorrowed(Some(ref lt), mtbl) => {
861 args.push_str(&format!("{}{} {}self", amp, *lt, MutableSpace(mtbl)));
862 args_plain.push_str(&format!("&{} {}self", *lt, MutableSpace(mtbl)));
864 clean::SelfBorrowed(None, mtbl) => {
865 args.push_str(&format!("{}{}self", amp, MutableSpace(mtbl)));
866 args_plain.push_str(&format!("&{}self", MutableSpace(mtbl)));
868 clean::SelfExplicit(ref typ) => {
870 args.push_str(&format!("self: {:#}", *typ));
872 args.push_str(&format!("self: {}", *typ));
874 args_plain.push_str(&format!("self: {:#}", *typ));
879 args.push_str("<br> ");
880 args_plain.push_str(" ");
882 if !input.name.is_empty() {
883 args.push_str(&format!("{}: ", input.name));
884 args_plain.push_str(&format!("{}: ", input.name));
888 args.push_str(&format!("{:#}", input.type_));
890 args.push_str(&format!("{}", input.type_));
892 args_plain.push_str(&format!("{:#}", input.type_));
894 if i + 1 < decl.inputs.values.len() {
896 args_plain.push_str(",");
901 args.push_str(",<br> ...");
902 args_plain.push_str(", ...");
905 let arrow_plain = format!("{:#}", decl.output);
906 let arrow = if f.alternate() {
907 format!("{:#}", decl.output)
909 format!("{}", decl.output)
912 let mut output: String;
914 let pad = repeat(" ").take(indent).collect::<String>();
915 if arrow.is_empty() {
916 output = format!("({})", args);
917 plain = format!("{}({})", pad, args_plain);
919 output = format!("({args})<br>{arrow}", args = args, arrow = arrow);
920 plain = format!("{pad}({args}){arrow}",
923 arrow = arrow_plain);
926 if plain.len() > 80 {
927 let pad = repeat(" ").take(indent).collect::<String>();
928 let pad = format!("<br>{}", pad);
929 output = output.replace("<br>", &pad);
931 output = output.replace("<br>", "");
934 write!(f, "{}", output.replace("<br>", "\n"))
936 write!(f, "{}", output)
941 impl<'a> fmt::Display for VisSpace<'a> {
942 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
944 Some(clean::Public) => write!(f, "pub "),
945 Some(clean::Inherited) | None => Ok(())
950 impl fmt::Display for UnsafetySpace {
951 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
953 hir::Unsafety::Unsafe => write!(f, "unsafe "),
954 hir::Unsafety::Normal => Ok(())
959 impl fmt::Display for ConstnessSpace {
960 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
962 hir::Constness::Const => write!(f, "const "),
963 hir::Constness::NotConst => Ok(())
968 impl fmt::Display for clean::Import {
969 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
971 clean::Import::Simple(ref name, ref src) => {
972 if *name == src.path.last_name() {
973 write!(f, "use {};", *src)
975 write!(f, "use {} as {};", *src, *name)
978 clean::Import::Glob(ref src) => {
979 write!(f, "use {}::*;", *src)
985 impl fmt::Display for clean::ImportSource {
986 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
988 Some(did) => resolved_path(f, did, &self.path, true, false),
990 for (i, seg) in self.path.segments.iter().enumerate() {
994 write!(f, "{}", seg.name)?;
1002 impl fmt::Display for clean::TypeBinding {
1003 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1005 write!(f, "{}={:#}", self.name, self.ty)
1007 write!(f, "{}={}", self.name, self.ty)
1012 impl fmt::Display for MutableSpace {
1013 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1015 MutableSpace(clean::Immutable) => Ok(()),
1016 MutableSpace(clean::Mutable) => write!(f, "mut "),
1021 impl fmt::Display for RawMutableSpace {
1022 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1024 RawMutableSpace(clean::Immutable) => write!(f, "const "),
1025 RawMutableSpace(clean::Mutable) => write!(f, "mut "),
1030 impl fmt::Display for AbiSpace {
1031 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1032 let quot = if f.alternate() { "\"" } else { """ };
1034 Abi::Rust => Ok(()),
1035 Abi::C => write!(f, "extern "),
1036 abi => write!(f, "extern {0}{1}{0} ", quot, abi.name()),