rustdoc: Negative impls are not notable · rust-lang/rust@8994840 (original) (raw)

File tree

4 files changed

lines changed

4 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -1424,6 +1424,10 @@ pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &mut Context<'_>) -> O
1424 1424 if let Some(impls) = cx.cache().impls.get(&did) {
1425 1425 for i in impls {
1426 1426 let impl_ = i.inner_impl();
1427 +if impl_.polarity != ty::ImplPolarity::Positive {
1428 +continue;
1429 +}
1430 +
1427 1431 if !ty.is_doc_subtype_of(&impl_.for_, cx.cache()) {
1428 1432 // Two different types might have the same did,
1429 1433 // without actually being the same.
@@ -1459,6 +1463,10 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {
1459 1463
1460 1464 for i in impls {
1461 1465 let impl_ = i.inner_impl();
1466 +if impl_.polarity != ty::ImplPolarity::Positive {
1467 +continue;
1468 +}
1469 +
1462 1470 if !ty.is_doc_subtype_of(&impl_.for_, cx.cache()) {
1463 1471 // Two different types might have the same did,
1464 1472 // without actually being the same.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 +<script type="text/json" id="notable-traits-data">{"Negative":"</code></pre>"}</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 +<script type="text/json" id="notable-traits-data">{"Positive":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.Positive.html\" title=\"struct doc_notable_trait_negative::Positive\">Positive</a></code></h3><pre><code><div class=\"where\">impl <a class=\"trait\" href=\"trait.SomeTrait.html\" title=\"trait doc_notable_trait_negative::SomeTrait\">SomeTrait</a> for <a class=\"struct\" href=\"struct.Positive.html\" title=\"struct doc_notable_trait_negative::Positive\">Positive</a></div>"}</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1 +#![feature(doc_notable_trait, negative_impls)]
2 +
3 +#[doc(notable_trait)]
4 +pub trait SomeTrait {}
5 +
6 +pub struct Positive;
7 +impl SomeTrait for Positive {}
8 +
9 +pub struct Negative;
10 +impl !SomeTrait for Negative {}
11 +
12 +// @has doc_notable_trait_negative/fn.positive.html
13 +// @snapshot positive - '//script[@id="notable-traits-data"]'
14 +pub fn positive() -> Positive {
15 +todo!()
16 +}
17 +
18 +// @has doc_notable_trait_negative/fn.negative.html
19 +// @count - '//script[@id="notable-traits-data"]' 0
20 +pub fn negative() -> Negative {
21 +&[]
22 +}