Skip to content

rustdoc: Fully support RTN (now missing: support for inlined cross-crate re-exports) #123996

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
fmease opened this issue Apr 16, 2024 · 0 comments
Assignees
Labels
A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate C-bug Category: This is a bug. F-return_type_notation `#[feature(return_type_notation)]` T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented Apr 16, 2024

This is blocked by T-lang's decision on the final syntax of RTN! Unblocked (IINM)


Source:

#![feature(return_type_notation)]

pub fn f<T: Trait<f(): Copy>>() {}

pub trait Trait { fn f() -> impl Clone; }

Current rendered output of f (local scenario, HIR-based cleaning): Fixed by: #137956

pub fn f<T: Trait<f: Copy>>()

Current rendered output of f (inlined cross-crate re-export scenario, rustc_middle::ty-based cleaning):

pub fn f<T>()
where
    T: Trait,
    impl Clone: Copy,
@fmease fmease added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. P-low Low priority C-bug Category: This is a bug. S-blocked Status: Blocked on something else such as an RFC or other implementation work. F-return_type_notation `#[feature(return_type_notation)]` labels Apr 16, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 16, 2024
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 16, 2024
@compiler-errors compiler-errors self-assigned this Apr 16, 2024
@fmease fmease removed the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Mar 12, 2025
jieyouxu added a commit to jieyouxu/rust that referenced this issue Mar 16, 2025
Add RTN support to rustdoc

This adds support to rustdoc and rustdoc-json for rendering `(..)` RTN (return type notation) style generics.

---

Cleaning `rustc_middle::ty::Ty` is not correct still, though, and ends up rendering a function like:

```rust
pub fn foreign<T: Foreign<bar(..): Send>>()
where
    <T as Foreign>::bar(..): 'static,
    T::bar(..): Sync,
```

Into this:

```rust
pub fn foreign<T>()
where
    T: Foreign,
    impl Future<Output = ()>: Send + 'static + Sync,
```

This is because `clean_middle_ty` doesn't actually have sufficient context about whether the RPITIT is in its "defining scope" or not, so we don't know if the type was originally written like `-> impl Trait` or with RTN like `T::method(..)`.

Partially addresses rust-lang#123996 (i.e., HIR side, not middle::ty one)
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 16, 2025
Rollup merge of rust-lang#137956 - compiler-errors:rtn-rustdoc, r=fmease

Add RTN support to rustdoc

This adds support to rustdoc and rustdoc-json for rendering `(..)` RTN (return type notation) style generics.

---

Cleaning `rustc_middle::ty::Ty` is not correct still, though, and ends up rendering a function like:

```rust
pub fn foreign<T: Foreign<bar(..): Send>>()
where
    <T as Foreign>::bar(..): 'static,
    T::bar(..): Sync,
```

Into this:

```rust
pub fn foreign<T>()
where
    T: Foreign,
    impl Future<Output = ()>: Send + 'static + Sync,
```

This is because `clean_middle_ty` doesn't actually have sufficient context about whether the RPITIT is in its "defining scope" or not, so we don't know if the type was originally written like `-> impl Trait` or with RTN like `T::method(..)`.

Partially addresses rust-lang#123996 (i.e., HIR side, not middle::ty one)
@fmease fmease changed the title rustdoc: support RTN once its syntax is somewhat finalized rustdoc: Fully support RTN Jun 7, 2025
@fmease fmease added A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate and removed P-low Low priority labels Jun 7, 2025
@fmease fmease changed the title rustdoc: Fully support RTN rustdoc: Fully support RTN (now missing: support for inlined cross-crate re-exports) Jun 7, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate C-bug Category: This is a bug. F-return_type_notation `#[feature(return_type_notation)]` T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants