rustdoc: remove many unnecessary .as_ref()
calls.
This commit is contained in:
parent
10b1c9aa8b
commit
1e4637cf4d
1 changed files with 29 additions and 38 deletions
|
@ -263,7 +263,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
|
||||||
indices.dedup_by_key(|i| {
|
indices.dedup_by_key(|i| {
|
||||||
(
|
(
|
||||||
items[*i].def_id,
|
items[*i].def_id,
|
||||||
if items[*i].name.as_ref().is_some() { Some(full_path(cx, &items[*i])) } else { None },
|
if items[*i].name.is_some() { Some(full_path(cx, &items[*i])) } else { None },
|
||||||
items[*i].type_(),
|
items[*i].type_(),
|
||||||
if items[*i].is_import() { *i } else { 0 },
|
if items[*i].is_import() { *i } else { 0 },
|
||||||
)
|
)
|
||||||
|
@ -310,13 +310,13 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
|
||||||
"<div class=\"item-left\"><code>{}extern crate {} as {};",
|
"<div class=\"item-left\"><code>{}extern crate {} as {};",
|
||||||
myitem.visibility.print_with_space(myitem.def_id, cx),
|
myitem.visibility.print_with_space(myitem.def_id, cx),
|
||||||
anchor(myitem.def_id.expect_def_id(), src, cx),
|
anchor(myitem.def_id.expect_def_id(), src, cx),
|
||||||
myitem.name.as_ref().unwrap(),
|
myitem.name.unwrap(),
|
||||||
),
|
),
|
||||||
None => write!(
|
None => write!(
|
||||||
w,
|
w,
|
||||||
"<div class=\"item-left\"><code>{}extern crate {};",
|
"<div class=\"item-left\"><code>{}extern crate {};",
|
||||||
myitem.visibility.print_with_space(myitem.def_id, cx),
|
myitem.visibility.print_with_space(myitem.def_id, cx),
|
||||||
anchor(myitem.def_id.expect_def_id(), *myitem.name.as_ref().unwrap(), cx),
|
anchor(myitem.def_id.expect_def_id(), myitem.name.unwrap(), cx),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
w.write_str("</code></div>");
|
w.write_str("</code></div>");
|
||||||
|
@ -388,7 +388,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
|
||||||
{stab_tags}\
|
{stab_tags}\
|
||||||
</div>\
|
</div>\
|
||||||
<div class=\"item-right docblock-short\">{docs}</div>",
|
<div class=\"item-right docblock-short\">{docs}</div>",
|
||||||
name = *myitem.name.as_ref().unwrap(),
|
name = myitem.name.unwrap(),
|
||||||
stab_tags = extra_info_tags(myitem, item, cx.tcx()),
|
stab_tags = extra_info_tags(myitem, item, cx.tcx()),
|
||||||
docs = MarkdownSummaryLine(&doc_value, &myitem.links(cx)).into_string(),
|
docs = MarkdownSummaryLine(&doc_value, &myitem.links(cx)).into_string(),
|
||||||
class = myitem.type_(),
|
class = myitem.type_(),
|
||||||
|
@ -460,7 +460,7 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::
|
||||||
let asyncness = f.header.asyncness.print_with_space();
|
let asyncness = f.header.asyncness.print_with_space();
|
||||||
let unsafety = f.header.unsafety.print_with_space();
|
let unsafety = f.header.unsafety.print_with_space();
|
||||||
let abi = print_abi_with_space(f.header.abi).to_string();
|
let abi = print_abi_with_space(f.header.abi).to_string();
|
||||||
let name = it.name.as_ref().unwrap();
|
let name = it.name.unwrap();
|
||||||
|
|
||||||
let generics_len = format!("{:#}", f.generics.print(cx)).len();
|
let generics_len = format!("{:#}", f.generics.print(cx)).len();
|
||||||
let header_len = "fn ".len()
|
let header_len = "fn ".len()
|
||||||
|
@ -516,7 +516,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
|
||||||
it.visibility.print_with_space(it.def_id, cx),
|
it.visibility.print_with_space(it.def_id, cx),
|
||||||
t.unsafety.print_with_space(),
|
t.unsafety.print_with_space(),
|
||||||
if t.is_auto { "auto " } else { "" },
|
if t.is_auto { "auto " } else { "" },
|
||||||
it.name.as_ref().unwrap(),
|
it.name.unwrap(),
|
||||||
t.generics.print(cx),
|
t.generics.print(cx),
|
||||||
bounds
|
bounds
|
||||||
);
|
);
|
||||||
|
@ -657,7 +657,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trait_item(w: &mut Buffer, cx: &Context<'_>, m: &clean::Item, t: &clean::Item) {
|
fn trait_item(w: &mut Buffer, cx: &Context<'_>, m: &clean::Item, t: &clean::Item) {
|
||||||
let name = m.name.as_ref().unwrap();
|
let name = m.name.unwrap();
|
||||||
info!("Documenting {} on {:?}", name, t.name);
|
info!("Documenting {} on {:?}", name, t.name);
|
||||||
let item_type = m.type_();
|
let item_type = m.type_();
|
||||||
let id = cx.derive_id(format!("{}.{}", item_type, name));
|
let id = cx.derive_id(format!("{}.{}", item_type, name));
|
||||||
|
@ -867,7 +867,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
|
||||||
join_with_slash(None, &path[..path.len() - 1])
|
join_with_slash(None, &path[..path.len() - 1])
|
||||||
},
|
},
|
||||||
ty = it.type_(),
|
ty = it.type_(),
|
||||||
name = *it.name.as_ref().unwrap()
|
name = it.name.unwrap()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -878,7 +878,7 @@ fn item_trait_alias(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clea
|
||||||
write!(
|
write!(
|
||||||
w,
|
w,
|
||||||
"trait {}{}{} = {};",
|
"trait {}{}{} = {};",
|
||||||
it.name.as_ref().unwrap(),
|
it.name.unwrap(),
|
||||||
t.generics.print(cx),
|
t.generics.print(cx),
|
||||||
print_where_clause(&t.generics, cx, 0, true),
|
print_where_clause(&t.generics, cx, 0, true),
|
||||||
bounds(&t.bounds, true, cx)
|
bounds(&t.bounds, true, cx)
|
||||||
|
@ -902,7 +902,7 @@ fn item_opaque_ty(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean:
|
||||||
write!(
|
write!(
|
||||||
w,
|
w,
|
||||||
"type {}{}{where_clause} = impl {bounds};",
|
"type {}{}{where_clause} = impl {bounds};",
|
||||||
it.name.as_ref().unwrap(),
|
it.name.unwrap(),
|
||||||
t.generics.print(cx),
|
t.generics.print(cx),
|
||||||
where_clause = print_where_clause(&t.generics, cx, 0, true),
|
where_clause = print_where_clause(&t.generics, cx, 0, true),
|
||||||
bounds = bounds(&t.bounds, false, cx),
|
bounds = bounds(&t.bounds, false, cx),
|
||||||
|
@ -941,7 +941,7 @@ fn item_typedef(
|
||||||
write!(
|
write!(
|
||||||
w,
|
w,
|
||||||
"type {}{}{where_clause} = {type_};",
|
"type {}{}{where_clause} = {type_};",
|
||||||
it.name.as_ref().unwrap(),
|
it.name.unwrap(),
|
||||||
t.generics.print(cx),
|
t.generics.print(cx),
|
||||||
where_clause = print_where_clause(&t.generics, cx, 0, true),
|
where_clause = print_where_clause(&t.generics, cx, 0, true),
|
||||||
type_ = t.type_.print(cx),
|
type_ = t.type_.print(cx),
|
||||||
|
@ -994,7 +994,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
|
||||||
Fields<a href=\"#fields\" class=\"anchor\"></a></h2>"
|
Fields<a href=\"#fields\" class=\"anchor\"></a></h2>"
|
||||||
);
|
);
|
||||||
for (field, ty) in fields {
|
for (field, ty) in fields {
|
||||||
let name = field.name.as_ref().expect("union field name");
|
let name = field.name.expect("union field name");
|
||||||
let id = format!("{}.{}", ItemType::StructField, name);
|
let id = format!("{}.{}", ItemType::StructField, name);
|
||||||
write!(
|
write!(
|
||||||
w,
|
w,
|
||||||
|
@ -1039,7 +1039,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
|
||||||
w,
|
w,
|
||||||
"{}enum {}{}{}",
|
"{}enum {}{}{}",
|
||||||
it.visibility.print_with_space(it.def_id, cx),
|
it.visibility.print_with_space(it.def_id, cx),
|
||||||
it.name.as_ref().unwrap(),
|
it.name.unwrap(),
|
||||||
e.generics.print(cx),
|
e.generics.print(cx),
|
||||||
print_where_clause(&e.generics, cx, 0, true),
|
print_where_clause(&e.generics, cx, 0, true),
|
||||||
);
|
);
|
||||||
|
@ -1054,7 +1054,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
|
||||||
}
|
}
|
||||||
for v in &e.variants {
|
for v in &e.variants {
|
||||||
w.write_str(" ");
|
w.write_str(" ");
|
||||||
let name = v.name.as_ref().unwrap();
|
let name = v.name.unwrap();
|
||||||
match *v.kind {
|
match *v.kind {
|
||||||
clean::VariantItem(ref var) => match var {
|
clean::VariantItem(ref var) => match var {
|
||||||
clean::Variant::CLike => write!(w, "{}", name),
|
clean::Variant::CLike => write!(w, "{}", name),
|
||||||
|
@ -1103,15 +1103,14 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
|
||||||
);
|
);
|
||||||
document_non_exhaustive(w, it);
|
document_non_exhaustive(w, it);
|
||||||
for variant in &e.variants {
|
for variant in &e.variants {
|
||||||
let id =
|
let id = cx.derive_id(format!("{}.{}", ItemType::Variant, variant.name.unwrap()));
|
||||||
cx.derive_id(format!("{}.{}", ItemType::Variant, variant.name.as_ref().unwrap()));
|
|
||||||
write!(
|
write!(
|
||||||
w,
|
w,
|
||||||
"<h3 id=\"{id}\" class=\"variant small-section-header\">\
|
"<h3 id=\"{id}\" class=\"variant small-section-header\">\
|
||||||
<a href=\"#{id}\" class=\"anchor field\"></a>\
|
<a href=\"#{id}\" class=\"anchor field\"></a>\
|
||||||
<code>{name}",
|
<code>{name}",
|
||||||
id = id,
|
id = id,
|
||||||
name = variant.name.as_ref().unwrap()
|
name = variant.name.unwrap()
|
||||||
);
|
);
|
||||||
if let clean::VariantItem(clean::Variant::Tuple(ref s)) = *variant.kind {
|
if let clean::VariantItem(clean::Variant::Tuple(ref s)) = *variant.kind {
|
||||||
w.write_str("(");
|
w.write_str("(");
|
||||||
|
@ -1137,11 +1136,8 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some((heading, fields)) = heading_and_fields {
|
if let Some((heading, fields)) = heading_and_fields {
|
||||||
let variant_id = cx.derive_id(format!(
|
let variant_id =
|
||||||
"{}.{}.fields",
|
cx.derive_id(format!("{}.{}.fields", ItemType::Variant, variant.name.unwrap()));
|
||||||
ItemType::Variant,
|
|
||||||
variant.name.as_ref().unwrap()
|
|
||||||
));
|
|
||||||
write!(w, "<div class=\"sub-variant\" id=\"{id}\">", id = variant_id);
|
write!(w, "<div class=\"sub-variant\" id=\"{id}\">", id = variant_id);
|
||||||
write!(w, "<h4>{heading}</h4>", heading = heading);
|
write!(w, "<h4>{heading}</h4>", heading = heading);
|
||||||
document_non_exhaustive(w, variant);
|
document_non_exhaustive(w, variant);
|
||||||
|
@ -1151,8 +1147,8 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
|
||||||
clean::StructFieldItem(ref ty) => {
|
clean::StructFieldItem(ref ty) => {
|
||||||
let id = cx.derive_id(format!(
|
let id = cx.derive_id(format!(
|
||||||
"variant.{}.field.{}",
|
"variant.{}.field.{}",
|
||||||
variant.name.as_ref().unwrap(),
|
variant.name.unwrap(),
|
||||||
field.name.as_ref().unwrap()
|
field.name.unwrap()
|
||||||
));
|
));
|
||||||
write!(
|
write!(
|
||||||
w,
|
w,
|
||||||
|
@ -1162,7 +1158,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
|
||||||
<code>{f}: {t}</code>\
|
<code>{f}: {t}</code>\
|
||||||
</span>",
|
</span>",
|
||||||
id = id,
|
id = id,
|
||||||
f = field.name.as_ref().unwrap(),
|
f = field.name.unwrap(),
|
||||||
t = ty.print(cx)
|
t = ty.print(cx)
|
||||||
);
|
);
|
||||||
document(w, cx, field, Some(variant), HeadingOffset::H5);
|
document(w, cx, field, Some(variant), HeadingOffset::H5);
|
||||||
|
@ -1201,7 +1197,7 @@ fn item_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Mac
|
||||||
|
|
||||||
fn item_proc_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, m: &clean::ProcMacro) {
|
fn item_proc_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, m: &clean::ProcMacro) {
|
||||||
wrap_into_docblock(w, |w| {
|
wrap_into_docblock(w, |w| {
|
||||||
let name = it.name.as_ref().expect("proc-macros always have names");
|
let name = it.name.expect("proc-macros always have names");
|
||||||
match m.kind {
|
match m.kind {
|
||||||
MacroKind::Bang => {
|
MacroKind::Bang => {
|
||||||
wrap_item(w, "macro", |w| {
|
wrap_item(w, "macro", |w| {
|
||||||
|
@ -1245,7 +1241,7 @@ fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::
|
||||||
w,
|
w,
|
||||||
"{vis}const {name}: {typ}",
|
"{vis}const {name}: {typ}",
|
||||||
vis = it.visibility.print_with_space(it.def_id, cx),
|
vis = it.visibility.print_with_space(it.def_id, cx),
|
||||||
name = it.name.as_ref().unwrap(),
|
name = it.name.unwrap(),
|
||||||
typ = c.type_.print(cx),
|
typ = c.type_.print(cx),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1338,7 +1334,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
|
||||||
"{vis}static {mutability}{name}: {typ}",
|
"{vis}static {mutability}{name}: {typ}",
|
||||||
vis = it.visibility.print_with_space(it.def_id, cx),
|
vis = it.visibility.print_with_space(it.def_id, cx),
|
||||||
mutability = s.mutability.print_with_space(),
|
mutability = s.mutability.print_with_space(),
|
||||||
name = it.name.as_ref().unwrap(),
|
name = it.name.unwrap(),
|
||||||
typ = s.type_.print(cx)
|
typ = s.type_.print(cx)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -1355,7 +1351,7 @@ fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
|
||||||
w,
|
w,
|
||||||
" {}type {};\n}}",
|
" {}type {};\n}}",
|
||||||
it.visibility.print_with_space(it.def_id, cx),
|
it.visibility.print_with_space(it.def_id, cx),
|
||||||
it.name.as_ref().unwrap(),
|
it.name.unwrap(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1523,12 +1519,7 @@ fn render_union(
|
||||||
tab: &str,
|
tab: &str,
|
||||||
cx: &Context<'_>,
|
cx: &Context<'_>,
|
||||||
) {
|
) {
|
||||||
write!(
|
write!(w, "{}union {}", it.visibility.print_with_space(it.def_id, cx), it.name.unwrap());
|
||||||
w,
|
|
||||||
"{}union {}",
|
|
||||||
it.visibility.print_with_space(it.def_id, cx),
|
|
||||||
it.name.as_ref().unwrap()
|
|
||||||
);
|
|
||||||
if let Some(g) = g {
|
if let Some(g) = g {
|
||||||
write!(w, "{}", g.print(cx));
|
write!(w, "{}", g.print(cx));
|
||||||
write!(w, "{}", print_where_clause(g, cx, 0, true));
|
write!(w, "{}", print_where_clause(g, cx, 0, true));
|
||||||
|
@ -1548,7 +1539,7 @@ fn render_union(
|
||||||
w,
|
w,
|
||||||
" {}{}: {},\n{}",
|
" {}{}: {},\n{}",
|
||||||
field.visibility.print_with_space(field.def_id, cx),
|
field.visibility.print_with_space(field.def_id, cx),
|
||||||
field.name.as_ref().unwrap(),
|
field.name.unwrap(),
|
||||||
ty.print(cx),
|
ty.print(cx),
|
||||||
tab
|
tab
|
||||||
);
|
);
|
||||||
|
@ -1579,7 +1570,7 @@ fn render_struct(
|
||||||
"{}{}{}",
|
"{}{}{}",
|
||||||
it.visibility.print_with_space(it.def_id, cx),
|
it.visibility.print_with_space(it.def_id, cx),
|
||||||
if structhead { "struct " } else { "" },
|
if structhead { "struct " } else { "" },
|
||||||
it.name.as_ref().unwrap()
|
it.name.unwrap()
|
||||||
);
|
);
|
||||||
if let Some(g) = g {
|
if let Some(g) = g {
|
||||||
write!(w, "{}", g.print(cx))
|
write!(w, "{}", g.print(cx))
|
||||||
|
@ -1604,7 +1595,7 @@ fn render_struct(
|
||||||
"\n{} {}{}: {},",
|
"\n{} {}{}: {},",
|
||||||
tab,
|
tab,
|
||||||
field.visibility.print_with_space(field.def_id, cx),
|
field.visibility.print_with_space(field.def_id, cx),
|
||||||
field.name.as_ref().unwrap(),
|
field.name.unwrap(),
|
||||||
ty.print(cx),
|
ty.print(cx),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue