Skip to content

Commit 588b522

Browse files
committed
rustdoc: Reduce rightward drift in render_impl
1 parent af9c8d7 commit 588b522

1 file changed

Lines changed: 101 additions & 104 deletions

File tree

  • src/librustdoc/html/render

‎src/librustdoc/html/render/mod.rs‎

Lines changed: 101 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,7 @@ fn render_impl(
18191819
let item_type = item.type_();
18201820
let name = item.name.as_ref().unwrap();
18211821

1822-
let render_method_item = rendering_params.show_non_assoc_items
1822+
let render_assoc_fn = rendering_params.show_non_assoc_items
18231823
&& match render_mode {
18241824
RenderMode::Normal => true,
18251825
RenderMode::ForDeref { mut_: deref_mut_, is_deref_target_copy } => {
@@ -1834,7 +1834,7 @@ fn render_impl(
18341834
let mut short_documented = true;
18351835

18361836
let mut trait_item_deprecated = false;
1837-
if render_method_item {
1837+
if render_assoc_fn {
18381838
if !is_default_item {
18391839
if let Some(t) = trait_ {
18401840
// The trait item may have been stripped so we might not
@@ -1897,116 +1897,113 @@ fn render_impl(
18971897
deprecation_class = "";
18981898
}
18991899
match &item.kind {
1900-
ItemKind::AssocFn(..) => {
1901-
// Only render when the method is not static or we allow static methods
1902-
if render_method_item {
1903-
let id = cx.derive_id(format!("{item_type}.{name}"));
1904-
let source_id = trait_
1905-
.and_then(|trait_| {
1906-
trait_
1907-
.items
1908-
.iter()
1909-
.find(|item| item.name.map(|n| n == *name).unwrap_or(false))
1910-
})
1911-
.map(|item| format!("{}.{name}", item.type_()));
1912-
write!(
1913-
w,
1914-
"<section id=\"{id}\" class=\"{item_type}{in_trait_class}{deprecation_class}\">\
1915-
{}",
1916-
render_rightside(cx, item, render_mode)
1917-
)?;
1918-
if trait_.is_some() {
1919-
// Anchors are only used on trait impls.
1920-
write!(w, "<a href=\"#{id}\" class=\"anchor\">§</a>")?;
1921-
}
1922-
write!(
1923-
w,
1924-
"<h4 class=\"code-header\">{}</h4></section>",
1925-
render_assoc_item(
1926-
item,
1927-
link.anchor(source_id.as_ref().unwrap_or(&id)),
1928-
ItemType::Impl,
1929-
0,
1930-
Ending::Newline,
1931-
render_mode,
1932-
cx,
1933-
),
1934-
)?;
1900+
ItemKind::AssocFn(_) if !render_assoc_fn => {}
1901+
ItemKind::AssocConst(_) | ItemKind::AssocTy(_)
1902+
if let RenderMode::ForDeref { .. } = render_mode => {}
1903+
1904+
ItemKind::AssocFn(_) => {
1905+
let id = cx.derive_id(format!("{item_type}.{name}"));
1906+
let source_id = trait_
1907+
.and_then(|trait_| {
1908+
trait_
1909+
.items
1910+
.iter()
1911+
.find(|item| item.name.map(|n| n == *name).unwrap_or(false))
1912+
})
1913+
.map(|item| format!("{}.{name}", item.type_()));
1914+
write!(
1915+
w,
1916+
"<section id=\"{id}\" class=\"{item_type}{in_trait_class}{deprecation_class}\">\
1917+
{}",
1918+
render_rightside(cx, item, render_mode)
1919+
)?;
1920+
if trait_.is_some() {
1921+
// Anchors are only used on trait impls.
1922+
write!(w, "<a href=\"#{id}\" class=\"anchor\">§</a>")?;
19351923
}
1924+
write!(
1925+
w,
1926+
"<h4 class=\"code-header\">{}</h4></section>",
1927+
render_assoc_item(
1928+
item,
1929+
link.anchor(source_id.as_ref().unwrap_or(&id)),
1930+
ItemType::Impl,
1931+
0,
1932+
Ending::Newline,
1933+
render_mode,
1934+
cx,
1935+
),
1936+
)?;
19361937
}
19371938
ItemKind::AssocConst(ct) => {
1938-
if !matches!(render_mode, RenderMode::ForDeref { .. }) {
1939-
let source_id = format!("{item_type}.{name}");
1940-
let id = cx.derive_id(&source_id);
1941-
write!(
1942-
w,
1943-
"<section id=\"{id}\" class=\"{item_type}{in_trait_class}{deprecation_class}\">\
1944-
{}",
1945-
render_rightside(cx, item, render_mode),
1946-
)?;
1947-
if trait_.is_some() {
1948-
// Anchors are only used on trait impls.
1949-
write!(w, "<a href=\"#{id}\" class=\"anchor\">§</a>")?;
1950-
}
1951-
write!(
1952-
w,
1953-
"<h4 class=\"code-header\">{}</h4></section>",
1954-
assoc_const(
1955-
item,
1956-
&ct.generics,
1957-
&ct.ty,
1958-
match &ct.rhs {
1959-
Some(rhs) => AssocConstValue::Impl(rhs),
1960-
None => AssocConstValue::None,
1961-
},
1962-
link.anchor(if trait_.is_some() { &source_id } else { &id }),
1963-
0,
1964-
Ending::Newline,
1965-
cx,
1966-
),
1967-
)?;
1968-
write!(
1969-
w,
1970-
"<h4 class=\"code-header\">{}</h4></section>",
1971-
assoc_const(
1972-
item,
1973-
ct,
1974-
ItemType::Impl,
1975-
link.anchor(if trait_.is_some() { &source_id } else { &id }),
1976-
0,
1977-
Ending::Newline,
1978-
cx,
1979-
),
1980-
)?;
1939+
let source_id = format!("{item_type}.{name}");
1940+
let id = cx.derive_id(&source_id);
1941+
write!(
1942+
w,
1943+
"<section id=\"{id}\" class=\"{item_type}{in_trait_class}{deprecation_class}\">\
1944+
{}",
1945+
render_rightside(cx, item, render_mode),
1946+
)?;
1947+
if trait_.is_some() {
1948+
// Anchors are only used on trait impls.
1949+
write!(w, "<a href=\"#{id}\" class=\"anchor\">§</a>")?;
19811950
}
1951+
write!(
1952+
w,
1953+
"<h4 class=\"code-header\">{}</h4></section>",
1954+
assoc_const(
1955+
item,
1956+
&ct.generics,
1957+
&ct.ty,
1958+
match &ct.rhs {
1959+
Some(rhs) => AssocConstValue::Impl(rhs),
1960+
None => AssocConstValue::None,
1961+
},
1962+
link.anchor(if trait_.is_some() { &source_id } else { &id }),
1963+
0,
1964+
Ending::Newline,
1965+
cx,
1966+
),
1967+
)?;
1968+
write!(
1969+
w,
1970+
"<h4 class=\"code-header\">{}</h4></section>",
1971+
assoc_const(
1972+
item,
1973+
ct,
1974+
ItemType::Impl,
1975+
link.anchor(if trait_.is_some() { &source_id } else { &id }),
1976+
0,
1977+
Ending::Newline,
1978+
cx,
1979+
),
1980+
)?;
19821981
}
19831982
ItemKind::AssocTy(ty) => {
1984-
if !matches!(render_mode, RenderMode::ForDeref { .. }) {
1985-
let source_id = format!("{item_type}.{name}");
1986-
let id = cx.derive_id(&source_id);
1987-
write!(
1988-
w,
1989-
"<section id=\"{id}\" class=\"{item_type}{in_trait_class}{deprecation_class}\">\
1983+
let source_id = format!("{item_type}.{name}");
1984+
let id = cx.derive_id(&source_id);
1985+
write!(
1986+
w,
1987+
"<section id=\"{id}\" class=\"{item_type}{in_trait_class}{deprecation_class}\">\
19901988
{}",
1991-
render_rightside(cx, item, render_mode),
1992-
)?;
1993-
if trait_.is_some() {
1994-
// Anchors are only used on trait impls.
1995-
write!(w, "<a href=\"#{id}\" class=\"anchor\">§</a>")?;
1996-
}
1997-
write!(
1998-
w,
1999-
"<h4 class=\"code-header\">{}</h4></section>",
2000-
assoc_ty(
2001-
item,
2002-
ty,
2003-
link.anchor(if trait_.is_some() { &source_id } else { &id }),
2004-
0,
2005-
Ending::Newline,
2006-
cx,
2007-
),
2008-
)?;
1989+
render_rightside(cx, item, render_mode),
1990+
)?;
1991+
if trait_.is_some() {
1992+
// Anchors are only used on trait impls.
1993+
write!(w, "<a href=\"#{id}\" class=\"anchor\">§</a>")?;
20091994
}
1995+
write!(
1996+
w,
1997+
"<h4 class=\"code-header\">{}</h4></section>",
1998+
assoc_ty(
1999+
item,
2000+
ty,
2001+
link.anchor(if trait_.is_some() { &source_id } else { &id }),
2002+
0,
2003+
Ending::Newline,
2004+
cx,
2005+
),
2006+
)?;
20102007
}
20112008
ItemKind::Stripped(..) => return Ok(()),
20122009
_ => panic!("can't make docs for trait item with name {:?}", item.name),

0 commit comments

Comments
 (0)