Skip to content
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

Indent return types separated from params by newline #4368

Merged
merged 2 commits into from
Aug 7, 2020
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
12 changes: 8 additions & 4 deletions src/formatting/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2368,6 +2368,7 @@ fn rewrite_fn_base(

// Return type.
if let ast::FnRetTy::Ty(..) = fd.output {
let mut ret_on_nl = false;
let ret_should_indent = match context.config.indent_style() {
// If our params are block layout then we surely must have space.
IndentStyle::Block if put_params_in_block || fd.inputs.is_empty() => false,
Expand All @@ -2385,7 +2386,8 @@ fn rewrite_fn_base(
sig_length += 2;
}

sig_length > context.config.max_width()
ret_on_nl = sig_length > context.config.max_width();
ret_on_nl
}
};
let ret_shape = if ret_should_indent {
Expand All @@ -2405,10 +2407,12 @@ fn rewrite_fn_base(
Shape::indented(indent, context.config)
} else {
let mut ret_shape = Shape::indented(indent, context.config);
if param_str.is_empty() {
// Aligning with non-existent params looks silly.
if param_str.is_empty() || ret_on_nl {
// Aligning with non-existent params looks silly, as does aligning the return
// type when it is on a newline entirely disconnected from the parentheses of
// the parameters.
force_new_line_for_brace = true;
ret_shape = if context.use_block_indent() {
ret_shape = if context.use_block_indent() && !ret_on_nl {
ret_shape.offset_left(4).unwrap_or(ret_shape)
} else {
ret_shape.indent = ret_shape.indent + 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

trait Story {
fn swap_context<T: 'static + Context + Send + Sync> (&mut self, context: T)
-> Option<Box<Context + Send + Sync>>;
-> Option<Box<Context + Send + Sync>>;
}

impl Story for () {
Expand Down
6 changes: 6 additions & 0 deletions tests/target/issue-4306.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// rustfmt-max_width: 80

trait GetMetadata {
fn metadata(loc: ApiEndpointParameterLocation)
-> Vec<ApiEndpointParameter>;
}