我有一个涉及宏的编译错误:
<mdo macros>:6:19: 6:50 error: cannot move out of captured outer variable in an `FnMut` closure
<mdo macros>:6 bind ( $ e , move | $ p | mdo ! { $ ( $ t ) * } ) ) ; (
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<mdo macros>:1:1: 14:36 note: in expansion of mdo!
<mdo macros>:6:27: 6:50 note: expansion site
<mdo macros>:1:1: 14:36 note: in expansion of mdo!
<mdo macros>:6:27: 6:50 note: expansion site
<mdo macros>:1:1: 14:36 note: in expansion of mdo!
src/parser.rs:30:42: …Run Code Online (Sandbox Code Playgroud) 我对借贷和所有权感到困惑.在Rust 文档中有关引用和借用的内容
let mut x = 5;
{
let y = &mut x;
*y += 1;
}
println!("{}", x);
Run Code Online (Sandbox Code Playgroud)
他们说
println!可以借x.
我很困惑.如果println!借入x,为什么它通过x不&x?
我尝试在下面运行此代码
fn main() {
let mut x = 5;
{
let y = &mut x;
*y += 1;
}
println!("{}", &x);
}
Run Code Online (Sandbox Code Playgroud)
除了传递&x给代码之外,这段代码与上面的代码相同println!.它将'6'打印到控制台,这是正确的,与第一个代码的结果相同.