Skip to content

Additional NonZero conversions #129036

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

clarfonthey
Copy link
Contributor

@clarfonthey clarfonthey commented Aug 13, 2024

ACP: rust-lang/libs-team#145

Requires FCP due to insta-stable APIs added:

impl<T> From<&NonZero<T>> for &T;
impl<T> From<&[NonZero<T>]> for &[T];
impl<T, const N: usize> From<[NonZero<T>; N]> for [T; N];
impl<T> TryFrom<&T> for &NonZero<T>;
impl<T> TryFrom<&[T]> for &[NonZero<T>];
impl<T, const N: usize> TryFrom<[T; N]> for [NonZero<T>; N];

Note that the Error for the TryFrom implementations is TryFromIntError to match the similar impls.

r? rust-lang/libs-api


Leaving as a draft at the moment because I'm not sure how to fix the below error:

error[E0119]: conflicting implementations of trait `TryFrom<&_>` for type `&NonZero<_>`
   --> core/src/convert/mod.rs:805:1
    |
805 | / impl<T, U> TryFrom<U> for T
806 | | where
807 | |     U: Into<T>,
    | |_______________^ conflicting implementation for `&NonZero<_>`
    |
   ::: core/src/num/nonzero.rs:310:1
    |
310 | / impl<'a, T> TryFrom<&'a T> for &'a NonZero<T>
311 | | where
312 | |     T: ZeroablePrimitive,
    | |_________________________- first implementation here
    |
    = note: downstream crates may implement trait `convert::From<&_>` for type `&num::nonzero::NonZero<_>`

This shouldn't be possible given the fact that the ZeroablePrimitive trait is sealed, but I'm not quite sure how to fix it. If I can't figure it out before FCP ends, then I'll just replace it with a macro version that enumerates through the options for T.

@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 Aug 13, 2024
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Aug 29, 2024

☔ The latest upstream changes (presumably #129750) made this pull request unmergeable. Please resolve the merge conflicts.

@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)
#16 2.839 Building wheels for collected packages: reuse
#16 2.840   Building wheel for reuse (pyproject.toml): started
#16 3.082   Building wheel for reuse (pyproject.toml): finished with status 'done'
#16 3.084   Created wheel for reuse: filename=reuse-4.0.3-cp310-cp310-manylinux_2_35_x86_64.whl size=132715 sha256=dfa09868353292d98f811d3efdb0d54d07389e808efc71d68e3b93c514bf8bec
#16 3.084   Stored in directory: /tmp/pip-ephem-wheel-cache-pfpcc6uy/wheels/3d/8d/0a/e0fc6aba4494b28a967ab5eaf951c121d9c677958714e34532
#16 3.087 Installing collected packages: boolean-py, binaryornot, tomlkit, reuse, python-debian, markupsafe, license-expression, jinja2, chardet, attrs
#16 3.492 Successfully installed attrs-23.2.0 binaryornot-0.4.4 boolean-py-4.0 chardet-5.2.0 jinja2-3.1.4 license-expression-30.3.0 markupsafe-2.1.5 python-debian-0.1.49 reuse-4.0.3 tomlkit-0.13.0
#16 3.492 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#16 DONE 3.6s
---
   Compiling std v0.0.0 (/checkout/library/std)
error: unused import: `hint`
  --> core/src/num/nonzero.rs:10:18
   |
10 | use crate::{fmt, hint, intrinsics, ptr, slice, ub_checks};
   |
   = note: `-D unused-imports` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(unused_imports)]`


error[E0119]: conflicting implementations of trait `TryFrom<&_>` for type `&NonZero<_>`
   --> core/src/convert/mod.rs:805:1
    |
805 | / impl<T, U> TryFrom<U> for T
807 | |     U: Into<T>,
807 | |     U: Into<T>,
    | |_______________^ conflicting implementation for `&NonZero<_>`
   ::: core/src/num/nonzero.rs:310:1
    |
    |
310 | / impl<'a, T> TryFrom<&'a T> for &'a NonZero<T>
311 | | where
312 | |     T: ZeroablePrimitive,
    | |_________________________- first implementation here
    |
    = note: downstream crates may implement trait `convert::From<&_>` for type `&num::nonzero::NonZero<_>`
For more information about this error, try `rustc --explain E0119`.
error: could not compile `core` (lib) due to 2 previous errors
Build completed unsuccessfully in 0:00:24
  local time: Sun Sep  1 20:02:44 UTC 2024

@tgross35 tgross35 added needs-fcp This change is insta-stable, so needs a completed FCP to proceed. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 19, 2024
@Dylan-DPC
Copy link
Member

@clarfonthey since this is waiting on a review, do you still want this to be as a draft? or is this ready for review?

@clarfonthey
Copy link
Contributor Author

It is ready for review; see the OP.

I should just unmark it as draft and do what I said I was going to do, which is manually implement everything for all the NonZero types. I don't think it's going to be possible to fix the errors unless we actually come up with a way to track sealed traits for coherence, which I don't think is going to happen for a long time.

I'll unmark as draft once I make those changes.

@bors
Copy link
Collaborator

bors commented Mar 7, 2025

☔ The latest upstream changes (presumably #138177) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC Dylan-DPC added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 23, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
needs-fcp This change is insta-stable, so needs a completed FCP to proceed. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants