I apologize if this seemed flippant. I sent it sincerely to show that
such an analysis is possible, and it makes up one of the key features
of Rust. I have no idea how feasible this is to implement in C++, but
I suspect it must be hard as it is one of the main motivations for
Rust.

jack.

On Wed, Apr 27, 2016 at 6:04 PM, Jack Moffitt <j...@metajack.im> wrote:
> On Wed, Apr 27, 2016 at 5:29 PM, Kyle Huey <m...@kylehuey.com> wrote:
>> Can we catch this pattern with a compiler somehow?
>
> Yes. Example:
>
> foo.rs:
>
> struct Foo {
>     x: u64,
> }
>
> fn do_bar(foo: Foo) {
> }
>
> fn main() {
>     let foo = Foo {
>         x: 0,
>     };
>     do_bar(foo);
>     if foo.x == 0 {
>         // do stuff
>     }
> }
>
>
> $ rustc foo.rs
> foo.rs:13:8: 13:13 error: use of moved value: `foo.x` [E0382]
> foo.rs:13     if foo.x == 0 {
>                  ^~~~~
>
> jack.
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to