- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
          Suggest into instead of try_into if possible with int types
          #71617
        
          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
Conversation
| (rust_highfive has picked a reviewer for you, use r? to override) | 
If it is possible to convert an integer type into another using
`into`, don't suggest `try_into`. This commit changes the suggested
method to convert from one integer type to another for the following
cases:
- u{n} -> i{m} where n < m
- u8 -> isize
- i{n} -> isize where n <= 16
- u{n} -> usize where n <= 16
    0090f2a    to
    1f0a864      
    Compare
  
    | Your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact  | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As Jonas noted on the issue, this suggestion would probably be better implemented by looking for an Into impl for the target type. Since this PR just extends the existing approach to be more complete, however, I'm fine merging it as-is.
@samrat You need to run ./x.py fmt. If it helps, I like to run ./x.py test src/tools/tidy as part of a pre-push hook to catch formatting errors locally.
Since Into<isize> is not implemented for uint of width greater than 8
Remove `integer-into.rs` since the numeric-cast tests already cover these cases.
| @bors r+ rollup | 
| 📌 Commit a6033e3 has been approved by  | 
Rollup of 6 pull requests Successful merges: - rust-lang#71507 (Document unsafety in core::ptr) - rust-lang#71572 (test iterator chain type length blowup) - rust-lang#71617 (Suggest `into` instead of `try_into` if possible with int types) - rust-lang#71627 (Fix wrong argument in autoderef process) - rust-lang#71678 (Add an index page for nightly rustc docs.) - rust-lang#71680 (Fix doc link to Eq trait from PartialEq trait) Failed merges: - rust-lang#71597 (Rename Unique::empty() -> Unique::dangling()) r? @ghost
If it is possible to convert an integer type into another using
into, don't suggesttry_into. This commit changes the suggested method to convert from one integer type to another for the following cases:Fixes #71580