rust/tests/target/chains.rs

307 lines
6.9 KiB
Rust
Raw Normal View History

// rustfmt-use_small_heuristics: Off
2015-09-09 23:13:37 +02:00
// Test chain formatting.
fn main() {
2017-03-28 11:25:59 +13:00
let a = b.c.d.1.foo(|x| x + 1);
2015-09-09 23:13:37 +02:00
2017-03-07 11:28:25 +13:00
bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddd();
2015-09-09 23:13:37 +02:00
2017-03-28 11:01:44 +13:00
bbbbbbbbbbbbbbbbbbb
.ccccccccccccccccccccccccccccccccccccc
.ddddddddddddddddddddddddddd
.eeeeeeee();
2015-09-09 23:13:37 +02:00
2017-05-03 11:26:31 +09:00
let f = fooooooooooooooooooooooooooooooooooooooooooooooooooo
.baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar;
2015-09-11 00:53:21 +02:00
// Test case where first chain element isn't a path, but is shorter than
// the size of a tab.
x().y(|| match cond() {
2017-06-12 16:01:41 +12:00
true => (),
false => (),
});
2017-11-02 21:38:20 +09:00
loong_func().quux(move || {
if true {
1
} else {
2
}
2017-06-12 16:01:41 +12:00
});
2015-09-09 23:13:37 +02:00
some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
let x = c;
x
});
some_fuuuuuuuuunction()
.method_call_a(aaaaa, bbbbb, |c| {
let x = c;
x
2018-09-19 23:19:24 +09:00
})
.method_call_b(aaaaa, bbbbb, |c| {
let x = c;
x
});
fffffffffffffffffffffffffffffffffff(a, {
SCRIPT_TASK_ROOT.with(|root| {
*root.borrow_mut() = Some(&script_task);
});
});
2015-09-09 23:14:09 +02:00
2017-03-07 11:28:25 +13:00
let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum =
xxxxxxx.map(|x| x + 5).map(|x| x / 2).fold(0, |acc, x| acc + x);
2015-09-09 23:14:54 +02:00
2017-12-05 10:02:49 +09:00
body.fold(Body::new(), |mut body, chunk| {
body.extend(chunk);
Ok(body)
2018-09-19 23:19:24 +09:00
})
.and_then(move |body| {
2017-12-05 10:02:49 +09:00
let req = Request::from_parts(parts, body);
f(req).map_err(|_| io::Error::new(io::ErrorKind::Other, ""))
});
2017-03-28 11:01:44 +13:00
aaaaaaaaaaaaaaaa
.map(|x| {
2017-06-12 16:01:41 +12:00
x += 1;
x
2018-09-19 23:19:24 +09:00
})
.filter(some_mod::some_filter)
2015-09-09 23:13:37 +02:00
}
2015-10-18 17:56:13 +02:00
fn floaters() {
let z = Foo {
field1: val1,
field2: val2,
};
let x = Foo {
2017-05-23 22:13:29 +09:00
field1: val1,
field2: val2,
2018-09-19 23:19:24 +09:00
}
.method_call()
2018-07-12 14:05:50 +12:00
.method_call();
2015-10-18 17:56:13 +02:00
let y = if cond {
2017-05-23 22:13:29 +09:00
val1
} else {
val2
2018-09-19 23:19:24 +09:00
}
.method_call();
2015-10-18 17:56:13 +02:00
{
match x {
PushParam => {
// params are 1-indexed
2017-06-12 16:01:41 +12:00
stack.push(
mparams[match cur.to_digit(10) {
2018-09-19 23:19:24 +09:00
Some(d) => d as usize - 1,
None => return Err("bad param number".to_owned()),
}]
.clone(),
2017-06-12 16:01:41 +12:00
);
2015-10-18 17:56:13 +02:00
}
}
}
if cond {
2017-05-23 22:13:29 +09:00
some();
} else {
none();
2018-09-19 23:19:24 +09:00
}
.bar()
2018-07-12 14:05:50 +12:00
.baz();
2015-10-18 17:56:13 +02:00
Foo {
x: val,
2018-09-19 23:19:24 +09:00
}
.baz(|| {
force();
multiline();
2018-09-19 23:19:24 +09:00
})
.quux();
2015-10-18 17:56:13 +02:00
Foo {
2017-05-23 22:13:29 +09:00
y: i_am_multi_line,
z: ok,
2018-09-19 23:19:24 +09:00
}
.baz(|| {
2017-06-12 16:01:41 +12:00
force();
multiline();
2018-09-19 23:19:24 +09:00
})
.quux();
2015-10-18 17:56:13 +02:00
2017-07-21 17:55:52 +09:00
a + match x {
true => "yay!",
false => "boo!",
2018-09-19 23:19:24 +09:00
}
.bar()
2015-10-18 17:56:13 +02:00
}
fn is_replaced_content() -> bool {
2017-03-07 11:28:25 +13:00
constellat.send(ConstellationMsg::ViewportConstrained(self.id, constraints)).unwrap();
}
fn issue587() {
a.b::<()>(c);
std::mem::transmute(dl.symbol::<()>("init").unwrap())
}
2016-05-09 20:07:59 +02:00
fn try_shorthand() {
let x = expr?;
let y = expr.kaas()?.test();
2017-03-28 11:25:59 +13:00
let loooooooooooooooooooooooooooooooooooooooooong =
does_this?.look?.good?.should_we_break?.after_the_first_question_mark?;
2017-04-24 16:50:11 +09:00
let yyyy = expr?.another?.another?.another?.another?.another?.another?.another?.another?.test();
2017-03-28 11:25:59 +13:00
let zzzz = expr?.another?.another?.another?.another?;
2016-05-09 20:07:59 +02:00
let aaa = x??????????????????????????????????????????????????????????????????????????;
let y = a
.very
2016-05-12 21:50:43 +02:00
.loooooooooooooooooooooooooooooooooooooong()
.chain()
.inside()
.weeeeeeeeeeeeeee()?
.test()
.0
.x;
parameterized(f, substs, def_id, Ns::Value, &[], |tcx| tcx.lookup_item_type(def_id).generics)?;
fooooooooooooooooooooooooooo()?
.bar()?
.baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()?;
2016-05-09 20:07:59 +02:00
}
fn issue_1004() {
match *self {
ty::ImplOrTraitItem::MethodTraitItem(ref i) => write!(f, "{:?}", i),
ty::ImplOrTraitItem::ConstTraitItem(ref i) => write!(f, "{:?}", i),
ty::ImplOrTraitItem::TypeTraitItem(ref i) => write!(f, "{:?}", i),
}?;
ty::tls::with(|tcx| {
2017-06-12 16:01:41 +12:00
let tap = ty::Binder(TraitAndProjections(principal, projections));
in_binder(f, tcx, &ty::Binder(""), Some(tap))
})?;
}
fn issue1392() {
test_method(
r#"
if foo {
a();
}
else {
b();
}
2018-09-19 23:19:24 +09:00
"#
.trim(),
);
}
2017-10-18 22:02:05 +09:00
// #2067
impl Settings {
fn save(&self) -> Result<()> {
let mut file = File::create(&settings_path)
.chain_err(|| ErrorKind::WriteError(settings_path.clone()))?;
}
}
2017-11-08 08:25:09 +09:00
fn issue2126() {
{
{
{
{
{
let x = self
.span_from(sub_span.expect("No span found for struct arant variant"));
2017-11-08 08:25:09 +09:00
self.sspanpan_from_span(
sub_span.expect("No span found for struct variant"),
);
let x = self.spanpan_from_span(
sub_span.expect("No span found for struct variant"),
)?;
}
}
}
}
}
}
2017-11-29 12:34:09 +09:00
// #2200
impl Foo {
pub fn from_ast(diagnostic: &::errors::Handler, attrs: &[ast::Attribute]) -> Attributes {
let other_attrs = attrs
.iter()
.filter_map(|attr| {
attr.with_desugared_doc(|attr| {
if attr.check_name("doc") {
if let Some(mi) = attr.meta() {
if let Some(value) = mi.value_str() {
2017-11-29 17:29:06 +09:00
doc_strings.push(DocFragment::Include(
2018-03-26 07:38:39 +09:00
line, attr.span, filename, contents,
2017-11-29 17:29:06 +09:00
));
2017-11-29 12:34:09 +09:00
}
}
}
})
2018-09-19 23:19:24 +09:00
})
.collect();
2017-11-29 12:34:09 +09:00
}
}
2018-02-06 09:36:29 +09:00
// #2415
// Avoid orphan in chain
fn issue2415() {
let base_url = (|| {
// stuff
Ok((|| {
// stuff
Some(value.to_string())
2018-09-19 23:19:24 +09:00
})()
.ok_or("")?)
})()
.unwrap_or_else(|_: Box<::std::error::Error>| String::from(""));
2018-02-06 09:36:29 +09:00
}
2018-07-12 14:08:16 +12:00
impl issue_2786 {
fn thing(&self) {
foo(|a| {
println!("a");
println!("b");
2018-09-19 23:19:24 +09:00
})
.bar(|c| {
2018-07-12 14:08:16 +12:00
println!("a");
println!("b");
2018-09-19 23:19:24 +09:00
})
.baz(|c| {
2018-07-12 14:08:16 +12:00
println!("a");
println!("b");
})
}
}
fn issue_2773() {
let bar = Some(0);
bar.or_else(|| {
// do stuff
None
2018-09-19 23:19:24 +09:00
})
.or_else(|| {
2018-07-12 14:08:16 +12:00
// do other stuff
None
2018-09-19 23:19:24 +09:00
})
.and_then(|val| {
2018-07-12 14:08:16 +12:00
// do this stuff
None
});
}
2018-10-15 12:09:53 +13:00
fn issue_3034() {
disallowed_headers.iter().any(|header| *header == name)
|| disallowed_header_prefixes.iter().any(|prefix| name.starts_with(prefix))
}