Skip to content
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 primitive numeric traits #124243

Closed
wants to merge 3 commits into from
Closed

Conversation

CAD97
Copy link
Contributor

@CAD97 CAD97 commented Apr 21, 2024

@rustbot
Copy link
Collaborator

rustbot commented Apr 21, 2024

r? @workingjubilee

rustbot has assigned @workingjubilee.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 21, 2024
@rust-log-analyzer

This comment has been minimized.

@workingjubilee workingjubilee added S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 21, 2024
@CAD97
Copy link
Contributor Author

CAD97 commented Apr 21, 2024

If this is to actually land, I'll probably want to take a stab at refactoring the primitive impl macros to reduce duplication of the docs, e.g. something like

macro_rules! int_methods {
    (
        type Self = $SelfT:ty;
        // …

        $callback:path!($);
    ) => {
        $callback!(
            #[doc(concat!())]
            fn count_ones;
        );
        // …
    };
}

trait Integer {
    int_methods!(
        type Self = Self;
        int_decl!($);
    );
}

impl i32 {
    int_methods!(
        type Self = i32;
        int_impl!($);
    );
}

I'm not 100% confident this'd be an overall improvement, but centralizing the docs so they can't diverge at least sounds good on paper. (Such could land separately.)

@CAD97 CAD97 force-pushed the primitive-traits branch 2 times, most recently from d06246a to 2cd0a21 Compare April 22, 2024 01:09
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@CAD97 CAD97 force-pushed the primitive-traits branch from 88e9bff to 473b997 Compare April 22, 2024 04:23
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
   Compiling compiler_builtins v0.1.109
error: unresolved link to `ilog2`
   --> library/core/src/primitive/int_macros.rs:21:15
    |
21  |         /// [`ilog2`] function which returns a consistent number, even if the type widens.
    |               ^^^^^ no item named `ilog2` in scope
   ::: library/core/src/primitive/mod.rs:200:5
    |
200 |     int_decl!();
    |     ----------- in this macro invocation
---

error: unresolved link to `checked_add`
   --> library/core/src/primitive/int_macros.rs:86:19
    |
86  |         /// `x.`[`checked_add`]`(y).`[`unwrap_unchecked`]`()`.
    |                   ^^^^^^^^^^^ no item named `checked_add` in scope
   ::: library/core/src/primitive/mod.rs:200:5
    |
200 |     int_decl!();
    |     ----------- in this macro invocation
    |     ----------- in this macro invocation
    |
    = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
    = note: this error originates in the macro `int_decl` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unresolved link to `unwrap_unchecked`
   --> library/core/src/primitive/int_macros.rs:86:40
    |
86  |         /// `x.`[`checked_add`]`(y).`[`unwrap_unchecked`]`()`.
    |
   ::: library/core/src/primitive/mod.rs:200:5
    |
200 |     int_decl!();
---

error: unresolved link to `wrapping_add`
   --> library/core/src/primitive/int_macros.rs:89:54
    |
89  |         /// use this.  Instead, you're looking for [`wrapping_add`].
    |                                                      ^^^^^^^^^^^^ no item named `wrapping_add` in scope
   ::: library/core/src/primitive/mod.rs:200:5
    |
200 |     int_decl!();
    |     ----------- in this macro invocation
    |     ----------- in this macro invocation
    |
    = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
    = note: this error originates in the macro `int_decl` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unresolved link to `checked_add`
   --> library/core/src/primitive/int_macros.rs:94:51
    |
94  |         /// `self + rhs < Self::MIN`, i.e. when [`checked_add`] would return `None`.
    |                                                   ^^^^^^^^^^^ no item named `checked_add` in scope
   ::: library/core/src/primitive/mod.rs:200:5
    |
200 |     int_decl!();
    |     ----------- in this macro invocation
    |     ----------- in this macro invocation
    |
    = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
    = note: this error originates in the macro `int_decl` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unresolved link to `checked_sub`
   --> library/core/src/primitive/int_macros.rs:110:19
    |
110 |         /// `x.`[`checked_sub`]`(y).`[`unwrap_unchecked`]`()`.
    |                   ^^^^^^^^^^^ no item named `checked_sub` in scope
   ::: library/core/src/primitive/mod.rs:200:5
    |
200 |     int_decl!();
    |     ----------- in this macro invocation
    |     ----------- in this macro invocation
    |
    = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
    = note: this error originates in the macro `int_decl` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unresolved link to `unwrap_unchecked`
   --> library/core/src/primitive/int_macros.rs:110:40
    |
110 |         /// `x.`[`checked_sub`]`(y).`[`unwrap_unchecked`]`()`.
    |
   ::: library/core/src/primitive/mod.rs:200:5
    |
200 |     int_decl!();
---

error: unresolved link to `wrapping_sub`
   --> library/core/src/primitive/int_macros.rs:113:54
    |
113 |         /// use this.  Instead, you're looking for [`wrapping_sub`].
    |                                                      ^^^^^^^^^^^^ no item named `wrapping_sub` in scope
   ::: library/core/src/primitive/mod.rs:200:5
    |
200 |     int_decl!();
    |     ----------- in this macro invocation
    |     ----------- in this macro invocation
    |
    = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
    = note: this error originates in the macro `int_decl` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unresolved link to `checked_sub`
   --> library/core/src/primitive/int_macros.rs:118:51
    |
118 |         /// `self - rhs < Self::MIN`, i.e. when [`checked_sub`] would return `None`.
    |                                                   ^^^^^^^^^^^ no item named `checked_sub` in scope
   ::: library/core/src/primitive/mod.rs:200:5
    |
200 |     int_decl!();
    |     ----------- in this macro invocation
    |     ----------- in this macro invocation
    |
    = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
    = note: this error originates in the macro `int_decl` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unresolved link to `checked_mul`
   --> library/core/src/primitive/int_macros.rs:134:19
    |
134 |         /// `x.`[`checked_mul`]`(y).`[`unwrap_unchecked`]`()`.
    |                   ^^^^^^^^^^^ no item named `checked_mul` in scope
   ::: library/core/src/primitive/mod.rs:200:5
    |
200 |     int_decl!();
    |     ----------- in this macro invocation
    |     ----------- in this macro invocation
    |
    = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
    = note: this error originates in the macro `int_decl` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unresolved link to `unwrap_unchecked`
   --> library/core/src/primitive/int_macros.rs:134:40
    |
134 |         /// `x.`[`checked_mul`]`(y).`[`unwrap_unchecked`]`()`.
    |
   ::: library/core/src/primitive/mod.rs:200:5
    |
200 |     int_decl!();
---

error: unresolved link to `wrapping_mul`
   --> library/core/src/primitive/int_macros.rs:137:54
    |
137 |         /// use this.  Instead, you're looking for [`wrapping_mul`].
    |                                                      ^^^^^^^^^^^^ no item named `wrapping_mul` in scope
   ::: library/core/src/primitive/mod.rs:200:5
    |
200 |     int_decl!();
    |     ----------- in this macro invocation
    |     ----------- in this macro invocation
    |
    = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
    = note: this error originates in the macro `int_decl` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unresolved link to `checked_mul`
   --> library/core/src/primitive/int_macros.rs:142:51
    |
142 |         /// `self * rhs < Self::MIN`, i.e. when [`checked_mul`] would return `None`.
    |                                                   ^^^^^^^^^^^ no item named `checked_mul` in scope
   ::: library/core/src/primitive/mod.rs:200:5
    |
200 |     int_decl!();
    |     ----------- in this macro invocation
    |     ----------- in this macro invocation
    |
    = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
    = note: this error originates in the macro `int_decl` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unresolved link to `checked_shl`
   --> library/core/src/primitive/int_macros.rs:200:25
    |
200 |         /// i.e. when [`checked_shl`] would return `None`.
    |                         ^^^^^^^^^^^ no item named `checked_shl` in scope
   ::: library/core/src/primitive/mod.rs:200:5
    |
200 |     int_decl!();
    |     ----------- in this macro invocation
    |     ----------- in this macro invocation
    |
    = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
    = note: this error originates in the macro `int_decl` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unresolved link to `checked_shr`
   --> library/core/src/primitive/int_macros.rs:218:25
    |
218 |         /// i.e. when [`checked_shr`] would return `None`.
    |                         ^^^^^^^^^^^ no item named `checked_shr` in scope
   ::: library/core/src/primitive/mod.rs:200:5
    |
200 |     int_decl!();
    |     ----------- in this macro invocation

@CAD97
Copy link
Contributor Author

CAD97 commented Jun 4, 2024

Closing this as the ACP seems unlikely to be accepted.

@CAD97 CAD97 closed this Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants