PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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

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