From 8994840f7e61c1e90db35e7d966d0271880d905c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 14 May 2024 20:40:47 -0400 Subject: [PATCH] rustdoc: Negative impls are not notable --- src/librustdoc/html/render/mod.rs | 8 +++++++ .../doc-notable_trait-negative.negative.html | 1 + .../doc-notable_trait-negative.positive.html | 1 + .../doc-notable_trait-negative.rs | 22 +++++++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 tests/rustdoc/notable-trait/doc-notable_trait-negative.negative.html create mode 100644 tests/rustdoc/notable-trait/doc-notable_trait-negative.positive.html create mode 100644 tests/rustdoc/notable-trait/doc-notable_trait-negative.rs diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index b4e62e39d8d..18323e0b8ad 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1424,6 +1424,10 @@ pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &mut Context<'_>) -> O if let Some(impls) = cx.cache().impls.get(&did) { for i in impls { let impl_ = i.inner_impl(); + if impl_.polarity != ty::ImplPolarity::Positive { + continue; + } + if !ty.is_doc_subtype_of(&impl_.for_, cx.cache()) { // Two different types might have the same did, // without actually being the same. @@ -1459,6 +1463,10 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) { for i in impls { let impl_ = i.inner_impl(); + if impl_.polarity != ty::ImplPolarity::Positive { + continue; + } + if !ty.is_doc_subtype_of(&impl_.for_, cx.cache()) { // Two different types might have the same did, // without actually being the same. diff --git a/tests/rustdoc/notable-trait/doc-notable_trait-negative.negative.html b/tests/rustdoc/notable-trait/doc-notable_trait-negative.negative.html new file mode 100644 index 00000000000..6f19558cc15 --- /dev/null +++ b/tests/rustdoc/notable-trait/doc-notable_trait-negative.negative.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/rustdoc/notable-trait/doc-notable_trait-negative.positive.html b/tests/rustdoc/notable-trait/doc-notable_trait-negative.positive.html new file mode 100644 index 00000000000..a3d0fedaaf4 --- /dev/null +++ b/tests/rustdoc/notable-trait/doc-notable_trait-negative.positive.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/rustdoc/notable-trait/doc-notable_trait-negative.rs b/tests/rustdoc/notable-trait/doc-notable_trait-negative.rs new file mode 100644 index 00000000000..2bbe0a3ef8c --- /dev/null +++ b/tests/rustdoc/notable-trait/doc-notable_trait-negative.rs @@ -0,0 +1,22 @@ +#![feature(doc_notable_trait, negative_impls)] + +#[doc(notable_trait)] +pub trait SomeTrait {} + +pub struct Positive; +impl SomeTrait for Positive {} + +pub struct Negative; +impl !SomeTrait for Negative {} + +// @has doc_notable_trait_negative/fn.positive.html +// @snapshot positive - '//script[@id="notable-traits-data"]' +pub fn positive() -> Positive { + todo!() +} + +// @has doc_notable_trait_negative/fn.negative.html +// @count - '//script[@id="notable-traits-data"]' 0 +pub fn negative() -> Negative { + &[] +}