Skip to content

Commit

Permalink
Temporary fix rustfmt for let-else
Browse files Browse the repository at this point in the history
  • Loading branch information
camsteffen committed Aug 31, 2021
1 parent 20ddab3 commit a603756
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Rewrite for ast::Local {

skip_out_of_file_lines_range!(context, self.span);

if contains_skip(&self.attrs) {
if contains_skip(&self.attrs) || matches!(self.kind, ast::LocalKind::InitElse(..)) {
return None;
}

Expand Down Expand Up @@ -97,7 +97,7 @@ impl Rewrite for ast::Local {
infix.push_str(&rewrite);
}

if self.init.is_some() {
if self.kind.init().is_some() {
infix.push_str(" =");
}

Expand All @@ -106,11 +106,12 @@ impl Rewrite for ast::Local {

result.push_str(&infix);

if let Some(ref ex) = self.init {
if let Some((init, _els)) = self.kind.init_else_opt() {
// 1 = trailing semicolon;
let nested_shape = shape.sub_width(1)?;

result = rewrite_assign_rhs(context, result, &**ex, nested_shape)?;
result = rewrite_assign_rhs(context, result, init, nested_shape)?;
// todo else
}

result.push(';');
Expand Down
3 changes: 3 additions & 0 deletions tests/source/let_else.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
let Some(1) = Some(1) else { return };
}
3 changes: 3 additions & 0 deletions tests/target/let_else.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
let Some(1) = Some(1) else { return };
}

0 comments on commit a603756

Please sign in to comment.