Skip to content

Commit 4b0b42a

Browse files
authored
Rollup merge of #76730 - ebkalderon:rustdoc-fix-mut-args-async-fn, r=tmandry
Fix rustdoc rendering of by-value mutable arguments in async fn r? `@jyn514` Fixes #76517.
2 parents 9722952 + 38127ca commit 4b0b42a

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

compiler/rustc_ast_lowering/src/item.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1096,8 +1096,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
10961096
// Check if this is a binding pattern, if so, we can optimize and avoid adding a
10971097
// `let <pat> = __argN;` statement. In this case, we do not rename the parameter.
10981098
let (ident, is_simple_parameter) = match parameter.pat.kind {
1099-
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, _) => {
1100-
(ident, true)
1099+
hir::PatKind::Binding(
1100+
hir::BindingAnnotation::Unannotated | hir::BindingAnnotation::Mutable,
1101+
_,
1102+
ident,
1103+
_,
1104+
) => (ident, true),
1105+
// For `ref mut` or wildcard arguments, we can't reuse the binding, but
1106+
// we can keep the same name for the parameter.
1107+
// This lets rustdoc render it correctly in documentation.
1108+
hir::PatKind::Binding(_, _, ident, _) => (ident, false),
1109+
hir::PatKind::Wild => {
1110+
(Ident::with_dummy_span(rustc_span::symbol::kw::Underscore), false)
11011111
}
11021112
_ => {
11031113
// Replace the ident for bindings that aren't simple.

src/test/rustdoc/async-fn.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// edition:2018
2+
#![feature(min_const_generics)]
23

34
// @has async_fn/fn.foo.html '//pre[@class="rust fn"]' 'pub async fn foo() -> Option<Foo>'
45
pub async fn foo() -> Option<Foo> {
@@ -20,6 +21,12 @@ pub async unsafe fn qux() -> char {
2021
'⚠'
2122
}
2223

24+
// @has async_fn/fn.mut_args.html '//pre[@class="rust fn"]' 'pub async fn mut_args(a: usize)'
25+
pub async fn mut_args(mut a: usize) {}
26+
27+
// @has async_fn/fn.mut_ref.html '//pre[@class="rust fn"]' 'pub async fn mut_ref(x: i32)'
28+
pub async fn mut_ref(ref mut x: i32) {}
29+
2330
trait Bar {}
2431

2532
impl Bar for () {}
@@ -32,9 +39,16 @@ pub async fn quux() -> impl Bar {
3239
// @has async_fn/struct.Foo.html
3340
// @matches - '//code' 'pub async fn f\(\)$'
3441
// @matches - '//code' 'pub async unsafe fn g\(\)$'
42+
// @matches - '//code' 'pub async fn mut_self\(self, first: usize\)$'
3543
pub struct Foo;
3644

3745
impl Foo {
3846
pub async fn f() {}
3947
pub async unsafe fn g() {}
48+
pub async fn mut_self(mut self, mut first: usize) {}
4049
}
50+
51+
pub trait Trait<const N: usize> {}
52+
// @has async_fn/fn.const_generics.html
53+
// @has - '//pre[@class="rust fn"]' 'pub async fn const_generics<const N: usize>(_: impl Trait<N>)'
54+
pub async fn const_generics<const N: usize>(_: impl Trait<N>) {}

src/test/rustdoc/const-generics/const-generics-docs.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ pub async fn a_sink<const N: usize>(v: [u8; N]) -> impl Trait<N> {
7070
}
7171

7272
// @has foo/fn.b_sink.html '//pre[@class="rust fn"]' \
73-
// 'pub async fn b_sink<const N: usize>(__arg0: impl Trait<N>)'
74-
// FIXME(const_generics): This should be `_` not `__arg0`.
73+
// 'pub async fn b_sink<const N: usize>(_: impl Trait<N>)'
7574
pub async fn b_sink<const N: usize>(_: impl Trait<N>) {}
7675

7776
// @has foo/fn.concrete.html '//pre[@class="rust fn"]' \

0 commit comments

Comments
 (0)