diff --git a/src/expr.rs b/src/expr.rs index 6b4669a70e7..8e2fe782ce9 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -561,7 +561,7 @@ fn rewrite_closure_fn_decl( fn_decl.inputs.iter(), "|", |arg| span_lo_for_arg(arg), - |arg| span_hi_for_arg(arg), + |arg| span_hi_for_arg(context, arg), |arg| arg.rewrite(context, arg_shape), context.codemap.span_after(span, "|"), body.span.lo, diff --git a/src/items.rs b/src/items.rs index 02a35286117..9a6bb08d3b6 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1657,6 +1657,16 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { } } +fn is_empty_infer(context: &RewriteContext, ty: &ast::Ty) -> bool { + match ty.node { + ast::TyKind::Infer => { + let original = context.snippet(ty.span); + original != "_" + } + _ => false, + } +} + impl Rewrite for ast::Arg { fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { if is_named_arg(self) { @@ -1665,7 +1675,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { Shape::legacy(shape.width, shape.indent), )); - if self.ty.node != ast::TyKind::Infer { + if !is_empty_infer(context, &*self.ty) { if context.config.space_before_type_annotation() { result.push_str(" "); } @@ -1750,8 +1760,9 @@ pub fn span_lo_for_arg(arg: &ast::Arg) -> BytePos { } } -pub fn span_hi_for_arg(arg: &ast::Arg) -> BytePos { +pub fn span_hi_for_arg(context: &RewriteContext, arg: &ast::Arg) -> BytePos { match arg.ty.node { + ast::TyKind::Infer if context.snippet(arg.ty.span) == "_" => arg.ty.span.hi, ast::TyKind::Infer if is_named_arg(arg) => arg.pat.span.hi, _ => arg.ty.span.hi, } diff --git a/src/visitor.rs b/src/visitor.rs index a303e099f7a..b8225aaed1c 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -792,7 +792,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { } else { format!("#[{}]", rw) } - } + }, ) } } diff --git a/tests/source/closure.rs b/tests/source/closure.rs index 2f695e771b6..b52643f2fb8 100644 --- a/tests/source/closure.rs +++ b/tests/source/closure.rs @@ -147,3 +147,7 @@ fn issue325() { fn issue1697() { Test.func_a(A_VERY_LONG_CONST_VARIABLE_NAME, move |arg1, arg2, arg3, arg4| arg1 + arg2 + arg3 + arg4) } + +fn issue1694() { + foooooo(|_referencefffffffff: _, _target_reference: _, _oid: _, _target_oid: _| format!("refs/pull/{}/merge", pr_id)) +} diff --git a/tests/target/closure.rs b/tests/target/closure.rs index 7f09b1d7f68..3d6d322a103 100644 --- a/tests/target/closure.rs +++ b/tests/target/closure.rs @@ -174,3 +174,11 @@ fn issue1697() { move |arg1, arg2, arg3, arg4| arg1 + arg2 + arg3 + arg4, ) } + +fn issue1694() { + foooooo( + |_referencefffffffff: _, _target_reference: _, _oid: _, _target_oid: _| { + format!("refs/pull/{}/merge", pr_id) + }, + ) +}