Skip to content

Commit d984671

Browse files
Rollup merge of rust-lang#109937 - compiler-errors:rustdoc-rpit-cant-be-documented, r=GuillaumeGomez
Don't collect return-position impl traits for documentation rust-lang#104889 modified the rustdoc ast collection step to use a HIR visitor, which more thoroughly walks the HIR tree. that means that we're going to encounter inner items (incl return-position impl traits and async fn opaque futures) that are not possible to document. FIxes (but does not close due to being a beta regression) rust-lang#109931 r? `@GuillaumeGomez`
2 parents 72e535e + 72ef85d commit d984671

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/librustdoc/visit_ast.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,20 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
421421
| hir::ItemKind::Struct(..)
422422
| hir::ItemKind::Union(..)
423423
| hir::ItemKind::TyAlias(..)
424-
| hir::ItemKind::OpaqueTy(..)
424+
| hir::ItemKind::OpaqueTy(hir::OpaqueTy {
425+
origin: hir::OpaqueTyOrigin::TyAlias, ..
426+
})
425427
| hir::ItemKind::Static(..)
426428
| hir::ItemKind::Trait(..)
427429
| hir::ItemKind::TraitAlias(..) => {
428430
self.add_to_current_mod(item, renamed, import_id);
429431
}
432+
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
433+
origin: hir::OpaqueTyOrigin::AsyncFn(_) | hir::OpaqueTyOrigin::FnReturn(_),
434+
..
435+
}) => {
436+
// return-position impl traits are never nameable, and should never be documented.
437+
}
430438
hir::ItemKind::Const(..) => {
431439
// Underscore constants do not correspond to a nameable item and
432440
// so are never useful in documentation.

tests/rustdoc/async-fn-opaque-item.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// compile-flags: --document-private-items --crate-type=lib
2+
// edition: 2021
3+
4+
// Issue 109931 -- test against accidentally documenting the `impl Future`
5+
// that comes from an async fn desugaring.
6+
7+
// Check that we don't document an unnamed opaque type
8+
// @!has async_fn_opaque_item/opaque..html
9+
10+
// Checking there is only a "Functions" header and no "Opaque types".
11+
// @has async_fn_opaque_item/index.html
12+
// @count - '//*[@class="small-section-header"]' 1
13+
// @has - '//*[@class="small-section-header"]' 'Functions'
14+
15+
pub async fn test() {}

0 commit comments

Comments
 (0)