Skip to content

Commit 0a59654

Browse files
authored
Merge pull request #2084 from topecongiro/issue-2081
Use rewrite_assign_rhs when rewriting unit variant
2 parents 038f711 + a67b8b0 commit 0a59654

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

src/items.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -537,21 +537,9 @@ impl<'a> FmtVisitor<'a> {
537537
)?
538538
}
539539
ast::VariantData::Unit(..) => if let Some(ref expr) = field.node.disr_expr {
540-
let one_line_width =
541-
field.node.name.to_string().len() + self.snippet(expr.span).len() + 3;
542-
if one_line_width <= shape.width {
543-
format!("{} = {}", field.node.name, self.snippet(expr.span))
544-
} else {
545-
format!(
546-
"{}\n{}{}",
547-
field.node.name,
548-
shape
549-
.indent
550-
.block_indent(self.config)
551-
.to_string(self.config),
552-
self.snippet(expr.span)
553-
)
554-
}
540+
let lhs = format!("{} =", field.node.name);
541+
// 1 = ','
542+
rewrite_assign_rhs(&context, lhs, expr, shape.sub_width(1)?)?
555543
} else {
556544
String::from(field.node.name.to_string())
557545
},

tests/source/enum.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,8 @@ pub enum Entry<'a, K: 'a, V: 'a> {
136136
OccupiedEntry<'a, K, V>,
137137
),
138138
}
139+
140+
// #2081
141+
pub enum ForegroundColor {
142+
CYAN = (winapi::FOREGROUND_INTENSITY | winapi::FOREGROUND_GREEN | winapi::FOREGROUND_BLUE) as u16,
143+
}

tests/target/enum.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,9 @@ pub enum Entry<'a, K: 'a, V: 'a> {
173173
Vacant(#[stable(feature = "rust1", since = "1.0.0")] VacantEntry<'a, K, V>),
174174
Occupied(#[stable(feature = "rust1", since = "1.0.0")] OccupiedEntry<'a, K, V>),
175175
}
176+
177+
// #2081
178+
pub enum ForegroundColor {
179+
CYAN =
180+
(winapi::FOREGROUND_INTENSITY | winapi::FOREGROUND_GREEN | winapi::FOREGROUND_BLUE) as u16,
181+
}

0 commit comments

Comments
 (0)