Use correct span for Infer type inside closure header

This commit is contained in:
topecongiro 2017-06-17 06:25:58 +09:00
parent 897d7bdcb9
commit e31f5eceac
5 changed files with 27 additions and 4 deletions

View File

@ -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,

View File

@ -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,
}

View File

@ -792,7 +792,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
} else {
format!("#[{}]", rw)
}
}
},
)
}
}

View File

@ -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))
}

View File

@ -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)
},
)
}