Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A cloned slice can escape the scope where it is valid. #19634

Closed
shepmaster opened this issue Dec 8, 2014 · 2 comments
Closed

A cloned slice can escape the scope where it is valid. #19634

shepmaster opened this issue Dec 8, 2014 · 2 comments

Comments

@shepmaster
Copy link
Member

This code compiles successfully, but doesn't seem like it should:

fn main() {
    let mut view;

    {
        let array2 = vec![4i, 5, 6];
        view = array2.as_slice().clone();
    }

    // Do not expect view to be valid here. Removing `clone` above makes this an error.

    println!("{}", view);
}

Version:

$ rustc --version=verbose
rustc 0.13.0-dev (358db12a8 2014-12-06 17:42:16 +0000)
binary: rustc
commit-hash: 358db12a89d6edf4a61cb3c8d170449faea925cc
commit-date: 2014-12-06 17:42:16 +0000
host: x86_64-apple-darwin
release: 0.13.0-dev
@shepmaster
Copy link
Member Author

Seems like a dup of #19261

@Fabiensk
Copy link

Fabiensk commented Dec 8, 2014

Note that if we replace the .clone() by a .slice_from(0), then it does not compile any more (as I would expect):

error: array2 does not live long enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants