2014-04-09 16:49:31 +09:00
|
|
|
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
2013-09-18 22:18:38 -07:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-10-03 10:24:40 -07:00
|
|
|
//! HTML formatting module
|
|
|
|
//!
|
2015-02-05 15:04:07 +03:00
|
|
|
//! This module contains a large number of `fmt::Display` implementations for
|
2013-10-03 10:24:40 -07:00
|
|
|
//! various types in `rustdoc::clean`. These implementations all currently
|
|
|
|
//! assume that HTML output is desired, although it may be possible to redesign
|
|
|
|
//! them in the future to instead emit any format desired.
|
|
|
|
|
2013-09-18 22:18:38 -07:00
|
|
|
use std::fmt;
|
2014-12-10 19:46:38 -08:00
|
|
|
use std::iter::repeat;
|
2013-09-18 22:18:38 -07:00
|
|
|
|
2015-11-25 01:23:22 +02:00
|
|
|
use rustc::middle::cstore::LOCAL_CRATE;
|
2016-03-29 12:54:26 +03:00
|
|
|
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
|
2015-04-07 14:22:55 -07:00
|
|
|
use syntax::abi::Abi;
|
2016-03-29 08:50:44 +03:00
|
|
|
use rustc::hir;
|
2013-09-18 22:18:38 -07:00
|
|
|
|
|
|
|
use clean;
|
2016-04-17 08:54:48 +02:00
|
|
|
use core::DocAccessLevels;
|
2014-04-09 16:49:31 +09:00
|
|
|
use html::item_type::ItemType;
|
2013-10-02 15:39:32 -07:00
|
|
|
use html::render;
|
2014-11-14 14:20:57 -08:00
|
|
|
use html::render::{cache, CURRENT_LOCATION_KEY};
|
2013-09-18 22:18:38 -07:00
|
|
|
|
2013-10-03 10:24:40 -07:00
|
|
|
/// Helper to render an optional visibility with a space after it (if the
|
|
|
|
/// visibility is preset)
|
2015-03-30 09:40:52 -04:00
|
|
|
#[derive(Copy, Clone)]
|
2016-04-11 08:15:14 +00:00
|
|
|
pub struct VisSpace<'a>(pub &'a Option<clean::Visibility>);
|
2014-04-06 18:04:40 -07:00
|
|
|
/// Similarly to VisSpace, this structure is used to render a function style with a
|
2013-10-03 10:24:40 -07:00
|
|
|
/// space after it.
|
2015-03-30 09:40:52 -04:00
|
|
|
#[derive(Copy, Clone)]
|
2015-07-31 00:04:06 -07:00
|
|
|
pub struct UnsafetySpace(pub hir::Unsafety);
|
2015-02-25 22:05:07 +02:00
|
|
|
/// Similarly to VisSpace, this structure is used to render a function constness
|
|
|
|
/// with a space after it.
|
2015-05-05 08:47:04 -04:00
|
|
|
#[derive(Copy, Clone)]
|
2015-07-31 00:04:06 -07:00
|
|
|
pub struct ConstnessSpace(pub hir::Constness);
|
2013-10-03 10:24:40 -07:00
|
|
|
/// Wrapper struct for properly emitting a method declaration.
|
2014-03-31 19:01:01 -07:00
|
|
|
pub struct Method<'a>(pub &'a clean::SelfTy, pub &'a clean::FnDecl);
|
2014-06-05 17:20:59 -07:00
|
|
|
/// Similar to VisSpace, but used for mutability
|
2015-03-30 09:40:52 -04:00
|
|
|
#[derive(Copy, Clone)]
|
2014-06-05 17:20:59 -07:00
|
|
|
pub struct MutableSpace(pub clean::Mutability);
|
2014-07-11 11:35:02 +02:00
|
|
|
/// Similar to VisSpace, but used for mutability
|
2015-03-30 09:40:52 -04:00
|
|
|
#[derive(Copy, Clone)]
|
2014-07-11 11:35:02 +02:00
|
|
|
pub struct RawMutableSpace(pub clean::Mutability);
|
2014-09-25 02:01:42 -07:00
|
|
|
/// Wrapper struct for emitting a where clause from Generics.
|
|
|
|
pub struct WhereClause<'a>(pub &'a clean::Generics);
|
|
|
|
/// Wrapper struct for emitting type parameter bounds.
|
2014-11-20 11:22:09 -08:00
|
|
|
pub struct TyParamBounds<'a>(pub &'a [clean::TyParamBound]);
|
2015-01-07 14:58:31 -08:00
|
|
|
/// Wrapper struct for emitting a comma-separated list of items
|
|
|
|
pub struct CommaSep<'a, T: 'a>(pub &'a [T]);
|
2015-04-07 14:22:55 -07:00
|
|
|
pub struct AbiSpace(pub Abi);
|
2013-09-18 22:18:38 -07:00
|
|
|
|
2016-03-25 06:08:11 +00:00
|
|
|
impl<'a> VisSpace<'a> {
|
2016-04-11 08:15:14 +00:00
|
|
|
pub fn get(self) -> &'a Option<clean::Visibility> {
|
2016-03-25 06:08:11 +00:00
|
|
|
let VisSpace(v) = self; v
|
2013-11-01 18:06:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-09 10:36:46 -05:00
|
|
|
impl UnsafetySpace {
|
2015-07-31 00:04:06 -07:00
|
|
|
pub fn get(&self) -> hir::Unsafety {
|
2014-12-09 10:36:46 -05:00
|
|
|
let UnsafetySpace(v) = *self; v
|
2013-11-01 18:06:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-25 22:05:07 +02:00
|
|
|
impl ConstnessSpace {
|
2015-07-31 00:04:06 -07:00
|
|
|
pub fn get(&self) -> hir::Constness {
|
2015-02-25 22:05:07 +02:00
|
|
|
let ConstnessSpace(v) = *self; v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl<'a, T: fmt::Display> fmt::Display for CommaSep<'a, T> {
|
2015-01-07 14:58:31 -08:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
for (i, item) in self.0.iter().enumerate() {
|
2016-03-22 22:01:37 -05:00
|
|
|
if i != 0 { write!(f, ", ")?; }
|
|
|
|
write!(f, "{}", item)?;
|
2015-01-07 14:58:31 -08:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl<'a> fmt::Display for TyParamBounds<'a> {
|
2014-09-25 02:01:42 -07:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let &TyParamBounds(bounds) = self;
|
|
|
|
for (i, bound) in bounds.iter().enumerate() {
|
|
|
|
if i > 0 {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(" + ")?;
|
2014-09-25 02:01:42 -07:00
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}", *bound)?;
|
2014-09-25 02:01:42 -07:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for clean::Generics {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2015-03-24 16:53:34 -07:00
|
|
|
if self.lifetimes.is_empty() && self.type_params.is_empty() { return Ok(()) }
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str("<")?;
|
2013-09-18 22:18:38 -07:00
|
|
|
|
2014-02-05 23:55:13 +11:00
|
|
|
for (i, life) in self.lifetimes.iter().enumerate() {
|
2014-01-30 11:30:21 -08:00
|
|
|
if i > 0 {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(", ")?;
|
2014-01-30 11:30:21 -08:00
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}", *life)?;
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
|
2015-03-24 16:54:09 -07:00
|
|
|
if !self.type_params.is_empty() {
|
|
|
|
if !self.lifetimes.is_empty() {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(", ")?;
|
2014-01-30 11:30:21 -08:00
|
|
|
}
|
2014-02-05 23:55:13 +11:00
|
|
|
for (i, tp) in self.type_params.iter().enumerate() {
|
2014-01-30 11:30:21 -08:00
|
|
|
if i > 0 {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(", ")?
|
2014-01-30 11:30:21 -08:00
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(&tp.name)?;
|
2013-09-18 22:18:38 -07:00
|
|
|
|
2015-03-24 16:54:09 -07:00
|
|
|
if !tp.bounds.is_empty() {
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, ": {}", TyParamBounds(&tp.bounds))?;
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-06-21 05:03:33 -07:00
|
|
|
|
|
|
|
match tp.default {
|
2016-03-22 22:01:37 -05:00
|
|
|
Some(ref ty) => { write!(f, " = {}", ty)?; },
|
2014-06-21 05:03:33 -07:00
|
|
|
None => {}
|
|
|
|
};
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(">")?;
|
2014-01-30 11:30:21 -08:00
|
|
|
Ok(())
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl<'a> fmt::Display for WhereClause<'a> {
|
2014-09-25 02:01:42 -07:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let &WhereClause(gens) = self;
|
2015-03-24 16:53:34 -07:00
|
|
|
if gens.where_predicates.is_empty() {
|
2014-09-25 02:01:42 -07:00
|
|
|
return Ok(());
|
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(" <span class='where'>where ")?;
|
2014-09-25 02:01:42 -07:00
|
|
|
for (i, pred) in gens.where_predicates.iter().enumerate() {
|
|
|
|
if i > 0 {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(", ")?;
|
2014-09-25 02:01:42 -07:00
|
|
|
}
|
2014-12-23 01:08:00 -08:00
|
|
|
match pred {
|
2014-12-24 00:58:21 -08:00
|
|
|
&clean::WherePredicate::BoundPredicate { ref ty, ref bounds } => {
|
2015-02-01 21:53:25 -05:00
|
|
|
let bounds = bounds;
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}: {}", ty, TyParamBounds(bounds))?;
|
2014-12-24 00:58:21 -08:00
|
|
|
}
|
2014-12-23 01:08:00 -08:00
|
|
|
&clean::WherePredicate::RegionPredicate { ref lifetime,
|
|
|
|
ref bounds } => {
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}: ", lifetime)?;
|
2014-12-23 01:08:00 -08:00
|
|
|
for (i, lifetime) in bounds.iter().enumerate() {
|
|
|
|
if i > 0 {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(" + ")?;
|
2014-12-23 01:08:00 -08:00
|
|
|
}
|
|
|
|
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}", lifetime)?;
|
2014-12-23 01:08:00 -08:00
|
|
|
}
|
2014-12-24 00:58:21 -08:00
|
|
|
}
|
2015-01-10 23:50:46 -08:00
|
|
|
&clean::WherePredicate::EqPredicate { ref lhs, ref rhs } => {
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{} == {}", lhs, rhs)?;
|
2014-12-23 01:08:00 -08:00
|
|
|
}
|
|
|
|
}
|
2014-09-25 02:01:42 -07:00
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str("</span>")?;
|
2014-09-25 02:01:42 -07:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for clean::Lifetime {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(self.get_ref())?;
|
2014-01-30 11:30:21 -08:00
|
|
|
Ok(())
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for clean::PolyTrait {
|
2014-12-16 08:50:52 -08:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2015-03-24 16:54:09 -07:00
|
|
|
if !self.lifetimes.is_empty() {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str("for<")?;
|
2014-12-16 08:50:52 -08:00
|
|
|
for (i, lt) in self.lifetimes.iter().enumerate() {
|
|
|
|
if i > 0 {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(", ")?;
|
2014-12-16 08:50:52 -08:00
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}", lt)?;
|
2014-12-16 08:50:52 -08:00
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str("> ")?;
|
2014-12-16 08:50:52 -08:00
|
|
|
}
|
|
|
|
write!(f, "{}", self.trait_)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for clean::TyParamBound {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
2014-10-05 07:35:04 -07:00
|
|
|
clean::RegionBound(ref lt) => {
|
|
|
|
write!(f, "{}", *lt)
|
|
|
|
}
|
2014-12-24 22:34:57 +13:00
|
|
|
clean::TraitBound(ref ty, modifier) => {
|
|
|
|
let modifier_str = match modifier {
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::TraitBoundModifier::None => "",
|
|
|
|
hir::TraitBoundModifier::Maybe => "?",
|
2014-12-24 22:34:57 +13:00
|
|
|
};
|
|
|
|
write!(f, "{}{}", modifier_str, *ty)
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for clean::PathParameters {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2014-12-16 12:40:43 -08:00
|
|
|
match *self {
|
2015-01-07 16:10:40 -08:00
|
|
|
clean::PathParameters::AngleBracketed {
|
|
|
|
ref lifetimes, ref types, ref bindings
|
|
|
|
} => {
|
2015-03-24 16:54:09 -07:00
|
|
|
if !lifetimes.is_empty() || !types.is_empty() || !bindings.is_empty() {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str("<")?;
|
2014-12-16 12:40:43 -08:00
|
|
|
let mut comma = false;
|
2015-01-31 12:20:46 -05:00
|
|
|
for lifetime in lifetimes {
|
2014-12-16 12:40:43 -08:00
|
|
|
if comma {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(", ")?;
|
2014-12-16 12:40:43 -08:00
|
|
|
}
|
|
|
|
comma = true;
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}", *lifetime)?;
|
2014-01-30 11:30:21 -08:00
|
|
|
}
|
2015-01-31 12:20:46 -05:00
|
|
|
for ty in types {
|
2014-12-16 12:40:43 -08:00
|
|
|
if comma {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(", ")?;
|
2014-12-16 12:40:43 -08:00
|
|
|
}
|
|
|
|
comma = true;
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}", *ty)?;
|
2014-12-16 12:40:43 -08:00
|
|
|
}
|
2015-01-31 12:20:46 -05:00
|
|
|
for binding in bindings {
|
2015-01-07 16:10:40 -08:00
|
|
|
if comma {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(", ")?;
|
2015-01-07 16:10:40 -08:00
|
|
|
}
|
|
|
|
comma = true;
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}", *binding)?;
|
2015-01-07 16:10:40 -08:00
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(">")?;
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-12-16 12:40:43 -08:00
|
|
|
}
|
|
|
|
clean::PathParameters::Parenthesized { ref inputs, ref output } => {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str("(")?;
|
2014-12-16 12:40:43 -08:00
|
|
|
let mut comma = false;
|
2015-01-31 12:20:46 -05:00
|
|
|
for ty in inputs {
|
2014-01-30 11:30:21 -08:00
|
|
|
if comma {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(", ")?;
|
2014-01-30 11:30:21 -08:00
|
|
|
}
|
2013-10-29 06:03:32 -04:00
|
|
|
comma = true;
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}", *ty)?;
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(")")?;
|
2014-12-16 12:40:43 -08:00
|
|
|
if let Some(ref ty) = *output {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(" -> ")?;
|
|
|
|
write!(f, "{}", ty)?;
|
2014-12-16 12:40:43 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for clean::PathSegment {
|
2014-12-16 12:40:43 -08:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str(&self.name)?;
|
2014-12-16 12:40:43 -08:00
|
|
|
write!(f, "{}", self.params)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for clean::Path {
|
2014-12-16 12:40:43 -08:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
if self.global {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str("::")?
|
2014-12-16 12:40:43 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i, seg) in self.segments.iter().enumerate() {
|
|
|
|
if i > 0 {
|
2016-03-22 22:01:37 -05:00
|
|
|
f.write_str("::")?
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}", seg)?;
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-01-30 11:30:21 -08:00
|
|
|
Ok(())
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-16 06:32:28 -04:00
|
|
|
pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
|
2015-04-06 17:56:35 -07:00
|
|
|
let cache = cache();
|
|
|
|
let loc = CURRENT_LOCATION_KEY.with(|l| l.borrow().clone());
|
|
|
|
let &(ref fqp, shortty) = match cache.paths.get(&did) {
|
|
|
|
Some(p) => p,
|
|
|
|
None => return None,
|
|
|
|
};
|
2015-08-16 06:32:28 -04:00
|
|
|
let mut url = if did.is_local() || cache.inlined.contains(&did) {
|
2015-04-06 17:56:35 -07:00
|
|
|
repeat("../").take(loc.len()).collect::<String>()
|
|
|
|
} else {
|
2016-04-17 08:54:48 +02:00
|
|
|
if !cache.access_levels.is_doc_reachable(did) {
|
|
|
|
return None
|
|
|
|
}
|
2015-04-06 17:56:35 -07:00
|
|
|
match cache.extern_locations[&did.krate] {
|
2015-04-13 15:25:40 -07:00
|
|
|
(_, render::Remote(ref s)) => s.to_string(),
|
|
|
|
(_, render::Local) => repeat("../").take(loc.len()).collect(),
|
|
|
|
(_, render::Unknown) => return None,
|
2015-04-06 17:56:35 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
for component in &fqp[..fqp.len() - 1] {
|
|
|
|
url.push_str(component);
|
|
|
|
url.push_str("/");
|
|
|
|
}
|
|
|
|
match shortty {
|
|
|
|
ItemType::Module => {
|
|
|
|
url.push_str(fqp.last().unwrap());
|
|
|
|
url.push_str("/index.html");
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
url.push_str(shortty.to_static_str());
|
|
|
|
url.push_str(".");
|
|
|
|
url.push_str(fqp.last().unwrap());
|
|
|
|
url.push_str(".html");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some((url, shortty, fqp.to_vec()))
|
|
|
|
}
|
|
|
|
|
2013-10-03 10:24:40 -07:00
|
|
|
/// Used when rendering a `ResolvedPath` structure. This invokes the `path`
|
|
|
|
/// rendering function with the necessary arguments for linking to a local path.
|
2015-08-16 06:32:28 -04:00
|
|
|
fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path,
|
2014-01-30 11:30:21 -08:00
|
|
|
print_all: bool) -> fmt::Result {
|
2013-12-23 15:08:23 +01:00
|
|
|
let last = path.segments.last().unwrap();
|
2015-02-01 21:53:25 -05:00
|
|
|
let rel_root = match &*path.segments[0].name {
|
2014-05-25 03:10:11 -07:00
|
|
|
"self" => Some("./".to_string()),
|
2014-04-28 20:36:08 -07:00
|
|
|
_ => None,
|
|
|
|
};
|
2013-09-24 13:56:52 -07:00
|
|
|
|
2014-04-28 20:36:08 -07:00
|
|
|
if print_all {
|
|
|
|
let amt = path.segments.len() - 1;
|
|
|
|
match rel_root {
|
2015-06-08 16:55:35 +02:00
|
|
|
Some(mut root) => {
|
2015-01-31 12:20:46 -05:00
|
|
|
for seg in &path.segments[..amt] {
|
2015-04-06 17:56:35 -07:00
|
|
|
if "super" == seg.name || "self" == seg.name {
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(w, "{}::", seg.name)?;
|
2014-04-28 20:36:08 -07:00
|
|
|
} else {
|
2015-02-01 21:53:25 -05:00
|
|
|
root.push_str(&seg.name);
|
2014-04-28 20:36:08 -07:00
|
|
|
root.push_str("/");
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(w, "<a class='mod'
|
2016-03-22 17:58:45 -05:00
|
|
|
href='{}index.html'>{}</a>::",
|
|
|
|
root,
|
|
|
|
seg.name)?;
|
2013-12-05 18:19:06 -08:00
|
|
|
}
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
2013-12-05 18:19:06 -08:00
|
|
|
}
|
2014-04-28 20:36:08 -07:00
|
|
|
None => {
|
2015-01-31 12:20:46 -05:00
|
|
|
for seg in &path.segments[..amt] {
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(w, "{}::", seg.name)?;
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
2014-04-28 20:36:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-05 18:19:06 -08:00
|
|
|
|
2015-04-06 17:56:35 -07:00
|
|
|
match href(did) {
|
|
|
|
Some((url, shortty, fqp)) => {
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(w, "<a class='{}' href='{}' title='{}'>{}</a>",
|
2016-03-22 17:58:45 -05:00
|
|
|
shortty, url, fqp.join("::"), last.name)?;
|
2014-04-28 20:36:08 -07:00
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
_ => write!(w, "{}", last.name)?,
|
2014-04-28 20:36:08 -07:00
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(w, "{}", last.params)?;
|
2014-04-28 20:36:08 -07:00
|
|
|
Ok(())
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
|
2014-05-28 19:53:37 -07:00
|
|
|
fn primitive_link(f: &mut fmt::Formatter,
|
2014-09-11 17:07:49 +12:00
|
|
|
prim: clean::PrimitiveType,
|
2014-05-28 19:53:37 -07:00
|
|
|
name: &str) -> fmt::Result {
|
2014-11-14 14:20:57 -08:00
|
|
|
let m = cache();
|
2014-05-28 19:53:37 -07:00
|
|
|
let mut needs_termination = false;
|
2014-11-06 12:25:16 -05:00
|
|
|
match m.primitive_locations.get(&prim) {
|
2015-08-16 06:32:28 -04:00
|
|
|
Some(&LOCAL_CRATE) => {
|
2014-11-14 14:20:57 -08:00
|
|
|
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
|
|
|
|
let len = if len == 0 {0} else {len - 1};
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "<a class='primitive' href='{}primitive.{}.html'>",
|
2016-03-22 17:58:45 -05:00
|
|
|
repeat("../").take(len).collect::<String>(),
|
|
|
|
prim.to_url_str())?;
|
2014-05-28 19:53:37 -07:00
|
|
|
needs_termination = true;
|
|
|
|
}
|
|
|
|
Some(&cnum) => {
|
2015-08-16 06:32:28 -04:00
|
|
|
let path = &m.paths[&DefId {
|
2014-05-29 09:58:09 -07:00
|
|
|
krate: cnum,
|
2015-09-17 14:29:59 -04:00
|
|
|
index: CRATE_DEF_INDEX,
|
2014-08-02 18:48:44 +12:00
|
|
|
}];
|
2015-03-21 21:15:47 -04:00
|
|
|
let loc = match m.extern_locations[&cnum] {
|
2015-04-13 15:25:40 -07:00
|
|
|
(_, render::Remote(ref s)) => Some(s.to_string()),
|
|
|
|
(_, render::Local) => {
|
2014-11-14 14:20:57 -08:00
|
|
|
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
|
2014-12-10 19:46:38 -08:00
|
|
|
Some(repeat("../").take(len).collect::<String>())
|
2014-05-28 19:53:37 -07:00
|
|
|
}
|
2015-04-13 15:25:40 -07:00
|
|
|
(_, render::Unknown) => None,
|
2014-05-28 19:53:37 -07:00
|
|
|
};
|
|
|
|
match loc {
|
2014-05-29 09:58:09 -07:00
|
|
|
Some(root) => {
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "<a class='primitive' href='{}{}/primitive.{}.html'>",
|
2016-03-22 17:58:45 -05:00
|
|
|
root,
|
|
|
|
path.0.first().unwrap(),
|
|
|
|
prim.to_url_str())?;
|
2014-05-28 19:53:37 -07:00
|
|
|
needs_termination = true;
|
|
|
|
}
|
|
|
|
None => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => {}
|
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}", name)?;
|
2014-05-28 19:53:37 -07:00
|
|
|
if needs_termination {
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "</a>")?;
|
2014-05-28 19:53:37 -07:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2013-10-03 10:24:40 -07:00
|
|
|
/// Helper to render type parameters
|
2014-05-10 14:05:06 -07:00
|
|
|
fn tybounds(w: &mut fmt::Formatter,
|
2014-03-05 15:28:08 -08:00
|
|
|
typarams: &Option<Vec<clean::TyParamBound> >) -> fmt::Result {
|
2013-10-02 15:39:32 -07:00
|
|
|
match *typarams {
|
|
|
|
Some(ref params) => {
|
2015-01-31 12:20:46 -05:00
|
|
|
for param in params {
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(w, " + ")?;
|
|
|
|
write!(w, "{}", *param)?;
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
2014-01-30 11:30:21 -08:00
|
|
|
Ok(())
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
2014-01-30 11:30:21 -08:00
|
|
|
None => Ok(())
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for clean::Type {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
2014-12-27 19:42:27 -05:00
|
|
|
clean::Generic(ref name) => {
|
2015-02-01 21:53:25 -05:00
|
|
|
f.write_str(name)
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
2015-05-25 15:06:38 +02:00
|
|
|
clean::ResolvedPath{ did, ref typarams, ref path, is_generic } => {
|
|
|
|
// Paths like T::Output and Self::Output should be rendered with all segments
|
2016-03-22 22:01:37 -05:00
|
|
|
resolved_path(f, did, path, is_generic)?;
|
2014-05-11 11:14:14 -07:00
|
|
|
tybounds(f, typarams)
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-11-26 10:11:27 -05:00
|
|
|
clean::Infer => write!(f, "_"),
|
2014-06-21 03:39:03 -07:00
|
|
|
clean::Primitive(prim) => primitive_link(f, prim, prim.to_string()),
|
2013-09-18 22:18:38 -07:00
|
|
|
clean::BareFunction(ref decl) => {
|
2014-05-10 14:05:06 -07:00
|
|
|
write!(f, "{}{}fn{}{}",
|
2014-12-09 10:36:46 -05:00
|
|
|
UnsafetySpace(decl.unsafety),
|
2015-02-01 21:53:25 -05:00
|
|
|
match &*decl.abi {
|
2014-05-25 03:17:19 -07:00
|
|
|
"" => " extern ".to_string(),
|
|
|
|
"\"Rust\"" => "".to_string(),
|
2014-05-27 20:44:58 -07:00
|
|
|
s => format!(" extern {} ", s)
|
2013-09-18 22:18:38 -07:00
|
|
|
},
|
|
|
|
decl.generics,
|
2014-01-30 11:30:21 -08:00
|
|
|
decl.decl)
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
clean::Tuple(ref typs) => {
|
2016-01-22 23:15:47 +05:30
|
|
|
match &**typs {
|
|
|
|
[] => primitive_link(f, clean::PrimitiveTuple, "()"),
|
|
|
|
[ref one] => {
|
2016-03-22 22:01:37 -05:00
|
|
|
primitive_link(f, clean::PrimitiveTuple, "(")?;
|
|
|
|
write!(f, "{},", one)?;
|
2016-01-22 23:15:47 +05:30
|
|
|
primitive_link(f, clean::PrimitiveTuple, ")")
|
|
|
|
}
|
|
|
|
many => {
|
2016-03-22 22:01:37 -05:00
|
|
|
primitive_link(f, clean::PrimitiveTuple, "(")?;
|
|
|
|
write!(f, "{}", CommaSep(&many))?;
|
2016-01-22 23:15:47 +05:30
|
|
|
primitive_link(f, clean::PrimitiveTuple, ")")
|
|
|
|
}
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-05-28 19:53:37 -07:00
|
|
|
clean::Vector(ref t) => {
|
2016-03-22 22:01:37 -05:00
|
|
|
primitive_link(f, clean::Slice, &format!("["))?;
|
|
|
|
write!(f, "{}", t)?;
|
2016-01-22 23:15:47 +05:30
|
|
|
primitive_link(f, clean::Slice, &format!("]"))
|
2014-05-28 19:53:37 -07:00
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
clean::FixedVector(ref t, ref s) => {
|
2016-03-22 22:01:37 -05:00
|
|
|
primitive_link(f, clean::PrimitiveType::Array, "[")?;
|
|
|
|
write!(f, "{}", t)?;
|
2015-03-23 14:01:28 -07:00
|
|
|
primitive_link(f, clean::PrimitiveType::Array,
|
2016-01-22 23:15:47 +05:30
|
|
|
&format!("; {}]", *s))
|
2014-05-10 14:05:06 -07:00
|
|
|
}
|
2014-12-12 10:59:41 -08:00
|
|
|
clean::Bottom => f.write_str("!"),
|
2013-09-18 22:18:38 -07:00
|
|
|
clean::RawPointer(m, ref t) => {
|
2016-01-23 15:01:17 +05:30
|
|
|
match **t {
|
|
|
|
clean::Generic(_) | clean::ResolvedPath {is_generic: true, ..} => {
|
|
|
|
primitive_link(f, clean::PrimitiveType::PrimitiveRawPointer,
|
|
|
|
&format!("*{}{}", RawMutableSpace(m), t))
|
|
|
|
}
|
|
|
|
_ => {
|
2016-03-22 22:01:37 -05:00
|
|
|
primitive_link(f, clean::PrimitiveType::PrimitiveRawPointer,
|
2016-03-22 17:58:45 -05:00
|
|
|
&format!("*{}", RawMutableSpace(m)))?;
|
2016-01-23 15:01:17 +05:30
|
|
|
write!(f, "{}", t)
|
|
|
|
}
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
clean::BorrowedRef{ lifetime: ref l, mutability, type_: ref ty} => {
|
2014-05-16 10:45:16 -07:00
|
|
|
let lt = match *l {
|
|
|
|
Some(ref l) => format!("{} ", *l),
|
2014-05-25 03:17:19 -07:00
|
|
|
_ => "".to_string(),
|
2014-05-16 10:45:16 -07:00
|
|
|
};
|
2014-09-28 00:15:31 +08:00
|
|
|
let m = MutableSpace(mutability);
|
|
|
|
match **ty {
|
|
|
|
clean::Vector(ref bt) => { // BorrowedRef{ ... Vector(T) } is &[T]
|
|
|
|
match **bt {
|
|
|
|
clean::Generic(_) =>
|
|
|
|
primitive_link(f, clean::Slice,
|
2015-02-01 21:53:25 -05:00
|
|
|
&format!("&{}{}[{}]", lt, m, **bt)),
|
2014-09-28 00:15:31 +08:00
|
|
|
_ => {
|
2016-03-22 17:58:45 -05:00
|
|
|
primitive_link(f, clean::Slice, &format!("&{}{}[", lt, m))?;
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}", **bt)?;
|
2014-09-28 00:15:31 +08:00
|
|
|
primitive_link(f, clean::Slice, "]")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
write!(f, "&{}{}{}", lt, m, **ty)
|
|
|
|
}
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-12-16 08:50:52 -08:00
|
|
|
clean::PolyTraitRef(ref bounds) => {
|
|
|
|
for (i, bound) in bounds.iter().enumerate() {
|
|
|
|
if i != 0 {
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, " + ")?;
|
2014-12-16 08:50:52 -08:00
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}", *bound)?;
|
2014-12-16 08:50:52 -08:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
2015-04-07 00:16:35 -07:00
|
|
|
// It's pretty unsightly to look at `<A as B>::C` in output, and
|
|
|
|
// we've got hyperlinking on our side, so try to avoid longer
|
|
|
|
// notation as much as possible by making `C` a hyperlink to trait
|
|
|
|
// `B` to disambiguate.
|
|
|
|
//
|
|
|
|
// FIXME: this is still a lossy conversion and there should probably
|
|
|
|
// be a better way of representing this in general? Most of
|
|
|
|
// the ugliness comes from inlining across crates where
|
|
|
|
// everything comes in as a fully resolved QPath (hard to
|
|
|
|
// look at).
|
|
|
|
clean::QPath {
|
|
|
|
ref name,
|
|
|
|
ref self_type,
|
|
|
|
trait_: box clean::ResolvedPath { did, ref typarams, .. },
|
|
|
|
} => {
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}::", self_type)?;
|
2015-04-07 00:16:35 -07:00
|
|
|
let path = clean::Path::singleton(name.clone());
|
2016-03-22 22:01:37 -05:00
|
|
|
resolved_path(f, did, &path, false)?;
|
2015-04-07 00:16:35 -07:00
|
|
|
|
|
|
|
// FIXME: `typarams` are not rendered, and this seems bad?
|
|
|
|
drop(typarams);
|
|
|
|
Ok(())
|
|
|
|
}
|
2014-11-20 21:45:05 -08:00
|
|
|
clean::QPath { ref name, ref self_type, ref trait_ } => {
|
|
|
|
write!(f, "<{} as {}>::{}", self_type, trait_, name)
|
|
|
|
}
|
2014-10-01 01:42:04 +03:00
|
|
|
clean::Unique(..) => {
|
2014-10-09 15:17:22 -04:00
|
|
|
panic!("should have been cleaned")
|
2014-07-25 09:31:20 -07:00
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 01:11:08 +09:00
|
|
|
fn fmt_impl(i: &clean::Impl, f: &mut fmt::Formatter, link_trait: bool) -> fmt::Result {
|
|
|
|
write!(f, "impl{} ", i.generics)?;
|
|
|
|
if let Some(ref ty) = i.trait_ {
|
|
|
|
write!(f, "{}",
|
|
|
|
if i.polarity == Some(clean::ImplPolarity::Negative) { "!" } else { "" })?;
|
|
|
|
if link_trait {
|
|
|
|
write!(f, "{}", *ty)?;
|
|
|
|
} else {
|
|
|
|
write!(f, "{}", ty.trait_name().unwrap())?;
|
|
|
|
}
|
|
|
|
write!(f, " for ")?;
|
|
|
|
}
|
|
|
|
write!(f, "{}{}", i.for_, WhereClause(&i.generics))?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2015-07-18 02:02:57 -04:00
|
|
|
impl fmt::Display for clean::Impl {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2016-03-29 01:11:08 +09:00
|
|
|
fmt_impl(self, f, true)
|
2015-07-18 02:02:57 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 01:11:08 +09:00
|
|
|
// The difference from above is that trait is not hyperlinked.
|
|
|
|
pub fn fmt_impl_for_trait_page(i: &clean::Impl, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
fmt_impl(i, f, false)
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for clean::Arguments {
|
2014-02-13 06:41:34 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
for (i, input) in self.values.iter().enumerate() {
|
2016-03-22 22:01:37 -05:00
|
|
|
if i > 0 { write!(f, ", ")?; }
|
2015-03-24 16:54:09 -07:00
|
|
|
if !input.name.is_empty() {
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}: ", input.name)?;
|
2014-02-13 06:41:34 +11:00
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}", input.type_)?;
|
2014-02-13 06:41:34 +11:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for clean::FunctionRetTy {
|
2014-11-09 16:14:15 +01:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
|
|
|
clean::Return(clean::Tuple(ref tys)) if tys.is_empty() => Ok(()),
|
|
|
|
clean::Return(ref ty) => write!(f, " -> {}", ty),
|
2015-01-18 22:49:19 +09:00
|
|
|
clean::DefaultReturn => Ok(()),
|
2014-11-09 16:14:15 +01:00
|
|
|
clean::NoReturn => write!(f, " -> !")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for clean::FnDecl {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2015-08-20 18:27:53 +01:00
|
|
|
if self.variadic {
|
|
|
|
write!(f, "({args}, ...){arrow}", args = self.inputs, arrow = self.output)
|
|
|
|
} else {
|
|
|
|
write!(f, "({args}){arrow}", args = self.inputs, arrow = self.output)
|
|
|
|
}
|
2013-11-28 02:23:12 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl<'a> fmt::Display for Method<'a> {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let Method(selfty, d) = *self;
|
2014-05-22 16:57:53 -07:00
|
|
|
let mut args = String::new();
|
2013-09-18 22:18:38 -07:00
|
|
|
match *selfty {
|
|
|
|
clean::SelfStatic => {},
|
|
|
|
clean::SelfValue => args.push_str("self"),
|
2014-06-05 17:20:59 -07:00
|
|
|
clean::SelfBorrowed(Some(ref lt), mtbl) => {
|
2015-02-01 21:53:25 -05:00
|
|
|
args.push_str(&format!("&{} {}self", *lt, MutableSpace(mtbl)));
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-06-05 17:20:59 -07:00
|
|
|
clean::SelfBorrowed(None, mtbl) => {
|
2015-02-01 21:53:25 -05:00
|
|
|
args.push_str(&format!("&{}self", MutableSpace(mtbl)));
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-05-06 16:37:32 -07:00
|
|
|
clean::SelfExplicit(ref typ) => {
|
2015-02-01 21:53:25 -05:00
|
|
|
args.push_str(&format!("self: {}", *typ));
|
2014-05-06 16:37:32 -07:00
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-02-13 06:41:34 +11:00
|
|
|
for (i, input) in d.inputs.values.iter().enumerate() {
|
2015-03-24 16:54:09 -07:00
|
|
|
if i > 0 || !args.is_empty() { args.push_str(", "); }
|
|
|
|
if !input.name.is_empty() {
|
2015-02-01 21:53:25 -05:00
|
|
|
args.push_str(&format!("{}: ", input.name));
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2015-02-01 21:53:25 -05:00
|
|
|
args.push_str(&format!("{}", input.type_));
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-11-09 16:14:15 +01:00
|
|
|
write!(f, "({args}){arrow}", args = args, arrow = d.output)
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-25 06:08:11 +00:00
|
|
|
impl<'a> fmt::Display for VisSpace<'a> {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2016-03-25 06:08:11 +00:00
|
|
|
match *self.get() {
|
2016-04-11 08:15:14 +00:00
|
|
|
Some(clean::Public) => write!(f, "pub "),
|
|
|
|
Some(clean::Inherited) | None => Ok(())
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-23 20:38:17 -07:00
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for UnsafetySpace {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self.get() {
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::Unsafety::Unsafe => write!(f, "unsafe "),
|
|
|
|
hir::Unsafety::Normal => Ok(())
|
2013-09-23 20:38:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-24 13:56:52 -07:00
|
|
|
|
2015-02-25 22:05:07 +02:00
|
|
|
impl fmt::Display for ConstnessSpace {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self.get() {
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::Constness::Const => write!(f, "const "),
|
|
|
|
hir::Constness::NotConst => Ok(())
|
2015-02-25 22:05:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-21 11:56:00 -08:00
|
|
|
impl fmt::Display for clean::Import {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
2013-09-24 13:56:52 -07:00
|
|
|
clean::SimpleImport(ref name, ref src) => {
|
2016-03-29 01:11:08 +09:00
|
|
|
if *name == src.path.last_name() {
|
2014-05-10 14:05:06 -07:00
|
|
|
write!(f, "use {};", *src)
|
2013-09-24 13:56:52 -07:00
|
|
|
} else {
|
2014-08-18 08:29:44 -07:00
|
|
|
write!(f, "use {} as {};", *src, *name)
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
clean::GlobImport(ref src) => {
|
2014-05-10 14:05:06 -07:00
|
|
|
write!(f, "use {}::*;", *src)
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
|
|
|
clean::ImportList(ref src, ref names) => {
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "use {}::{{", *src)?;
|
2013-09-24 13:56:52 -07:00
|
|
|
for (i, n) in names.iter().enumerate() {
|
2014-01-30 11:30:21 -08:00
|
|
|
if i > 0 {
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, ", ")?;
|
2014-01-30 11:30:21 -08:00
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}", *n)?;
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
2014-05-28 09:24:28 -07:00
|
|
|
write!(f, "}};")
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for clean::ImportSource {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self.did {
|
2014-05-10 14:05:06 -07:00
|
|
|
Some(did) => resolved_path(f, did, &self.path, true),
|
2013-09-24 13:56:52 -07:00
|
|
|
_ => {
|
2014-02-05 23:55:13 +11:00
|
|
|
for (i, seg) in self.path.segments.iter().enumerate() {
|
2014-01-30 11:30:21 -08:00
|
|
|
if i > 0 {
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "::")?
|
2014-01-30 11:30:21 -08:00
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, "{}", seg.name)?;
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
2014-01-30 11:30:21 -08:00
|
|
|
Ok(())
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for clean::ViewListIdent {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self.source {
|
2014-05-09 13:52:17 -07:00
|
|
|
Some(did) => {
|
2015-04-07 00:16:35 -07:00
|
|
|
let path = clean::Path::singleton(self.name.clone());
|
2016-03-22 22:01:37 -05:00
|
|
|
resolved_path(f, did, &path, false)?;
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
2016-03-22 22:01:37 -05:00
|
|
|
_ => write!(f, "{}", self.name)?,
|
2015-07-31 22:20:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(ref name) = self.rename {
|
2016-03-22 22:01:37 -05:00
|
|
|
write!(f, " as {}", name)?;
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
2015-07-31 22:20:25 -07:00
|
|
|
Ok(())
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
|
|
|
}
|
2014-06-05 17:20:59 -07:00
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for clean::TypeBinding {
|
2015-01-07 16:10:40 -08:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "{}={}", self.name, self.ty)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for MutableSpace {
|
2014-06-05 17:20:59 -07:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
|
|
|
MutableSpace(clean::Immutable) => Ok(()),
|
|
|
|
MutableSpace(clean::Mutable) => write!(f, "mut "),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-26 11:37:39 -07:00
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
impl fmt::Display for RawMutableSpace {
|
2014-07-11 11:35:02 +02:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
|
|
|
RawMutableSpace(clean::Immutable) => write!(f, "const "),
|
|
|
|
RawMutableSpace(clean::Mutable) => write!(f, "mut "),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-07 14:22:55 -07:00
|
|
|
impl fmt::Display for AbiSpace {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self.0 {
|
|
|
|
Abi::Rust => Ok(()),
|
|
|
|
Abi::C => write!(f, "extern "),
|
|
|
|
abi => write!(f, "extern {} ", abi),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|