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
|
|
|
|
2016-11-29 08:15:16 +02:00
|
|
|
use rustc::hir::def_id::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
|
|
|
|
2016-08-23 18:48:10 -04:00
|
|
|
use clean::{self, PrimitiveType};
|
2016-04-17 08:54:48 +02:00
|
|
|
use core::DocAccessLevels;
|
2014-04-09 16:49:31 +09:00
|
|
|
use html::item_type::ItemType;
|
2016-05-03 13:31:12 +02:00
|
|
|
use html::escape::Escape;
|
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.
|
2016-10-17 09:55:18 -05:00
|
|
|
pub struct Method<'a>(pub &'a clean::FnDecl, pub usize);
|
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.
|
2016-10-17 09:55:18 -05:00
|
|
|
pub struct WhereClause<'a>(pub &'a clean::Generics, pub usize);
|
2014-09-25 02:01:42 -07:00
|
|
|
/// 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-04-25 08:24:50 +02:00
|
|
|
pub struct HRef<'a> {
|
|
|
|
pub did: DefId,
|
|
|
|
pub text: &'a str,
|
|
|
|
}
|
|
|
|
|
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, ", ")?; }
|
2016-09-26 16:02:21 -05:00
|
|
|
fmt::Display::fmt(item, f)?;
|
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-09-26 16:02:21 -05:00
|
|
|
fmt::Display::fmt(bound, f)?;
|
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-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
f.write_str("<")?;
|
|
|
|
} else {
|
|
|
|
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-09-26 16:02:21 -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-09-26 16:02:21 -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-09-26 16:02:21 -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-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
write!(f, ": {:#}", TyParamBounds(&tp.bounds))?;
|
|
|
|
} else {
|
|
|
|
write!(f, ": {}", TyParamBounds(&tp.bounds))?;
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2014-06-21 05:03:33 -07:00
|
|
|
|
2016-07-03 14:38:37 -07:00
|
|
|
if let Some(ref ty) = tp.default {
|
2016-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
write!(f, " = {:#}", ty)?;
|
|
|
|
} else {
|
|
|
|
write!(f, " = {}", ty)?;
|
|
|
|
}
|
2014-06-21 05:03:33 -07:00
|
|
|
};
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
2016-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
f.write_str(">")?;
|
|
|
|
} else {
|
|
|
|
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 {
|
2016-10-17 09:55:18 -05:00
|
|
|
let &WhereClause(gens, pad) = 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-10-13 10:17:25 -05:00
|
|
|
let mut clause = String::new();
|
2016-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
2016-10-13 10:17:25 -05:00
|
|
|
clause.push_str(" where ");
|
2016-09-26 16:02:21 -05:00
|
|
|
} else {
|
2017-01-21 15:34:11 +01:00
|
|
|
clause.push_str(" <span class='where fmt-newline'>where ");
|
2016-09-26 16:02:21 -05:00
|
|
|
}
|
2014-09-25 02:01:42 -07:00
|
|
|
for (i, pred) in gens.where_predicates.iter().enumerate() {
|
|
|
|
if i > 0 {
|
2016-10-13 10:17:25 -05:00
|
|
|
if f.alternate() {
|
|
|
|
clause.push_str(", ");
|
|
|
|
} else {
|
|
|
|
clause.push_str(",<br>");
|
|
|
|
}
|
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-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
2016-10-13 10:17:25 -05:00
|
|
|
clause.push_str(&format!("{:#}: {:#}", ty, TyParamBounds(bounds)));
|
2016-09-26 16:02:21 -05:00
|
|
|
} else {
|
2016-10-13 10:17:25 -05:00
|
|
|
clause.push_str(&format!("{}: {}", ty, TyParamBounds(bounds)));
|
2016-09-26 16:02:21 -05:00
|
|
|
}
|
2014-12-24 00:58:21 -08:00
|
|
|
}
|
2014-12-23 01:08:00 -08:00
|
|
|
&clean::WherePredicate::RegionPredicate { ref lifetime,
|
|
|
|
ref bounds } => {
|
2016-10-13 10:17:25 -05:00
|
|
|
clause.push_str(&format!("{}: ", lifetime));
|
2014-12-23 01:08:00 -08:00
|
|
|
for (i, lifetime) in bounds.iter().enumerate() {
|
|
|
|
if i > 0 {
|
2016-10-13 10:17:25 -05:00
|
|
|
clause.push_str(" + ");
|
2014-12-23 01:08:00 -08:00
|
|
|
}
|
|
|
|
|
2016-10-13 10:17:25 -05:00
|
|
|
clause.push_str(&format!("{}", 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-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
2016-10-13 10:17:25 -05:00
|
|
|
clause.push_str(&format!("{:#} == {:#}", lhs, rhs));
|
2016-09-26 16:02:21 -05:00
|
|
|
} else {
|
2016-10-13 10:17:25 -05:00
|
|
|
clause.push_str(&format!("{} == {}", lhs, rhs));
|
2016-09-26 16:02:21 -05:00
|
|
|
}
|
2014-12-23 01:08:00 -08:00
|
|
|
}
|
|
|
|
}
|
2014-09-25 02:01:42 -07:00
|
|
|
}
|
2016-09-26 16:02:21 -05:00
|
|
|
if !f.alternate() {
|
2016-10-13 13:58:04 -05:00
|
|
|
clause.push_str("</span>");
|
2016-10-13 10:17:25 -05:00
|
|
|
let plain = format!("{:#}", self);
|
2016-12-20 11:33:34 -06:00
|
|
|
if plain.len() + pad > 80 {
|
2017-01-21 15:34:11 +01:00
|
|
|
// break it onto its own line regardless, but make sure method impls and trait
|
|
|
|
// blocks keep their fixed padding (2 and 9, respectively)
|
2016-10-17 09:55:18 -05:00
|
|
|
let padding = if pad > 10 {
|
2016-10-15 10:29:47 -05:00
|
|
|
repeat(" ").take(8).collect::<String>()
|
|
|
|
} else {
|
2016-10-17 09:55:18 -05:00
|
|
|
repeat(" ").take(pad + 6).collect::<String>()
|
2016-10-15 10:29:47 -05:00
|
|
|
};
|
2016-10-13 10:17:25 -05:00
|
|
|
clause = clause.replace("<br>", &format!("<br>{}", padding));
|
|
|
|
} else {
|
|
|
|
clause = clause.replace("<br>", " ");
|
|
|
|
}
|
2016-09-26 16:02:21 -05:00
|
|
|
}
|
2016-10-13 10:17:25 -05:00
|
|
|
write!(f, "{}", clause)
|
2014-09-25 02:01:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
f.write_str("for<")?;
|
|
|
|
} else {
|
|
|
|
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-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
f.write_str("> ")?;
|
|
|
|
} else {
|
|
|
|
f.write_str("> ")?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if f.alternate() {
|
|
|
|
write!(f, "{:#}", self.trait_)
|
|
|
|
} else {
|
|
|
|
write!(f, "{}", self.trait_)
|
2014-12-16 08:50:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
};
|
2016-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
write!(f, "{}{:#}", modifier_str, *ty)
|
|
|
|
} else {
|
|
|
|
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-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
f.write_str("<")?;
|
|
|
|
} else {
|
|
|
|
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-09-26 16:02:21 -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-09-26 16:02:21 -05:00
|
|
|
f.write_str(", ")?;
|
2014-12-16 12:40:43 -08:00
|
|
|
}
|
|
|
|
comma = true;
|
2016-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
write!(f, "{:#}", *ty)?;
|
|
|
|
} else {
|
|
|
|
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-09-26 16:02:21 -05:00
|
|
|
f.write_str(", ")?;
|
2015-01-07 16:10:40 -08:00
|
|
|
}
|
|
|
|
comma = true;
|
2016-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
write!(f, "{:#}", *binding)?;
|
|
|
|
} else {
|
|
|
|
write!(f, "{}", *binding)?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if f.alternate() {
|
|
|
|
f.write_str(">")?;
|
|
|
|
} else {
|
|
|
|
f.write_str(">")?;
|
2015-01-07 16:10:40 -08:00
|
|
|
}
|
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-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
write!(f, "{:#}", *ty)?;
|
|
|
|
} else {
|
|
|
|
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-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
write!(f, " -> {:#}", ty)?;
|
|
|
|
} else {
|
|
|
|
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)?;
|
2016-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
write!(f, "{:#}", self.params)
|
|
|
|
} else {
|
|
|
|
write!(f, "{}", self.params)
|
|
|
|
}
|
2014-12-16 12:40:43 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
write!(f, "{:#}", seg)?;
|
|
|
|
} else {
|
|
|
|
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();
|
2016-04-24 14:11:26 +02:00
|
|
|
if !did.is_local() && !cache.access_levels.is_doc_reachable(did) {
|
|
|
|
return None
|
|
|
|
}
|
|
|
|
|
2015-04-06 17:56:35 -07:00
|
|
|
let loc = CURRENT_LOCATION_KEY.with(|l| l.borrow().clone());
|
2016-07-09 14:07:37 +01:00
|
|
|
let (fqp, shortty, mut url) = match cache.paths.get(&did) {
|
|
|
|
Some(&(ref fqp, shortty)) => {
|
|
|
|
(fqp, shortty, repeat("../").take(loc.len()).collect())
|
|
|
|
}
|
|
|
|
None => match cache.external_paths.get(&did) {
|
|
|
|
Some(&(ref fqp, shortty)) => {
|
|
|
|
(fqp, shortty, match cache.extern_locations[&did.krate] {
|
2016-11-29 08:15:16 +02:00
|
|
|
(.., render::Remote(ref s)) => s.to_string(),
|
|
|
|
(.., render::Local) => repeat("../").take(loc.len()).collect(),
|
|
|
|
(.., render::Unknown) => return None,
|
2016-07-09 14:07:37 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
None => 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");
|
|
|
|
}
|
|
|
|
_ => {
|
2016-08-03 13:14:59 +12:00
|
|
|
url.push_str(shortty.css_class());
|
2015-04-06 17:56:35 -07:00
|
|
|
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,
|
2016-12-15 23:13:00 -08:00
|
|
|
print_all: bool, use_absolute: 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] {
|
2016-09-26 16:02:21 -05:00
|
|
|
if "super" == seg.name || "self" == seg.name || w.alternate() {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-26 16:02:21 -05:00
|
|
|
if w.alternate() {
|
|
|
|
write!(w, "{:#}{:#}", HRef::new(did, &last.name), last.params)?;
|
|
|
|
} else {
|
2016-12-15 23:13:00 -08:00
|
|
|
let path = if use_absolute {
|
|
|
|
match href(did) {
|
|
|
|
Some((_, _, fqp)) => format!("{}::{}",
|
|
|
|
fqp[..fqp.len()-1].join("::"),
|
|
|
|
HRef::new(did, fqp.last().unwrap())),
|
|
|
|
None => format!("{}", HRef::new(did, &last.name)),
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
format!("{}", HRef::new(did, &last.name))
|
|
|
|
};
|
|
|
|
write!(w, "{}{}", path, last.params)?;
|
2016-09-26 16:02:21 -05:00
|
|
|
}
|
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;
|
2016-09-26 16:02:21 -05:00
|
|
|
if !f.alternate() {
|
|
|
|
match m.primitive_locations.get(&prim) {
|
2016-11-29 08:15:16 +02:00
|
|
|
Some(&def_id) if def_id.is_local() => {
|
2016-09-26 16:02:21 -05:00
|
|
|
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
|
|
|
|
let len = if len == 0 {0} else {len - 1};
|
|
|
|
write!(f, "<a class='primitive' href='{}primitive.{}.html'>",
|
|
|
|
repeat("../").take(len).collect::<String>(),
|
2016-07-03 14:38:37 -07:00
|
|
|
prim.to_url_str())?;
|
|
|
|
needs_termination = true;
|
2014-05-28 19:53:37 -07:00
|
|
|
}
|
2016-11-29 08:15:16 +02:00
|
|
|
Some(&def_id) => {
|
|
|
|
let loc = match m.extern_locations[&def_id.krate] {
|
|
|
|
(ref cname, _, render::Remote(ref s)) => {
|
|
|
|
Some((cname, s.to_string()))
|
|
|
|
}
|
|
|
|
(ref cname, _, render::Local) => {
|
2016-09-26 16:02:21 -05:00
|
|
|
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
|
|
|
|
Some((cname, repeat("../").take(len).collect::<String>()))
|
|
|
|
}
|
2016-11-29 08:15:16 +02:00
|
|
|
(.., render::Unknown) => None,
|
2016-09-26 16:02:21 -05:00
|
|
|
};
|
|
|
|
if let Some((cname, root)) = loc {
|
|
|
|
write!(f, "<a class='primitive' href='{}{}/primitive.{}.html'>",
|
|
|
|
root,
|
|
|
|
cname,
|
|
|
|
prim.to_url_str())?;
|
|
|
|
needs_termination = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => {}
|
2014-05-28 19:53:37 -07:00
|
|
|
}
|
|
|
|
}
|
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, " + ")?;
|
2016-09-26 16:02:21 -05:00
|
|
|
fmt::Display::fmt(param, w)?;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-25 08:24:50 +02:00
|
|
|
impl<'a> HRef<'a> {
|
|
|
|
pub fn new(did: DefId, text: &'a str) -> HRef<'a> {
|
|
|
|
HRef { did: did, text: text }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> fmt::Display for HRef<'a> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match href(self.did) {
|
2016-09-26 16:02:21 -05:00
|
|
|
Some((url, shortty, fqp)) => if !f.alternate() {
|
2016-04-25 08:24:50 +02:00
|
|
|
write!(f, "<a class='{}' href='{}' title='{}'>{}</a>",
|
|
|
|
shortty, url, fqp.join("::"), self.text)
|
2016-09-26 16:02:21 -05:00
|
|
|
} else {
|
|
|
|
write!(f, "{}", self.text)
|
|
|
|
},
|
2016-04-25 08:24:50 +02:00
|
|
|
_ => write!(f, "{}", self.text),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-22 23:20:22 -08:00
|
|
|
fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt::Result {
|
2016-12-15 23:13:00 -08:00
|
|
|
match *t {
|
|
|
|
clean::Generic(ref name) => {
|
|
|
|
f.write_str(name)
|
|
|
|
}
|
|
|
|
clean::ResolvedPath{ did, ref typarams, ref path, is_generic } => {
|
|
|
|
// Paths like T::Output and Self::Output should be rendered with all segments
|
2016-12-22 23:20:22 -08:00
|
|
|
resolved_path(f, did, path, is_generic, use_absolute)?;
|
2016-12-15 23:13:00 -08:00
|
|
|
tybounds(f, typarams)
|
|
|
|
}
|
|
|
|
clean::Infer => write!(f, "_"),
|
|
|
|
clean::Primitive(prim) => primitive_link(f, prim, prim.as_str()),
|
|
|
|
clean::BareFunction(ref decl) => {
|
|
|
|
if f.alternate() {
|
|
|
|
write!(f, "{}{}fn{:#}{:#}",
|
|
|
|
UnsafetySpace(decl.unsafety),
|
|
|
|
AbiSpace(decl.abi),
|
|
|
|
decl.generics,
|
|
|
|
decl.decl)
|
|
|
|
} else {
|
|
|
|
write!(f, "{}{}fn{}{}",
|
|
|
|
UnsafetySpace(decl.unsafety),
|
|
|
|
AbiSpace(decl.abi),
|
|
|
|
decl.generics,
|
|
|
|
decl.decl)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clean::Tuple(ref typs) => {
|
|
|
|
match &typs[..] {
|
|
|
|
&[] => primitive_link(f, PrimitiveType::Tuple, "()"),
|
|
|
|
&[ref one] => {
|
|
|
|
primitive_link(f, PrimitiveType::Tuple, "(")?;
|
|
|
|
//carry f.alternate() into this display w/o branching manually
|
|
|
|
fmt::Display::fmt(one, f)?;
|
|
|
|
primitive_link(f, PrimitiveType::Tuple, ",)")
|
2016-09-26 16:02:21 -05:00
|
|
|
}
|
2016-12-15 23:13:00 -08:00
|
|
|
many => {
|
|
|
|
primitive_link(f, PrimitiveType::Tuple, "(")?;
|
|
|
|
fmt::Display::fmt(&CommaSep(&many), f)?;
|
|
|
|
primitive_link(f, PrimitiveType::Tuple, ")")
|
2016-01-22 23:15:47 +05:30
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2016-12-15 23:13:00 -08:00
|
|
|
}
|
|
|
|
clean::Vector(ref t) => {
|
|
|
|
primitive_link(f, PrimitiveType::Slice, &format!("["))?;
|
|
|
|
fmt::Display::fmt(t, f)?;
|
|
|
|
primitive_link(f, PrimitiveType::Slice, &format!("]"))
|
|
|
|
}
|
|
|
|
clean::FixedVector(ref t, ref s) => {
|
|
|
|
primitive_link(f, PrimitiveType::Array, "[")?;
|
|
|
|
fmt::Display::fmt(t, f)?;
|
|
|
|
if f.alternate() {
|
|
|
|
primitive_link(f, PrimitiveType::Array,
|
|
|
|
&format!("; {}]", s))
|
|
|
|
} else {
|
|
|
|
primitive_link(f, PrimitiveType::Array,
|
|
|
|
&format!("; {}]", Escape(s)))
|
2014-05-10 14:05:06 -07:00
|
|
|
}
|
2016-12-15 23:13:00 -08:00
|
|
|
}
|
|
|
|
clean::Never => f.write_str("!"),
|
|
|
|
clean::RawPointer(m, ref t) => {
|
|
|
|
match **t {
|
|
|
|
clean::Generic(_) | clean::ResolvedPath {is_generic: true, ..} => {
|
|
|
|
if f.alternate() {
|
2016-08-23 18:51:56 -04:00
|
|
|
primitive_link(f, clean::PrimitiveType::RawPointer,
|
2016-12-15 23:13:00 -08:00
|
|
|
&format!("*{}{:#}", RawMutableSpace(m), t))
|
|
|
|
} else {
|
|
|
|
primitive_link(f, clean::PrimitiveType::RawPointer,
|
|
|
|
&format!("*{}{}", RawMutableSpace(m), t))
|
2016-01-23 15:01:17 +05:30
|
|
|
}
|
|
|
|
}
|
2016-12-15 23:13:00 -08:00
|
|
|
_ => {
|
|
|
|
primitive_link(f, clean::PrimitiveType::RawPointer,
|
|
|
|
&format!("*{}", RawMutableSpace(m)))?;
|
|
|
|
fmt::Display::fmt(t, f)
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2016-12-15 23:13:00 -08:00
|
|
|
}
|
|
|
|
clean::BorrowedRef{ lifetime: ref l, mutability, type_: ref ty} => {
|
|
|
|
let lt = match *l {
|
|
|
|
Some(ref l) => format!("{} ", *l),
|
|
|
|
_ => "".to_string(),
|
|
|
|
};
|
|
|
|
let m = MutableSpace(mutability);
|
|
|
|
match **ty {
|
|
|
|
clean::Vector(ref bt) => { // BorrowedRef{ ... Vector(T) } is &[T]
|
|
|
|
match **bt {
|
|
|
|
clean::Generic(_) =>
|
|
|
|
if f.alternate() {
|
|
|
|
primitive_link(f, PrimitiveType::Slice,
|
|
|
|
&format!("&{}{}[{:#}]", lt, m, **bt))
|
|
|
|
} else {
|
|
|
|
primitive_link(f, PrimitiveType::Slice,
|
|
|
|
&format!("&{}{}[{}]", lt, m, **bt))
|
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
if f.alternate() {
|
|
|
|
primitive_link(f, PrimitiveType::Slice,
|
|
|
|
&format!("&{}{}[", lt, m))?;
|
|
|
|
write!(f, "{:#}", **bt)?;
|
|
|
|
} else {
|
|
|
|
primitive_link(f, PrimitiveType::Slice,
|
|
|
|
&format!("&{}{}[", lt, m))?;
|
|
|
|
write!(f, "{}", **bt)?;
|
2014-09-28 00:15:31 +08:00
|
|
|
}
|
2016-12-15 23:13:00 -08:00
|
|
|
primitive_link(f, PrimitiveType::Slice, "]")
|
2016-09-26 16:02:21 -05:00
|
|
|
}
|
2014-09-28 00:15:31 +08:00
|
|
|
}
|
|
|
|
}
|
2016-12-15 23:13:00 -08:00
|
|
|
_ => {
|
2016-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
2016-12-15 23:13:00 -08:00
|
|
|
write!(f, "&{}{}{:#}", lt, m, **ty)
|
2016-09-26 16:02:21 -05:00
|
|
|
} else {
|
2016-12-15 23:13:00 -08:00
|
|
|
write!(f, "&{}{}{}", lt, m, **ty)
|
2016-09-26 16:02:21 -05:00
|
|
|
}
|
2014-12-16 08:50:52 -08:00
|
|
|
}
|
|
|
|
}
|
2016-12-15 23:13:00 -08:00
|
|
|
}
|
|
|
|
clean::ImplTrait(ref bounds) => {
|
|
|
|
write!(f, "impl ")?;
|
|
|
|
for (i, bound) in bounds.iter().enumerate() {
|
|
|
|
if i != 0 {
|
|
|
|
write!(f, " + ")?;
|
|
|
|
}
|
2016-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
2016-12-15 23:13:00 -08:00
|
|
|
write!(f, "{:#}", *bound)?;
|
2016-09-26 16:02:21 -05:00
|
|
|
} else {
|
2016-12-15 23:13:00 -08:00
|
|
|
write!(f, "{}", *bound)?;
|
2016-09-26 16:02:21 -05:00
|
|
|
}
|
2014-11-20 21:45:05 -08:00
|
|
|
}
|
2016-12-15 23:13:00 -08:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
// 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, .. },
|
|
|
|
} => {
|
|
|
|
if f.alternate() {
|
|
|
|
write!(f, "{:#}::", self_type)?;
|
|
|
|
} else {
|
|
|
|
write!(f, "{}::", self_type)?;
|
|
|
|
}
|
|
|
|
let path = clean::Path::singleton(name.clone());
|
2016-12-22 23:20:22 -08:00
|
|
|
resolved_path(f, did, &path, true, use_absolute)?;
|
2016-12-15 23:13:00 -08:00
|
|
|
|
|
|
|
// FIXME: `typarams` are not rendered, and this seems bad?
|
|
|
|
drop(typarams);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
clean::QPath { ref name, ref self_type, ref trait_ } => {
|
|
|
|
if f.alternate() {
|
|
|
|
write!(f, "<{:#} as {:#}>::{}", self_type, trait_, name)
|
|
|
|
} else {
|
|
|
|
write!(f, "<{} as {}>::{}", self_type, trait_, name)
|
2014-07-25 09:31:20 -07:00
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2016-12-15 23:13:00 -08:00
|
|
|
clean::Unique(..) => {
|
|
|
|
panic!("should have been cleaned")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for clean::Type {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
fmt_type(self, f, false)
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-22 23:20:22 -08:00
|
|
|
fn fmt_impl(i: &clean::Impl,
|
|
|
|
f: &mut fmt::Formatter,
|
|
|
|
link_trait: bool,
|
|
|
|
use_absolute: bool) -> fmt::Result {
|
2016-10-15 09:46:43 -05:00
|
|
|
let mut plain = String::new();
|
|
|
|
|
2016-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
write!(f, "impl{:#} ", i.generics)?;
|
|
|
|
} else {
|
|
|
|
write!(f, "impl{} ", i.generics)?;
|
|
|
|
}
|
2016-10-15 09:46:43 -05:00
|
|
|
plain.push_str(&format!("impl{:#} ", i.generics));
|
|
|
|
|
2016-03-29 01:11:08 +09:00
|
|
|
if let Some(ref ty) = i.trait_ {
|
2016-10-15 09:46:43 -05:00
|
|
|
if i.polarity == Some(clean::ImplPolarity::Negative) {
|
|
|
|
write!(f, "!")?;
|
|
|
|
plain.push_str("!");
|
|
|
|
}
|
|
|
|
|
2016-03-29 01:11:08 +09:00
|
|
|
if link_trait {
|
2016-09-26 16:02:21 -05:00
|
|
|
fmt::Display::fmt(ty, f)?;
|
2016-10-15 09:46:43 -05:00
|
|
|
plain.push_str(&format!("{:#}", ty));
|
2016-03-29 01:11:08 +09:00
|
|
|
} else {
|
2016-05-12 18:23:11 +01:00
|
|
|
match *ty {
|
2016-12-15 23:13:00 -08:00
|
|
|
clean::ResolvedPath { typarams: None, ref path, is_generic: false, .. } => {
|
2016-05-12 18:23:11 +01:00
|
|
|
let last = path.segments.last().unwrap();
|
2016-09-26 16:02:21 -05:00
|
|
|
fmt::Display::fmt(&last.name, f)?;
|
|
|
|
fmt::Display::fmt(&last.params, f)?;
|
2016-10-15 09:46:43 -05:00
|
|
|
plain.push_str(&format!("{:#}{:#}", last.name, last.params));
|
2016-05-12 18:23:11 +01:00
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
2016-03-29 01:11:08 +09:00
|
|
|
}
|
|
|
|
write!(f, " for ")?;
|
2016-10-15 09:46:43 -05:00
|
|
|
plain.push_str(" for ");
|
2016-03-29 01:11:08 +09:00
|
|
|
}
|
2016-10-15 09:46:43 -05:00
|
|
|
|
2016-12-22 23:20:22 -08:00
|
|
|
fmt_type(&i.for_, f, use_absolute)?;
|
2016-10-15 09:46:43 -05:00
|
|
|
plain.push_str(&format!("{:#}", i.for_));
|
|
|
|
|
2016-10-17 09:55:18 -05:00
|
|
|
fmt::Display::fmt(&WhereClause(&i.generics, plain.len() + 1), f)?;
|
2016-03-29 01:11:08 +09:00
|
|
|
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-12-15 23:13:00 -08:00
|
|
|
fmt_impl(self, f, true, false)
|
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.
|
2016-12-15 23:13:00 -08:00
|
|
|
pub fn fmt_impl_for_trait_page(i: &clean::Impl,
|
|
|
|
f: &mut fmt::Formatter,
|
2016-12-22 23:20:22 -08:00
|
|
|
use_absolute: bool) -> fmt::Result {
|
|
|
|
fmt_impl(i, f, false, use_absolute)
|
2016-03-29 01:11:08 +09:00
|
|
|
}
|
|
|
|
|
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() {
|
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-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
write!(f, "{:#}", input.type_)?;
|
|
|
|
} else {
|
|
|
|
write!(f, "{}", input.type_)?;
|
|
|
|
}
|
2016-09-26 18:47:09 -05:00
|
|
|
if i + 1 < self.values.len() { write!(f, ", ")?; }
|
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(()),
|
2016-09-26 16:02:21 -05:00
|
|
|
clean::Return(ref ty) if f.alternate() => write!(f, " -> {:#}", ty),
|
2014-11-09 16:14:15 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2016-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
write!(f, "({args:#}, ...){arrow:#}", args = self.inputs, arrow = self.output)
|
|
|
|
} else {
|
|
|
|
write!(f, "({args}, ...){arrow}", args = self.inputs, arrow = self.output)
|
|
|
|
}
|
2015-08-20 18:27:53 +01:00
|
|
|
} else {
|
2016-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
write!(f, "({args:#}){arrow:#}", args = self.inputs, arrow = self.output)
|
|
|
|
} else {
|
|
|
|
write!(f, "({args}){arrow}", args = self.inputs, arrow = self.output)
|
|
|
|
}
|
2015-08-20 18:27:53 +01:00
|
|
|
}
|
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 {
|
2016-05-08 21:19:29 +03:00
|
|
|
let decl = self.0;
|
2016-09-26 16:02:21 -05:00
|
|
|
let indent = self.1;
|
|
|
|
let amp = if f.alternate() { "&" } else { "&" };
|
2014-05-22 16:57:53 -07:00
|
|
|
let mut args = String::new();
|
2016-09-26 16:02:21 -05:00
|
|
|
let mut args_plain = String::new();
|
2016-05-08 21:19:29 +03:00
|
|
|
for (i, input) in decl.inputs.values.iter().enumerate() {
|
|
|
|
if let Some(selfty) = input.to_self() {
|
|
|
|
match selfty {
|
2016-09-26 16:02:21 -05:00
|
|
|
clean::SelfValue => {
|
|
|
|
args.push_str("self");
|
|
|
|
args_plain.push_str("self");
|
|
|
|
}
|
2016-05-08 21:19:29 +03:00
|
|
|
clean::SelfBorrowed(Some(ref lt), mtbl) => {
|
2016-09-26 18:47:09 -05:00
|
|
|
args.push_str(&format!("{}{} {}self", amp, *lt, MutableSpace(mtbl)));
|
|
|
|
args_plain.push_str(&format!("&{} {}self", *lt, MutableSpace(mtbl)));
|
2016-05-08 21:19:29 +03:00
|
|
|
}
|
|
|
|
clean::SelfBorrowed(None, mtbl) => {
|
2016-09-26 18:47:09 -05:00
|
|
|
args.push_str(&format!("{}{}self", amp, MutableSpace(mtbl)));
|
|
|
|
args_plain.push_str(&format!("&{}self", MutableSpace(mtbl)));
|
2016-05-08 21:19:29 +03:00
|
|
|
}
|
|
|
|
clean::SelfExplicit(ref typ) => {
|
2016-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
args.push_str(&format!("self: {:#}", *typ));
|
|
|
|
} else {
|
|
|
|
args.push_str(&format!("self: {}", *typ));
|
|
|
|
}
|
|
|
|
args_plain.push_str(&format!("self: {:#}", *typ));
|
2016-05-08 21:19:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2016-09-26 16:02:21 -05:00
|
|
|
if i > 0 {
|
2016-09-26 18:47:09 -05:00
|
|
|
args.push_str("<br> ");
|
|
|
|
args_plain.push_str(" ");
|
2016-09-26 16:02:21 -05:00
|
|
|
}
|
2016-05-08 21:19:29 +03:00
|
|
|
if !input.name.is_empty() {
|
|
|
|
args.push_str(&format!("{}: ", input.name));
|
2016-09-26 16:02:21 -05:00
|
|
|
args_plain.push_str(&format!("{}: ", input.name));
|
2016-05-08 21:19:29 +03:00
|
|
|
}
|
2016-09-26 18:47:09 -05:00
|
|
|
|
2016-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
args.push_str(&format!("{:#}", input.type_));
|
|
|
|
} else {
|
|
|
|
args.push_str(&format!("{}", input.type_));
|
|
|
|
}
|
|
|
|
args_plain.push_str(&format!("{:#}", input.type_));
|
|
|
|
}
|
|
|
|
if i + 1 < decl.inputs.values.len() {
|
|
|
|
args.push_str(",");
|
|
|
|
args_plain.push_str(",");
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
2016-09-26 16:02:21 -05:00
|
|
|
|
2016-09-26 18:47:09 -05:00
|
|
|
if decl.variadic {
|
|
|
|
args.push_str(",<br> ...");
|
|
|
|
args_plain.push_str(", ...");
|
|
|
|
}
|
|
|
|
|
2016-09-26 16:02:21 -05:00
|
|
|
let arrow_plain = format!("{:#}", decl.output);
|
|
|
|
let arrow = if f.alternate() {
|
|
|
|
format!("{:#}", decl.output)
|
|
|
|
} else {
|
|
|
|
format!("{}", decl.output)
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut output: String;
|
|
|
|
let plain: String;
|
2016-10-17 09:55:18 -05:00
|
|
|
let pad = repeat(" ").take(indent).collect::<String>();
|
2016-09-26 16:02:21 -05:00
|
|
|
if arrow.is_empty() {
|
|
|
|
output = format!("({})", args);
|
2016-10-17 09:55:18 -05:00
|
|
|
plain = format!("{}({})", pad, args_plain);
|
2016-09-26 16:02:21 -05:00
|
|
|
} else {
|
2016-09-26 18:47:09 -05:00
|
|
|
output = format!("({args})<br>{arrow}", args = args, arrow = arrow);
|
2016-10-17 09:55:18 -05:00
|
|
|
plain = format!("{pad}({args}){arrow}",
|
|
|
|
pad = pad,
|
2016-09-26 18:47:09 -05:00
|
|
|
args = args_plain,
|
|
|
|
arrow = arrow_plain);
|
2016-09-26 16:02:21 -05:00
|
|
|
}
|
|
|
|
|
2016-09-26 18:47:09 -05:00
|
|
|
if plain.len() > 80 {
|
2016-10-17 09:55:18 -05:00
|
|
|
let pad = repeat(" ").take(indent).collect::<String>();
|
|
|
|
let pad = format!("<br>{}", pad);
|
2016-09-26 18:47:09 -05:00
|
|
|
output = output.replace("<br>", &pad);
|
2016-09-26 16:02:21 -05:00
|
|
|
} else {
|
2016-09-26 18:47:09 -05:00
|
|
|
output = output.replace("<br>", "");
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2016-10-15 09:46:43 -05:00
|
|
|
if f.alternate() {
|
|
|
|
write!(f, "{}", output.replace("<br>", "\n"))
|
|
|
|
} else {
|
|
|
|
write!(f, "{}", 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 {
|
2016-10-01 17:35:53 -04:00
|
|
|
clean::Import::Simple(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
|
|
|
}
|
|
|
|
}
|
2016-10-01 17:35:53 -04:00
|
|
|
clean::Import::Glob(ref src) => {
|
2014-05-10 14:05:06 -07:00
|
|
|
write!(f, "use {}::*;", *src)
|
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 {
|
2016-12-15 23:13:00 -08:00
|
|
|
Some(did) => resolved_path(f, did, &self.path, true, false),
|
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::TypeBinding {
|
2015-01-07 16:10:40 -08:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2016-09-26 16:02:21 -05:00
|
|
|
if f.alternate() {
|
|
|
|
write!(f, "{}={:#}", self.name, self.ty)
|
|
|
|
} else {
|
|
|
|
write!(f, "{}={}", self.name, self.ty)
|
|
|
|
}
|
2015-01-07 16:10:40 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2016-09-26 16:02:21 -05:00
|
|
|
let quot = if f.alternate() { "\"" } else { """ };
|
2015-04-07 14:22:55 -07:00
|
|
|
match self.0 {
|
|
|
|
Abi::Rust => Ok(()),
|
|
|
|
Abi::C => write!(f, "extern "),
|
2016-09-26 16:02:21 -05:00
|
|
|
abi => write!(f, "extern {0}{1}{0} ", quot, abi.name()),
|
2015-04-07 14:22:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|