Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script type="text/json" id="notable-traits-data">{"Negative":"&lt;/code&gt;&lt;/pre&gt;"}</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script type="text/json" id="notable-traits-data">{"Positive":"&lt;h3&gt;Notable traits for &lt;code&gt;&lt;a class=\"struct\" href=\"struct.Positive.html\" title=\"struct doc_notable_trait_negative::Positive\"&gt;Positive&lt;/a&gt;&lt;/code&gt;&lt;/h3&gt;&lt;pre&gt;&lt;code&gt;&lt;div class=\"where\"&gt;impl &lt;a class=\"trait\" href=\"trait.SomeTrait.html\" title=\"trait doc_notable_trait_negative::SomeTrait\"&gt;SomeTrait&lt;/a&gt; for &lt;a class=\"struct\" href=\"struct.Positive.html\" title=\"struct doc_notable_trait_negative::Positive\"&gt;Positive&lt;/a&gt;&lt;/div&gt;"}</script>
22 changes: 22 additions & 0 deletions tests/rustdoc/notable-trait/doc-notable_trait-negative.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need the positive test because we have a bunch of them already (rg 'notable-traits-data' test/rustdoc)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't hurt to show that a negative impl doesn't disqualify the positive impl though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

Original file line number Diff line number Diff line change
@@ -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 {
&[]
}