-
Notifications
You must be signed in to change notification settings - Fork 13.3k
RFC: Implement base numeric types and bool as a library #11526
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
Comments
I'd like something like this to fix the documentation issues. Another similar option would be using lang items like |
Yeah, a less radical proposal could be: #[repr(u8)]
pub enum bool {
true = 1,
false = 0,
}
#[lang="u8"] pub struct u8;
#[lang="u16"] pub struct u16;
#[lang="u32"] pub struct u32;
#[lang="u64"] pub struct u64;
#[lang="uintptr"] pub struct uintptr;
#[lang="i8"] pub struct i8;
#[lang="i16"] pub struct i16;
#[lang="i32"] pub struct i32;
#[lang="i64"] pub struct i64;
#[lang="intptr"] pub struct intptr;
#[lang="f32"] pub struct f32;
#[lang="f64"] pub struct f64; |
I think we should make all built-in types lang items :). So also:
And supposing further hypothetical language features:
(Given good DST Which part of the original proposal requires CTFE? |
Rust can only evaluate constant expressions using the built-in primitive types at the moment. Calling library code in constant expressions means adding support for at least a limited form of CTFE. |
How about adding integer generic parameters, and have the uint type be |
At the moment, numeric operations are hard-wired into the compiler. This allows them to be called at compile time, as in: pub static BITS : uint = 32;
pub static BYTES : uint = (BITS / 8); If we removed this magic and implemented the operations in the operator traits directly, people would get very annoyed because their constexprs would stop working. CTFE would also allow us to do other neat things, like implementing casts (ie. the |
I think such a major redesign is unlikely to happen at this stage. |
This issue has been moved to the RFCs repo: rust-lang/rfcs#304 |
Add redundant_as_str lint This lint checks for `as_str` on a `String` immediately followed by `as_bytes` or `is_empty` as those methods are available on `String` too. This could possibly also be extended to `&[u8]` in the future. changelog: New lint [`redundant_as_str`] rust-lang#11526
Here is a (possibly crazy) proposal to remove some magic from the compiler:
This relies on many hypothetical language features including the
llvm!
macro, CTFE and possibly some way of implementing adding literal assignments, and so might be too ambitious for 1.0. But in the end it could make our language far more extensible and powerful. It might also help simplify our documentation issues with builtin types #10114 #11409The text was updated successfully, but these errors were encountered: