I did not know that the manual agrees with me, but I've noticed the
existing behaviour and find it very unintuitive.


Andrew



On Fri, May 30, 2014 at 06:02:51PM +0300, Tommi wrote:
> The manual says that the precedence of `as` operator is lower than that of 
> the binary `*` operator. Thus I would not expect the following to compile 
> (but it does):
> 
> let a: u16 = 1;
> let b: u32 = 2;
> 
> let r = a * b as u16;
> 
> 
> Since multiplication is supposed to have precedence over casting, I would 
> expect the last line to be equivalent to:
> 
> let r = (a * b) as u16;
> 
> ...which doesn't compile because `a` and `b` have different types.
> 
> 
> Here the compiler clearly first converts `b` to u16 and then multiplies `a` 
> with the result of that conversion:
> 
> let r = a * b as u16;
> 
> ...but that should happen only if the `as` operator has a higher precedence 
> than the binary `*` operator.
> 
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
> 

-- 
Andrew Poelstra
Mathematics Department, University of Texas at Austin
Email: apoelstra at wpsoftware.net
Web:   http://www.wpsoftware.net/andrew

"If they had taught a class on how to be the kind of citizen Dick Cheney
 worries about, I would have finished high school."   --Edward Snowden

Attachment: pgp0NAktEAbQS.pgp
Description: PGP signature

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to