mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
rustdoc: add line breaks to where clauses a la rustfmt
This commit is contained in:
parent
0b2c356420
commit
4a6921e10e
@ -161,48 +161,60 @@ impl<'a> fmt::Display for WhereClause<'a> {
|
||||
if gens.where_predicates.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
let mut clause = String::new();
|
||||
if f.alternate() {
|
||||
f.write_str(" ")?;
|
||||
clause.push_str(" where ");
|
||||
} else {
|
||||
f.write_str(" <span class='where'>where ")?;
|
||||
clause.push_str(" <span class='where'>where ");
|
||||
}
|
||||
for (i, pred) in gens.where_predicates.iter().enumerate() {
|
||||
if i > 0 {
|
||||
f.write_str(", ")?;
|
||||
if f.alternate() {
|
||||
clause.push_str(", ");
|
||||
} else {
|
||||
clause.push_str(",<br>");
|
||||
}
|
||||
}
|
||||
match pred {
|
||||
&clean::WherePredicate::BoundPredicate { ref ty, ref bounds } => {
|
||||
let bounds = bounds;
|
||||
if f.alternate() {
|
||||
write!(f, "{:#}: {:#}", ty, TyParamBounds(bounds))?;
|
||||
clause.push_str(&format!("{:#}: {:#}", ty, TyParamBounds(bounds)));
|
||||
} else {
|
||||
write!(f, "{}: {}", ty, TyParamBounds(bounds))?;
|
||||
clause.push_str(&format!("{}: {}", ty, TyParamBounds(bounds)));
|
||||
}
|
||||
}
|
||||
&clean::WherePredicate::RegionPredicate { ref lifetime,
|
||||
ref bounds } => {
|
||||
write!(f, "{}: ", lifetime)?;
|
||||
clause.push_str(&format!("{}: ", lifetime));
|
||||
for (i, lifetime) in bounds.iter().enumerate() {
|
||||
if i > 0 {
|
||||
f.write_str(" + ")?;
|
||||
clause.push_str(" + ");
|
||||
}
|
||||
|
||||
write!(f, "{}", lifetime)?;
|
||||
clause.push_str(&format!("{}", lifetime));
|
||||
}
|
||||
}
|
||||
&clean::WherePredicate::EqPredicate { ref lhs, ref rhs } => {
|
||||
if f.alternate() {
|
||||
write!(f, "{:#} == {:#}", lhs, rhs)?;
|
||||
clause.push_str(&format!("{:#} == {:#}", lhs, rhs));
|
||||
} else {
|
||||
write!(f, "{} == {}", lhs, rhs)?;
|
||||
clause.push_str(&format!("{} == {}", lhs, rhs));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !f.alternate() {
|
||||
f.write_str("</span>")?;
|
||||
let plain = format!("{:#}", self);
|
||||
if plain.len() > 80 {
|
||||
let padding = repeat(" ").take(8).collect::<String>();
|
||||
clause = clause.replace("<br>", &format!("<br>{}", padding));
|
||||
} else {
|
||||
clause = clause.replace("<br>", " ");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
write!(f, "{}", clause)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<T, U>(param_one: T,
|
||||
param_two: U)
|
||||
where T: Add<U> + Display + Copy,
|
||||
U: Add<T> + Display + Copy,
|
||||
T::Output: Display + Add<U::Output> + Copy,
|
||||
<T::Output as Add<U::Output>>::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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user