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

Allow casts from the result of checked_abs to unsigned #4764

Closed
wants to merge 3 commits into from

Conversation

chansuke
Copy link
Contributor

@chansuke chansuke commented Nov 1, 2019

Fixes #4743.

@JohnTitor JohnTitor added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 5, 2019
tests/ui/cast.rs Outdated
Comment on lines 50 to 54
(-1i8).checked_abs() as u8;
(-1i16).checked_abs() as u16;
(-1i32).checked_abs() as u32;
(-1i64).checked_abs() as u64;
(-1isize).checked_abs() as usize;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked_abs returns Option<T> so we should use unwrap or something else to get contained values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review, i will fix that

@JohnTitor JohnTitor added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Nov 5, 2019
clippy_lints/src/types.rs Outdated Show resolved Hide resolved
@phansch
Copy link
Member

phansch commented Nov 11, 2019

triggering a new build

@phansch phansch closed this Nov 11, 2019
@phansch phansch reopened this Nov 11, 2019
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This #4764 (comment) code duplication should still be addressed.

Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm working on a rustup. After that, we can merge this.

@chansuke
Copy link
Contributor Author

@flip1995 Thank you!!

@flip1995
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Nov 23, 2019

📌 Commit c3b0ece has been approved by flip1995

flip1995 added a commit to flip1995/rust-clippy that referenced this pull request Nov 23, 2019
Allow casts from the result of `checked_abs` to unsigned

Fixes rust-lang#4743.
bors added a commit that referenced this pull request Nov 23, 2019
Rollup of 6 pull requests

Successful merges:

 - #4730 (Fix check_infinite_loop (while_immutable_condition) by checking for break or return inside loop body)
 - #4764 (Allow casts from the result of `checked_abs` to unsigned)
 - #4766 (Fix false positive in derive_hash_xor_eq)
 - #4811 (Literal Representation Restructure)
 - #4820 (doc: fix the comment above the lint function)
 - #4830 (use more efficient code to generate repeated string)

Failed merges:

r? @ghost

changelog: none
// `abs` is an inherent impl of `i{N}`, so a method call with ident `abs` will always
// resolve to that spesific method
if_chain! {
if let ExprKind::MethodCall(ref path, _, _) = op.kind;
if path.ident.name.as_str() == "abs";
if ["abs", "checked_abs"].contains(path.ident.name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path.indent.name gives a type error

Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@flip1995
Copy link
Member

@bors r-

bors added a commit that referenced this pull request Dec 12, 2019
…lse-positive, r=flip1995

Fix false positive with cast_sign_loss lint

`cast_sign_loss` lint incorrectly suggests that the result of `checked_abs`, `rem_euclid` and `checked_rem_euclid` cannot be casted to an unsigned integer without loss.

Fixes #4818 #4764 #4743

changelog: Fix false positives in `cast_sign_loss` lint
@bors
Copy link
Collaborator

bors commented Dec 12, 2019

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

@phansch
Copy link
Member

phansch commented Dec 12, 2019

It seems a fix for #4743 was already included in #4883, so I'm going ahead and close this PR. Thank you for your time spent on improving Clippy 💟

@phansch phansch closed this Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive for cast_sign_loss
5 participants