Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

rustdoc: support RTN once its syntax is somewhat finalized #123996

Open
fmease opened this issue Apr 16, 2024 · 0 comments
Open

rustdoc: support RTN once its syntax is somewhat finalized #123996

fmease opened this issue Apr 16, 2024 · 0 comments
Assignees
Labels
C-bug Category: This is a bug. F-return_type_notation `#[feature(return_type_notation)]` P-low Low priority 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):

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-return_type_notation `#[feature(return_type_notation)]` P-low Low priority 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