Skip to content

Commit 3d2cd68

Browse files
committed
Use 'first_line_width'
1 parent 02c9ac9 commit 3d2cd68

File tree

3 files changed

+158
-2
lines changed

3 files changed

+158
-2
lines changed

src/chains.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
203203
shape) {
204204
// If the first line of the last method does not fit into a single line
205205
// after the others, allow new lines.
206-
let first_line = try_opt!(last[0].lines().nth(0));
207-
almost_total + first_line.len() < context.config.max_width
206+
almost_total + first_line_width(&last[0]) < context.config.max_width
208207
} else {
209208
false
210209
}

tests/source/match.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,81 @@ fn guards() {
295295
(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb || cccccccccccccccccccccccccccccccccccccccc) => {}
296296
}
297297
}
298+
299+
fn issue1371() {
300+
Some(match type_ {
301+
sfEvtClosed => Closed,
302+
sfEvtResized => {
303+
let e = unsafe { *event.size.as_ref() };
304+
305+
Resized {
306+
width: e.width,
307+
height: e.height,
308+
}
309+
}
310+
sfEvtLostFocus => LostFocus,
311+
sfEvtGainedFocus => GainedFocus,
312+
sfEvtTextEntered => {
313+
TextEntered {
314+
unicode: unsafe {
315+
::std::char::from_u32((*event.text.as_ref()).unicode)
316+
.expect("Invalid unicode encountered on TextEntered event")
317+
},
318+
}
319+
}
320+
sfEvtKeyPressed => {
321+
let e = unsafe { event.key.as_ref() };
322+
323+
KeyPressed {
324+
code: unsafe { ::std::mem::transmute(e.code) },
325+
alt: e.alt.to_bool(),
326+
ctrl: e.control.to_bool(),
327+
shift: e.shift.to_bool(),
328+
system: e.system.to_bool(),
329+
}
330+
}
331+
sfEvtKeyReleased => {
332+
let e = unsafe { event.key.as_ref() };
333+
334+
KeyReleased {
335+
code: unsafe { ::std::mem::transmute(e.code) },
336+
alt: e.alt.to_bool(),
337+
ctrl: e.control.to_bool(),
338+
shift: e.shift.to_bool(),
339+
system: e.system.to_bool(),
340+
}
341+
}
342+
})
343+
}
344+
345+
fn issue1395() {
346+
let bar = Some(true);
347+
let foo = Some(true);
348+
let mut x = false;
349+
bar.and_then(|_| {
350+
match foo {
351+
None => None,
352+
Some(b) => {
353+
x = true;
354+
Some(b)
355+
}
356+
}
357+
});
358+
}
359+
360+
fn issue1456() {
361+
Ok(Recording {
362+
artists: match reader.evaluate(".//mb:recording/mb:artist-credit/mb:name-credit")? {
363+
Nodeset(nodeset) => {
364+
let res: Result<Vec<ArtistRef>, ReadError> = nodeset
365+
.iter()
366+
.map(|node| {
367+
XPathNodeReader::new(node, &context).and_then(|r| ArtistRef::from_xml(&r))
368+
})
369+
.collect();
370+
res?
371+
}
372+
_ => Vec::new(),
373+
},
374+
})
375+
}

tests/target/match.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,82 @@ fn guards() {
310310
cccccccccccccccccccccccccccccccccccccccc) => {}
311311
}
312312
}
313+
314+
fn issue1371() {
315+
Some(match type_ {
316+
sfEvtClosed => Closed,
317+
sfEvtResized => {
318+
let e = unsafe { *event.size.as_ref() };
319+
320+
Resized {
321+
width: e.width,
322+
height: e.height,
323+
}
324+
}
325+
sfEvtLostFocus => LostFocus,
326+
sfEvtGainedFocus => GainedFocus,
327+
sfEvtTextEntered => {
328+
TextEntered {
329+
unicode:
330+
unsafe {
331+
::std::char::from_u32((*event.text.as_ref()).unicode)
332+
.expect("Invalid unicode encountered on TextEntered event")
333+
},
334+
}
335+
}
336+
sfEvtKeyPressed => {
337+
let e = unsafe { event.key.as_ref() };
338+
339+
KeyPressed {
340+
code: unsafe { ::std::mem::transmute(e.code) },
341+
alt: e.alt.to_bool(),
342+
ctrl: e.control.to_bool(),
343+
shift: e.shift.to_bool(),
344+
system: e.system.to_bool(),
345+
}
346+
}
347+
sfEvtKeyReleased => {
348+
let e = unsafe { event.key.as_ref() };
349+
350+
KeyReleased {
351+
code: unsafe { ::std::mem::transmute(e.code) },
352+
alt: e.alt.to_bool(),
353+
ctrl: e.control.to_bool(),
354+
shift: e.shift.to_bool(),
355+
system: e.system.to_bool(),
356+
}
357+
}
358+
})
359+
}
360+
361+
fn issue1395() {
362+
let bar = Some(true);
363+
let foo = Some(true);
364+
let mut x = false;
365+
bar.and_then(|_| match foo {
366+
None => None,
367+
Some(b) => {
368+
x = true;
369+
Some(b)
370+
}
371+
});
372+
}
373+
374+
fn issue1456() {
375+
Ok(Recording {
376+
artists: match reader
377+
.evaluate(".//mb:recording/mb:artist-credit/mb:name-credit")? {
378+
Nodeset(nodeset) => {
379+
let res: Result<Vec<ArtistRef>, ReadError> = nodeset
380+
.iter()
381+
.map(|node| {
382+
XPathNodeReader::new(node, &context)
383+
.and_then(|r| ArtistRef::from_xml(&r))
384+
})
385+
.collect();
386+
res?
387+
}
388+
_ => Vec::new(),
389+
},
390+
})
391+
}

0 commit comments

Comments
 (0)