-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
r? @xFrednet Can you take over this review please? (rust-highfive was down, so I'll give the 2 unassigned PRs to you) |
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.
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
};
Changes:
|
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.
LGTM, thank you for the quick fixes and nice work!
@flip1995 I would hand it over to you now :)
Changes:
|
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.
One more NIT
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; } | ||
} |
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.
Formattings:
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, | |
} |
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.
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.
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.
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.
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.
I understand. Thanks for the answer!
@bors r=xFrednet,flip1995 Thanks! |
📌 Commit 25e4c7d has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fix #7445
changelog:
default_numeric_fallback
: Fix FP with floating literal