From: topecongiro Date: Sun, 21 May 2017 10:56:37 +0000 (+0900) Subject: Update tests X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=2c15204f0c4a0b0d5f97460a23f10fa090f5aef9;p=rust.git Update tests --- diff --git a/src/expr.rs b/src/expr.rs index f0db88ae566..c1b130fd8f3 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1348,7 +1348,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { ast::ExprKind::Closure(..) => (true, &**body), _ => (false, &**body), }; - extend &= context.config.fn_call_style == IndentStyle::Block; + extend &= context.config.fn_call_style() == IndentStyle::Block; let comma = arm_comma(&context.config, body); let alt_block_sep = String::from("\n") + @@ -1746,9 +1746,9 @@ fn rewrite_call_args(context: &RewriteContext, if overflow_last { let last_arg = args.last().unwrap(); let arg_shape = match last_arg.node { - ast::ExprKind::Closure(..) if context.config.fn_call_style == IndentStyle::Block => { + ast::ExprKind::Closure(..) if context.config.fn_call_style() == IndentStyle::Block => { let mut arg_shape = shape.block(); - arg_shape.indent.block_indent -= context.config.tab_spaces; + arg_shape.indent.block_indent -= context.config.tab_spaces(); arg_shape } _ => shape.block(), diff --git a/tests/source/configs-fn_call_style-block.rs b/tests/source/configs-fn_call_style-block.rs index 35030189b8b..6708966fa69 100644 --- a/tests/source/configs-fn_call_style-block.rs +++ b/tests/source/configs-fn_call_style-block.rs @@ -45,3 +45,54 @@ fn query(conn: &Connection) -> Result<()> { Ok(()) } + +// #1449 +fn future_rayon_wait_1_thread() { + // run with only 1 worker thread; this would deadlock if we couldn't make progress + let mut result = None; + ThreadPool::new(Configuration::new().num_threads(1)) + .unwrap() + .install( + || { + scope( + |s| { + use std::sync::mpsc::channel; + let (tx, rx) = channel(); + let a = s.spawn_future(lazy(move || Ok::(rx.recv().unwrap()))); + // ^^^^ FIXME: why is this needed? + let b = s.spawn_future(a.map(|v| v + 1)); + let c = s.spawn_future(b.map(|v| v + 1)); + s.spawn(move |_| tx.send(20).unwrap()); + result = Some(c.rayon_wait().unwrap()); + }, + ); + }, + ); + assert_eq!(result, Some(22)); +} + +// #1494 +impl Cursor { + fn foo() { + self.cur_type() + .num_template_args() + .or_else(|| { + let n: c_int = unsafe { clang_Cursor_getNumTemplateArguments(self.x) }; + + if n >= 0 { + Some(n as u32) + } else { + debug_assert_eq!(n, -1); + None + } + }) + .or_else(|| { + let canonical = self.canonical(); + if canonical != *self { + canonical.num_template_args() + } else { + None + } + }); + } +} diff --git a/tests/source/expr-block.rs b/tests/source/expr-block.rs index ad959f8ee01..bf5d23a7d9e 100644 --- a/tests/source/expr-block.rs +++ b/tests/source/expr-block.rs @@ -143,3 +143,88 @@ fn foo() { DefinitiveListTactic::Horizontal } } + +fn combine_block() { + foo( + Bar { + x: value, + y: value2, + }, + ); + + let opt = Some( + Struct( + long_argument_one, + long_argument_two, + long_argggggggg, + ), + ); + + do_thing( + |param| { + action(); + foo(param) + }, + ); + + do_thing( + x, + |param| { + action(); + foo(param) + }, + ); + + Ok( + some_function( + lllllllllong_argument_one, + lllllllllong_argument_two, + lllllllllllllllllllllllllllllong_argument_three, + ), + ); + + foo( + thing, + bar( + param2, + pparam1param1param1param1param1param1param1param1param1param1aram1, + param3, + ), + ); + + foo.map_or( + || { + Ok( + SomeStruct { + f1: 0, + f2: 0, + f3: 0, + }, + ) + }, + ); + + match opt { + Some(x) => somefunc(anotherfunc( + long_argument_one, + long_argument_two, + long_argument_three, + )), + None => Ok(SomeStruct { + f1: long_argument_one, + f2: long_argument_two, + f3: long_argument_three, + }), + }; + + match x { + y => func( + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, + ), + _ => func( + x, + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, + zzz, + ), + } +} diff --git a/tests/target/closure-block-inside-macro.rs b/tests/target/closure-block-inside-macro.rs index b58527eb8fb..5d1e1de0f68 100644 --- a/tests/target/closure-block-inside-macro.rs +++ b/tests/target/closure-block-inside-macro.rs @@ -1,15 +1,13 @@ // rustfmt-fn_call_style: Block // #1547 -fuzz_target!( - |data: &[u8]| { - if let Some(first) = data.first() { - let index = *first as usize; - if index >= ENCODINGS.len() { - return; - } - let encoding = ENCODINGS[index]; - dispatch_test(encoding, &data[1..]); +fuzz_target!(|data: &[u8]| { + if let Some(first) = data.first() { + let index = *first as usize; + if index >= ENCODINGS.len() { + return; } + let encoding = ENCODINGS[index]; + dispatch_test(encoding, &data[1..]); } -); +}); diff --git a/tests/target/configs-fn_call_style-block.rs b/tests/target/configs-fn_call_style-block.rs index d7f65635379..ed3dd76c04d 100644 --- a/tests/target/configs-fn_call_style-block.rs +++ b/tests/target/configs-fn_call_style-block.rs @@ -13,18 +13,20 @@ fn main() { "elit", ); // #1501 - let hyper = Arc::new( - Client::with_connector(HttpsConnector::new(TlsClient::new())), - ); + let hyper = Arc::new(Client::with_connector(HttpsConnector::new( + TlsClient::new(), + ))); } // #1521 impl Foo { fn map_pixel_to_coords(&self, point: &Vector2i, view: &View) -> Vector2f { unsafe { - Vector2f::from_raw( - ffi::sfRenderTexture_mapPixelToCoords(self.render_texture, point.raw(), view.raw()), - ) + Vector2f::from_raw(ffi::sfRenderTexture_mapPixelToCoords( + self.render_texture, + point.raw(), + view.raw(), + )) } } } @@ -58,3 +60,50 @@ fn query(conn: &Connection) -> Result<()> { Ok(()) } + +// #1449 +fn future_rayon_wait_1_thread() { + // run with only 1 worker thread; this would deadlock if we couldn't make progress + let mut result = None; + ThreadPool::new(Configuration::new().num_threads(1)) + .unwrap() + .install(|| { + scope(|s| { + use std::sync::mpsc::channel; + let (tx, rx) = channel(); + let a = s.spawn_future(lazy(move || Ok::(rx.recv().unwrap()))); + // ^^^^ FIXME: why is this needed? + let b = s.spawn_future(a.map(|v| v + 1)); + let c = s.spawn_future(b.map(|v| v + 1)); + s.spawn(move |_| tx.send(20).unwrap()); + result = Some(c.rayon_wait().unwrap()); + }); + }); + assert_eq!(result, Some(22)); +} + +// #1494 +impl Cursor { + fn foo() { + self.cur_type() + .num_template_args() + .or_else(|| { + let n: c_int = unsafe { clang_Cursor_getNumTemplateArguments(self.x) }; + + if n >= 0 { + Some(n as u32) + } else { + debug_assert_eq!(n, -1); + None + } + }) + .or_else(|| { + let canonical = self.canonical(); + if canonical != *self { + canonical.num_template_args() + } else { + None + } + }); + } +} diff --git a/tests/target/expr-block.rs b/tests/target/expr-block.rs index b6f35f65aec..1f3082f3068 100644 --- a/tests/target/expr-block.rs +++ b/tests/target/expr-block.rs @@ -213,3 +213,75 @@ fn foo() { DefinitiveListTactic::Horizontal } } + +fn combine_block() { + foo(Bar { + x: value, + y: value2, + }); + + let opt = Some(Struct( + long_argument_one, + long_argument_two, + long_argggggggg, + )); + + do_thing(|param| { + action(); + foo(param) + }); + + do_thing(x, |param| { + action(); + foo(param) + }); + + Ok(some_function( + lllllllllong_argument_one, + lllllllllong_argument_two, + lllllllllllllllllllllllllllllong_argument_three, + )); + + foo( + thing, + bar( + param2, + pparam1param1param1param1param1param1param1param1param1param1aram1, + param3, + ), + ); + + foo.map_or(|| { + Ok(SomeStruct { + f1: 0, + f2: 0, + f3: 0, + }) + }); + + match opt { + Some(x) => somefunc(anotherfunc( + long_argument_one, + long_argument_two, + long_argument_three, + )), + None => Ok(SomeStruct { + f1: long_argument_one, + f2: long_argument_two, + f3: long_argument_three, + }), + }; + + match x { + y => func( + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, + ), + _ => { + func( + x, + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, + zzz, + ) + } + } +}