-
Notifications
You must be signed in to change notification settings - Fork 926
Formatting pre and post cast comments enhancements #4406
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Formatting pre and post cast comments enhancements #4406
Conversation
Thanks for the PR! Just as a heads up It'll probably be a few days before I have the bandwidth to go through this, need to deal with the broken toolstate issue on nightly first. |
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.
Thank you so much for the PR @davidBar-On, and all the accompanying tests! It looks fairly good overall and seems like the approach will be viable, although we will need to do a bit of refactoring before merging.
I've added inline comments which detail that needed refactoring for your review, please let us know if you have any questions!
@@ -172,8 +184,11 @@ where | |||
RHS: Rewrite, | |||
{ | |||
let tab_spaces = context.config.tab_spaces(); | |||
let infix_result = format!("{}{}", pp.infix, pp.infix_suffix); |
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.
let infix_result = format!("{}{}", pp.infix, pp.infix_suffix); | |
let infix_result = format!("{}{}", pp.infix, pp.infix_suffix); | |
let infix_suffix_separator = if pp.infix_suffix.is_empty() { "" } else { " " }; | |
let infix_prefix_separator = if pp.infix_prefix.is_empty() { "" } else { " " }; |
src/formatting/pairs.rs
Outdated
@@ -182,12 +197,12 @@ where | |||
}; | |||
let lhs_result = lhs | |||
.rewrite(context, lhs_shape) | |||
.map(|lhs_str| format!("{}{}", pp.prefix, lhs_str))?; | |||
.map(|lhs_str| format!("{}{}{}", pp.prefix, lhs_str, pp.infix_prefix))?; |
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.
.map(|lhs_str| format!("{}{}{}", pp.prefix, lhs_str, pp.infix_prefix))?; | |
.map(|lhs_str| format!("{}{}{}{}", pp.prefix, lhs_str, infix_prefix_separator, pp.infix_prefix))?; |
src/formatting/pairs.rs
Outdated
|
||
// Try to put both lhs and rhs on the same line. | ||
let rhs_orig_result = shape | ||
.offset_left(last_line_width(&lhs_result) + pp.infix.len()) | ||
.and_then(|s| s.sub_width(pp.suffix.len())) | ||
.and_then(|s| s.sub_width(pp.suffix.len() + pp.infix_suffix.len())) |
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.
.and_then(|s| s.sub_width(pp.suffix.len() + pp.infix_suffix.len())) | |
.and_then(|s| s.sub_width(pp.suffix.len() + pp.infix_suffix.len() + infix_suffix_separator.len())) |
I have no comments to the suggested changes (look quite final to me ...). I will update and test the PR accordingly. |
Thanks for the updates, LGTM! |
Heads up: filed a regression that bisects to this PR. Would love if one of you could have a look. #4534 fn main() {
- let z = (x as f64 / y as f64).floor() as usize;
+ let z = (x as f64 / y as f64).floor() as f64 / y as f64).floor()
+ as f64 / y as f64).floor() as usize;
} |
Enhancements for formatting pre and post cast comments:
/* pre */ as /* post */
.The enhancements are based on discussions and issues examples in #4391.
Test cases were added in
issueCastComments.rs
.Changes assume that pre/post cast comments should be trimmed, i.e. that comments' original leading and trailing whitespaces should be removed.
Changes seem to fix issue #3528 and issues of leaving trailing spaces which may be related to #2896. Test cases for these issues were also included .