Skip to content

Commit c61a32a

Browse files
authored
Rollup merge of rust-lang#103746 - notriddle:notriddle/incoherent-dyn-trait, r=GuillaumeGomez
rustdoc: add support for incoherent impls on structs and traits Fixes rust-lang#103170
2 parents 16ca462 + 3195388 commit c61a32a

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/librustdoc/clean/inline.rs

+15
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,21 @@ pub(crate) fn build_impls(
323323
for &did in tcx.inherent_impls(did).iter() {
324324
build_impl(cx, parent_module, did, attrs, ret);
325325
}
326+
327+
// This pretty much exists expressly for `dyn Error` traits that exist in the `alloc` crate.
328+
// See also:
329+
//
330+
// * https://github.com/rust-lang/rust/issues/103170 — where it didn't used to get documented
331+
// * https://github.com/rust-lang/rust/pull/99917 — where the feature got used
332+
// * https://github.com/rust-lang/rust/issues/53487 — overall tracking issue for Error
333+
if tcx.has_attr(did, sym::rustc_has_incoherent_inherent_impls) {
334+
use rustc_middle::ty::fast_reject::SimplifiedTypeGen::*;
335+
let type_ =
336+
if tcx.is_trait(did) { TraitSimplifiedType(did) } else { AdtSimplifiedType(did) };
337+
for &did in tcx.incoherent_impls(type_) {
338+
build_impl(cx, parent_module, did, attrs, ret);
339+
}
340+
}
326341
}
327342

328343
/// `parent_module` refers to the parent of the re-export, not the original item
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(rustc_attrs)]
2+
3+
#[rustc_has_incoherent_inherent_impls]
4+
pub trait FooTrait {}
5+
6+
#[rustc_has_incoherent_inherent_impls]
7+
pub struct FooStruct;
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// aux-build:incoherent-impl-types.rs
2+
// build-aux-docs
3+
4+
#![crate_name = "foo"]
5+
#![feature(rustc_attrs)]
6+
7+
extern crate incoherent_impl_types;
8+
9+
// The only way this actually shows up is if the type gets inlined.
10+
#[doc(inline)]
11+
pub use incoherent_impl_types::FooTrait;
12+
13+
// @has foo/trait.FooTrait.html
14+
// @count - '//section[@id="method.do_something"]' 1
15+
impl dyn FooTrait {
16+
#[rustc_allow_incoherent_impl]
17+
pub fn do_something() {}
18+
}
19+
20+
#[doc(inline)]
21+
pub use incoherent_impl_types::FooStruct;
22+
23+
// @has foo/struct.FooStruct.html
24+
// @count - '//section[@id="method.do_something"]' 1
25+
impl FooStruct {
26+
#[rustc_allow_incoherent_impl]
27+
pub fn do_something() {}
28+
}

0 commit comments

Comments
 (0)