();
+ let mut indent = prefix.len();
+ let where_indent = if parent == ItemType::Trait {
+ indent += 4;
+ 8
+ } else if parent == ItemType::Impl {
+ 2
+ } else {
+ let prefix = prefix + &format!("{:#}", Method(d, indent));
+ prefix.lines().last().unwrap().len() + 1
+ };
write!(w, "{}{}{}fn {name}\
{generics}{decl}{where_clause}",
ConstnessSpace(vis_constness),
@@ -2269,19 +2287,18 @@ fn render_assoc_item(w: &mut fmt::Formatter,
href = href,
name = name,
generics = *g,
- decl = Method(d, &indent),
- where_clause = WhereClause(g))
+ decl = Method(d, indent),
+ where_clause = WhereClause(g, where_indent))
}
match item.inner {
clean::StrippedItem(..) => Ok(()),
clean::TyMethodItem(ref m) => {
method(w, item, m.unsafety, hir::Constness::NotConst,
- m.abi, &m.generics, &m.decl, link)
+ m.abi, &m.generics, &m.decl, link, parent)
}
clean::MethodItem(ref m) => {
method(w, item, m.unsafety, m.constness,
- m.abi, &m.generics, &m.decl,
- link)
+ m.abi, &m.generics, &m.decl, link, parent)
}
clean::AssociatedConstItem(ref ty, ref default) => {
assoc_const(w, item, ty, default.as_ref(), link)
@@ -2378,11 +2395,15 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
e: &clean::Enum) -> fmt::Result {
write!(w, "")?;
render_attributes(w, it)?;
+ let padding = format!("{}enum {}{:#} ",
+ VisSpace(&it.visibility),
+ it.name.as_ref().unwrap(),
+ e.generics).len();
write!(w, "{}enum {}{}{}",
VisSpace(&it.visibility),
it.name.as_ref().unwrap(),
e.generics,
- WhereClause(&e.generics))?;
+ WhereClause(&e.generics, padding))?;
if e.variants.is_empty() && !e.variants_stripped {
write!(w, " {{}}")?;
} else {
@@ -2517,17 +2538,23 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
fields: &[clean::Item],
tab: &str,
structhead: bool) -> fmt::Result {
+ let mut plain = String::new();
write!(w, "{}{}{}",
VisSpace(&it.visibility),
if structhead {"struct "} else {""},
it.name.as_ref().unwrap())?;
+ plain.push_str(&format!("{}{}{}",
+ VisSpace(&it.visibility),
+ if structhead {"struct "} else {""},
+ it.name.as_ref().unwrap()));
if let Some(g) = g {
+ plain.push_str(&format!("{:#}", g));
write!(w, "{}", g)?
}
match ty {
doctree::Plain => {
if let Some(g) = g {
- write!(w, "{}", WhereClause(g))?
+ write!(w, "{}", WhereClause(g, plain.len() + 1))?
}
let mut has_visible_fields = false;
write!(w, " {{")?;
@@ -2556,30 +2583,35 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
}
doctree::Tuple => {
write!(w, "(")?;
+ plain.push_str("(");
for (i, field) in fields.iter().enumerate() {
if i > 0 {
write!(w, ", ")?;
+ plain.push_str(", ");
}
match field.inner {
clean::StrippedItem(box clean::StructFieldItem(..)) => {
+ plain.push_str("_");
write!(w, "_")?
}
clean::StructFieldItem(ref ty) => {
+ plain.push_str(&format!("{}{:#}", VisSpace(&field.visibility), *ty));
write!(w, "{}{}", VisSpace(&field.visibility), *ty)?
}
_ => unreachable!()
}
}
write!(w, ")")?;
+ plain.push_str(")");
if let Some(g) = g {
- write!(w, "{}", WhereClause(g))?
+ write!(w, "{}", WhereClause(g, plain.len() + 1))?
}
write!(w, ";")?;
}
doctree::Unit => {
// Needed for PhantomData.
if let Some(g) = g {
- write!(w, "{}", WhereClause(g))?
+ write!(w, "{}", WhereClause(g, plain.len() + 1))?
}
write!(w, ";")?;
}
@@ -2592,13 +2624,19 @@ fn render_union(w: &mut fmt::Formatter, it: &clean::Item,
fields: &[clean::Item],
tab: &str,
structhead: bool) -> fmt::Result {
+ let mut plain = String::new();
write!(w, "{}{}{}",
VisSpace(&it.visibility),
if structhead {"union "} else {""},
it.name.as_ref().unwrap())?;
+ plain.push_str(&format!("{}{}{}",
+ VisSpace(&it.visibility),
+ if structhead {"union "} else {""},
+ it.name.as_ref().unwrap()));
if let Some(g) = g {
write!(w, "{}", g)?;
- write!(w, "{}", WhereClause(g))?;
+ plain.push_str(&format!("{:#}", g));
+ write!(w, "{}", WhereClause(g, plain.len() + 1))?;
}
write!(w, " {{\n{}", tab)?;
@@ -2789,7 +2827,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
write!(w, "", id, item_type)?;
write!(w, "", ns_id)?;
write!(w, "")?;
- render_assoc_item(w, item, link.anchor(&id))?;
+ render_assoc_item(w, item, link.anchor(&id), ItemType::Impl)?;
write!(w, "")?;
render_stability_since_raw(w, item.stable_since(), outer_version)?;
write!(w, "
\n")?;
@@ -2899,10 +2937,11 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
fn item_typedef(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
t: &clean::Typedef) -> fmt::Result {
+ let indent = format!("type {}{:#} ", it.name.as_ref().unwrap(), t.generics).len();
write!(w, "type {}{}{where_clause} = {type_};",
it.name.as_ref().unwrap(),
t.generics,
- where_clause = WhereClause(&t.generics),
+ where_clause = WhereClause(&t.generics, indent),
type_ = t.type_)?;
document(w, cx, it)
diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css
index f8133ea49ceba..3b6ffa4a462f6 100644
--- a/src/librustdoc/html/static/rustdoc.css
+++ b/src/librustdoc/html/static/rustdoc.css
@@ -361,9 +361,17 @@ h4 > code, h3 > code, .invisible > code {
position: relative;
}
/* Shift "where ..." part of method or fn definition down a line */
-.content .method .where, .content .fn .where { display: block; }
+.content .method .where,
+.content .fn .where,
+.content .where.fmt-newline {
+ display: block;
+}
/* Bit of whitespace to indent it */
-.content .method .where::before, .content .fn .where::before { content: ' '; }
+.content .method .where::before,
+.content .fn .where::before,
+.content .where.fmt-newline::before {
+ content: ' ';
+}
.content .methods > div { margin-left: 40px; }
diff --git a/src/test/rustdoc/line-breaks.rs b/src/test/rustdoc/line-breaks.rs
index cc608a2447574..a1eabb515a5ce 100644
--- a/src/test/rustdoc/line-breaks.rs
+++ b/src/test/rustdoc/line-breaks.rs
@@ -10,6 +10,9 @@
#![crate_name = "foo"]
+use std::ops::Add;
+use std::fmt::Display;
+
//@count foo/fn.function_with_a_really_long_name.html //pre/br 2
pub fn function_with_a_really_long_name(parameter_one: i32,
parameter_two: i32)
@@ -19,3 +22,19 @@ pub fn function_with_a_really_long_name(parameter_one: i32,
//@count foo/fn.short_name.html //pre/br 0
pub fn short_name(param: i32) -> i32 { param + 1 }
+
+//@count foo/fn.where_clause.html //pre/br 4
+pub fn where_clause(param_one: T,
+ param_two: U)
+ where T: Add + Display + Copy,
+ U: Add + Display + Copy,
+ T::Output: Display + Add + Copy,
+ >::Output: Display,
+ U::Output: Display + Copy
+{
+ let x = param_one + param_two;
+ println!("{} + {} = {}", param_one, param_two, x);
+ let y = param_two + param_one;
+ println!("{} + {} = {}", param_two, param_one, y);
+ println!("{} + {} = {}", x, y, x + y);
+}