From 2baa0ceff4e6dc75751fdca4be68e87f5cf35a6e Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 8 Nov 2020 11:45:13 -0500 Subject: 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` ``` --- compiler/rustc_ast_lowering/src/item.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'compiler') diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 0cfcd843ddd..1335bb02580 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -1102,6 +1102,10 @@ impl<'hir> LoweringContext<'_, 'hir> { ident, _, ) => (ident, true), + // For `ref mut` arguments, we can't reuse the binding, but + // we can keep the same name for the parameter. + // This lets rustdoc render it correctly in documentation. + hir::PatKind::Binding(_, _, ident, _) => (ident, false), _ => { // Replace the ident for bindings that aren't simple. let name = format!("__arg{}", index); -- cgit 1.4.1-3-g733a5