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

<int>.signum() can be safely cast to any signed integer #5395

Closed
jhpratt opened this issue Mar 30, 2020 · 4 comments · Fixed by #7850
Closed

<int>.signum() can be safely cast to any signed integer #5395

jhpratt opened this issue Mar 30, 2020 · 4 comments · Fixed by #7850
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy

Comments

@jhpratt
Copy link
Member

jhpratt commented Mar 30, 2020

clippy version: clippy 0.0.212 (4ee1206 2020-02-01)

<int>.signum() always returns -1, 0, or 1. As such, it can safely be cast to any signed integer.

The following currently triggers clippy::cast_possible_truncation, but there's no reason it needs to.

let x: i64 = 5;
let _ = x.signum() as i32;

Related: #4605, #4818

@flip1995 flip1995 added good-first-issue These issues are a good way to get started with Clippy C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Mar 31, 2020
@spaihippo
Copy link

Hi, if it's ok, I would like to give this a try as my first issue.

@flip1995
Copy link
Member

flip1995 commented Apr 1, 2020

Awesome. There were previous PRs, that addressed similar issues linked above. You can use them for inspiration. To get familiar with testing in Clippy (and Clippy hacking in general) you can take a look at this document: https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md#testing

@spaihippo
Copy link

spaihippo commented Apr 2, 2020

Thanks! I'll take a look at those.

@brightly-salty
Copy link
Contributor

I can attempt to implement this and submit a PR if @s00kee isn't still working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
5 participants