Not only this, but match patterns are also extremely often used intentionally 
to move values. The trivial example is something like

match some_opt_val {
    Some(x) => do_something_with(x),
    None => default_behavior()
}

By-ref matching is actually the more infrequent type of matching in my 
experience.

-Kevin

On May 30, 2014, at 9:05 AM, Benjamin Striegel <ben.strie...@gmail.com> wrote:

> What you're overlooking is that patterns are used for more than just `match` 
> expressions. They can also be used in both assignment statements and in 
> function/closure signatures. For example, note that `x` and `y` are the same 
> type in the following program:
> 
>     fn main() {
>         let ref x = 3;
>         let y = &3;
>         foo(x);
>         foo(y);
>     }
>     
>     fn foo(x: &int) {
>         println!("{:i}", *x);
>     }
> 
> 
> Removing the `ref` keyword and making patterns reference by default would 
> make `let x = 3;` declare a reference to an integer. Then you'd need a new 
> keyword to express when you don't want this, and you're back at square one.
> 
> 
> On Fri, May 30, 2014 at 9:56 AM, Emmanuel Surleau 
> <emmanuel.surl...@gmail.com> wrote:
> I think the 'ref' keyword removal is a very good idea. It has bitten
> me several times, and the idea that pattern matching something
> essentially performs a side effect (moving the value) leaves me
> uncomfortable.
> 
> Cheers,
> 
> Emm
> _______________________________________________
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
> 
> _______________________________________________
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to