Skip to content

Overflow the last rhs of a binary expression #2509

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

Merged
merged 2 commits into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,15 @@ where
.and_then(|s| s.sub_width(pp.suffix.len()))
.and_then(|rhs_shape| rhs.rewrite(context, rhs_shape));
if let Some(ref rhs_result) = rhs_orig_result {
// If the rhs looks like block expression, we allow it to stay on the same line
// with the lhs even if it is multi-lined.
let allow_same_line = rhs_result
.lines()
.next()
.map(|first_line| first_line.ends_with('{'))
.unwrap_or(false);
// If the length of the lhs is equal to or shorter than the tab width or
// the rhs looks like block expression, we put the rhs on the same
// line with the lhs even if the rhs is multi-lined.
let allow_same_line = lhs_result.len() <= context.config.tab_spaces()
|| rhs_result
.lines()
.next()
.map(|first_line| first_line.ends_with('{'))
.unwrap_or(false);
if !rhs_result.contains('\n') || allow_same_line {
let one_line_width = last_line_width(&lhs_result) + pp.infix.len()
+ first_line_width(rhs_result) + pp.suffix.len();
Expand Down
14 changes: 14 additions & 0 deletions tests/source/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,17 @@ fn newlines_between_list_like_expr() {
fn issue2178() {
Ok(result.iter().map(|item| ls_util::rls_to_location(item)).collect())
}

// #2493
impl Foo {
fn bar(&self) {
{
let x = match () {
() => {
let i;
i == self.install_config.storage.experimental_compressed_block_size as usize
}
};
}
}
}
16 changes: 16 additions & 0 deletions tests/target/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,19 @@ fn issue2178() {
.map(|item| ls_util::rls_to_location(item))
.collect())
}

// #2493
impl Foo {
fn bar(&self) {
{
let x = match () {
() => {
let i;
i == self.install_config
.storage
.experimental_compressed_block_size as usize
}
};
}
}
}