about summary refs log tree commit diff
path: root/src/tools/rustfmt/tests/source
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-06-23 00:42:26 +0000
committerbors <bors@rust-lang.org>2024-06-23 00:42:26 +0000
commitacb62737aca7045f331e7a05adc38bed213e278d (patch)
treee1dfb2c42874bdfc719f801c334a58e0daa8ab72 /src/tools/rustfmt/tests/source
parent3cb521a4344f0b556b81c55eec8facddeb1ead83 (diff)
parentffad9842bddb4fcad6b8b29eaf4906512246c546 (diff)
downloadrust-acb62737aca7045f331e7a05adc38bed213e278d.tar.gz
rust-acb62737aca7045f331e7a05adc38bed213e278d.zip
Auto merge of #126842 - calebcartwright:sync-from-rustfmt-24-06, r=calebcartwright
rustfmt subtree update

r? ghost
Diffstat (limited to 'src/tools/rustfmt/tests/source')
-rw-r--r--src/tools/rustfmt/tests/source/arrow_in_comments/arrow_in_single_comment.rs10
-rw-r--r--src/tools/rustfmt/tests/source/arrow_in_comments/multiple_arrows.rs14
-rw-r--r--src/tools/rustfmt/tests/source/configs/format_generated_files/false_with_generated_marker_line_search_limit.rs10
-rw-r--r--src/tools/rustfmt/tests/source/configs/format_generated_files/false_with_marker_out_scope_size.rs10
-rw-r--r--src/tools/rustfmt/tests/source/configs/format_generated_files/false_with_zero_search_limit.rs9
-rw-r--r--src/tools/rustfmt/tests/source/configs/format_generated_files/true_with_marker_in_scope_size.rs10
-rw-r--r--src/tools/rustfmt/tests/source/configs/format_generated_files/true_with_marker_not_in_header.rs9
-rw-r--r--src/tools/rustfmt/tests/source/issue-3805.rs65
-rw-r--r--src/tools/rustfmt/tests/source/issue-5801/attribute_unexpectedly_wraps_before_max_width.rs8
-rw-r--r--src/tools/rustfmt/tests/source/issue-5801/comment_unexpectedly_wraps_before_max_width.rs17
-rw-r--r--src/tools/rustfmt/tests/source/issue-5987/two.rs13
-rw-r--r--src/tools/rustfmt/tests/source/issue-6059/repro.rs3
-rw-r--r--src/tools/rustfmt/tests/source/issue-6147/case_rustfmt_v1.rs20
-rw-r--r--src/tools/rustfmt/tests/source/issue-6147/case_rustfmt_v2.rs20
-rw-r--r--src/tools/rustfmt/tests/source/issue_5912.rs15
-rw-r--r--src/tools/rustfmt/tests/source/let_else.rs6
-rw-r--r--src/tools/rustfmt/tests/source/no_arg_with_commnet.rs2
17 files changed, 237 insertions, 4 deletions
diff --git a/src/tools/rustfmt/tests/source/arrow_in_comments/arrow_in_single_comment.rs b/src/tools/rustfmt/tests/source/arrow_in_comments/arrow_in_single_comment.rs
new file mode 100644
index 00000000000..fb0576a4822
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/arrow_in_comments/arrow_in_single_comment.rs
@@ -0,0 +1,10 @@
+// rustfmt-version: Two
+fn main() {
+    match a {
+        _ =>
+        // comment with =>
+                {
+            println!("A")
+        }
+    }
+}
diff --git a/src/tools/rustfmt/tests/source/arrow_in_comments/multiple_arrows.rs b/src/tools/rustfmt/tests/source/arrow_in_comments/multiple_arrows.rs
new file mode 100644
index 00000000000..fc696b309f2
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/arrow_in_comments/multiple_arrows.rs
@@ -0,0 +1,14 @@
+// rustfmt-version: Two
+fn main() {
+    match a {
+        _ => // comment with => 
+        match b {
+            // one goes to =>
+            one => {
+                println("1");
+            }
+            // two goes to =>
+            two => { println("2"); }
+        } 
+    }
+}
diff --git a/src/tools/rustfmt/tests/source/configs/format_generated_files/false_with_generated_marker_line_search_limit.rs b/src/tools/rustfmt/tests/source/configs/format_generated_files/false_with_generated_marker_line_search_limit.rs
new file mode 100644
index 00000000000..be03849fe10
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/configs/format_generated_files/false_with_generated_marker_line_search_limit.rs
@@ -0,0 +1,10 @@
+// rustfmt-format_generated_files: false
+// rustfmt-generated_marker_line_search_limit: 15
+
+fn main()
+{
+    println!("hello, world")
+    ;
+}
+
+// @generated
\ No newline at end of file
diff --git a/src/tools/rustfmt/tests/source/configs/format_generated_files/false_with_marker_out_scope_size.rs b/src/tools/rustfmt/tests/source/configs/format_generated_files/false_with_marker_out_scope_size.rs
new file mode 100644
index 00000000000..abb97e6259f
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/configs/format_generated_files/false_with_marker_out_scope_size.rs
@@ -0,0 +1,10 @@
+// rustfmt-format_generated_files: false
+// rustfmt-generated_marker_line_search_limit: 1
+
+fn main()
+{
+    println!("hello, world")
+    ;
+}
+
+// @generated
\ No newline at end of file
diff --git a/src/tools/rustfmt/tests/source/configs/format_generated_files/false_with_zero_search_limit.rs b/src/tools/rustfmt/tests/source/configs/format_generated_files/false_with_zero_search_limit.rs
new file mode 100644
index 00000000000..f6978d0f355
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/configs/format_generated_files/false_with_zero_search_limit.rs
@@ -0,0 +1,9 @@
+// rustfmt-format_generated_files: false
+// rustfmt-generated_marker_line_search_limit: 0
+
+// @generated
+fn main() {
+    println!("hello, world")
+    ;
+}
+// @generated
diff --git a/src/tools/rustfmt/tests/source/configs/format_generated_files/true_with_marker_in_scope_size.rs b/src/tools/rustfmt/tests/source/configs/format_generated_files/true_with_marker_in_scope_size.rs
new file mode 100644
index 00000000000..53cc116ec2b
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/configs/format_generated_files/true_with_marker_in_scope_size.rs
@@ -0,0 +1,10 @@
+// rustfmt-format_generated_files: true
+// rustfmt-generated_marker_line_search_limit: 20
+
+fn main()
+{
+    println!("hello, world")
+    ;
+}
+
+// @generated
diff --git a/src/tools/rustfmt/tests/source/configs/format_generated_files/true_with_marker_not_in_header.rs b/src/tools/rustfmt/tests/source/configs/format_generated_files/true_with_marker_not_in_header.rs
new file mode 100644
index 00000000000..8eff1a3b0ee
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/configs/format_generated_files/true_with_marker_not_in_header.rs
@@ -0,0 +1,9 @@
+// rustfmt-format_generated_files: true
+
+fn main()
+{
+    println!("hello, world")
+    ;
+}
+
+// @generated
\ No newline at end of file
diff --git a/src/tools/rustfmt/tests/source/issue-3805.rs b/src/tools/rustfmt/tests/source/issue-3805.rs
new file mode 100644
index 00000000000..a0289b57974
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-3805.rs
@@ -0,0 +1,65 @@
+// rustfmt-version: Two
+// rustfmt-format_macro_matchers: true
+
+// From original issue example - Line length 101
+macro_rules! test {
+($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeio:expr, $add:expr) => {{
+return;
+}};
+}
+
+// Spaces between the `{` and `}`
+macro_rules! test {
+($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeio:expr, $add:expr) => {     {
+return;
+}      };
+}
+
+// Multi  `{}`
+macro_rules! test {
+($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeio:expr, $add:expr) => {{{{
+return;
+}}}};
+}
+
+// Multi  `{}` with spaces
+macro_rules! test {
+($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeio:expr, $add:expr) => {    {    {    {
+return;
+}     }     }    };
+}
+    
+// Line length 102
+macro_rules! test {
+($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeiou:expr, $add:expr) => {{
+return;
+}};
+}
+
+// Line length 103
+macro_rules! test {
+($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeioua:expr, $add:expr) => {{
+return;
+}};
+}
+
+// With extended macro body - Line length 101
+macro_rules! test {
+($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeio:expr, $add:expr) => {{
+let VAR = "VALUE"; return VAR;
+}};
+}
+
+// With extended macro body - Line length 102
+macro_rules! test {
+($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeiou:expr, $add:expr) => {{
+let VAR = "VALUE"; return VAR;
+}};
+}
+
+// With extended macro body - Line length 103
+macro_rules! test {
+($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeioua:expr, $add:expr) => {{
+let VAR = "VALUE"; return VAR;
+}};
+}
diff --git a/src/tools/rustfmt/tests/source/issue-5801/attribute_unexpectedly_wraps_before_max_width.rs b/src/tools/rustfmt/tests/source/issue-5801/attribute_unexpectedly_wraps_before_max_width.rs
new file mode 100644
index 00000000000..59902c7bcce
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-5801/attribute_unexpectedly_wraps_before_max_width.rs
@@ -0,0 +1,8 @@
+// rustfmt-config: issue-5801-v1.toml
+
+pub enum Severity {
+    #[something(AAAAAAAAAAAAA, BBBBBBBBBBBBBB, CCCCCCCCCCCCCCCC, DDDDDDDDDDDDD, EEEEEEEEEEEE, FFFFFFFFFFF, GGGGGGGGGGG)]
+    AttrsWillWrap,
+    #[something_else(hhhhhhhhhhhhhhhh, iiiiiiiiiiiiiiii, jjjjjjjjjjjjjjj, kkkkkkkkkkkkk, llllllllllll, mmmmmmmmmmmmmm)]
+    AttrsWontWrap,
+}
diff --git a/src/tools/rustfmt/tests/source/issue-5801/comment_unexpectedly_wraps_before_max_width.rs b/src/tools/rustfmt/tests/source/issue-5801/comment_unexpectedly_wraps_before_max_width.rs
new file mode 100644
index 00000000000..5847afd9560
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-5801/comment_unexpectedly_wraps_before_max_width.rs
@@ -0,0 +1,17 @@
+// rustfmt-comment_width: 120
+// rustfmt-wrap_comments: true
+// rustfmt-max_width: 120
+// rustfmt-version: One
+
+/// This function is 120 columns wide and is left alone. This comment is 120 columns wide and the formatter is also fine
+fn my_super_cool_function_name(my_very_cool_argument_name: String, my_other_very_cool_argument_name: String) -> String {
+    unimplemented!()
+}
+
+pub enum Severity {
+    /// In version one, the below line got wrapped prematurely as we subtracted 1 to account for `,`. See issue #5801.
+    /// But here, this comment is 120 columns wide and the formatter wants to split it up onto two separate lines still.
+    Error,
+    /// This comment is 119 columns wide and works perfectly. Lorem ipsum. lorem ipsum. lorem ipsum. lorem ipsum lorem.
+    Warning,
+}
diff --git a/src/tools/rustfmt/tests/source/issue-5987/two.rs b/src/tools/rustfmt/tests/source/issue-5987/two.rs
new file mode 100644
index 00000000000..e20026b5565
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-5987/two.rs
@@ -0,0 +1,13 @@
+// rustfmt-version: Two
+
+fn main() {
+    trace!(
+        "get some longer length in here yes yes {} {}",
+        "hello",
+        "world"
+    );
+    debug!(
+        "get some longer length in here yes yes {} {}",
+        "hello", "world"
+    );
+}
diff --git a/src/tools/rustfmt/tests/source/issue-6059/repro.rs b/src/tools/rustfmt/tests/source/issue-6059/repro.rs
new file mode 100644
index 00000000000..1dc62cc8d26
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-6059/repro.rs
@@ -0,0 +1,3 @@
+fn float_range_tests() {
+    self.coords.x -= rng.gen_range(-self.radius / 2. .. self.radius / 2.);
+}
diff --git a/src/tools/rustfmt/tests/source/issue-6147/case_rustfmt_v1.rs b/src/tools/rustfmt/tests/source/issue-6147/case_rustfmt_v1.rs
new file mode 100644
index 00000000000..2ac2e0361c3
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-6147/case_rustfmt_v1.rs
@@ -0,0 +1,20 @@
+// rustfmt-version: One
+
+pub fn main() {
+let a = Some(12);
+match a {
+#![attr1]
+#![attr2]
+#![attr3]
+_ => None,
+}
+
+{
+match a {
+#![attr1]
+#![attr2]
+#![attr3]
+_ => None,
+}
+}
+}
diff --git a/src/tools/rustfmt/tests/source/issue-6147/case_rustfmt_v2.rs b/src/tools/rustfmt/tests/source/issue-6147/case_rustfmt_v2.rs
new file mode 100644
index 00000000000..c1bf1ad4bf8
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-6147/case_rustfmt_v2.rs
@@ -0,0 +1,20 @@
+// rustfmt-version: Two
+
+pub fn main() {
+let a = Some(12);
+match a {
+#![attr1]
+#![attr2]
+#![attr3]
+_ => None,
+}
+
+{
+match a {
+#![attr1]
+#![attr2]
+#![attr3]
+_ => None,
+}
+}
+}
diff --git a/src/tools/rustfmt/tests/source/issue_5912.rs b/src/tools/rustfmt/tests/source/issue_5912.rs
new file mode 100644
index 00000000000..2265fd2146c
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue_5912.rs
@@ -0,0 +1,15 @@
+// rustfmt-match_arm_blocks: false
+// rustfmt-control_brace_style: AlwaysNextLine
+
+fn foo() {
+    match 0 {
+        0 => {
+            aaaaaaaaaaaaaaaaaaaaaaaa
+                + bbbbbbbbbbbbbbbbbbbbbbbbb
+                + bbbbbbbbbbbbbbbbbbbbbbbbb
+                + bbbbbbbbbbbbbbbbbbbbbbbbb
+                + bbbbbbbbbbbbbbbbbbbbbbbbb
+        }
+        _ => 2,
+    }
+}
diff --git a/src/tools/rustfmt/tests/source/let_else.rs b/src/tools/rustfmt/tests/source/let_else.rs
index cb2859e805d..c589ab75cd3 100644
--- a/src/tools/rustfmt/tests/source/let_else.rs
+++ b/src/tools/rustfmt/tests/source/let_else.rs
@@ -117,8 +117,8 @@ fn unbreakable_initializer_expr_pre_formatting_length_through_initializer_expr_n
     // Break after the `=` and put the initializer expr on it's own line.
     // Because the initializer expr is multi-lined the else is placed on it's own line.
     // The initializer expr has a length of 91, which when indented on the next line
-    // The `(indent)init` line has a lengh of 99. This is the max length that the `init` can be
-    // before we start running into max_width issues. I suspect this is becuase the shape is
+    // The `(indent)init` line has a length of 99. This is the max length that the `init` can be
+    // before we start running into max_width issues. I suspect this is because the shape is
     // accounting for the `;` at the end of the `let-else` statement.
     let Some(x) = some_really_really_really_really_really_really_really_really_really_really_long_name______I else {return};
 
@@ -127,7 +127,7 @@ fn unbreakable_initializer_expr_pre_formatting_length_through_initializer_expr_n
     // Post Formatting:
     // Max length issues prevent us from formatting.
     // The initializer expr has a length of 92, which if it would be indented on the next line
-    // the `(indent)init` line has a lengh of 100 which == max_width of 100.
+    // the `(indent)init` line has a length of 100 which == max_width of 100.
     // One might expect formatting to succeed, but I suspect the reason we hit max_width issues is
     // because the Shape is accounting for the `;` at the end of the `let-else` statement.
     let Some(x) = some_really_really_really_really_really_really_really_really_really_really_really_long_nameJ else {return};
diff --git a/src/tools/rustfmt/tests/source/no_arg_with_commnet.rs b/src/tools/rustfmt/tests/source/no_arg_with_commnet.rs
index ea4ee0f1eee..41c3c6bea48 100644
--- a/src/tools/rustfmt/tests/source/no_arg_with_commnet.rs
+++ b/src/tools/rustfmt/tests/source/no_arg_with_commnet.rs
@@ -1,2 +1,2 @@
-fn foo(  /* cooment */
+fn foo(  /* comment */
 ) {}