Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 77824a2

Browse files
authored
Merge pull request rust-lang#2988 from YaLTeR/fix-issue-2922
Use correct indent in rewrite_bare_fn with Visual style
2 parents 29df217 + 54f8bcb commit 77824a2

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/types.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ where
298298
<I as Iterator>::Item: Deref,
299299
<I::Item as Deref>::Target: Rewrite + Spanned + 'a,
300300
{
301+
debug!("format_function_type {:#?}", shape);
302+
301303
// Code for handling variadics is somewhat duplicated for items, but they
302304
// are different enough to need some serious refactoring to share code.
303305
enum ArgumentKind<T>
@@ -706,6 +708,8 @@ fn rewrite_bare_fn(
706708
context: &RewriteContext,
707709
shape: Shape,
708710
) -> Option<String> {
711+
debug!("rewrite_bare_fn {:#?}", shape);
712+
709713
let mut result = String::with_capacity(128);
710714

711715
if let Some(ref lifetime_str) = rewrite_lifetime_param(context, shape, &bare_fn.generic_params)
@@ -728,7 +732,11 @@ fn rewrite_bare_fn(
728732

729733
result.push_str("fn");
730734

731-
let func_ty_shape = shape.offset_left(result.len())?;
735+
let func_ty_shape = if context.use_block_indent() {
736+
shape.offset_left(result.len())?
737+
} else {
738+
shape.visual_indent(result.len()).sub_width(result.len())?
739+
};
732740

733741
let rewrite = format_function_type(
734742
bare_fn.decl.inputs.iter(),

tests/source/issue-2922.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// rustfmt-indent_style: Visual
2+
struct Functions {
3+
RunListenServer: unsafe extern "C" fn(*mut c_void,
4+
*mut c_char,
5+
*mut c_char,
6+
*mut c_char,
7+
*mut c_void,
8+
*mut c_void) -> c_int,
9+
}

tests/target/issue-2922.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// rustfmt-indent_style: Visual
2+
struct Functions {
3+
RunListenServer: unsafe extern "C" fn(*mut c_void,
4+
*mut c_char,
5+
*mut c_char,
6+
*mut c_char,
7+
*mut c_void,
8+
*mut c_void)
9+
-> c_int,
10+
}

0 commit comments

Comments
 (0)