Skip to content

Commit 26b11d6

Browse files
committed
Don't reuse bindings for ref mut
Reusing bindings causes errors later in lowering: ``` error[E0596]: cannot borrow `vec` as mutable, as it is not declared as mutable --> /checkout/src/test/ui/async-await/argument-patterns.rs:12:20 | LL | async fn b(n: u32, ref mut vec: A) { | ^^^^^^^^^^^ | | | cannot borrow as mutable | help: consider changing this to be mutable: `mut vec` ```
1 parent 1216432 commit 26b11d6

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

compiler/rustc_ast_lowering/src/item.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
11021102
ident,
11031103
_,
11041104
) => (ident, true),
1105+
// For `ref mut` 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),
11051109
_ => {
11061110
// Replace the ident for bindings that aren't simple.
11071111
let name = format!("__arg{}", index);

src/test/rustdoc/async-fn.rs

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ pub async unsafe fn qux() -> char {
2020
'⚠'
2121
}
2222

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

2531
impl Bar for () {}
@@ -32,9 +38,11 @@ pub async fn quux() -> impl Bar {
3238
// @has async_fn/struct.Foo.html
3339
// @matches - '//code' 'pub async fn f\(\)$'
3440
// @matches - '//code' 'pub async unsafe fn g\(\)$'
41+
// @matches - '//code' 'pub async fn mut_self\(self, first: usize\)$'
3542
pub struct Foo;
3643

3744
impl Foo {
3845
pub async fn f() {}
3946
pub async unsafe fn g() {}
47+
pub async fn mut_self(mut self, mut first: usize) {}
4048
}

0 commit comments

Comments
 (0)