Tommi: Yes, that's a bug. Thanks for uncovering it! Filed it here:
https://github.com/mozilla/rust/issues/10615

Denis: The reason you get that error is because you're using an older
version (0.8 maybe?). In builds from git master you can now place self
in a mut slot.

On Fri, Nov 22, 2013 at 9:13 AM, spir <[email protected]> wrote:
> On 11/22/2013 07:01 AM, Tommi wrote:
>>
>> Now, off-topic: I've been trying to post the following question to this
>> mailing list for like 4 times, but no dice. I seem to have better luck when
>> replying to posts, so here it goes:
>>
>> struct Value {
>>      n: int
>> }
>>
>> impl Value {
>>      fn squared(mut self) -> Value {
>>          self.n *= self.n;
>>          self
>>      }
>> }
>>
>> fn main() {
>>      let x = Value{ n: 3 };
>>      let y = x.squared();
>>      println!("{} {}", x.n, y.n); // prints 9 9
>> }
>>
>> self isn't being passed by value to squared, since x.n gets mutated as
>> well. This must be a bug, right?
>
>
> That is not what I'd expect, in any case!
> ;-)
>
> PS: cannot run the code, get:
>
> _.rs:12:16: 12:19 error: found `self` in ident position
> _.rs:12     fn squared (mut self) -> Value {
>                         ^~~
>
> ??? (also, underlining looks wrong; unless the actual error is about mut?)
>
> Denis
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to