PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/src/tools/rustfmt/tests/target/chains-visual.rs

https://gitlab.com/rust-lang/rust
Rust | 158 lines | 125 code | 27 blank | 6 comment | 9 complexity | f15ed28a3de6c0873c91090468546565 MD5 | raw file
  1. // rustfmt-indent_style: Visual
  2. // Test chain formatting.
  3. fn main() {
  4. // Don't put chains on a single line if it wasn't so in source.
  5. let a = b.c.d.1.foo(|x| x + 1);
  6. bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
  7. .ddddddddddddddddddddddddddd();
  8. bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
  9. .ddddddddddddddddddddddddddd
  10. .eeeeeeee();
  11. // Test case where first chain element isn't a path, but is shorter than
  12. // the size of a tab.
  13. x().y(|| match cond() {
  14. true => (),
  15. false => (),
  16. });
  17. loong_func().quux(move || if true { 1 } else { 2 });
  18. some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
  19. let x = c;
  20. x
  21. });
  22. some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
  23. let x = c;
  24. x
  25. })
  26. .method_call_b(aaaaa, bbbbb, |c| {
  27. let x = c;
  28. x
  29. });
  30. fffffffffffffffffffffffffffffffffff(a, {
  31. SCRIPT_TASK_ROOT.with(|root| {
  32. *root.borrow_mut() = Some(&script_task);
  33. });
  34. });
  35. let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum =
  36. xxxxxxx.map(|x| x + 5)
  37. .map(|x| x / 2)
  38. .fold(0, |acc, x| acc + x);
  39. aaaaaaaaaaaaaaaa.map(|x| {
  40. x += 1;
  41. x
  42. })
  43. .filter(some_mod::some_filter)
  44. }
  45. fn floaters() {
  46. let z = Foo { field1: val1,
  47. field2: val2 };
  48. let x = Foo { field1: val1,
  49. field2: val2 }.method_call()
  50. .method_call();
  51. let y = if cond { val1 } else { val2 }.method_call();
  52. {
  53. match x {
  54. PushParam => {
  55. // params are 1-indexed
  56. stack.push(mparams[match cur.to_digit(10) {
  57. Some(d) => d as usize - 1,
  58. None => return Err("bad param number".to_owned()),
  59. }].clone());
  60. }
  61. }
  62. }
  63. if cond {
  64. some();
  65. } else {
  66. none();
  67. }.bar()
  68. .baz();
  69. Foo { x: val }.baz(|| {
  70. force();
  71. multiline();
  72. })
  73. .quux();
  74. Foo { y: i_am_multi_line,
  75. z: ok }.baz(|| {
  76. force();
  77. multiline();
  78. })
  79. .quux();
  80. a + match x {
  81. true => "yay!",
  82. false => "boo!",
  83. }.bar()
  84. }
  85. fn is_replaced_content() -> bool {
  86. constellat.send(ConstellationMsg::ViewportConstrained(self.id, constraints))
  87. .unwrap();
  88. }
  89. fn issue587() {
  90. a.b::<()>(c);
  91. std::mem::transmute(dl.symbol::<()>("init").unwrap())
  92. }
  93. fn issue_1389() {
  94. let names = String::from_utf8(names)?.split('|')
  95. .map(str::to_owned)
  96. .collect();
  97. }
  98. fn issue1217() -> Result<Mnemonic, Error> {
  99. let random_chars: String = OsRng::new()?.gen_ascii_chars()
  100. .take(self.bit_length)
  101. .collect();
  102. Ok(Mnemonic::new(&random_chars))
  103. }
  104. fn issue1236(options: Vec<String>) -> Result<Option<String>> {
  105. let process = Command::new("dmenu").stdin(Stdio::piped())
  106. .stdout(Stdio::piped())
  107. .spawn()
  108. .chain_err(|| "failed to spawn dmenu")?;
  109. }
  110. fn issue1434() {
  111. for _ in 0..100 {
  112. let prototype_id =
  113. PrototypeIdData::from_reader::<_, B>(&mut self.file_cursor).chain_err(|| {
  114. format!("could not read prototype ID at offset {:#010x}",
  115. current_offset)
  116. })?;
  117. }
  118. }
  119. fn issue2264() {
  120. {
  121. something.function()
  122. .map(|| {
  123. if let a_very_very_very_very_very_very_very_very_long_variable =
  124. compute_this_variable()
  125. {
  126. println!("Hello");
  127. }
  128. })
  129. .collect();
  130. }
  131. }