相关疑难解决方法(0)

如何查看导致编译错误的扩展宏代码?

我有一个涉及宏的编译错误:

<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

44
推荐指数
4
解决办法
1万
查看次数

println!借用或拥有变量?

我对借贷和所有权感到困惑.在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'打印到控制台,这是正确的,与第一个代码的结果相同.

ownership rust

39
推荐指数
1
解决办法
2219
查看次数

标签 统计

rust ×2

ownership ×1