Skip to content

BUG: compiler doesn't detect method-chain lifetime breach? #12568

Closed
@phildawes

Description

@phildawes

The following code results in corrupt output: (Ubuntu 12.04 LTS, rust master pulled 25th Feb)

let arr : ~[&str] = std::os::args()[1].split_str("::").collect();
std::io::println("first " + arr[0]);
std::io::println("first again " + arr[0]);

$ rustc isolate_issue.rs
$ ./isolate_issue "foo::bar"
first fir
first again

Ashish Myles noted that an earlier version of rust failed to compile this code, giving an error about the reference to the return value of std::os::args() not being valid for the duration of its use.

https://mail.mozilla.org/pipermail/rust-dev/2014-February/008796.html

Pulling 'args' into a separate local variable works:

let args = std::os::args();
let arr : ~[&str] = args[1].split_str("::").collect();
std::io::println("first " + arr[0]);
std::io::println("first again " + arr[0]);

$ ./isolate_issue "foo::bar"
first foo
first again foo

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