Skip to content

[Design] confusing target_pointer_width = "64" usize convertion design #138218

Open
@loynoir

Description

@loynoir

Title

confusing target_pointer_width = "64" usize convertion design

Actual

        #[cfg(target_pointer_width = "64")]
        {
            let _ = usize::try_from(42u64).unwrap();
            let _ = usize::try_from(42u32).unwrap();
            let _ = usize::from(42u16);
        }

Expected

When under target_pointer_width 64, should always success, and try is not necessary.

        #[cfg(CONDITION)]
        {
            let _ = usize::from(42u64);
            let _ = usize::from(42u32);
            let _ = usize::from(42u16);
        }

Related

https://github.com/rust-lang/rust/blob/master/library/core/src/convert/num.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions