-
Notifications
You must be signed in to change notification settings - Fork 925
Issue4392 resolution - No new line after operation #4397
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
Changes from all commits
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 |
---|---|---|
|
@@ -116,6 +116,19 @@ fn rewrite_pairs_multiline<T: Rewrite>( | |
|
||
result.push_str(&list.list[0].1.as_ref()?); | ||
|
||
/* Determine the expression kind */ | ||
let (e, _s) = match list.list.first() { | ||
Some(x) => x, | ||
None => return None, | ||
}; | ||
let list_len = list.list.len(); | ||
/* ???? Is there better way than transmute() ???? */ | ||
let list_expr = unsafe { std::mem::transmute::<&T, &ast::Expr>(e) }; | ||
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. As noted on the other thread, there's a root problem with comments between the subexpr and type in cast expressions which is most certainly impacting the formatting you are seeing with your snippets. We really need to focus on the addressing the core issue instead of associated items, especially an approach like this as there are currently no unsafe blocks within the rustfmt source to my knowledge. |
||
let list_expr_lit = match list_expr.kind { | ||
ast::ExprKind::Lit(_) => true, | ||
_ => false, | ||
}; | ||
|
||
for ((e, default_rw), s) in list.list[1..].iter().zip(list.separators.iter()) { | ||
// The following test checks if we should keep two subexprs on the same | ||
// line. We do this if not doing so would create an orphan and there is | ||
|
@@ -125,7 +138,15 @@ fn rewrite_pairs_multiline<T: Rewrite>( | |
} else { | ||
shape.used_width() | ||
}; | ||
if last_line_width(&result) + offset <= nested_shape.used_width() { | ||
|
||
/* Do not force adding add new line between Lit operation and righ operand */ | ||
let w = if list_len > 2 || !list_expr_lit { | ||
nested_shape.used_width() | ||
} else { | ||
nested_shape.width | ||
}; | ||
|
||
if last_line_width(&result) + offset <= w { | ||
// We must snuggle the next line onto the previous line to avoid an orphan. | ||
if let Some(line_shape) = | ||
shape.offset_left(s.len() + 2 + trimmed_last_line_width(&result)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* No new line should be added after the operation ('==', etc.) */ | ||
|
||
fn main() { | ||
if 'a' == b /* x */ | ||
as char {} | ||
} | ||
|
||
fn main() { | ||
if 'a' == 0 | ||
/* x */ as char {} } | ||
|
||
fn main() { | ||
if 1234 == 0 | ||
/* x */ & cc & dd {} } | ||
|
||
fn main() { | ||
if 1234 == 'a' | ||
/* x */ as i32 {} } | ||
|
||
fn main() { | ||
if 0 == 'a' | ||
/* x */ as i32 {} } | ||
|
||
fn main() { | ||
if 'a' == b /* x */ as char { println!("Match"); } | ||
} | ||
|
||
fn main() { | ||
while aaaaaa < bbbbb | ||
as char /* x */ {} } | ||
|
||
fn main() { | ||
if 'a' == b // x | ||
as char {} | ||
} | ||
|
||
fn main() { | ||
if 'a' == /* x */ b | ||
as char {} | ||
} | ||
|
||
fn main() { | ||
if 'a' == b | ||
as char {} | ||
|
||
let a = 5; // inline | ||
} |
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.
You've got these same changes in three separate PRs. Please keep various commits and changes separate for easier review and potential for merging.
As I noted in #4391 (comment), I do not believe this is the right approach to address the related issue.