Skip to content

Function return does not always perform a move #995

Closed
@brson

Description

@brson

This is a problem for unique pointers

use std;
import std::unsafe;

fn f(addr: @mutable int) -> ~int {
    let i = ~100;
    let a: int = unsafe::reinterpret_cast(i);
    log a;
    *addr = a;
    // Since i is not a temporary it gets copied, which is not what you expect
    ret i;
}

fn main() {
    let addr = @mutable 0;
    let i <- f(addr);
    let expected = *addr;
    let actual: int = unsafe::reinterpret_cast(i);
    log expected;
    log actual;
    assert expected == actual;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions