闭包参数列表中的 &: 部分是什么?

What's the &: part in a closure argument list?

看代码:

let add_one = |&: x| { 1 + x };

我知道x是闭包参数,但是闭包中的&:是什么意思?

这是 Rust 的一个文档不足的部分(已过时,请参阅评论)。我知道最好的参考是博客 post Purging proc:

Because the current inference scheme is limited, you will sometimes need to specify which of the three fn traits you want explicitly. (Some people also just prefer to do that.) The current syntax is to use a leading &:, &mut:, or :, kind of like an “anonymous parameter”:

// Explicitly create a `Fn` closure.
foo(|&:| { ... })

// Explicitly create a `FnMut` closure.
foo(|&mut:| { ... })

// Explicitly create a `FnOnce` closure.
foo(|:| { ... }) // (ERROR)

Caveat: It is still possible we’ll change the &:/&mut:/: syntax before 1.0; if we can improve inference enough, we might even get rid of it altogether.

看起来它已在 #21843 中删除!感谢您指出这一点,@swizard!