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

default_numeric_fallback: Fix FP with floating literal #7446

Merged
merged 4 commits into from
Jul 13, 2021

Conversation

Y-Nak
Copy link
Contributor

@Y-Nak Y-Nak commented Jul 8, 2021

Fix #7445

changelog: default_numeric_fallback: Fix FP with floating literal

@flip1995
Copy link
Member

flip1995 commented Jul 8, 2021

r? @xFrednet Can you take over this review please? (rust-highfive was down, so I'll give the 2 unassigned PRs to you)

@flip1995 flip1995 self-assigned this Jul 8, 2021
@camsteffen camsteffen assigned flip1995 and unassigned flip1995 Jul 8, 2021
Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

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

The changes LGTM.

The FP was a result of tests which only checked for the int type. I've looked through the test file, and it seems to me that the first test cases still miss a float counterpart. Could you also add them as a precaution?

// in the `basic_expr` module
        let x = [1.0, 2.0, 3.0];
        let x = if true { (1.0, 2.0) } else { (3.0, 4.0) };
        let x = match 1.0 {
            1.0 => 1.0,
            _ => 2.0,
        };
 // in the `nested_local` module
         let x: _ = {
            // Should lint this because this literal is not bound to any types.
            let y = 1.0;

            // Should NOT lint this because this literal is bound to `_` of outer `Local`.
            1.0
        };

@Y-Nak
Copy link
Contributor Author

Y-Nak commented Jul 9, 2021

Changes:

  1. Add more test cases for floating literal
  2. Split the i32 and f64 test cases into their own files, otherwise cargo dev limit_stderr_length fails

Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for the quick fixes and nice work!

@flip1995 I would hand it over to you now :)

@Y-Nak
Copy link
Contributor Author

Y-Nak commented Jul 13, 2021

Changes:

  • Fix NumericLiteral::format, there was a possibility of producing invalid literals like 1._f32
  • Remove duplication of #![allow(clippy::branches_sharing_code)]
  • Add // run-rustfix

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.

One more NIT

Comment on lines 91 to 98
let src = if let Some(src) = snippet_opt(self.cx, lit.span){
src
} else {
match lit.node {
LitKind::Int(src, _) =>format!("{}", src),
LitKind::Float(src, _) => format!("{}", src),
_ => { return; }
}
Copy link
Member

Choose a reason for hiding this comment

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

Formattings:

Suggested change
let src = if let Some(src) = snippet_opt(self.cx, lit.span){
src
} else {
match lit.node {
LitKind::Int(src, _) =>format!("{}", src),
LitKind::Float(src, _) => format!("{}", src),
_ => { return; }
}
let src = if let Some(src) = snippet_opt(self.cx, lit.span) {
src
} else {
match lit.node {
LitKind::Int(src, _) => format!("{}", src),
LitKind::Float(src, _) => format!("{}", src),
_ => return,
}

Copy link
Contributor Author

@Y-Nak Y-Nak Jul 13, 2021

Choose a reason for hiding this comment

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

Fixed.

Just a question:
Could you tell me how do you find formatting problems inside if_chain? Is there a good way(e.g. editor support) for that.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know of anything that would help here. Maybe implementing formatting rules in rustfmt for the if_chain macro. Not sure if that would be accepted there though, since this isn't a std macro.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand. Thanks for the answer!

@flip1995
Copy link
Member

@bors r=xFrednet,flip1995

Thanks!

@bors
Copy link
Contributor

bors commented Jul 13, 2021

📌 Commit 25e4c7d has been approved by xFrednet,flip1995

@bors
Copy link
Contributor

bors commented Jul 13, 2021

⌛ Testing commit 25e4c7d with merge 8131445...

@bors
Copy link
Contributor

bors commented Jul 13, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: xFrednet,flip1995
Pushing 8131445 to master...

@bors bors merged commit 8131445 into rust-lang:master Jul 13, 2021
@Y-Nak Y-Nak deleted the fix-7445 branch November 6, 2022 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FP: default_numeric_fallback with floating literal
4 participants