2017-01-15 19:50:27 -06:00
|
|
|
// rustfmt-normalize_comments: true
|
2015-08-14 03:00:22 -05:00
|
|
|
// Match expressions.
|
|
|
|
|
|
|
|
fn foo() {
|
|
|
|
// A match expression.
|
|
|
|
match x {
|
|
|
|
// Some comment.
|
|
|
|
a => foo(),
|
|
|
|
b if 0 < 42 => foo(),
|
2015-10-19 14:41:47 -05:00
|
|
|
c => {
|
|
|
|
// Another comment.
|
2015-08-14 03:00:22 -05:00
|
|
|
// Comment.
|
|
|
|
an_expression;
|
|
|
|
foo()
|
|
|
|
}
|
2015-11-20 14:05:10 -06:00
|
|
|
Foo(ref bar) => {
|
|
|
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
|
|
}
|
2015-08-14 03:00:22 -05:00
|
|
|
Pattern1 | Pattern2 | Pattern3 => false,
|
|
|
|
Paternnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn |
|
2015-11-14 14:57:31 -06:00
|
|
|
Paternnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn => blah,
|
2015-08-14 03:00:22 -05:00
|
|
|
Patternnnnnnnnnnnnnnnnnnn |
|
|
|
|
Patternnnnnnnnnnnnnnnnnnn |
|
|
|
|
Patternnnnnnnnnnnnnnnnnnn |
|
|
|
|
Patternnnnnnnnnnnnnnnnnnn => meh,
|
|
|
|
|
|
|
|
Patternnnnnnnnnnnnnnnnnnn |
|
|
|
|
Patternnnnnnnnnnnnnnnnnnn if looooooooooooooooooong_guard => meh,
|
|
|
|
|
|
|
|
Patternnnnnnnnnnnnnnnnnnnnnnnnn |
|
2015-11-20 14:05:10 -06:00
|
|
|
Patternnnnnnnnnnnnnnnnnnnnnnnnn if looooooooooooooooooooooooooooooooooooooooong_guard => {
|
|
|
|
meh
|
|
|
|
}
|
2015-08-16 16:41:45 -05:00
|
|
|
|
|
|
|
// Test that earlier patterns can take the guard space
|
2016-03-14 02:51:06 -05:00
|
|
|
(aaaa, bbbbb, ccccccc, aaaaa, bbbbbbbb, cccccc, aaaa, bbbbbbbb, cccccc, dddddd) |
|
2015-08-16 16:41:45 -05:00
|
|
|
Patternnnnnnnnnnnnnnnnnnnnnnnnn if loooooooooooooooooooooooooooooooooooooooooong_guard => {}
|
|
|
|
|
2015-08-14 03:00:22 -05:00
|
|
|
_ => {}
|
2015-08-18 22:15:54 -05:00
|
|
|
ast::PathParameters::AngleBracketedParameters(ref data) if data.lifetimes.len() > 0 ||
|
|
|
|
data.types.len() > 0 ||
|
2015-09-23 19:22:06 -05:00
|
|
|
data.bindings.len() > 0 => {}
|
2015-08-14 03:00:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let whatever = match something {
|
|
|
|
/// DOC COMMENT!
|
|
|
|
Some(_) => 42,
|
2015-08-18 22:15:54 -05:00
|
|
|
// Comment on an attribute.
|
2015-08-14 03:00:22 -05:00
|
|
|
#[an_attribute]
|
2015-08-16 16:41:45 -05:00
|
|
|
// Comment after an attribute.
|
2015-08-14 03:00:22 -05:00
|
|
|
None => 0,
|
2015-08-16 16:41:45 -05:00
|
|
|
#[rustfmt_skip]
|
|
|
|
Blurb => { }
|
2015-08-14 03:00:22 -05:00
|
|
|
};
|
|
|
|
}
|
2015-09-01 21:29:47 -05:00
|
|
|
|
|
|
|
// Test that a match on an overflow line is laid out properly.
|
|
|
|
fn main() {
|
|
|
|
let sub_span =
|
2015-09-09 16:15:37 -05:00
|
|
|
match xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
|
2015-09-01 21:29:47 -05:00
|
|
|
Some(sub_span) => Some(sub_span),
|
|
|
|
None => sub_span,
|
|
|
|
};
|
|
|
|
}
|
2015-09-01 21:45:56 -05:00
|
|
|
|
|
|
|
// Test that one-line bodies align.
|
|
|
|
fn main() {
|
|
|
|
match r {
|
2015-11-20 14:05:10 -06:00
|
|
|
Variableeeeeeeeeeeeeeeeee => {
|
2016-03-14 02:51:06 -05:00
|
|
|
("variable", vec!["id", "name", "qualname", "value", "type", "scopeid"], true, true)
|
2015-11-20 14:05:10 -06:00
|
|
|
}
|
|
|
|
Enummmmmmmmmmmmmmmmmmmmm => {
|
2016-03-14 02:51:06 -05:00
|
|
|
("enum", vec!["id", "qualname", "scopeid", "value"], true, true)
|
2015-11-20 14:05:10 -06:00
|
|
|
}
|
|
|
|
Variantttttttttttttttttttttttt => {
|
2016-03-14 02:51:06 -05:00
|
|
|
("variant", vec!["id", "name", "qualname", "type", "value", "scopeid"], true, true)
|
2015-11-20 14:05:10 -06:00
|
|
|
}
|
2015-11-14 14:59:04 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
match x {
|
2017-01-15 21:37:58 -06:00
|
|
|
y => { /*Block with comment. Preserve me.*/ }
|
2015-11-14 14:59:04 -06:00
|
|
|
z => {
|
|
|
|
stmt();
|
|
|
|
}
|
2015-09-26 11:16:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn matches() {
|
|
|
|
match 1 {
|
2015-10-17 08:56:53 -05:00
|
|
|
-1 => 10,
|
2015-09-26 11:16:07 -05:00
|
|
|
1 => 1, // foo
|
|
|
|
2 => 2,
|
|
|
|
// bar
|
|
|
|
3 => 3,
|
|
|
|
_ => 0, // baz
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-08 02:03:41 -06:00
|
|
|
fn match_skip() {
|
|
|
|
let _ = match Some(1) {
|
|
|
|
#[rustfmt_skip]
|
|
|
|
Some( n ) => n,
|
|
|
|
None => 1,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-09-26 11:16:07 -05:00
|
|
|
fn issue339() {
|
|
|
|
match a {
|
|
|
|
b => {}
|
|
|
|
c => {}
|
|
|
|
d => {}
|
|
|
|
e => {}
|
|
|
|
// collapsing here is safe
|
|
|
|
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff => {}
|
|
|
|
// collapsing here exceeds line length
|
|
|
|
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffg => {
|
|
|
|
}
|
2015-10-19 14:41:47 -05:00
|
|
|
h => {
|
|
|
|
// comment above block
|
2015-09-26 11:16:07 -05:00
|
|
|
}
|
|
|
|
i => {} // comment below block
|
|
|
|
j => {
|
|
|
|
// comment inside block
|
|
|
|
}
|
|
|
|
j2 => {
|
|
|
|
// comments inside...
|
|
|
|
} // ... and after
|
|
|
|
// TODO uncomment when vertical whitespace is handled better
|
|
|
|
// k => {
|
|
|
|
//
|
|
|
|
// // comment with WS above
|
|
|
|
// }
|
|
|
|
// l => {
|
|
|
|
// // comment with ws below
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
m => {}
|
|
|
|
n => {}
|
|
|
|
o => {}
|
2015-10-19 14:41:47 -05:00
|
|
|
p => {
|
|
|
|
// Dont collapse me
|
2015-09-26 11:16:07 -05:00
|
|
|
}
|
|
|
|
q => {}
|
|
|
|
r => {}
|
|
|
|
s => 0, // s comment
|
|
|
|
// t comment
|
|
|
|
t => 1,
|
|
|
|
u => 2,
|
|
|
|
// TODO uncomment when block-support exists
|
|
|
|
// v => {
|
|
|
|
// } /* funky block
|
|
|
|
// * comment */
|
|
|
|
// final comment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue355() {
|
|
|
|
match mac {
|
|
|
|
a => println!("a", b),
|
2015-10-16 15:54:32 -05:00
|
|
|
b => vec![1, 2],
|
2017-05-19 05:25:53 -05:00
|
|
|
c => vec![3; 4],
|
2015-11-14 14:57:31 -06:00
|
|
|
d => println!("a", b),
|
|
|
|
e => vec![1, 2],
|
2017-05-19 05:25:53 -05:00
|
|
|
f => vec![3; 4],
|
2015-09-26 11:16:07 -05:00
|
|
|
h => println!("a", b), // h comment
|
2015-10-16 15:54:32 -05:00
|
|
|
i => vec![1, 2], // i comment
|
2017-05-19 05:25:53 -05:00
|
|
|
j => vec![3; 4], // j comment
|
2015-09-26 11:16:07 -05:00
|
|
|
// k comment
|
|
|
|
k => println!("a", b),
|
|
|
|
// l comment
|
2015-10-16 15:54:32 -05:00
|
|
|
l => vec![1, 2],
|
2015-09-26 11:16:07 -05:00
|
|
|
// m comment
|
2017-05-19 05:25:53 -05:00
|
|
|
m => vec![3; 4],
|
2015-09-26 11:16:07 -05:00
|
|
|
// Rewrite splits macro
|
2015-11-20 14:05:10 -06:00
|
|
|
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn => {
|
|
|
|
println!("a", b)
|
|
|
|
}
|
2015-09-26 11:16:07 -05:00
|
|
|
// Rewrite splits macro
|
2015-11-20 14:05:10 -06:00
|
|
|
oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo => {
|
|
|
|
vec![1, 2]
|
|
|
|
}
|
2015-09-26 11:16:07 -05:00
|
|
|
// Macro support fails to recognise this macro as splitable
|
|
|
|
// We push the whole expr to a new line, TODO split this macro as well
|
2015-11-20 14:05:10 -06:00
|
|
|
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp => {
|
2017-05-19 05:25:53 -05:00
|
|
|
vec![3; 4]
|
2015-11-20 14:05:10 -06:00
|
|
|
}
|
2015-09-26 11:16:07 -05:00
|
|
|
// q, r and s: Rewrite splits match arm
|
2015-11-20 14:05:10 -06:00
|
|
|
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq => {
|
|
|
|
println!("a", b)
|
|
|
|
}
|
|
|
|
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr => {
|
|
|
|
vec![1, 2]
|
|
|
|
}
|
|
|
|
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss => {
|
2017-05-19 05:25:53 -05:00
|
|
|
vec![3; 4]
|
2015-11-20 14:05:10 -06:00
|
|
|
}
|
2015-09-26 11:16:07 -05:00
|
|
|
// Funky bracketing styles
|
|
|
|
t => println!{"a", b},
|
2015-10-16 15:54:32 -05:00
|
|
|
u => vec![1, 2],
|
2017-05-19 05:25:53 -05:00
|
|
|
v => vec![3; 4],
|
2015-09-26 11:16:07 -05:00
|
|
|
w => println!["a", b],
|
|
|
|
x => vec![1, 2],
|
|
|
|
y => vec![3; 4],
|
|
|
|
// Brackets with comments
|
|
|
|
tc => println!{"a", b}, // comment
|
2015-10-16 15:54:32 -05:00
|
|
|
uc => vec![1, 2], // comment
|
2017-05-19 05:25:53 -05:00
|
|
|
vc => vec![3; 4], // comment
|
2015-09-26 11:16:07 -05:00
|
|
|
wc => println!["a", b], // comment
|
|
|
|
xc => vec![1, 2], // comment
|
|
|
|
yc => vec![3; 4], // comment
|
2015-11-20 14:05:10 -06:00
|
|
|
yd => {
|
|
|
|
looooooooooooooooooooooooooooooooooooooooooooooooooooooooong_func(aaaaaaaaaa,
|
|
|
|
bbbbbbbbbb,
|
|
|
|
cccccccccc,
|
|
|
|
dddddddddd)
|
|
|
|
}
|
2015-09-01 21:45:56 -05:00
|
|
|
}
|
|
|
|
}
|
2015-09-27 04:58:26 -05:00
|
|
|
|
|
|
|
fn issue280() {
|
|
|
|
{
|
|
|
|
match x {
|
2016-04-09 01:40:00 -05:00
|
|
|
CompressionMode::DiscardNewline |
|
|
|
|
CompressionMode::CompressWhitespaceNewline => ch == '\n',
|
2015-11-20 14:05:10 -06:00
|
|
|
ast::ItemConst(ref typ, ref expr) => {
|
|
|
|
self.process_static_or_const_item(item, &typ, &expr)
|
|
|
|
}
|
2015-09-27 04:58:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-27 15:11:17 -05:00
|
|
|
|
|
|
|
fn issue383() {
|
|
|
|
match resolution.last_private {
|
2016-02-11 19:59:13 -06:00
|
|
|
LastImport { .. } => false,
|
2015-09-27 15:11:17 -05:00
|
|
|
_ => true,
|
2015-11-08 18:23:19 -06:00
|
|
|
};
|
2015-09-27 15:11:17 -05:00
|
|
|
}
|
2015-10-21 16:35:45 -05:00
|
|
|
|
|
|
|
fn issue507() {
|
|
|
|
match 1 {
|
|
|
|
1 => unsafe { std::intrinsics::abort() },
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue508() {
|
|
|
|
match s.type_id() {
|
|
|
|
Some(NodeTypeId::Element(ElementTypeId::HTMLElement(
|
|
|
|
HTMLElementTypeId::HTMLCanvasElement))) => true,
|
|
|
|
Some(NodeTypeId::Element(ElementTypeId::HTMLElement(
|
|
|
|
HTMLElementTypeId::HTMLObjectElement))) => s.has_object_data(),
|
|
|
|
Some(NodeTypeId::Element(_)) => false,
|
|
|
|
}
|
|
|
|
}
|
2015-10-23 14:20:43 -05:00
|
|
|
|
|
|
|
fn issue496() {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
match def {
|
2016-04-09 01:40:00 -05:00
|
|
|
def::DefConst(def_id) |
|
|
|
|
def::DefAssociatedConst(def_id) => {
|
2015-10-23 14:20:43 -05:00
|
|
|
match const_eval::lookup_const_by_id(cx.tcx, def_id, Some(self.pat.id)) {
|
2015-11-14 14:57:31 -06:00
|
|
|
Some(const_expr) => x,
|
2015-11-20 14:05:10 -06:00
|
|
|
}
|
|
|
|
}
|
2015-10-23 14:20:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue494() {
|
|
|
|
{
|
|
|
|
match stmt.node {
|
2016-04-09 01:40:00 -05:00
|
|
|
hir::StmtExpr(ref expr, id) |
|
|
|
|
hir::StmtSemi(ref expr, id) => {
|
2015-10-23 14:20:43 -05:00
|
|
|
result.push(StmtRef::Mirror(Box::new(Stmt {
|
2017-02-22 13:52:52 -06:00
|
|
|
span: stmt.span,
|
|
|
|
kind: StmtKind::Expr {
|
|
|
|
scope: cx.tcx
|
|
|
|
.region_maps
|
|
|
|
.node_extent(id),
|
|
|
|
expr: expr.to_ref(),
|
|
|
|
},
|
|
|
|
})))
|
2015-11-20 14:05:10 -06:00
|
|
|
}
|
2015-10-23 14:20:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-09 01:40:00 -05:00
|
|
|
|
|
|
|
fn issue386() {
|
|
|
|
match foo {
|
|
|
|
BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => true,
|
|
|
|
BiAnd | BiOr | BiAdd | BiSub | BiMul | BiDiv | BiRem | BiBitXor | BiBitAnd | BiBitOr |
|
|
|
|
BiShl | BiShr => false,
|
|
|
|
}
|
|
|
|
}
|
2016-04-11 17:30:57 -05:00
|
|
|
|
|
|
|
fn guards() {
|
|
|
|
match foo {
|
|
|
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if foooooooooooooo &&
|
|
|
|
barrrrrrrrrrrr => {}
|
|
|
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
|
|
|
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if foooooooooooooo &&
|
|
|
|
barrrrrrrrrrrr => {}
|
|
|
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
|
|
if fooooooooooooooooooooo &&
|
|
|
|
(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb ||
|
|
|
|
cccccccccccccccccccccccccccccccccccccccc) => {}
|
|
|
|
}
|
|
|
|
}
|
2017-04-18 20:14:27 -05:00
|
|
|
|
|
|
|
fn issue1371() {
|
|
|
|
Some(match type_ {
|
|
|
|
sfEvtClosed => Closed,
|
|
|
|
sfEvtResized => {
|
|
|
|
let e = unsafe { *event.size.as_ref() };
|
|
|
|
|
|
|
|
Resized {
|
|
|
|
width: e.width,
|
|
|
|
height: e.height,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sfEvtLostFocus => LostFocus,
|
|
|
|
sfEvtGainedFocus => GainedFocus,
|
|
|
|
sfEvtTextEntered => {
|
|
|
|
TextEntered {
|
|
|
|
unicode:
|
|
|
|
unsafe {
|
|
|
|
::std::char::from_u32((*event.text.as_ref()).unicode)
|
|
|
|
.expect("Invalid unicode encountered on TextEntered event")
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sfEvtKeyPressed => {
|
|
|
|
let e = unsafe { event.key.as_ref() };
|
|
|
|
|
|
|
|
KeyPressed {
|
|
|
|
code: unsafe { ::std::mem::transmute(e.code) },
|
|
|
|
alt: e.alt.to_bool(),
|
|
|
|
ctrl: e.control.to_bool(),
|
|
|
|
shift: e.shift.to_bool(),
|
|
|
|
system: e.system.to_bool(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sfEvtKeyReleased => {
|
|
|
|
let e = unsafe { event.key.as_ref() };
|
|
|
|
|
|
|
|
KeyReleased {
|
|
|
|
code: unsafe { ::std::mem::transmute(e.code) },
|
|
|
|
alt: e.alt.to_bool(),
|
|
|
|
ctrl: e.control.to_bool(),
|
|
|
|
shift: e.shift.to_bool(),
|
|
|
|
system: e.system.to_bool(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue1395() {
|
|
|
|
let bar = Some(true);
|
|
|
|
let foo = Some(true);
|
|
|
|
let mut x = false;
|
|
|
|
bar.and_then(|_| match foo {
|
|
|
|
None => None,
|
|
|
|
Some(b) => {
|
|
|
|
x = true;
|
|
|
|
Some(b)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue1456() {
|
|
|
|
Ok(Recording {
|
|
|
|
artists: match reader
|
|
|
|
.evaluate(".//mb:recording/mb:artist-credit/mb:name-credit")? {
|
|
|
|
Nodeset(nodeset) => {
|
|
|
|
let res: Result<Vec<ArtistRef>, ReadError> = nodeset
|
|
|
|
.iter()
|
|
|
|
.map(|node| {
|
|
|
|
XPathNodeReader::new(node, &context)
|
|
|
|
.and_then(|r| ArtistRef::from_xml(&r))
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
res?
|
|
|
|
}
|
|
|
|
_ => Vec::new(),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2017-05-01 06:00:21 -05:00
|
|
|
|
|
|
|
fn issue1460() {
|
|
|
|
let _ = match foo {
|
|
|
|
REORDER_BUFFER_CHANGE_INTERNAL_SPEC_INSERT => {
|
|
|
|
"internal_spec_insert_internal_spec_insert_internal_spec_insert"
|
|
|
|
}
|
|
|
|
_ => "reorder_something",
|
|
|
|
};
|
|
|
|
}
|
2017-05-08 18:28:05 -05:00
|
|
|
|
|
|
|
fn issue525() {
|
|
|
|
foobar(f, "{}", match *self {
|
|
|
|
TaskState::Started => "started",
|
|
|
|
TaskState::Success => "success",
|
|
|
|
TaskState::Failed => "failed",
|
|
|
|
});
|
|
|
|
}
|