Skip to content

Mutable vector modified in-place while evaluating right side of assignment #16602

Closed
@MrAlert

Description

@MrAlert

Assigning to a mutable vector causes it to be modified in-place even if the right side of the assignment references it.

#[test]
fn mutable_vector_in_place_assignment () {
    let mut t = [1u, ..2];
    t = [t[1] * 2, t[0] * 2];
    assert_eq!(t.as_slice(), &[2, 2]);
}
running 1 test
test mutable_vector_in_place_assignment ... FAILED

failures:

---- mutable_vector_in_place_assignment stdout ----
        task 'mutable_vector_in_place_assignment' failed at 'assertion failed: `(left == right) && (right == left)` (left: `[2, 4]`, right: `[2, 2]`)', test2.rs:5



failures:
    mutable_vector_in_place_assignment

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured

task '<main>' failed at 'Some tests failed', /build/rust-git/src/rust/src/libtest/lib.rs:242

On IRC, @Kimundi pointed me to #15300, which might be related.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.P-mediumMedium priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions