about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCaleb Cartwright <caleb.cartwright@outlook.com>2024-08-01 23:26:00 -0500
committerCaleb Cartwright <calebcartwright@users.noreply.github.com>2024-08-27 20:49:15 -0500
commit065258659db720bfbb4987fa56137450e63d3cc4 (patch)
tree4e2d47c0b81bafc5c145fd5f4589f0021d51af9a
parent0c6515cacc4465ae29d90f4bacc7f95ace7afe0b (diff)
downloadrust-065258659db720bfbb4987fa56137450e63d3cc4.tar.gz
rust-065258659db720bfbb4987fa56137450e63d3cc4.zip
feat: implement 2024 Style Edition for expr overflows
-rw-r--r--rustfmt.toml1
-rw-r--r--src/bin/main.rs32
-rw-r--r--src/config/mod.rs2
-rw-r--r--src/config/options.rs2
-rw-r--r--tests/config/style-edition/overrides/rustfmt.toml2
-rw-r--r--tests/source/configs/style_edition/overflow_delim_expr_2015.rs155
-rw-r--r--tests/source/configs/style_edition/overflow_delim_expr_2024.rs155
-rw-r--r--tests/target/configs/style_edition/overflow_delim_expr_2015.rs135
-rw-r--r--tests/target/configs/style_edition/overflow_delim_expr_2024.rs120
9 files changed, 602 insertions, 2 deletions
diff --git a/rustfmt.toml b/rustfmt.toml
index 52e4d728b64..86447eac2e6 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -1,3 +1,4 @@
 error_on_line_overflow = true
 error_on_unformatted = true
 style_edition = "2024"
+overflow_delimited_expr = false
diff --git a/src/bin/main.rs b/src/bin/main.rs
index 2e4877c7569..9e7476b1f81 100644
--- a/src/bin/main.rs
+++ b/src/bin/main.rs
@@ -915,4 +915,36 @@ mod test {
         let config = get_config(config_file, Some(options));
         assert_eq!(config.style_edition(), StyleEdition::Edition2021);
     }
+
+    #[nightly_only_test]
+    #[test]
+    fn correct_defaults_for_style_edition_loaded() {
+        let mut options = GetOptsOptions::default();
+        options.style_edition = Some(StyleEdition::Edition2024);
+        let config = get_config(None, Some(options));
+        assert_eq!(config.style_edition(), StyleEdition::Edition2024);
+        assert_eq!(config.overflow_delimited_expr(), true);
+    }
+
+    #[nightly_only_test]
+    #[test]
+    fn style_edition_defaults_overridden_from_config() {
+        let options = GetOptsOptions::default();
+        let config_file = Some(Path::new("tests/config/style-edition/overrides"));
+        let config = get_config(config_file, Some(options));
+        assert_eq!(config.style_edition(), StyleEdition::Edition2024);
+        assert_eq!(config.overflow_delimited_expr(), false);
+    }
+
+    #[nightly_only_test]
+    #[test]
+    fn style_edition_defaults_overridden_from_cli() {
+        let mut options = GetOptsOptions::default();
+        let config_file = Some(Path::new("tests/config/style-edition/just-style-edition"));
+        options.inline_config =
+            HashMap::from([("overflow_delimited_expr".to_owned(), "false".to_owned())]);
+        let config = get_config(config_file, Some(options));
+        assert_eq!(config.style_edition(), StyleEdition::Edition2024);
+        assert_eq!(config.overflow_delimited_expr(), false);
+    }
 }
diff --git a/src/config/mod.rs b/src/config/mod.rs
index da7adea5a74..cd6870e3890 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -828,7 +828,7 @@ binop_separator = "Front"
 remove_nested_parens = true
 combine_control_expr = true
 short_array_element_width_threshold = 10
-overflow_delimited_expr = false
+overflow_delimited_expr = true
 struct_field_align_threshold = 0
 enum_discrim_align_threshold = 0
 match_arm_blocks = true
diff --git a/src/config/options.rs b/src/config/options.rs
index f7a8c114330..46db5186b11 100644
--- a/src/config/options.rs
+++ b/src/config/options.rs
@@ -627,7 +627,7 @@ config_option_with_style_edition_default!(
     RemoveNestedParens, bool, _ => true;
     CombineControlExpr, bool, _ => true;
     ShortArrayElementWidthThreshold, usize, _ => 10;
-    OverflowDelimitedExpr, bool, _ => false;
+    OverflowDelimitedExpr, bool, Edition2024 => true, _ => false;
     StructFieldAlignThreshold, usize, _ => 0;
     EnumDiscrimAlignThreshold, usize, _ => 0;
     MatchArmBlocks, bool, _ => true;
diff --git a/tests/config/style-edition/overrides/rustfmt.toml b/tests/config/style-edition/overrides/rustfmt.toml
new file mode 100644
index 00000000000..24205692b1f
--- /dev/null
+++ b/tests/config/style-edition/overrides/rustfmt.toml
@@ -0,0 +1,2 @@
+style_edition = "2024"
+overflow_delimited_expr = false
diff --git a/tests/source/configs/style_edition/overflow_delim_expr_2015.rs b/tests/source/configs/style_edition/overflow_delim_expr_2015.rs
new file mode 100644
index 00000000000..5cb4a870fc1
--- /dev/null
+++ b/tests/source/configs/style_edition/overflow_delim_expr_2015.rs
@@ -0,0 +1,155 @@
+// rustfmt-style_edition: 2015
+
+fn combine_blocklike() {
+    do_thing(
+        |param| {
+            action();
+            foo(param)
+        },
+    );
+
+    do_thing(
+        x,
+        |param| {
+            action();
+            foo(param)
+        },
+    );
+
+    do_thing(
+        x,
+
+        // I'll be discussing the `action` with your para(m)legal counsel
+        |param| {
+            action();
+            foo(param)
+        },
+    );
+
+    do_thing(
+        Bar {
+            x: value,
+            y: value2,
+        },
+    );
+
+    do_thing(
+        x,
+        Bar {
+            x: value,
+            y: value2,
+        },
+    );
+
+    do_thing(
+        x,
+
+        // Let me tell you about that one time at the `Bar`
+        Bar {
+            x: value,
+            y: value2,
+        },
+    );
+
+    do_thing(
+        &[
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(
+        x,
+        &[
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(
+        x,
+
+        // Just admit it; my list is longer than can be folded on to one line
+        &[
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(
+        vec![
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(
+        x,
+        vec![
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(
+        x,
+
+        // Just admit it; my list is longer than can be folded on to one line
+        vec![
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(
+        x,
+        (
+            1,
+            2,
+            3,
+            |param| {
+                action();
+                foo(param)
+            },
+        ),
+    );
+}
+
+fn combine_struct_sample() {
+    let identity = verify(
+        &ctx,
+        VerifyLogin {
+            type_: LoginType::Username,
+            username: args.username.clone(),
+            password: Some(args.password.clone()),
+            domain: None,
+        },
+    )?;
+}
+
+fn combine_macro_sample() {
+    rocket::ignite()
+        .mount(
+            "/",
+            routes![
+                http::auth::login,
+                http::auth::logout,
+                http::cors::options,
+                http::action::dance,
+                http::action::sleep,
+            ],
+        )
+        .launch();
+}
diff --git a/tests/source/configs/style_edition/overflow_delim_expr_2024.rs b/tests/source/configs/style_edition/overflow_delim_expr_2024.rs
new file mode 100644
index 00000000000..66c95e71aa9
--- /dev/null
+++ b/tests/source/configs/style_edition/overflow_delim_expr_2024.rs
@@ -0,0 +1,155 @@
+// rustfmt-style_edition: 2024
+
+fn combine_blocklike() {
+    do_thing(
+        |param| {
+            action();
+            foo(param)
+        },
+    );
+
+    do_thing(
+        x,
+        |param| {
+            action();
+            foo(param)
+        },
+    );
+
+    do_thing(
+        x,
+
+        // I'll be discussing the `action` with your para(m)legal counsel
+        |param| {
+            action();
+            foo(param)
+        },
+    );
+
+    do_thing(
+        Bar {
+            x: value,
+            y: value2,
+        },
+    );
+
+    do_thing(
+        x,
+        Bar {
+            x: value,
+            y: value2,
+        },
+    );
+
+    do_thing(
+        x,
+
+        // Let me tell you about that one time at the `Bar`
+        Bar {
+            x: value,
+            y: value2,
+        },
+    );
+
+    do_thing(
+        &[
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(
+        x,
+        &[
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(
+        x,
+
+        // Just admit it; my list is longer than can be folded on to one line
+        &[
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(
+        vec![
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(
+        x,
+        vec![
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(
+        x,
+
+        // Just admit it; my list is longer than can be folded on to one line
+        vec![
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(
+        x,
+        (
+            1,
+            2,
+            3,
+            |param| {
+                action();
+                foo(param)
+            },
+        ),
+    );
+}
+
+fn combine_struct_sample() {
+    let identity = verify(
+        &ctx,
+        VerifyLogin {
+            type_: LoginType::Username,
+            username: args.username.clone(),
+            password: Some(args.password.clone()),
+            domain: None,
+        },
+    )?;
+}
+
+fn combine_macro_sample() {
+    rocket::ignite()
+        .mount(
+            "/",
+            routes![
+                http::auth::login,
+                http::auth::logout,
+                http::cors::options,
+                http::action::dance,
+                http::action::sleep,
+            ],
+        )
+        .launch();
+}
diff --git a/tests/target/configs/style_edition/overflow_delim_expr_2015.rs b/tests/target/configs/style_edition/overflow_delim_expr_2015.rs
new file mode 100644
index 00000000000..05d4b8b6d33
--- /dev/null
+++ b/tests/target/configs/style_edition/overflow_delim_expr_2015.rs
@@ -0,0 +1,135 @@
+// rustfmt-style_edition: 2015
+
+fn combine_blocklike() {
+    do_thing(|param| {
+        action();
+        foo(param)
+    });
+
+    do_thing(x, |param| {
+        action();
+        foo(param)
+    });
+
+    do_thing(
+        x,
+        // I'll be discussing the `action` with your para(m)legal counsel
+        |param| {
+            action();
+            foo(param)
+        },
+    );
+
+    do_thing(Bar {
+        x: value,
+        y: value2,
+    });
+
+    do_thing(
+        x,
+        Bar {
+            x: value,
+            y: value2,
+        },
+    );
+
+    do_thing(
+        x,
+        // Let me tell you about that one time at the `Bar`
+        Bar {
+            x: value,
+            y: value2,
+        },
+    );
+
+    do_thing(&[
+        value_with_longer_name,
+        value2_with_longer_name,
+        value3_with_longer_name,
+        value4_with_longer_name,
+    ]);
+
+    do_thing(
+        x,
+        &[
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(
+        x,
+        // Just admit it; my list is longer than can be folded on to one line
+        &[
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(vec![
+        value_with_longer_name,
+        value2_with_longer_name,
+        value3_with_longer_name,
+        value4_with_longer_name,
+    ]);
+
+    do_thing(
+        x,
+        vec![
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(
+        x,
+        // Just admit it; my list is longer than can be folded on to one line
+        vec![
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(
+        x,
+        (1, 2, 3, |param| {
+            action();
+            foo(param)
+        }),
+    );
+}
+
+fn combine_struct_sample() {
+    let identity = verify(
+        &ctx,
+        VerifyLogin {
+            type_: LoginType::Username,
+            username: args.username.clone(),
+            password: Some(args.password.clone()),
+            domain: None,
+        },
+    )?;
+}
+
+fn combine_macro_sample() {
+    rocket::ignite()
+        .mount(
+            "/",
+            routes![
+                http::auth::login,
+                http::auth::logout,
+                http::cors::options,
+                http::action::dance,
+                http::action::sleep,
+            ],
+        )
+        .launch();
+}
diff --git a/tests/target/configs/style_edition/overflow_delim_expr_2024.rs b/tests/target/configs/style_edition/overflow_delim_expr_2024.rs
new file mode 100644
index 00000000000..ecd2e8ca797
--- /dev/null
+++ b/tests/target/configs/style_edition/overflow_delim_expr_2024.rs
@@ -0,0 +1,120 @@
+// rustfmt-style_edition: 2024
+
+fn combine_blocklike() {
+    do_thing(|param| {
+        action();
+        foo(param)
+    });
+
+    do_thing(x, |param| {
+        action();
+        foo(param)
+    });
+
+    do_thing(
+        x,
+        // I'll be discussing the `action` with your para(m)legal counsel
+        |param| {
+            action();
+            foo(param)
+        },
+    );
+
+    do_thing(Bar {
+        x: value,
+        y: value2,
+    });
+
+    do_thing(x, Bar {
+        x: value,
+        y: value2,
+    });
+
+    do_thing(
+        x,
+        // Let me tell you about that one time at the `Bar`
+        Bar {
+            x: value,
+            y: value2,
+        },
+    );
+
+    do_thing(&[
+        value_with_longer_name,
+        value2_with_longer_name,
+        value3_with_longer_name,
+        value4_with_longer_name,
+    ]);
+
+    do_thing(x, &[
+        value_with_longer_name,
+        value2_with_longer_name,
+        value3_with_longer_name,
+        value4_with_longer_name,
+    ]);
+
+    do_thing(
+        x,
+        // Just admit it; my list is longer than can be folded on to one line
+        &[
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(vec![
+        value_with_longer_name,
+        value2_with_longer_name,
+        value3_with_longer_name,
+        value4_with_longer_name,
+    ]);
+
+    do_thing(x, vec![
+        value_with_longer_name,
+        value2_with_longer_name,
+        value3_with_longer_name,
+        value4_with_longer_name,
+    ]);
+
+    do_thing(
+        x,
+        // Just admit it; my list is longer than can be folded on to one line
+        vec![
+            value_with_longer_name,
+            value2_with_longer_name,
+            value3_with_longer_name,
+            value4_with_longer_name,
+        ],
+    );
+
+    do_thing(
+        x,
+        (1, 2, 3, |param| {
+            action();
+            foo(param)
+        }),
+    );
+}
+
+fn combine_struct_sample() {
+    let identity = verify(&ctx, VerifyLogin {
+        type_: LoginType::Username,
+        username: args.username.clone(),
+        password: Some(args.password.clone()),
+        domain: None,
+    })?;
+}
+
+fn combine_macro_sample() {
+    rocket::ignite()
+        .mount("/", routes![
+            http::auth::login,
+            http::auth::logout,
+            http::cors::options,
+            http::action::dance,
+            http::action::sleep,
+        ])
+        .launch();
+}