Allow overflowing rhs of unit variant (#3566)
This commit is contained in:
parent
72ca0e5f2c
commit
b5449ba785
@ -1894,6 +1894,9 @@ pub(crate) enum RhsTactics {
|
||||
Default,
|
||||
/// Put the rhs on the next line if it uses multiple line, without extra indentation.
|
||||
ForceNextLineWithoutIndent,
|
||||
/// Allow overflowing max width if neither `Default` nor `ForceNextLineWithoutIndent`
|
||||
/// did not work.
|
||||
AllowOverflow,
|
||||
}
|
||||
|
||||
// The left hand side must contain everything up to, and including, the
|
||||
@ -1970,6 +1973,10 @@ fn choose_rhs<R: Rewrite>(
|
||||
Some(format!("{}{}", new_indent_str, new_rhs))
|
||||
}
|
||||
(None, Some(ref new_rhs)) => Some(format!("{}{}", new_indent_str, new_rhs)),
|
||||
(None, None) if rhs_tactics == RhsTactics::AllowOverflow => {
|
||||
let shape = shape.infinite_width();
|
||||
expr.rewrite(context, shape).map(|s| format!(" {}", s))
|
||||
}
|
||||
(None, None) => None,
|
||||
(Some(orig_rhs), _) => Some(format!(" {}", orig_rhs)),
|
||||
}
|
||||
@ -1986,7 +1993,7 @@ fn shape_from_rhs_tactic(
|
||||
RhsTactics::ForceNextLineWithoutIndent => shape
|
||||
.with_max_width(context.config)
|
||||
.sub_width(shape.indent.width()),
|
||||
RhsTactics::Default => {
|
||||
RhsTactics::Default | RhsTactics::AllowOverflow => {
|
||||
Shape::indented(shape.indent.block_indent(context.config), context.config)
|
||||
.sub_width(shape.rhs_overhead(context.config))
|
||||
}
|
||||
|
@ -592,7 +592,13 @@ impl<'a> FmtVisitor<'a> {
|
||||
rewrite_ident(&context, field.node.ident),
|
||||
pad_discrim_ident_to
|
||||
);
|
||||
rewrite_assign_rhs(&context, lhs, &*expr.value, shape)?
|
||||
rewrite_assign_rhs_with(
|
||||
&context,
|
||||
lhs,
|
||||
&*expr.value,
|
||||
shape,
|
||||
RhsTactics::AllowOverflow,
|
||||
)?
|
||||
} else {
|
||||
rewrite_ident(&context, field.node.ident).to_owned()
|
||||
}
|
||||
|
11
src/shape.rs
11
src/shape.rs
@ -136,6 +136,9 @@ impl Sub<usize> for Indent {
|
||||
}
|
||||
}
|
||||
|
||||
// 8096 is close enough to infinite for rustfmt.
|
||||
const INFINITE_SHAPE_WIDTH: usize = 8096;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub(crate) struct Shape {
|
||||
pub(crate) width: usize,
|
||||
@ -274,6 +277,14 @@ impl Shape {
|
||||
offset_indent.alignment = self.offset;
|
||||
offset_indent.to_string_inner(config, 0)
|
||||
}
|
||||
|
||||
/// Creates a `Shape` with a virtually infinite width.
|
||||
pub(crate) fn infinite_width(&self) -> Shape {
|
||||
Shape {
|
||||
width: INFINITE_SHAPE_WIDTH,
|
||||
..*self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -195,3 +195,10 @@ pub enum QlError {
|
||||
// #2594
|
||||
enum Foo {}
|
||||
enum Bar { }
|
||||
|
||||
// #3562
|
||||
enum PublishedFileVisibility {
|
||||
Public = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPublic,
|
||||
FriendsOnly = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityFriendsOnly,
|
||||
Private = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPrivate,
|
||||
}
|
||||
|
@ -264,3 +264,12 @@ pub enum QlError {
|
||||
// #2594
|
||||
enum Foo {}
|
||||
enum Bar {}
|
||||
|
||||
// #3562
|
||||
enum PublishedFileVisibility {
|
||||
Public =
|
||||
sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPublic,
|
||||
FriendsOnly = sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityFriendsOnly,
|
||||
Private =
|
||||
sys::ERemoteStoragePublishedFileVisibility_k_ERemoteStoragePublishedFileVisibilityPrivate,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user