Skip to content

Rustlings #33

@leno23

Description

@leno23
fn main() {
    // You can optionally experiment here.
}

#[cfg(test)]
mod tests {
    // TODO: Fix the compiler errors only by reordering the lines in the tes    t.
    // Don't add, change or remove any line.
    #[test]
    fn move_semantics4() {
        let mut x = Vec::new();
        let y = &mut x;
        let z = &mut x;
// 同时存在两个可变引用(y 和 z)指向 x,违反了 Rust 的借用规则。
// 在 Rust 中,可变引用在最后一次使用后离开作用域
        y.push(42);
        z.push(13);
        assert_eq!(x, [42, 13]);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions