Use correct span for Infer type inside closure header
This commit is contained in:
parent
897d7bdcb9
commit
e31f5eceac
@ -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,
|
||||
|
15
src/items.rs
15
src/items.rs
@ -1657,6 +1657,16 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
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<String> {
|
||||
if is_named_arg(self) {
|
||||
@ -1665,7 +1675,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
|
||||
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,
|
||||
}
|
||||
|
@ -792,7 +792,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
|
||||
} else {
|
||||
format!("#[{}]", rw)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user