From 3973cdd0a8dcccd986d38d7b3915e88ceeff1a8c Mon Sep 17 00:00:00 2001 From: topecongiro Date: Fri, 3 Nov 2017 23:53:07 +0900 Subject: [PATCH] Use correct span for tuple struct's body --- src/items.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/items.rs b/src/items.rs index 27e46cb0874b..5151ec92ced8 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1189,12 +1189,13 @@ fn format_tuple_struct( result.push_str(&header_str); let body_lo = if fields.is_empty() { - context.codemap.span_after(span, "(") + let lo = get_bytepos_after_visibility(context, vis, span, ")"); + context.codemap.span_after(mk_sp(lo, span.hi()), "(") } else { fields[0].span.lo() }; let body_hi = if fields.is_empty() { - context.codemap.span_after(span, ")") + context.codemap.span_after(mk_sp(body_lo, span.hi()), ")") } else { // This is a dirty hack to work around a missing `)` from the span of the last field. let last_arg_span = fields[fields.len() - 1].span; @@ -1242,7 +1243,10 @@ fn format_tuple_struct( .to_string(context.config)) } result.push('('); - let snippet = context.snippet(mk_sp(body_lo, context.codemap.span_before(span, ")"))); + let snippet = context.snippet(mk_sp( + body_lo, + context.codemap.span_before(mk_sp(body_lo, span.hi()), ")"), + )); if snippet.is_empty() { // `struct S ()` } else if snippet.trim_right_matches(&[' ', '\t'][..]).ends_with('\n') {