rustdoc renames parameters with `mut` in async fn

Created on 9 Sep 2020  路  7Comments  路  Source: rust-lang/rust

Original:

pub struct Foo;

impl Foo {
    pub async fn good(self, first: usize, second: usize) {}
    pub async fn bad(mut self, mut first: usize, mut second: usize) {}
}

Rendered:

rustdoc output screenshot

This example was tested on Rust 1.46.0, but it has been broken for quite a while. For example, see Server::serve() in tower-lsp version 0.7.0 (built with Rust 1.43.0-nightly, see docs.rs build info).

A-async-await AsyncAwait-Triaged C-bug T-rustdoc

All 7 comments

Thanks for the helpful hint, @jyn514! However, I'm not convinced this is the root cause because it's happening to all mutable by-value function arguments, not just to async functions with self as the first argument. For example, this free function emits similar results:

pub async fn foo(mut first: usize, mut second: usize) {}

Screen Shot 2020-09-15 at 9 56 26 AM

I think the actual root cause may be deeper than the interpretation of Self types, but I can't tell for sure.

This example confirms that the behavior appears to be per-argument instead of per-function. It's not like one bad argument ruins the formatting of the entire function.

pub async fn foo(good: usize, mut bad: usize) {}

Screen Shot 2020-09-15 at 10 04 39 AM

Perhaps we could investigate where in the code the __argN text is being generated and work our way backwards to see what is triggering it?

Hmm, the only relevant location I could find through GitHub search is in rustc_ast_lowering in item.rs:

https://github.com/rust-lang/rust/blob/94b4de0e0793c8921d30e0fb886be712d17db6e5/compiler/rustc_ast_lowering/src/item.rs#L1104

Is rustdoc operating on a desugared form of the AST? I don't think this is the case, since async fn is being successfully displayed here. Is there something else I'm missing?

Here's the issue: https://github.com/rust-lang/rust/blob/c1011165e63480dabf1913e308da8b344dfa8f8a/compiler/rustc_ast_lowering/src/item.rs#L1096-L1109

Looks like it should use hir::PatKind::Binding(_, _, ident, _) => { instead. Are you interested in making a PR? ;)

Is rustdoc operating on a desugared form of the AST? I don't think this is the case, since async fn is being successfully displayed here. Is there something else I'm missing?

Yes, rustdoc works on a desugared version and has to reconstruct the async by hand.

Sure, @jyn514! I will prepare one right away. Thanks for investigating with me. 馃槃

Was this page helpful?
0 / 5 - 0 ratings