On Mon, Oct 22, 2012 at 7:08 PM, Graydon Hoare <gray...@mozilla.com> wrote:
> On 22/10/2012 6:52 AM, Henri Sivonen wrote:
>
>> I can make the translator generate integer literals as the patterns
>> for the arms of the match. However, I think the generated Rust code
>> would be nicer for humans to read with char literals in the patterns.
>
> Write it like: "match c as char { ... }" then. I imagine the resulting
> generated code is identical.

That would work for match but doesn’t work for using char literals for
initializing u8 arrays and the like. Absent the ability to use char
literals the same way unsuffixed integer literals work, I guess the
easiest path forward is for me to generate hex integer literals
instead of char literals. :-(

>> I suggest allowing char literals when matching on an integer (or when
>> otherwise comparing to an integer or when assigning to an integer
>> variable) as long as the Unicode code point of the character
>> represented by the character literal is not greater than the largest
>> integer representable by the integer type.
>
> Interesting possibility. As in: add char literals to the set of types to
> which integer-type inference applies?

Yes. For any code that holds ASCII-compatible data as u8 (including
UTF-8) or that holds UTF-16 data as u16, being able to use char
literals as alternative spellings of integer literals makes code more
readable.

-- 
Henri Sivonen
hsivo...@iki.fi
http://hsivonen.iki.fi/
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to