-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add arbitrary-base literals #10338
Comments
I like it. 👍 |
I like it, but I have some questions:
|
Couldn't it be case-insensitive for radix below 36 and case-sensitive above? I say the format just be The common base64 indexing should be kept, and we could define an indexing up to base 95 using standard ASCII, alternatively the indexing for > 36 could simply be the order they appear after space. Yes, the common bases should be kept. |
The current base variants have clear use-cases. I haven't seen a clear use case for arbitrary base numeric literals, and to that end I'd suggest using a syntax extension to do this. Depending on its design, it can avoid the character set issues and other tokenizing ambiguities. Possible API: // Actual number in a string, to avoid tokenizing issues
base!(12, "1ab")
base!(1, "111111")
// Option to separate individual digits with a comma
// (similar to how sexagesimal digits were written by the Babylonians)
// thus avoiding an arbitrary maximum base. Individual digits written in
// the natively supported bases (2, 8, 10, 16)
base!(64, "10,32,17")
// Possible idea of where to stick the type ascription
base!(64, "32", u32)
// Also could work with floating point literals
// (although those actually have a clear use case
// and probably should be added in a non-syntax extension manner)
base!(16, "0x1.fffffffffffffp+1023", f32) The floating point literal syntax was taken from #1433. |
I'm alright with the syntax extension approach as well, personally. |
Is there any use case for other bases? I don't think I've ever used or wanted to use any base other than 2, 8, 10 or 16 when programming. Would this proposal support balanced ternary and base e? |
I like the syntax extention idea. One problem with the proposed arbitrary base literal syntax, is that there's no way to know whether the type suffix (u16,u32) is a type suffix or part of the number above a certain base without adding a token between them. |
Closing, a feature such as this needs to go through the RFC process we have in place now (didn't exist when this issue was created). |
Ignore synthetic type parameters for `extra_unused_type_parameters` There was a minor bug around calculating spans when forming the help message. An example: ```rust fn unused_opaque<A, B>(dummy: impl Default) {} // ^^ ^ ``` In this case, the entire list of generics should be highlighted, instead of each individual parameter. The culprit is the `impl Default`, which registers as a type parameter but doesn't live within the `<...>`. Because synthetic parameters can't ever be manually created, we just ignore them for this lint. r? `@flip1995` changelog: none <!-- changelog_checked -->
We now have hex, binary, and octal literals, but when will it end? #10243 suggested adding literals with any radix, like
64rABC
. What say you?The text was updated successfully, but these errors were encountered: