Skip to content

Commit c416246

Browse files
authored
Merge pull request rust-lang#2509 from topecongiro/issue-2493
Overflow the last rhs of a binary expression
2 parents 65ce7bb + 822dd41 commit c416246

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

src/expr.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,15 @@ where
369369
.and_then(|s| s.sub_width(pp.suffix.len()))
370370
.and_then(|rhs_shape| rhs.rewrite(context, rhs_shape));
371371
if let Some(ref rhs_result) = rhs_orig_result {
372-
// If the rhs looks like block expression, we allow it to stay on the same line
373-
// with the lhs even if it is multi-lined.
374-
let allow_same_line = rhs_result
375-
.lines()
376-
.next()
377-
.map(|first_line| first_line.ends_with('{'))
378-
.unwrap_or(false);
372+
// If the length of the lhs is equal to or shorter than the tab width or
373+
// the rhs looks like block expression, we put the rhs on the same
374+
// line with the lhs even if the rhs is multi-lined.
375+
let allow_same_line = lhs_result.len() <= context.config.tab_spaces()
376+
|| rhs_result
377+
.lines()
378+
.next()
379+
.map(|first_line| first_line.ends_with('{'))
380+
.unwrap_or(false);
379381
if !rhs_result.contains('\n') || allow_same_line {
380382
let one_line_width = last_line_width(&lhs_result) + pp.infix.len()
381383
+ first_line_width(rhs_result) + pp.suffix.len();

tests/source/expr.rs

+14
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,17 @@ fn newlines_between_list_like_expr() {
370370
fn issue2178() {
371371
Ok(result.iter().map(|item| ls_util::rls_to_location(item)).collect())
372372
}
373+
374+
// #2493
375+
impl Foo {
376+
fn bar(&self) {
377+
{
378+
let x = match () {
379+
() => {
380+
let i;
381+
i == self.install_config.storage.experimental_compressed_block_size as usize
382+
}
383+
};
384+
}
385+
}
386+
}

tests/target/expr.rs

+16
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,19 @@ fn issue2178() {
393393
.map(|item| ls_util::rls_to_location(item))
394394
.collect())
395395
}
396+
397+
// #2493
398+
impl Foo {
399+
fn bar(&self) {
400+
{
401+
let x = match () {
402+
() => {
403+
let i;
404+
i == self.install_config
405+
.storage
406+
.experimental_compressed_block_size as usize
407+
}
408+
};
409+
}
410+
}
411+
}

0 commit comments

Comments
 (0)