From 145a90da0544bb483ff3322687fb65b7d32f0ca6 Mon Sep 17 00:00:00 2001 From: Sinh Pham Date: Thu, 27 Aug 2015 23:15:21 -0400 Subject: [PATCH] Fix #201 --- src/expr.rs | 10 ++++++++-- tests/source/struct_lits.rs | 8 ++++++++ tests/target/struct_lits.rs | 8 ++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index f39dece3272..20b5ea92bd0 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -959,8 +959,14 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext, |item| { match *item { StructLitField::Regular(ref field) => field.span.lo, - // 2 = .. - StructLitField::Base(ref expr) => expr.span.lo - BytePos(2), + StructLitField::Base(ref expr) => { + let last_field_hi = + fields.last().map_or(span.lo, |field| field.span.hi); + let snippet = + context.snippet(mk_sp(last_field_hi, expr.span.lo)); + let pos = snippet.find_uncommented("..").unwrap(); + last_field_hi + BytePos(pos as u32) + } } }, |item| { diff --git a/tests/source/struct_lits.rs b/tests/source/struct_lits.rs index 225d3a16985..1caf20e99a5 100644 --- a/tests/source/struct_lits.rs +++ b/tests/source/struct_lits.rs @@ -53,3 +53,11 @@ fn issue177() { struct Foo { memb: T } let foo = Foo:: { memb: 10 }; } + +fn issue201() { + let s = S{a:0, .. b}; +} + +fn issue201_2() { + let s = S{a: S2{ .. c}, .. b}; +} diff --git a/tests/target/struct_lits.rs b/tests/target/struct_lits.rs index cc2887fc51f..6dd4180a708 100644 --- a/tests/target/struct_lits.rs +++ b/tests/target/struct_lits.rs @@ -71,3 +71,11 @@ fn issue177() { } let foo = Foo:: { memb: 10 }; } + +fn issue201() { + let s = S { a: 0, ..b }; +} + +fn issue201_2() { + let s = S { a: S2 { ..c }, ..b }; +}