Skip to content

Commit 978597f

Browse files
Rollup merge of rust-lang#103432 - jsha:box-is-not-notable, r=GuillaumeGomez
rustdoc: don't mark Box<T> as Iterator, Read, etc Because Box<T> has pass-through implementations, rustdoc was giving it the "Notable Traits" treatment for Iterator, Read, Write, and Future, even when the type of T was unspecified. Pin had the same problem, but just for Future. Fixes rust-lang#100320
2 parents 485adb5 + 63d1a72 commit 978597f

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/librustdoc/html/render/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,15 @@ fn notable_traits_decl(decl: &clean::FnDecl, cx: &Context<'_>) -> String {
12761276

12771277
if let Some((did, ty)) = decl.output.as_return().and_then(|t| Some((t.def_id(cx.cache())?, t)))
12781278
{
1279+
// Box has pass-through impls for Read, Write, Iterator, and Future when the
1280+
// boxed type implements one of those. We don't want to treat every Box return
1281+
// as being notably an Iterator (etc), though, so we exempt it. Pin has the same
1282+
// issue, with a pass-through impl for Future.
1283+
if Some(did) == cx.tcx().lang_items().owned_box()
1284+
|| Some(did) == cx.tcx().lang_items().pin_type()
1285+
{
1286+
return "".to_string();
1287+
}
12791288
if let Some(impls) = cx.cache().impls.get(&did) {
12801289
for i in impls {
12811290
let impl_ = i.inner_impl();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#![feature(doc_notable_trait)]
2+
#![feature(lang_items)]
3+
#![feature(no_core)]
4+
#![no_core]
5+
#[lang = "owned_box"]
6+
pub struct Box<T>;
7+
8+
impl<T> Box<T> {
9+
pub fn new(x: T) -> Box<T> {
10+
Box
11+
}
12+
}
13+
14+
#[doc(notable_trait)]
15+
pub trait FakeIterator {}
16+
17+
impl<I: FakeIterator> FakeIterator for Box<I> {}
18+
19+
#[lang = "pin"]
20+
pub struct Pin<T>;
21+
22+
impl<T> Pin<T> {
23+
pub fn new(x: T) -> Pin<T> {
24+
Pin
25+
}
26+
}
27+
28+
impl<I: FakeIterator> FakeIterator for Pin<I> {}
29+
30+
// @!has doc_notable_trait_box_is_not_an_iterator/fn.foo.html '//*' 'Notable'
31+
pub fn foo<T>(x: T) -> Box<T> {
32+
Box::new(x)
33+
}
34+
35+
// @!has doc_notable_trait_box_is_not_an_iterator/fn.bar.html '//*' 'Notable'
36+
pub fn bar<T>(x: T) -> Pin<T> {
37+
Pin::new(x)
38+
}

0 commit comments

Comments
 (0)