diff --git a/Configurations.md b/Configurations.md index 12437a51f3d..94d5fe1a182 100644 --- a/Configurations.md +++ b/Configurations.md @@ -2610,22 +2610,6 @@ fn main() { } ``` -## `version` - -Which version of the formatting rules to use. `Version::One` is backwards-compatible -with Rustfmt 1.0. Other versions are only backwards compatible within a major -version number. - -- **Default value**: `One` -- **Possible values**: `One`, `Two` -- **Stable**: No (tracking issue: [#3383](https://github.com/rust-lang/rustfmt/issues/3383)) - -### Example - -```toml -version = "Two" -``` - ## `where_single_line` Forces the `where` clause to be laid out on a single line. diff --git a/Makefile.toml b/Makefile.toml index da9b5775906..1fa985e86e9 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -33,6 +33,7 @@ args = [ ] [tasks.test-all] +dependencies = ["build-bin"] run_task = { name = ["test", "test-ignored"] } [tasks.test-ignored] diff --git a/config_proc_macro/.gitignore b/config_proc_macro/.gitignore index 9f970225adb..d84cd72e174 100644 --- a/config_proc_macro/.gitignore +++ b/config_proc_macro/.gitignore @@ -1 +1,3 @@ -target/ \ No newline at end of file +target/ + +Cargo.lock diff --git a/rustfmt.toml b/rustfmt.toml index eccd5f9bd19..9b935b0a287 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,2 @@ error_on_line_overflow = true error_on_unformatted = true -version = "Two" diff --git a/src/config.rs b/src/config.rs index b80de6cd009..8067830f8b1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -126,7 +126,6 @@ create_config! { blank_lines_lower_bound: usize, 0, false, "Minimum number of blank lines which must be put between items"; edition: Edition, Edition::Edition2018, true, "The edition of the parser (RFC 2052)"; - version: Version, Version::One, false, "Version of formatting rules"; inline_attribute_width: usize, 0, false, "Write an item and its attribute on the same line \ if their combined width is below a threshold"; @@ -615,7 +614,6 @@ match_block_trailing_comma = false blank_lines_upper_bound = 1 blank_lines_lower_bound = 0 edition = "2018" -version = "One" inline_attribute_width = 0 merge_derives = true use_try_shorthand = false diff --git a/src/config/license.rs b/src/config/license.rs index c7feb502ea9..ea449f949aa 100644 --- a/src/config/license.rs +++ b/src/config/license.rs @@ -3,8 +3,11 @@ use std::fs::File; use std::io; use std::io::Read; +use itertools::Itertools; use regex::Regex; +use self::ParsingState::*; + #[derive(Debug)] pub(crate) enum LicenseError { IO(io::Error), @@ -44,8 +47,6 @@ enum ParsingState { Abort(String), } -use self::ParsingState::*; - pub(crate) struct TemplateParser { parsed: String, buffer: String, @@ -111,7 +112,7 @@ impl TemplateParser { /// ``` pub(crate) fn parse(template: &str) -> Result { let mut parser = Self::new(); - for chr in template.chars() { + for chr in template.lines().join("\n").chars() { if chr == '\n' { parser.linum += 1; } diff --git a/tests/source/configs/indent_style/block_trailing_comma_call/two.rs b/tests/source/configs/indent_style/block_trailing_comma_call.rs similarity index 93% rename from tests/source/configs/indent_style/block_trailing_comma_call/two.rs rename to tests/source/configs/indent_style/block_trailing_comma_call.rs index 7a62d722c6e..c907ec50d45 100644 --- a/tests/source/configs/indent_style/block_trailing_comma_call/two.rs +++ b/tests/source/configs/indent_style/block_trailing_comma_call.rs @@ -1,4 +1,3 @@ -// rustfmt-version: Two // rustfmt-error_on_line_overflow: false // rustfmt-indent_style: Block diff --git a/tests/source/fn-single-line/version_two.rs b/tests/source/fn-single-line.rs similarity index 97% rename from tests/source/fn-single-line/version_two.rs rename to tests/source/fn-single-line.rs index bf381ff1065..6d7f764d280 100644 --- a/tests/source/fn-single-line/version_two.rs +++ b/tests/source/fn-single-line.rs @@ -1,5 +1,4 @@ // rustfmt-fn_single_line: true -// rustfmt-version: Two // Test single-line functions. fn foo_expr() { diff --git a/tests/source/issue-2179/two.rs b/tests/source/issue-2179.rs similarity index 98% rename from tests/source/issue-2179/two.rs rename to tests/source/issue-2179.rs index f4cc9cc488b..ade953971ec 100644 --- a/tests/source/issue-2179/two.rs +++ b/tests/source/issue-2179.rs @@ -1,4 +1,3 @@ -// rustfmt-version: Two // rustfmt-error_on_line_overflow: false fn issue_2179() { diff --git a/tests/source/issue-3213/version_two.rs b/tests/source/issue-3213.rs similarity index 91% rename from tests/source/issue-3213/version_two.rs rename to tests/source/issue-3213.rs index 0f068c19d74..a00ec4d3661 100644 --- a/tests/source/issue-3213/version_two.rs +++ b/tests/source/issue-3213.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - fn foo() { match 0 { 0 => return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, diff --git a/tests/source/issue-3227/two.rs b/tests/source/issue-3227.rs similarity index 87% rename from tests/source/issue-3227/two.rs rename to tests/source/issue-3227.rs index c1572c00d57..cd23ef05134 100644 --- a/tests/source/issue-3227/two.rs +++ b/tests/source/issue-3227.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - fn main() { thread::spawn(|| { while true { diff --git a/tests/source/issue-3270/two.rs b/tests/source/issue-3270/default.rs similarity index 82% rename from tests/source/issue-3270/two.rs rename to tests/source/issue-3270/default.rs index 0eb756471e7..9b1a66a63b7 100644 --- a/tests/source/issue-3270/two.rs +++ b/tests/source/issue-3270/default.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - pub fn main() { /* let s = String::from( " diff --git a/tests/source/issue-3272/v2.rs b/tests/source/issue-3272.rs similarity index 91% rename from tests/source/issue-3272/v2.rs rename to tests/source/issue-3272.rs index 0148368edc8..ff3e6e8cb56 100644 --- a/tests/source/issue-3272/v2.rs +++ b/tests/source/issue-3272.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - fn main() { assert!(HAYSTACK .par_iter() diff --git a/tests/target/issue-3278/version_two.rs b/tests/source/issue-3278.rs similarity index 84% rename from tests/target/issue-3278/version_two.rs rename to tests/source/issue-3278.rs index c17b1742d39..07219295a7a 100644 --- a/tests/target/issue-3278/version_two.rs +++ b/tests/source/issue-3278.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - pub fn parse_conditional<'a, I: 'a>() -> impl Parser + 'a where diff --git a/tests/source/issue-3295/two.rs b/tests/source/issue-3295.rs similarity index 92% rename from tests/source/issue-3295/two.rs rename to tests/source/issue-3295.rs index 0eaf022249b..77d450d9a8d 100644 --- a/tests/source/issue-3295/two.rs +++ b/tests/source/issue-3295.rs @@ -1,4 +1,3 @@ -// rustfmt-version: Two pub enum TestEnum { a, b, diff --git a/tests/source/issue-3302.rs b/tests/source/issue-3302.rs index c037584fd71..686851d6041 100644 --- a/tests/source/issue-3302.rs +++ b/tests/source/issue-3302.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - macro_rules! moo1 { () => { bar! { diff --git a/tests/source/issue-3701/two.rs b/tests/source/issue-3701.rs similarity index 92% rename from tests/source/issue-3701/two.rs rename to tests/source/issue-3701.rs index 8e15c58b8b2..254a8c2ca51 100644 --- a/tests/source/issue-3701/two.rs +++ b/tests/source/issue-3701.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - fn build_sorted_static_get_entry_names( mut entries: Vec<(u8, &'static str)>, ) -> (impl Fn( diff --git a/tests/source/issue-3840/version-two_hard-tabs.rs b/tests/source/issue-3840/hard-tabs.rs similarity index 95% rename from tests/source/issue-3840/version-two_hard-tabs.rs rename to tests/source/issue-3840/hard-tabs.rs index 7b505fda87c..bf7ea7da0eb 100644 --- a/tests/source/issue-3840/version-two_hard-tabs.rs +++ b/tests/source/issue-3840/hard-tabs.rs @@ -1,5 +1,4 @@ // rustfmt-hard_tabs: true -// rustfmt-version: Two impl + FromEvent, A: Widget2, B: Widget2, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter { diff --git a/tests/source/issue-3840/version-two_soft-tabs.rs b/tests/source/issue-3840/soft-tabs.rs similarity index 94% rename from tests/source/issue-3840/version-two_soft-tabs.rs rename to tests/source/issue-3840/soft-tabs.rs index 39c8ef31292..3fc26224d50 100644 --- a/tests/source/issue-3840/version-two_soft-tabs.rs +++ b/tests/source/issue-3840/soft-tabs.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - impl + FromEvent, A: Widget2, B: Widget2, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter { type Ctx = C; diff --git a/tests/source/issue-3904/two.rs b/tests/source/issue-3904.rs similarity index 82% rename from tests/source/issue-3904/two.rs rename to tests/source/issue-3904.rs index 45eeb90e2fe..529ef3f9cbf 100644 --- a/tests/source/issue-3904/two.rs +++ b/tests/source/issue-3904.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - fn main() { let checkkwd = (0x2i32 | 0x1i32) as i64; /* unrecognized "\z": print both chars unless ' or " */ diff --git a/tests/source/long-fn-1/version_two.rs b/tests/source/long-fn-1.rs similarity index 96% rename from tests/source/long-fn-1/version_two.rs rename to tests/source/long-fn-1.rs index f402a26e8b6..1f53d78802d 100644 --- a/tests/source/long-fn-1/version_two.rs +++ b/tests/source/long-fn-1.rs @@ -1,4 +1,3 @@ -// rustfmt-version: Two // Tests that a function which is almost short enough, but not quite, gets // formatted correctly. diff --git a/tests/source/one_line_if_v2.rs b/tests/source/one_line_if.rs similarity index 95% rename from tests/source/one_line_if_v2.rs rename to tests/source/one_line_if.rs index 40c834959f9..7c57577badd 100644 --- a/tests/source/one_line_if_v2.rs +++ b/tests/source/one_line_if.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - fn plain_if(x: bool) -> u8 { if x { 0 diff --git a/tests/source/single-line-macro/v2.rs b/tests/source/single-line-macro.rs similarity index 92% rename from tests/source/single-line-macro/v2.rs rename to tests/source/single-line-macro.rs index 51a665f7560..da777361620 100644 --- a/tests/source/single-line-macro/v2.rs +++ b/tests/source/single-line-macro.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - // #2652 // Preserve trailing comma inside macro, even if it looks an array. macro_rules! bar { diff --git a/tests/source/trailing_comments/hard_tabs.rs b/tests/source/trailing_comments/hard_tabs.rs index 88249aa5fb9..a1b493a1b53 100644 --- a/tests/source/trailing_comments/hard_tabs.rs +++ b/tests/source/trailing_comments/hard_tabs.rs @@ -1,4 +1,3 @@ -// rustfmt-version: Two // rustfmt-wrap_comments: true // rustfmt-hard_tabs: true diff --git a/tests/source/trailing_comments/soft_tabs.rs b/tests/source/trailing_comments/soft_tabs.rs index 7845f713b8a..ba13944f0c9 100644 --- a/tests/source/trailing_comments/soft_tabs.rs +++ b/tests/source/trailing_comments/soft_tabs.rs @@ -1,4 +1,3 @@ -// rustfmt-version: Two // rustfmt-wrap_comments: true pub const IFF_MULTICAST: ::c_int = 0x0000000800; // Supports multicast diff --git a/tests/target/configs/indent_style/block_trailing_comma_call/two.rs b/tests/target/configs/indent_style/block_trailing_comma_call.rs similarity index 94% rename from tests/target/configs/indent_style/block_trailing_comma_call/two.rs rename to tests/target/configs/indent_style/block_trailing_comma_call.rs index 4f4292e5f48..7dd4c8dccea 100644 --- a/tests/target/configs/indent_style/block_trailing_comma_call/two.rs +++ b/tests/target/configs/indent_style/block_trailing_comma_call.rs @@ -1,4 +1,3 @@ -// rustfmt-version: Two // rustfmt-error_on_line_overflow: false // rustfmt-indent_style: Block diff --git a/tests/target/fn-single-line/version_two.rs b/tests/target/fn-single-line.rs similarity index 97% rename from tests/target/fn-single-line/version_two.rs rename to tests/target/fn-single-line.rs index b8053d4c2f5..2a4509acc19 100644 --- a/tests/target/fn-single-line/version_two.rs +++ b/tests/target/fn-single-line.rs @@ -1,5 +1,4 @@ // rustfmt-fn_single_line: true -// rustfmt-version: Two // Test single-line functions. fn foo_expr() { 1 } diff --git a/tests/target/issue-2179/two.rs b/tests/target/issue-2179.rs similarity index 98% rename from tests/target/issue-2179/two.rs rename to tests/target/issue-2179.rs index 96531509ea2..ad405f05878 100644 --- a/tests/target/issue-2179/two.rs +++ b/tests/target/issue-2179.rs @@ -1,4 +1,3 @@ -// rustfmt-version: Two // rustfmt-error_on_line_overflow: false fn issue_2179() { diff --git a/tests/target/issue-3132.rs b/tests/target/issue-3132.rs index 4dffe0ab836..c3d24fc10f6 100644 --- a/tests/target/issue-3132.rs +++ b/tests/target/issue-3132.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - fn test() { /* a diff --git a/tests/target/issue-3213/version_two.rs b/tests/target/issue-3213.rs similarity index 92% rename from tests/target/issue-3213/version_two.rs rename to tests/target/issue-3213.rs index de93d04ba95..bd2ee48138a 100644 --- a/tests/target/issue-3213/version_two.rs +++ b/tests/target/issue-3213.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - fn foo() { match 0 { 0 => { diff --git a/tests/target/issue-3227/two.rs b/tests/target/issue-3227.rs similarity index 89% rename from tests/target/issue-3227/two.rs rename to tests/target/issue-3227.rs index 374ab54305d..e87c28f9ca1 100644 --- a/tests/target/issue-3227/two.rs +++ b/tests/target/issue-3227.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - fn main() { thread::spawn(|| { while true { diff --git a/tests/target/issue-3270/two.rs b/tests/target/issue-3270/default.rs similarity index 83% rename from tests/target/issue-3270/two.rs rename to tests/target/issue-3270/default.rs index e48b5921329..4f624f1193b 100644 --- a/tests/target/issue-3270/two.rs +++ b/tests/target/issue-3270/default.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - pub fn main() { /* let s = String::from( " diff --git a/tests/target/issue-3270/wrap.rs b/tests/target/issue-3270/wrap.rs index 7435c5f0866..3dbacab3384 100644 --- a/tests/target/issue-3270/wrap.rs +++ b/tests/target/issue-3270/wrap.rs @@ -1,5 +1,4 @@ // rustfmt-wrap_comments: true -// rustfmt-version: Two // check that a line below max_width does not get over the limit when wrapping // it in a block comment diff --git a/tests/target/issue-3272/v2.rs b/tests/target/issue-3272.rs similarity index 91% rename from tests/target/issue-3272/v2.rs rename to tests/target/issue-3272.rs index a42a2fccd5b..6f40ef42dda 100644 --- a/tests/target/issue-3272/v2.rs +++ b/tests/target/issue-3272.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - fn main() { assert!( HAYSTACK diff --git a/tests/source/issue-3278/version_two.rs b/tests/target/issue-3278.rs similarity index 84% rename from tests/source/issue-3278/version_two.rs rename to tests/target/issue-3278.rs index c17b1742d39..07219295a7a 100644 --- a/tests/source/issue-3278/version_two.rs +++ b/tests/target/issue-3278.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - pub fn parse_conditional<'a, I: 'a>() -> impl Parser + 'a where diff --git a/tests/target/issue-3295/two.rs b/tests/target/issue-3295.rs similarity index 92% rename from tests/target/issue-3295/two.rs rename to tests/target/issue-3295.rs index 3e669a0bb75..cf6f9e2ad8b 100644 --- a/tests/target/issue-3295/two.rs +++ b/tests/target/issue-3295.rs @@ -1,4 +1,3 @@ -// rustfmt-version: Two pub enum TestEnum { a, b, diff --git a/tests/target/issue-3302.rs b/tests/target/issue-3302.rs index 146cb983819..536e2dab40b 100644 --- a/tests/target/issue-3302.rs +++ b/tests/target/issue-3302.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - macro_rules! moo1 { () => { bar! { diff --git a/tests/target/issue-3614/version_two.rs b/tests/target/issue-3614.rs similarity index 77% rename from tests/target/issue-3614/version_two.rs rename to tests/target/issue-3614.rs index 5d6f8e7a313..a316be84cac 100644 --- a/tests/target/issue-3614/version_two.rs +++ b/tests/target/issue-3614.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - fn main() { let toto = || { if true { 42 } else { 24 } diff --git a/tests/target/issue-3701/two.rs b/tests/target/issue-3701.rs similarity index 92% rename from tests/target/issue-3701/two.rs rename to tests/target/issue-3701.rs index 62ffc9d823d..8e0d7e62dad 100644 --- a/tests/target/issue-3701/two.rs +++ b/tests/target/issue-3701.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - fn build_sorted_static_get_entry_names( mut entries: Vec<(u8, &'static str)>, ) -> ( diff --git a/tests/target/issue-3840/version-two_hard-tabs.rs b/tests/target/issue-3840/hard-tabs.rs similarity index 95% rename from tests/target/issue-3840/version-two_hard-tabs.rs rename to tests/target/issue-3840/hard-tabs.rs index 084db3d1465..0dd57c93163 100644 --- a/tests/target/issue-3840/version-two_hard-tabs.rs +++ b/tests/target/issue-3840/hard-tabs.rs @@ -1,5 +1,4 @@ // rustfmt-hard_tabs: true -// rustfmt-version: Two impl< Target: FromEvent + FromEvent, diff --git a/tests/target/issue-3840/version-two_soft-tabs.rs b/tests/target/issue-3840/soft-tabs.rs similarity index 95% rename from tests/target/issue-3840/version-two_soft-tabs.rs rename to tests/target/issue-3840/soft-tabs.rs index bc59b0baa56..44e979629b7 100644 --- a/tests/target/issue-3840/version-two_soft-tabs.rs +++ b/tests/target/issue-3840/soft-tabs.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - impl< Target: FromEvent + FromEvent, A: Widget2, diff --git a/tests/target/issue-3882.rs b/tests/target/issue-3882.rs index 5eb442af974..1a6749c7c6c 100644 --- a/tests/target/issue-3882.rs +++ b/tests/target/issue-3882.rs @@ -1,4 +1,3 @@ -// rustfmt-version: Two fn bar(_t: T, // bar ) { } diff --git a/tests/target/issue-3904/two.rs b/tests/target/issue-3904.rs similarity index 82% rename from tests/target/issue-3904/two.rs rename to tests/target/issue-3904.rs index 00fe4b1a629..054f892fc1f 100644 --- a/tests/target/issue-3904/two.rs +++ b/tests/target/issue-3904.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - fn main() { let checkkwd = (0x2i32 | 0x1i32) as i64; /* unrecognized "\z": print both chars unless ' or " */ } diff --git a/tests/target/long-fn-1/version_two.rs b/tests/target/long-fn-1.rs similarity index 96% rename from tests/target/long-fn-1/version_two.rs rename to tests/target/long-fn-1.rs index 32794bccde2..320617f2772 100644 --- a/tests/target/long-fn-1/version_two.rs +++ b/tests/target/long-fn-1.rs @@ -1,4 +1,3 @@ -// rustfmt-version: Two // Tests that a function which is almost short enough, but not quite, gets // formatted correctly. diff --git a/tests/target/one_line_if_v2.rs b/tests/target/one_line_if.rs similarity index 95% rename from tests/target/one_line_if_v2.rs rename to tests/target/one_line_if.rs index 81ca4c8b8b4..695f63c2453 100644 --- a/tests/target/one_line_if_v2.rs +++ b/tests/target/one_line_if.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - fn plain_if(x: bool) -> u8 { if x { 0 } else { 1 } } diff --git a/tests/target/single-line-macro/v2.rs b/tests/target/single-line-macro.rs similarity index 93% rename from tests/target/single-line-macro/v2.rs rename to tests/target/single-line-macro.rs index 9c6bcf33ad5..f9f980000b1 100644 --- a/tests/target/single-line-macro/v2.rs +++ b/tests/target/single-line-macro.rs @@ -1,5 +1,3 @@ -// rustfmt-version: Two - // #2652 // Preserve trailing comma inside macro, even if it looks an array. macro_rules! bar { diff --git a/tests/target/trailing_comments/hard_tabs.rs b/tests/target/trailing_comments/hard_tabs.rs index 9044ef6c334..f55862398fe 100644 --- a/tests/target/trailing_comments/hard_tabs.rs +++ b/tests/target/trailing_comments/hard_tabs.rs @@ -1,4 +1,3 @@ -// rustfmt-version: Two // rustfmt-wrap_comments: true // rustfmt-hard_tabs: true diff --git a/tests/target/trailing_comments/soft_tabs.rs b/tests/target/trailing_comments/soft_tabs.rs index 116f55f6aab..c6c4e7be244 100644 --- a/tests/target/trailing_comments/soft_tabs.rs +++ b/tests/target/trailing_comments/soft_tabs.rs @@ -1,4 +1,3 @@ -// rustfmt-version: Two // rustfmt-wrap_comments: true pub const IFF_MULTICAST: ::c_int = 0x0000000800; // Supports multicast