Skip to content

Commit a0ac4a7

Browse files
authored
Unrolled build for rust-lang#128923
Rollup merge of rust-lang#128923 - GuillaumeGomez:negative-impls-items, r=fmease [rustdoc] Stop showing impl items for negative impls Fixes rust-lang#128799. As discussed with `@fmease,` they have a broader patch in progress, so this (small) PR will at least allow for them to have a regression test. :) r? `@fmease`
2 parents 8291d68 + 5baf7c2 commit a0ac4a7

File tree

4 files changed

+53
-19
lines changed

4 files changed

+53
-19
lines changed

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)]

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 ")?;

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>\
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// This test ensures that negative impls don't have items listed inside them.
2+
3+
#![feature(negative_impls)]
4+
#![crate_name = "foo"]
5+
6+
pub struct Thing;
7+
8+
//@ has 'foo/struct.Thing.html'
9+
// We check the full path to ensure there is no `<details>` element.
10+
//@ has - '//div[@id="trait-implementations-list"]/section[@id="impl-Iterator-for-Thing"]/h3' \
11+
// 'impl !Iterator for Thing'
12+
impl !Iterator for Thing {}
13+
14+
// This struct will allow us to compare both paths.
15+
pub struct Witness;
16+
17+
//@ has 'foo/struct.Witness.html'
18+
//@ has - '//div[@id="trait-implementations-list"]/details//section[@id="impl-Iterator-for-Witness"]/h3' \
19+
// 'impl Iterator for Witness'
20+
impl Iterator for Witness {
21+
type Item = u8;
22+
23+
fn next(&mut self) -> Option<Self::Item> {
24+
None
25+
}
26+
}

0 commit comments

Comments
 (0)