rustdoc: Use unboxed closure sugar
This unfortunately leaves sugaring Fn/FnMut/FnOnce on cross-crate re-exports for future work. cc #19909
This commit is contained in:
parent
37225288be
commit
c639cf6ee9
2 changed files with 100 additions and 60 deletions
|
@ -526,8 +526,10 @@ fn external_path(cx: &DocContext, name: &str, substs: &subst::Substs) -> Path {
|
||||||
global: false,
|
global: false,
|
||||||
segments: vec![PathSegment {
|
segments: vec![PathSegment {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
lifetimes: lifetimes,
|
params: PathParameters::AngleBracketed {
|
||||||
types: types,
|
lifetimes: lifetimes,
|
||||||
|
types: types,
|
||||||
|
}
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1743,32 +1745,49 @@ impl Clean<Path> for ast::Path {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)]
|
||||||
|
pub enum PathParameters {
|
||||||
|
AngleBracketed {
|
||||||
|
lifetimes: Vec<Lifetime>,
|
||||||
|
types: Vec<Type>,
|
||||||
|
},
|
||||||
|
Parenthesized {
|
||||||
|
inputs: Vec<Type>,
|
||||||
|
output: Option<Type>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Clean<PathParameters> for ast::PathParameters {
|
||||||
|
fn clean(&self, cx: &DocContext) -> PathParameters {
|
||||||
|
match *self {
|
||||||
|
ast::AngleBracketedParameters(ref data) => {
|
||||||
|
PathParameters::AngleBracketed {
|
||||||
|
lifetimes: data.lifetimes.clean(cx),
|
||||||
|
types: data.types.clean(cx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ast::ParenthesizedParameters(ref data) => {
|
||||||
|
PathParameters::Parenthesized {
|
||||||
|
inputs: data.inputs.clean(cx),
|
||||||
|
output: data.output.clean(cx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)]
|
#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)]
|
||||||
pub struct PathSegment {
|
pub struct PathSegment {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub lifetimes: Vec<Lifetime>,
|
pub params: PathParameters
|
||||||
pub types: Vec<Type>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<PathSegment> for ast::PathSegment {
|
impl Clean<PathSegment> for ast::PathSegment {
|
||||||
fn clean(&self, cx: &DocContext) -> PathSegment {
|
fn clean(&self, cx: &DocContext) -> PathSegment {
|
||||||
let (lifetimes, types) = match self.parameters {
|
|
||||||
ast::AngleBracketedParameters(ref data) => {
|
|
||||||
(data.lifetimes.clean(cx), data.types.clean(cx))
|
|
||||||
}
|
|
||||||
|
|
||||||
ast::ParenthesizedParameters(ref data) => {
|
|
||||||
// FIXME -- rustdoc should be taught about Foo() notation
|
|
||||||
let inputs = Tuple(data.inputs.clean(cx));
|
|
||||||
let output = data.output.as_ref().map(|t| t.clean(cx)).unwrap_or(Tuple(Vec::new()));
|
|
||||||
(Vec::new(), vec![inputs, output])
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
PathSegment {
|
PathSegment {
|
||||||
name: self.identifier.clean(cx),
|
name: self.identifier.clean(cx),
|
||||||
lifetimes: lifetimes,
|
params: self.parameters.clean(cx)
|
||||||
types: types,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2399,8 +2418,10 @@ fn lang_struct(cx: &DocContext, did: Option<ast::DefId>,
|
||||||
global: false,
|
global: false,
|
||||||
segments: vec![PathSegment {
|
segments: vec![PathSegment {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
lifetimes: vec![],
|
params: PathParameters::AngleBracketed {
|
||||||
types: vec![t.clean(cx)],
|
lifetimes: vec![],
|
||||||
|
types: vec![t.clean(cx)],
|
||||||
|
}
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,6 +171,58 @@ impl fmt::Show for clean::TyParamBound {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Show for clean::PathParameters {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match *self {
|
||||||
|
clean::PathParameters::AngleBracketed { ref lifetimes, ref types } => {
|
||||||
|
if lifetimes.len() > 0 || types.len() > 0 {
|
||||||
|
try!(f.write("<".as_bytes()));
|
||||||
|
let mut comma = false;
|
||||||
|
for lifetime in lifetimes.iter() {
|
||||||
|
if comma {
|
||||||
|
try!(f.write(", ".as_bytes()));
|
||||||
|
}
|
||||||
|
comma = true;
|
||||||
|
try!(write!(f, "{}", *lifetime));
|
||||||
|
}
|
||||||
|
for ty in types.iter() {
|
||||||
|
if comma {
|
||||||
|
try!(f.write(", ".as_bytes()));
|
||||||
|
}
|
||||||
|
comma = true;
|
||||||
|
try!(write!(f, "{}", *ty));
|
||||||
|
}
|
||||||
|
try!(f.write(">".as_bytes()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
clean::PathParameters::Parenthesized { ref inputs, ref output } => {
|
||||||
|
try!(f.write("(".as_bytes()));
|
||||||
|
let mut comma = false;
|
||||||
|
for ty in inputs.iter() {
|
||||||
|
if comma {
|
||||||
|
try!(f.write(", ".as_bytes()));
|
||||||
|
}
|
||||||
|
comma = true;
|
||||||
|
try!(write!(f, "{}", *ty));
|
||||||
|
}
|
||||||
|
try!(f.write(")".as_bytes()));
|
||||||
|
if let Some(ref ty) = *output {
|
||||||
|
try!(f.write(" -> ".as_bytes()));
|
||||||
|
try!(write!(f, "{}", ty));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Show for clean::PathSegment {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
try!(f.write(self.name.as_bytes()));
|
||||||
|
write!(f, "{}", self.params)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Show for clean::Path {
|
impl fmt::Show for clean::Path {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
if self.global {
|
if self.global {
|
||||||
|
@ -181,27 +233,7 @@ impl fmt::Show for clean::Path {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
try!(f.write("::".as_bytes()))
|
try!(f.write("::".as_bytes()))
|
||||||
}
|
}
|
||||||
try!(f.write(seg.name.as_bytes()));
|
try!(write!(f, "{}", seg));
|
||||||
|
|
||||||
if seg.lifetimes.len() > 0 || seg.types.len() > 0 {
|
|
||||||
try!(f.write("<".as_bytes()));
|
|
||||||
let mut comma = false;
|
|
||||||
for lifetime in seg.lifetimes.iter() {
|
|
||||||
if comma {
|
|
||||||
try!(f.write(", ".as_bytes()));
|
|
||||||
}
|
|
||||||
comma = true;
|
|
||||||
try!(write!(f, "{}", *lifetime));
|
|
||||||
}
|
|
||||||
for ty in seg.types.iter() {
|
|
||||||
if comma {
|
|
||||||
try!(f.write(", ".as_bytes()));
|
|
||||||
}
|
|
||||||
comma = true;
|
|
||||||
try!(write!(f, "{}", *ty));
|
|
||||||
}
|
|
||||||
try!(f.write(">".as_bytes()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -243,23 +275,8 @@ fn path<F, G>(w: &mut fmt::Formatter,
|
||||||
G: FnOnce(&render::Cache) -> Option<(Vec<String>, ItemType)>,
|
G: FnOnce(&render::Cache) -> Option<(Vec<String>, ItemType)>,
|
||||||
{
|
{
|
||||||
// The generics will get written to both the title and link
|
// The generics will get written to both the title and link
|
||||||
let mut generics = String::new();
|
|
||||||
let last = path.segments.last().unwrap();
|
let last = path.segments.last().unwrap();
|
||||||
if last.lifetimes.len() > 0 || last.types.len() > 0 {
|
let generics = format!("{}", last.params);
|
||||||
let mut counter = 0u;
|
|
||||||
generics.push_str("<");
|
|
||||||
for lifetime in last.lifetimes.iter() {
|
|
||||||
if counter > 0 { generics.push_str(", "); }
|
|
||||||
counter += 1;
|
|
||||||
generics.push_str(format!("{}", *lifetime).as_slice());
|
|
||||||
}
|
|
||||||
for ty in last.types.iter() {
|
|
||||||
if counter > 0 { generics.push_str(", "); }
|
|
||||||
counter += 1;
|
|
||||||
generics.push_str(format!("{}", *ty).as_slice());
|
|
||||||
}
|
|
||||||
generics.push_str(">");
|
|
||||||
}
|
|
||||||
|
|
||||||
let loc = CURRENT_LOCATION_KEY.with(|l| l.borrow().clone());
|
let loc = CURRENT_LOCATION_KEY.with(|l| l.borrow().clone());
|
||||||
let cache = cache();
|
let cache = cache();
|
||||||
|
@ -660,8 +677,10 @@ impl fmt::Show for clean::ViewListIdent {
|
||||||
global: false,
|
global: false,
|
||||||
segments: vec!(clean::PathSegment {
|
segments: vec!(clean::PathSegment {
|
||||||
name: self.name.clone(),
|
name: self.name.clone(),
|
||||||
lifetimes: Vec::new(),
|
params: clean::PathParameters::AngleBracketed {
|
||||||
types: Vec::new(),
|
lifetimes: Vec::new(),
|
||||||
|
types: Vec::new(),
|
||||||
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
resolved_path(f, did, &path, false)
|
resolved_path(f, did, &path, false)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue