Skip to content

Commit b21b74b

Browse files
committed
Auto merge of #125134 - compiler-errors:negative-traits-are-not-notable, r=fmease
rustdoc: Negative impls are not notable In #124097, we add `impl !Iterator for [T]` for coherence reasons, and since `Iterator` is a [notable trait](https://github.com/rust-lang/rust/blob/8387315ab3c26a57a1f53a90f188f0bc88514bca/library/core/src/iter/traits/iterator.rs#L40), this means that all `-> &[_]` now are tagged with a `!Iterator` impl as a notable trait. I "fixed" the failing tests in that PR with 6cbbb8b, where I just blessed the tests, since I didn't want to mix these changes with that PR; however, don't believe negative impls are notable, and this PR aims to prevent these impls from being mentioned. In the standard library, we use negative impls purely to guide coherence. They're not really a signal of anything useful to the end-user. If there ever is a case that we want negative impls to be mentioned as notable, this really should be an opt-in feature.
2 parents ade234d + 8994840 commit b21b74b

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

src/librustdoc/html/render/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,10 @@ pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &mut Context<'_>) -> O
14241424
if let Some(impls) = cx.cache().impls.get(&did) {
14251425
for i in impls {
14261426
let impl_ = i.inner_impl();
1427+
if impl_.polarity != ty::ImplPolarity::Positive {
1428+
continue;
1429+
}
1430+
14271431
if !ty.is_doc_subtype_of(&impl_.for_, cx.cache()) {
14281432
// Two different types might have the same did,
14291433
// without actually being the same.
@@ -1459,6 +1463,10 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {
14591463

14601464
for i in impls {
14611465
let impl_ = i.inner_impl();
1466+
if impl_.polarity != ty::ImplPolarity::Positive {
1467+
continue;
1468+
}
1469+
14621470
if !ty.is_doc_subtype_of(&impl_.for_, cx.cache()) {
14631471
// Two different types might have the same did,
14641472
// without actually being the same.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script type="text/json" id="notable-traits-data">{"Negative":"&lt;/code&gt;&lt;/pre&gt;"}</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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>
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)