-
Notifications
You must be signed in to change notification settings - Fork 906
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
Add option to control trailing zero in floating-point literals #5834
base: master
Are you sure you want to change the base?
Changes from all commits
366f35b
3436b40
004bc6b
497e17e
cb2929a
9af25c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,7 +264,7 @@ impl ChainItemKind { | |
return ( | ||
ChainItemKind::Parent { | ||
expr: expr.clone(), | ||
parens: is_method_call_receiver && should_add_parens(expr), | ||
parens: is_method_call_receiver && should_add_parens(expr, context), | ||
}, | ||
expr.span, | ||
); | ||
|
@@ -1049,12 +1049,12 @@ fn trim_tries(s: &str) -> String { | |
/// 1. .method(); | ||
/// ``` | ||
/// Which all need parenthesis or a space before `.method()`. | ||
fn should_add_parens(expr: &ast::Expr) -> bool { | ||
fn should_add_parens(expr: &ast::Expr, context: &RewriteContext<'_>) -> bool { | ||
match expr.kind { | ||
ast::ExprKind::Lit(ref lit) => crate::expr::lit_ends_in_dot(lit), | ||
ast::ExprKind::Lit(ref lit) => crate::expr::lit_ends_in_dot(lit, context), | ||
ast::ExprKind::Closure(ref cl) => match cl.body.kind { | ||
ast::ExprKind::Range(_, _, ast::RangeLimits::HalfOpen) => true, | ||
ast::ExprKind::Lit(ref lit) => crate::expr::lit_ends_in_dot(lit), | ||
ast::ExprKind::Lit(ref lit) => crate::expr::lit_ends_in_dot(lit, context), | ||
Comment on lines
+1052
to
+1057
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missed this before, but can we also add test cases to the existing files to make sure we're correctly adding parentheses around method calls on float literals and closures that contain a single float literal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is actually possible to achieve: https://doc.rust-lang.org/error_codes/E0689.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can ignore the closure test cases, but we should add some for method calls on floats. The following fn main() {
1.0 .neg();
2. .neg();
} formats as: fn main() {
1.0.neg();
(2.).neg();
} As long as the code parses as valid rust, rustfmt should be able to handle it even if it errors at compile time. |
||
_ => false, | ||
}, | ||
_ => false, | ||
|
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.
Also, we'll need to add a new tracking issue for this one. #3187 isn't a tracking issue. We can certainly add the tracking issue after this PR is merged.
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.
Why don't we create an issue now, so that we don't have to go back and modify the link later?
Is there a document that describes how a tracking issue should look like?