Skip to content

Commit 6a90be3

Browse files
Stop showing impl items for negative impls
1 parent 6d69b2e commit 6a90be3

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

Diff for: src/librustdoc/clean/types.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2446,6 +2446,10 @@ impl Impl {
24462446
.map(|did| tcx.provided_trait_methods(did).map(|meth| meth.name).collect())
24472447
.unwrap_or_default()
24482448
}
2449+
2450+
pub(crate) fn is_negative_trait_impl(&self) -> bool {
2451+
matches!(self.polarity, ty::ImplPolarity::Negative)
2452+
}
24492453
}
24502454

24512455
#[derive(Clone, Debug)]

Diff for: src/librustdoc/html/format.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1285,9 +1285,8 @@ impl clean::Impl {
12851285
f.write_str(" ")?;
12861286

12871287
if let Some(ref ty) = self.trait_ {
1288-
match self.polarity {
1289-
ty::ImplPolarity::Positive | ty::ImplPolarity::Reservation => {}
1290-
ty::ImplPolarity::Negative => write!(f, "!")?,
1288+
if self.is_negative_trait_impl() {
1289+
write!(f, "!")?;
12911290
}
12921291
ty.print(cx).fmt(f)?;
12931292
write!(f, " for ")?;

Diff for: src/librustdoc/html/render/mod.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -1780,20 +1780,23 @@ fn render_impl(
17801780

17811781
let mut impl_items = Buffer::empty_from(w);
17821782
let mut default_impl_items = Buffer::empty_from(w);
1783+
let impl_ = i.inner_impl();
17831784

1784-
for trait_item in &i.inner_impl().items {
1785-
doc_impl_item(
1786-
&mut default_impl_items,
1787-
&mut impl_items,
1788-
cx,
1789-
trait_item,
1790-
if trait_.is_some() { &i.impl_item } else { parent },
1791-
link,
1792-
render_mode,
1793-
false,
1794-
trait_,
1795-
rendering_params,
1796-
);
1785+
if !impl_.is_negative_trait_impl() {
1786+
for trait_item in &impl_.items {
1787+
doc_impl_item(
1788+
&mut default_impl_items,
1789+
&mut impl_items,
1790+
cx,
1791+
trait_item,
1792+
if trait_.is_some() { &i.impl_item } else { parent },
1793+
link,
1794+
render_mode,
1795+
false,
1796+
trait_,
1797+
rendering_params,
1798+
);
1799+
}
17971800
}
17981801

17991802
fn render_default_items(
@@ -1844,13 +1847,15 @@ fn render_impl(
18441847
// We don't emit documentation for default items if they appear in the
18451848
// Implementations on Foreign Types or Implementors sections.
18461849
if rendering_params.show_default_items {
1847-
if let Some(t) = trait_ {
1850+
if let Some(t) = trait_
1851+
&& !impl_.is_negative_trait_impl()
1852+
{
18481853
render_default_items(
18491854
&mut default_impl_items,
18501855
&mut impl_items,
18511856
cx,
18521857
t,
1853-
i.inner_impl(),
1858+
impl_,
18541859
&i.impl_item,
18551860
render_mode,
18561861
rendering_params,
@@ -1882,7 +1887,7 @@ fn render_impl(
18821887
}
18831888

18841889
if let Some(ref dox) = i.impl_item.opt_doc_value() {
1885-
if trait_.is_none() && i.inner_impl().items.is_empty() {
1890+
if trait_.is_none() && impl_.items.is_empty() {
18861891
w.write_str(
18871892
"<div class=\"item-info\">\
18881893
<div class=\"stab empty-impl\">This impl block contains no items.</div>\

0 commit comments

Comments
 (0)