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(),
|
|
|
|
c => { // Another comment.
|
|
|
|
// Comment.
|
|
|
|
an_expression;
|
|
|
|
foo()
|
|
|
|
}
|
|
|
|
// Perhaps this should introduce braces?
|
|
|
|
Foo(ref bar) =>
|
|
|
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
|
|
|
|
Pattern1 | Pattern2 | Pattern3 => false,
|
|
|
|
Paternnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn |
|
|
|
|
Paternnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn => {
|
|
|
|
blah
|
|
|
|
}
|
|
|
|
Patternnnnnnnnnnnnnnnnnnn |
|
|
|
|
Patternnnnnnnnnnnnnnnnnnn |
|
|
|
|
Patternnnnnnnnnnnnnnnnnnn |
|
|
|
|
Patternnnnnnnnnnnnnnnnnnn => meh,
|
|
|
|
|
|
|
|
Patternnnnnnnnnnnnnnnnnnn |
|
|
|
|
Patternnnnnnnnnnnnnnnnnnn if looooooooooooooooooong_guard => meh,
|
|
|
|
|
|
|
|
Patternnnnnnnnnnnnnnnnnnnnnnnnn |
|
2015-08-16 16:41:45 -05:00
|
|
|
Patternnnnnnnnnnnnnnnnnnnnnnnnn if looooooooooooooooooooooooooooooooooooooooong_guard =>
|
|
|
|
meh,
|
|
|
|
|
|
|
|
// Test that earlier patterns can take the guard space
|
|
|
|
(aaaa, bbbbb, ccccccc, aaaaa, bbbbbbbb, cccccc, aaaa, bbbbbbbb, cccccc, dddddd) |
|
|
|
|
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-09-26 16:16:11 -05:00
|
|
|
Variableeeeeeeeeeeeeeeeee => ("variable",
|
2015-10-16 15:54:32 -05:00
|
|
|
vec!["id", "name", "qualname", "value", "type", "scopeid"],
|
2015-09-26 16:16:11 -05:00
|
|
|
true,
|
|
|
|
true),
|
|
|
|
Enummmmmmmmmmmmmmmmmmmmm => ("enum",
|
2015-10-16 15:54:32 -05:00
|
|
|
vec!["id", "qualname", "scopeid", "value"],
|
2015-09-26 16:16:11 -05:00
|
|
|
true,
|
|
|
|
true),
|
2015-09-26 11:16:07 -05:00
|
|
|
Variantttttttttttttttttttttttt =>
|
2015-09-26 16:16:11 -05:00
|
|
|
("variant",
|
2015-10-16 15:54:32 -05:00
|
|
|
vec!["id", "name", "qualname", "type", "value", "scopeid"],
|
2015-09-26 16:16:11 -05:00
|
|
|
true,
|
|
|
|
true),
|
2015-09-26 11:16:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn matches() {
|
|
|
|
match 1 {
|
|
|
|
1 => 1, // foo
|
|
|
|
2 => 2,
|
|
|
|
// bar
|
|
|
|
3 => 3,
|
|
|
|
_ => 0, // baz
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue339() {
|
|
|
|
match a {
|
|
|
|
b => {}
|
|
|
|
c => {}
|
|
|
|
d => {}
|
|
|
|
e => {}
|
|
|
|
// collapsing here is safe
|
|
|
|
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff => {}
|
|
|
|
// collapsing here exceeds line length
|
|
|
|
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffg => {
|
|
|
|
}
|
|
|
|
h => { // comment above block
|
|
|
|
}
|
|
|
|
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 => {}
|
|
|
|
p => { // Dont collapse me
|
|
|
|
}
|
|
|
|
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],
|
2015-09-26 11:16:07 -05:00
|
|
|
c => vec!(3; 4),
|
|
|
|
d => {
|
|
|
|
println!("a", b)
|
|
|
|
}
|
|
|
|
e => {
|
2015-10-16 15:54:32 -05:00
|
|
|
vec![1, 2]
|
2015-09-26 11:16:07 -05:00
|
|
|
}
|
|
|
|
f => {
|
|
|
|
vec!(3; 4)
|
|
|
|
}
|
|
|
|
h => println!("a", b), // h comment
|
2015-10-16 15:54:32 -05:00
|
|
|
i => vec![1, 2], // i comment
|
2015-09-26 11:16:07 -05:00
|
|
|
j => vec!(3; 4), // j comment
|
|
|
|
// 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
|
|
|
|
m => vec!(3; 4),
|
|
|
|
// Rewrite splits macro
|
|
|
|
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn =>
|
|
|
|
println!("a", b),
|
|
|
|
// Rewrite splits macro
|
|
|
|
oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo =>
|
2015-10-16 15:54:32 -05:00
|
|
|
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
|
|
|
|
pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp =>
|
|
|
|
vec!(3; 4),
|
|
|
|
// q, r and s: Rewrite splits match arm
|
|
|
|
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq =>
|
|
|
|
println!("a", b),
|
|
|
|
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr =>
|
2015-10-16 15:54:32 -05:00
|
|
|
vec![1, 2],
|
2015-09-26 11:16:07 -05:00
|
|
|
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss =>
|
|
|
|
vec!(3; 4),
|
|
|
|
// Funky bracketing styles
|
|
|
|
t => println!{"a", b},
|
2015-10-16 15:54:32 -05:00
|
|
|
u => vec![1, 2],
|
2015-09-26 11:16:07 -05:00
|
|
|
v => vec!{3; 4},
|
|
|
|
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
|
2015-09-26 11:16:07 -05:00
|
|
|
vc => vec!{3; 4}, // comment
|
|
|
|
wc => println!["a", b], // comment
|
|
|
|
xc => vec![1, 2], // comment
|
|
|
|
yc => vec![3; 4], // comment
|
|
|
|
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 {
|
|
|
|
CompressionMode::DiscardNewline | CompressionMode::CompressWhitespaceNewline =>
|
|
|
|
ch == '\n',
|
|
|
|
ast::ItemConst(ref typ, ref expr) =>
|
|
|
|
self.process_static_or_const_item(item, &typ, &expr),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-27 15:11:17 -05:00
|
|
|
|
|
|
|
fn issue383() {
|
|
|
|
match resolution.last_private {
|
|
|
|
LastImport{..} => false,
|
|
|
|
_ => true,
|
2015-10-14 15:28:17 -05:00
|
|
|
}
|
2015-09-27 15:11:17 -05:00
|
|
|
}
|