diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/tools/rustfmt/tests/source/configs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
125 files changed, 2119 insertions, 0 deletions
diff --git a/src/tools/rustfmt/tests/source/configs/blank_lines_lower_bound/1.rs b/src/tools/rustfmt/tests/source/configs/blank_lines_lower_bound/1.rs new file mode 100644 index 000000000..c6058a55b --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/blank_lines_lower_bound/1.rs @@ -0,0 +1,13 @@ +// rustfmt-blank_lines_lower_bound: 1 + +fn foo() {} +fn bar() {} +// comment +fn foobar() {} + +fn foo1() {} +fn bar1() {} + +// comment + +fn foobar1() {} diff --git a/src/tools/rustfmt/tests/source/configs/brace_style/fn_always_next_line.rs b/src/tools/rustfmt/tests/source/configs/brace_style/fn_always_next_line.rs new file mode 100644 index 000000000..d3bd9ac09 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/brace_style/fn_always_next_line.rs @@ -0,0 +1,14 @@ +// rustfmt-brace_style: AlwaysNextLine +// Function brace style + +fn lorem() { + // body +} + +fn lorem(ipsum: usize) { + // body +} + +fn lorem<T>(ipsum: T) where T: Add + Sub + Mul + Div { + // body +} diff --git a/src/tools/rustfmt/tests/source/configs/brace_style/fn_prefer_same_line.rs b/src/tools/rustfmt/tests/source/configs/brace_style/fn_prefer_same_line.rs new file mode 100644 index 000000000..78a449524 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/brace_style/fn_prefer_same_line.rs @@ -0,0 +1,14 @@ +// rustfmt-brace_style: PreferSameLine +// Function brace style + +fn lorem() { + // body +} + +fn lorem(ipsum: usize) { + // body +} + +fn lorem<T>(ipsum: T) where T: Add + Sub + Mul + Div { + // body +} diff --git a/src/tools/rustfmt/tests/source/configs/brace_style/fn_same_line_where.rs b/src/tools/rustfmt/tests/source/configs/brace_style/fn_same_line_where.rs new file mode 100644 index 000000000..3b78932e1 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/brace_style/fn_same_line_where.rs @@ -0,0 +1,14 @@ +// rustfmt-brace_style: SameLineWhere +// Function brace style + +fn lorem() { + // body +} + +fn lorem(ipsum: usize) { + // body +} + +fn lorem<T>(ipsum: T) where T: Add + Sub + Mul + Div { + // body +} diff --git a/src/tools/rustfmt/tests/source/configs/brace_style/item_always_next_line.rs b/src/tools/rustfmt/tests/source/configs/brace_style/item_always_next_line.rs new file mode 100644 index 000000000..0cc19b34d --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/brace_style/item_always_next_line.rs @@ -0,0 +1,20 @@ +// rustfmt-brace_style: AlwaysNextLine +// Item brace style + +enum Foo {} + +struct Bar {} + +struct Lorem { + ipsum: bool, +} + +struct Dolor<T> where T: Eq { + sit: T, +} + +#[cfg(test)] +mod tests { + #[test] + fn it_works() {} +} diff --git a/src/tools/rustfmt/tests/source/configs/brace_style/item_prefer_same_line.rs b/src/tools/rustfmt/tests/source/configs/brace_style/item_prefer_same_line.rs new file mode 100644 index 000000000..4412bc869 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/brace_style/item_prefer_same_line.rs @@ -0,0 +1,16 @@ +// rustfmt-brace_style: PreferSameLine +// Item brace style + +struct Lorem { + ipsum: bool, +} + +struct Dolor<T> where T: Eq { + sit: T, +} + +#[cfg(test)] +mod tests { + #[test] + fn it_works() {} +} diff --git a/src/tools/rustfmt/tests/source/configs/brace_style/item_same_line_where.rs b/src/tools/rustfmt/tests/source/configs/brace_style/item_same_line_where.rs new file mode 100644 index 000000000..b8e69147d --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/brace_style/item_same_line_where.rs @@ -0,0 +1,16 @@ +// rustfmt-brace_style: SameLineWhere +// Item brace style + +struct Lorem { + ipsum: bool, +} + +struct Dolor<T> where T: Eq { + sit: T, +} + +#[cfg(test)] +mod tests { + #[test] + fn it_works() {} +} diff --git a/src/tools/rustfmt/tests/source/configs/chain_width/always.rs b/src/tools/rustfmt/tests/source/configs/chain_width/always.rs new file mode 100644 index 000000000..2d16d66ae --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/chain_width/always.rs @@ -0,0 +1,23 @@ +// rustfmt-chain_width: 1 +// setting an unachievable chain_width to always get chains +// on separate lines + +struct Fluent {} + +impl Fluent { + fn blorp(&self) -> &Self { + self + } +} + +fn main() { + let test = Fluent {}; + + // should be left alone + test.blorp(); + + // should be wrapped + test.blorp().blorp(); + test.blorp().blorp().blorp(); + test.blorp().blorp().blorp().blorp(); +} diff --git a/src/tools/rustfmt/tests/source/configs/chain_width/small.rs b/src/tools/rustfmt/tests/source/configs/chain_width/small.rs new file mode 100644 index 000000000..26f935453 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/chain_width/small.rs @@ -0,0 +1,23 @@ +// rustfmt-chain_width: 40 + +struct Fluent {} + +impl Fluent { + fn blorp(&self) -> &Self { + self + } +} + +fn main() { + let test = Fluent {}; + + // should not be wrapped + test.blorp(); + test.blorp().blorp(); + test.blorp().blorp().blorp(); + test.blorp().blorp().blorp().blorp(); + + // should be wrapped + test.blorp().blorp().blorp().blorp().blorp(); + test.blorp().blorp().blorp().blorp().blorp().blorp(); +} diff --git a/src/tools/rustfmt/tests/source/configs/chain_width/tiny.rs b/src/tools/rustfmt/tests/source/configs/chain_width/tiny.rs new file mode 100644 index 000000000..fffc81dd5 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/chain_width/tiny.rs @@ -0,0 +1,21 @@ +// rustfmt-chain_width: 20 + +struct Fluent {} + +impl Fluent { + fn blorp(&self) -> &Self { + self + } +} + +fn main() { + let test = Fluent {}; + + // should not be wrapped + test.blorp(); + test.blorp().blorp(); + + // should be wrapped + test.blorp().blorp().blorp(); + test.blorp().blorp().blorp().blorp(); +} diff --git a/src/tools/rustfmt/tests/source/configs/comment_width/above.rs b/src/tools/rustfmt/tests/source/configs/comment_width/above.rs new file mode 100644 index 000000000..36187ce0a --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/comment_width/above.rs @@ -0,0 +1,7 @@ +// rustfmt-comment_width: 40 +// rustfmt-wrap_comments: true +// Comment width + +fn main() { + // Lorem ipsum dolor sit amet, consectetur adipiscing elit. +} diff --git a/src/tools/rustfmt/tests/source/configs/comment_width/below.rs b/src/tools/rustfmt/tests/source/configs/comment_width/below.rs new file mode 100644 index 000000000..abbc5930c --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/comment_width/below.rs @@ -0,0 +1,7 @@ +// rustfmt-comment_width: 80 +// rustfmt-wrap_comments: true +// Comment width + +fn main() { + // Lorem ipsum dolor sit amet, consectetur adipiscing elit. +} diff --git a/src/tools/rustfmt/tests/source/configs/comment_width/ignore.rs b/src/tools/rustfmt/tests/source/configs/comment_width/ignore.rs new file mode 100644 index 000000000..c86e71c28 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/comment_width/ignore.rs @@ -0,0 +1,7 @@ +// rustfmt-comment_width: 40 +// rustfmt-wrap_comments: false +// Comment width + +fn main() { + // Lorem ipsum dolor sit amet, consectetur adipiscing elit. +} diff --git a/src/tools/rustfmt/tests/source/configs/condense_wildcard_suffixes/false.rs b/src/tools/rustfmt/tests/source/configs/condense_wildcard_suffixes/false.rs new file mode 100644 index 000000000..3b967f35a --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/condense_wildcard_suffixes/false.rs @@ -0,0 +1,6 @@ +// rustfmt-condense_wildcard_suffixes: false +// Condense wildcard suffixes + +fn main() { + let (lorem, ipsum, _, _) = (1, 2, 3, 4); +} diff --git a/src/tools/rustfmt/tests/source/configs/condense_wildcard_suffixes/true.rs b/src/tools/rustfmt/tests/source/configs/condense_wildcard_suffixes/true.rs new file mode 100644 index 000000000..3798a6b99 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/condense_wildcard_suffixes/true.rs @@ -0,0 +1,6 @@ +// rustfmt-condense_wildcard_suffixes: true +// Condense wildcard suffixes + +fn main() { + let (lorem, ipsum, _, _) = (1, 2, 3, 4); +} diff --git a/src/tools/rustfmt/tests/source/configs/control_brace_style/always_next_line.rs b/src/tools/rustfmt/tests/source/configs/control_brace_style/always_next_line.rs new file mode 100644 index 000000000..c4ddad9ce --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/control_brace_style/always_next_line.rs @@ -0,0 +1,10 @@ +// rustfmt-control_brace_style: AlwaysNextLine +// Control brace style + +fn main() { + if lorem { println!("ipsum!"); } else { println!("dolor!"); } + match magi { + Homura => "Akemi", + Madoka => "Kaname", + } +} diff --git a/src/tools/rustfmt/tests/source/configs/control_brace_style/always_same_line.rs b/src/tools/rustfmt/tests/source/configs/control_brace_style/always_same_line.rs new file mode 100644 index 000000000..a9c699d27 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/control_brace_style/always_same_line.rs @@ -0,0 +1,10 @@ +// rustfmt-control_brace_style: AlwaysSameLine +// Control brace style + +fn main() { + if lorem { println!("ipsum!"); } else { println!("dolor!"); } + match magi { + Homura => "Akemi", + Madoka => "Kaname", + } +} diff --git a/src/tools/rustfmt/tests/source/configs/control_brace_style/closing_next_line.rs b/src/tools/rustfmt/tests/source/configs/control_brace_style/closing_next_line.rs new file mode 100644 index 000000000..1a74a28f2 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/control_brace_style/closing_next_line.rs @@ -0,0 +1,10 @@ +// rustfmt-control_brace_style: ClosingNextLine +// Control brace style + +fn main() { + if lorem { println!("ipsum!"); } else { println!("dolor!"); } + match magi { + Homura => "Akemi", + Madoka => "Kaname", + } +} diff --git a/src/tools/rustfmt/tests/source/configs/disable_all_formatting/false.rs b/src/tools/rustfmt/tests/source/configs/disable_all_formatting/false.rs new file mode 100644 index 000000000..834ca7a3c --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/disable_all_formatting/false.rs @@ -0,0 +1,6 @@ +// rustfmt-disable_all_formatting: false +// Disable all formatting + +fn main() { + if lorem{println!("ipsum!");}else{println!("dolor!");} +} diff --git a/src/tools/rustfmt/tests/source/configs/disable_all_formatting/true.rs b/src/tools/rustfmt/tests/source/configs/disable_all_formatting/true.rs new file mode 100644 index 000000000..56955bf38 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/disable_all_formatting/true.rs @@ -0,0 +1,6 @@ +// rustfmt-disable_all_formatting: true +// Disable all formatting + +fn main() { + iflorem{println!("ipsum!");}else{println!("dolor!");} +} diff --git a/src/tools/rustfmt/tests/source/configs/doc_comment_code_block_width/100.rs b/src/tools/rustfmt/tests/source/configs/doc_comment_code_block_width/100.rs new file mode 100644 index 000000000..515780761 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/doc_comment_code_block_width/100.rs @@ -0,0 +1,16 @@ +// rustfmt-format_code_in_doc_comments: true +// rustfmt-doc_comment_code_block_width: 100 + +/// ```rust +/// impl Test { +/// pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> { +/// Self::from_bytes_manual_slice(v, 0, v.len() ) +/// } +/// } +/// ``` + +impl Test { + pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> { + Self::from_bytes_manual_slice(v, 0, v.len() ) + } +} diff --git a/src/tools/rustfmt/tests/source/configs/doc_comment_code_block_width/100_greater_max_width.rs b/src/tools/rustfmt/tests/source/configs/doc_comment_code_block_width/100_greater_max_width.rs new file mode 100644 index 000000000..96505c697 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/doc_comment_code_block_width/100_greater_max_width.rs @@ -0,0 +1,17 @@ +// rustfmt-max_width: 50 +// rustfmt-format_code_in_doc_comments: true +// rustfmt-doc_comment_code_block_width: 100 + +/// ```rust +/// impl Test { +/// pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> { +/// Self::from_bytes_manual_slice(v, 0, v.len() ) +/// } +/// } +/// ``` + +impl Test { + pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> { + Self::from_bytes_manual_slice(v, 0, v.len() ) + } +} diff --git a/src/tools/rustfmt/tests/source/configs/doc_comment_code_block_width/50.rs b/src/tools/rustfmt/tests/source/configs/doc_comment_code_block_width/50.rs new file mode 100644 index 000000000..2c6307951 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/doc_comment_code_block_width/50.rs @@ -0,0 +1,16 @@ +// rustfmt-format_code_in_doc_comments: true +// rustfmt-doc_comment_code_block_width: 50 + +/// ```rust +/// impl Test { +/// pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> { +/// Self::from_bytes_manual_slice(v, 0, v.len() ) +/// } +/// } +/// ``` + +impl Test { + pub const fn from_bytes(v: &[u8]) -> Result<Self, ParserError> { + Self::from_bytes_manual_slice(v, 0, v.len() ) + } +} diff --git a/src/tools/rustfmt/tests/source/configs/empty_item_single_line/false.rs b/src/tools/rustfmt/tests/source/configs/empty_item_single_line/false.rs new file mode 100644 index 000000000..9bfb2b964 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/empty_item_single_line/false.rs @@ -0,0 +1,16 @@ +// rustfmt-empty_item_single_line: false +// Empty impl on single line + +impl Lorem { + +} + +impl Ipsum { + +} + +fn lorem() { +} + +fn lorem() { +} diff --git a/src/tools/rustfmt/tests/source/configs/empty_item_single_line/true.rs b/src/tools/rustfmt/tests/source/configs/empty_item_single_line/true.rs new file mode 100644 index 000000000..8af8b88ff --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/empty_item_single_line/true.rs @@ -0,0 +1,16 @@ +// rustfmt-empty_item_single_line: true +// Empty impl on single line + +impl Lorem { + +} + +impl Ipsum { + +} + +fn lorem() { +} + +fn lorem() { +} diff --git a/src/tools/rustfmt/tests/source/configs/enum_discrim_align_threshold/40.rs b/src/tools/rustfmt/tests/source/configs/enum_discrim_align_threshold/40.rs new file mode 100644 index 000000000..796e47c38 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/enum_discrim_align_threshold/40.rs @@ -0,0 +1,34 @@ +// rustfmt-enum_discrim_align_threshold: 40
+
+enum Standard {
+ A = 1,
+ Bcdef = 2,
+}
+
+enum NoDiscrims {
+ ThisIsAFairlyLongEnumVariantWithoutDiscrimLongerThan40,
+ A = 1,
+ ThisIsAnotherFairlyLongEnumVariantWithoutDiscrimLongerThan40,
+ Bcdef = 2,
+}
+
+enum TooLong {
+ ThisOneHasDiscrimAaaaaaaaaaaaaaaaaaaaaaChar40 = 10,
+ A = 1,
+ Bcdef = 2,
+}
+
+enum Borderline {
+ ThisOneHasDiscrimAaaaaaaaaaaaaaaaaaaaaa = 10,
+ A = 1,
+ Bcdef = 2,
+}
+
+// Live specimen from #1686
+enum LongWithSmallDiff {
+ SceneColorimetryEstimates = 0x73636F65,
+ SceneAppearanceEstimates = 0x73617065,
+ FocalPlaneColorimetryEstimates = 0x66706365,
+ ReflectionHardcopyOriginalColorimetry = 0x72686F63,
+ ReflectionPrintOutputColorimetry = 0x72706F63,
+}
\ No newline at end of file diff --git a/src/tools/rustfmt/tests/source/configs/error_on_line_overflow/false.rs b/src/tools/rustfmt/tests/source/configs/error_on_line_overflow/false.rs new file mode 100644 index 000000000..fa70ae783 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/error_on_line_overflow/false.rs @@ -0,0 +1,6 @@ +// rustfmt-error_on_line_overflow: false +// Error on line overflow + +fn main() { + let lorem_ipsum_dolor_sit_amet_consectetur_adipiscing_elit_lorem_ipsum_dolor_sit_amet_consectetur_adipiscing_elit; +} diff --git a/src/tools/rustfmt/tests/source/configs/fn_args_layout/compressed.rs b/src/tools/rustfmt/tests/source/configs/fn_args_layout/compressed.rs new file mode 100644 index 000000000..66a371c25 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/fn_args_layout/compressed.rs @@ -0,0 +1,16 @@ +// rustfmt-fn_args_layout: Compressed +// Function arguments density + +trait Lorem { + fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet); + + fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) { + // body + } + + fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: onsectetur, adipiscing: Adipiscing, elit: Elit); + + fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: onsectetur, adipiscing: Adipiscing, elit: Elit) { + // body + } +} diff --git a/src/tools/rustfmt/tests/source/configs/fn_args_layout/tall.rs b/src/tools/rustfmt/tests/source/configs/fn_args_layout/tall.rs new file mode 100644 index 000000000..f11e86fd3 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/fn_args_layout/tall.rs @@ -0,0 +1,16 @@ +// rustfmt-fn_args_layout: Tall +// Function arguments density + +trait Lorem { + fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet); + + fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) { + // body + } + + fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: onsectetur, adipiscing: Adipiscing, elit: Elit); + + fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: onsectetur, adipiscing: Adipiscing, elit: Elit) { + // body + } +} diff --git a/src/tools/rustfmt/tests/source/configs/fn_args_layout/vertical.rs b/src/tools/rustfmt/tests/source/configs/fn_args_layout/vertical.rs new file mode 100644 index 000000000..a23cc0252 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/fn_args_layout/vertical.rs @@ -0,0 +1,16 @@ +// rustfmt-fn_args_layout: Vertical +// Function arguments density + +trait Lorem { + fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet); + + fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) { + // body + } + + fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: onsectetur, adipiscing: Adipiscing, elit: Elit); + + fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: onsectetur, adipiscing: Adipiscing, elit: Elit) { + // body + } +} diff --git a/src/tools/rustfmt/tests/source/configs/fn_single_line/false.rs b/src/tools/rustfmt/tests/source/configs/fn_single_line/false.rs new file mode 100644 index 000000000..3d092f0c0 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/fn_single_line/false.rs @@ -0,0 +1,11 @@ +// rustfmt-fn_single_line: false +// Single-expression function on single line + +fn lorem() -> usize { + 42 +} + +fn lorem() -> usize { + let ipsum = 42; + ipsum +} diff --git a/src/tools/rustfmt/tests/source/configs/fn_single_line/true.rs b/src/tools/rustfmt/tests/source/configs/fn_single_line/true.rs new file mode 100644 index 000000000..3cb0fdedf --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/fn_single_line/true.rs @@ -0,0 +1,11 @@ +// rustfmt-fn_single_line: true +// Single-expression function on single line + +fn lorem() -> usize { + 42 +} + +fn lorem() -> usize { + let ipsum = 42; + ipsum +} diff --git a/src/tools/rustfmt/tests/source/configs/force_explicit_abi/false.rs b/src/tools/rustfmt/tests/source/configs/force_explicit_abi/false.rs new file mode 100644 index 000000000..3c48f8e0c --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/force_explicit_abi/false.rs @@ -0,0 +1,6 @@ +// rustfmt-force_explicit_abi: false +// Force explicit abi + +extern { + pub static lorem: c_int; +} diff --git a/src/tools/rustfmt/tests/source/configs/force_explicit_abi/true.rs b/src/tools/rustfmt/tests/source/configs/force_explicit_abi/true.rs new file mode 100644 index 000000000..e5ff6cf7d --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/force_explicit_abi/true.rs @@ -0,0 +1,6 @@ +// rustfmt-force_explicit_abi: true +// Force explicit abi + +extern { + pub static lorem: c_int; +} diff --git a/src/tools/rustfmt/tests/source/configs/force_multiline_block/false.rs b/src/tools/rustfmt/tests/source/configs/force_multiline_block/false.rs new file mode 100644 index 000000000..b97e348e5 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/force_multiline_block/false.rs @@ -0,0 +1,22 @@ +// rustfmt-force_multiline_blocks: false +// Option forces multiline match arm and closure bodies to be wrapped in a block + +fn main() { + match lorem { + Lorem::Ipsum => { + if ipsum { + println!("dolor"); + } + } + Lorem::Dolor => println!("amet"), + } +} + +fn main() { + result.and_then(|maybe_value| { + match maybe_value { + None => Err("oops"), + Some(value) => Ok(1), + } + }); +} diff --git a/src/tools/rustfmt/tests/source/configs/force_multiline_block/true.rs b/src/tools/rustfmt/tests/source/configs/force_multiline_block/true.rs new file mode 100644 index 000000000..db9d3de46 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/force_multiline_block/true.rs @@ -0,0 +1,18 @@ +// rustfmt-force_multiline_blocks: true +// Option forces multiline match arm and closure bodies to be wrapped in a block + +fn main() { + match lorem { + Lorem::Ipsum => if ipsum { + println!("dolor"); + }, + Lorem::Dolor => println!("amet"), + } +} + +fn main() { + result.and_then(|maybe_value| match maybe_value { + None => Err("oops"), + Some(value) => Ok(1), + }); +} diff --git a/src/tools/rustfmt/tests/source/configs/format_generated_files/false.rs b/src/tools/rustfmt/tests/source/configs/format_generated_files/false.rs new file mode 100644 index 000000000..dec1e00d1 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/format_generated_files/false.rs @@ -0,0 +1,8 @@ +// @generated +// rustfmt-format_generated_files: false + +fn main() +{ + println!("hello, world") + ; +} diff --git a/src/tools/rustfmt/tests/source/configs/format_generated_files/true.rs b/src/tools/rustfmt/tests/source/configs/format_generated_files/true.rs new file mode 100644 index 000000000..a25ddc25a --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/format_generated_files/true.rs @@ -0,0 +1,8 @@ +// @generated +// rustfmt-format_generated_files: true + +fn main() +{ + println!("hello, world") + ; +} diff --git a/src/tools/rustfmt/tests/source/configs/format_macro_bodies/false.rs b/src/tools/rustfmt/tests/source/configs/format_macro_bodies/false.rs new file mode 100644 index 000000000..d618a1ac3 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/format_macro_bodies/false.rs @@ -0,0 +1,7 @@ +// rustfmt-format_macro_bodies: false + +macro_rules! foo { + ($a: ident : $b: ty) => { $a(42): $b; }; + ($a: ident $b: ident $c: ident) => { $a=$b+$c; }; +} + diff --git a/src/tools/rustfmt/tests/source/configs/format_macro_bodies/true.rs b/src/tools/rustfmt/tests/source/configs/format_macro_bodies/true.rs new file mode 100644 index 000000000..b254b82d7 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/format_macro_bodies/true.rs @@ -0,0 +1,7 @@ +// rustfmt-format_macro_bodies: true + +macro_rules! foo { + ($a: ident : $b: ty) => { $a(42): $b; }; + ($a: ident $b: ident $c: ident) => { $a=$b+$c; }; +} + diff --git a/src/tools/rustfmt/tests/source/configs/format_macro_matchers/false.rs b/src/tools/rustfmt/tests/source/configs/format_macro_matchers/false.rs new file mode 100644 index 000000000..a721bb55c --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/format_macro_matchers/false.rs @@ -0,0 +1,7 @@ +// rustfmt-format_macro_matchers: false + +macro_rules! foo { + ($a: ident : $b: ty) => { $a(42): $b; }; + ($a: ident $b: ident $c: ident) => { $a=$b+$c; }; +} + diff --git a/src/tools/rustfmt/tests/source/configs/format_macro_matchers/true.rs b/src/tools/rustfmt/tests/source/configs/format_macro_matchers/true.rs new file mode 100644 index 000000000..fa0442e22 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/format_macro_matchers/true.rs @@ -0,0 +1,6 @@ +// rustfmt-format_macro_matchers: true + +macro_rules! foo { + ($a: ident : $b: ty) => { $a(42): $b; }; + ($a: ident $b: ident $c: ident) => { $a=$b+$c; }; +} diff --git a/src/tools/rustfmt/tests/source/configs/format_strings/false.rs b/src/tools/rustfmt/tests/source/configs/format_strings/false.rs new file mode 100644 index 000000000..ecca0d7d1 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/format_strings/false.rs @@ -0,0 +1,8 @@ +// rustfmt-format_strings: false +// rustfmt-max_width: 50 +// rustfmt-error_on_line_overflow: false +// Force format strings + +fn main() { + let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit"; +} diff --git a/src/tools/rustfmt/tests/source/configs/format_strings/true.rs b/src/tools/rustfmt/tests/source/configs/format_strings/true.rs new file mode 100644 index 000000000..337314478 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/format_strings/true.rs @@ -0,0 +1,7 @@ +// rustfmt-format_strings: true +// rustfmt-max_width: 50 +// Force format strings + +fn main() { + let lorem = "ipsum dolor sit amet consectetur adipiscing elit lorem ipsum dolor sit"; +} diff --git a/src/tools/rustfmt/tests/source/configs/group_imports/One-merge_imports.rs b/src/tools/rustfmt/tests/source/configs/group_imports/One-merge_imports.rs new file mode 100644 index 000000000..157d38579 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/group_imports/One-merge_imports.rs @@ -0,0 +1,17 @@ +// rustfmt-group_imports: One +// rustfmt-imports_granularity: Crate +use chrono::Utc; +use super::update::convert_publish_payload; + +use juniper::{FieldError, FieldResult}; +use uuid::Uuid; +use alloc::alloc::Layout; + +use std::sync::Arc; +use alloc::vec::Vec; + +use broker::database::PooledConnection; + +use super::schema::{Context, Payload}; +use core::f32; +use crate::models::Event; diff --git a/src/tools/rustfmt/tests/source/configs/group_imports/One-nested.rs b/src/tools/rustfmt/tests/source/configs/group_imports/One-nested.rs new file mode 100644 index 000000000..109bd07e1 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/group_imports/One-nested.rs @@ -0,0 +1,7 @@ +// rustfmt-group_imports: One +mod test { + use crate::foo::bar; + + use std::path; + use crate::foo::bar2; +} diff --git a/src/tools/rustfmt/tests/source/configs/group_imports/One-no_reorder.rs b/src/tools/rustfmt/tests/source/configs/group_imports/One-no_reorder.rs new file mode 100644 index 000000000..f82f62c7f --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/group_imports/One-no_reorder.rs @@ -0,0 +1,16 @@ +// rustfmt-group_imports: One +// rustfmt-reorder_imports: false +use chrono::Utc; +use super::update::convert_publish_payload; + +use juniper::{FieldError, FieldResult}; +use uuid::Uuid; +use alloc::alloc::Layout; + +use std::sync::Arc; + +use broker::database::PooledConnection; + +use super::schema::{Context, Payload}; +use core::f32; +use crate::models::Event; diff --git a/src/tools/rustfmt/tests/source/configs/group_imports/One.rs b/src/tools/rustfmt/tests/source/configs/group_imports/One.rs new file mode 100644 index 000000000..5ab7a9508 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/group_imports/One.rs @@ -0,0 +1,15 @@ +// rustfmt-group_imports: One +use chrono::Utc; +use super::update::convert_publish_payload; + +use juniper::{FieldError, FieldResult}; +use uuid::Uuid; +use alloc::alloc::Layout; + +use std::sync::Arc; + +use broker::database::PooledConnection; + +use super::schema::{Context, Payload}; +use core::f32; +use crate::models::Event; diff --git a/src/tools/rustfmt/tests/source/configs/group_imports/StdExternalCrate-merge_imports.rs b/src/tools/rustfmt/tests/source/configs/group_imports/StdExternalCrate-merge_imports.rs new file mode 100644 index 000000000..ea7f6280a --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/group_imports/StdExternalCrate-merge_imports.rs @@ -0,0 +1,17 @@ +// rustfmt-group_imports: StdExternalCrate +// rustfmt-imports_granularity: Crate +use chrono::Utc; +use super::update::convert_publish_payload; + +use juniper::{FieldError, FieldResult}; +use uuid::Uuid; +use alloc::alloc::Layout; + +use std::sync::Arc; +use alloc::vec::Vec; + +use broker::database::PooledConnection; + +use super::schema::{Context, Payload}; +use core::f32; +use crate::models::Event; diff --git a/src/tools/rustfmt/tests/source/configs/group_imports/StdExternalCrate-nested.rs b/src/tools/rustfmt/tests/source/configs/group_imports/StdExternalCrate-nested.rs new file mode 100644 index 000000000..08f4e07b7 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/group_imports/StdExternalCrate-nested.rs @@ -0,0 +1,6 @@ +// rustfmt-group_imports: StdExternalCrate +mod test { + use crate::foo::bar; + use std::path; + use crate::foo::bar2; +} diff --git a/src/tools/rustfmt/tests/source/configs/group_imports/StdExternalCrate-no_reorder.rs b/src/tools/rustfmt/tests/source/configs/group_imports/StdExternalCrate-no_reorder.rs new file mode 100644 index 000000000..08c9a72ae --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/group_imports/StdExternalCrate-no_reorder.rs @@ -0,0 +1,17 @@ +// rustfmt-group_imports: StdExternalCrate +// rustfmt-reorder_imports: false + +use chrono::Utc; +use super::update::convert_publish_payload; + +use juniper::{FieldError, FieldResult}; +use uuid::Uuid; +use alloc::alloc::Layout; + +use std::sync::Arc; + +use broker::database::PooledConnection; + +use super::schema::{Context, Payload}; +use core::f32; +use crate::models::Event; diff --git a/src/tools/rustfmt/tests/source/configs/group_imports/StdExternalCrate-non_consecutive.rs b/src/tools/rustfmt/tests/source/configs/group_imports/StdExternalCrate-non_consecutive.rs new file mode 100644 index 000000000..f239a0efa --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/group_imports/StdExternalCrate-non_consecutive.rs @@ -0,0 +1,27 @@ +// rustfmt-group_imports: StdExternalCrate +use chrono::Utc; +use super::update::convert_publish_payload; + + + + + +use juniper::{FieldError, FieldResult}; + +use uuid::Uuid; +use alloc::alloc::Layout; + +extern crate uuid; + + + + + +use std::sync::Arc; + + +use broker::database::PooledConnection; + +use super::schema::{Context, Payload}; +use core::f32; +use crate::models::Event; diff --git a/src/tools/rustfmt/tests/source/configs/group_imports/StdExternalCrate.rs b/src/tools/rustfmt/tests/source/configs/group_imports/StdExternalCrate.rs new file mode 100644 index 000000000..d49c8941e --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/group_imports/StdExternalCrate.rs @@ -0,0 +1,15 @@ +// rustfmt-group_imports: StdExternalCrate +use chrono::Utc; +use super::update::convert_publish_payload; + +use juniper::{FieldError, FieldResult}; +use uuid::Uuid; +use alloc::alloc::Layout; + +use std::sync::Arc; + +use broker::database::PooledConnection; + +use super::schema::{Context, Payload}; +use core::f32; +use crate::models::Event; diff --git a/src/tools/rustfmt/tests/source/configs/hard_tabs/false.rs b/src/tools/rustfmt/tests/source/configs/hard_tabs/false.rs new file mode 100644 index 000000000..bf92162b4 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/hard_tabs/false.rs @@ -0,0 +1,6 @@ +// rustfmt-hard_tabs: false +// Hard tabs + +fn lorem() -> usize { +42 // spaces before 42 +} diff --git a/src/tools/rustfmt/tests/source/configs/hard_tabs/true.rs b/src/tools/rustfmt/tests/source/configs/hard_tabs/true.rs new file mode 100644 index 000000000..738922a4d --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/hard_tabs/true.rs @@ -0,0 +1,6 @@ +// rustfmt-hard_tabs: true +// Hard tabs + +fn lorem() -> usize { +42 // spaces before 42 +} diff --git a/src/tools/rustfmt/tests/source/configs/imports_layout/merge_mixed.rs b/src/tools/rustfmt/tests/source/configs/imports_layout/merge_mixed.rs new file mode 100644 index 000000000..477c4aa16 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/imports_layout/merge_mixed.rs @@ -0,0 +1,6 @@ +// rustfmt-imports_indent: Block +// rustfmt-imports_granularity: Crate +// rustfmt-imports_layout: Mixed + +use std::{fmt, io, str}; +use std::str::FromStr; diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/block_args.rs b/src/tools/rustfmt/tests/source/configs/indent_style/block_args.rs new file mode 100644 index 000000000..4d2d280a1 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/block_args.rs @@ -0,0 +1,26 @@ +// rustfmt-indent_style: Block +// Function arguments layout + +fn lorem() {} + +fn lorem(ipsum: usize) {} + +fn lorem(ipsum: usize, dolor: usize, sit: usize, amet: usize, consectetur: usize, adipiscing: usize, elit: usize) { + // body +} + +// #1441 +extern "system" { + pub fn GetConsoleHistoryInfo(console_history_info: *mut ConsoleHistoryInfo) -> Boooooooooooooool; +} + +// rustfmt should not add trailing comma for variadic function. See #1623. +extern "C" { + pub fn variadic_fn(first_parameter: FirstParameterType, + second_parameter: SecondParameterType, + ...); +} + +// #1652 +fn deconstruct(foo: Bar) -> (SocketAddr, Header, Method, RequestUri, HttpVersion, AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) { +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/block_array.rs b/src/tools/rustfmt/tests/source/configs/indent_style/block_array.rs new file mode 100644 index 000000000..8404f65f4 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/block_array.rs @@ -0,0 +1,6 @@ +// rustfmt-indent_style: Block +// Array layout + +fn main() { + let lorem = vec!["ipsum","dolor","sit","amet","consectetur","adipiscing","elit"]; +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/block_call.rs b/src/tools/rustfmt/tests/source/configs/indent_style/block_call.rs new file mode 100644 index 000000000..c82b6b8e3 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/block_call.rs @@ -0,0 +1,133 @@ +// rustfmt-indent_style: Block +// Function call style + +fn main() { + lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit"); + // #1501 + let hyper = Arc::new(Client::with_connector(HttpsConnector::new(TlsClient::new()))); + + // chain + let x = yooooooooooooo.fooooooooooooooo.baaaaaaaaaaaaar(hello, world); + + // #1380 + { + { + let creds = self.client + .client_credentials(&self.config.auth.oauth2.id, &self.config.auth.oauth2.secret)?; + } + } + + // nesting macro and function call + try!(foo(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)); + try!(foo(try!(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx))); +} + +// #1521 +impl Foo { + fn map_pixel_to_coords(&self, point: &Vector2i, view: &View) -> Vector2f { + unsafe { + Vector2f::from_raw(ffi::sfRenderTexture_mapPixelToCoords(self.render_texture, point.raw(), view.raw())) + } + } +} + +fn issue1420() { + given( + r#" + # Getting started + ... + "#, + ) + .running(waltz) +} + +// #1563 +fn query(conn: &Connection) -> Result<()> { + conn.query_row( + r#" + SELECT title, date + FROM posts, + WHERE DATE(date) = $1 + "#, + &[], + |row| { + Post { + title: row.get(0), + date: row.get(1), + } + }, + )?; + + Ok(()) +} + +// #1449 +fn future_rayon_wait_1_thread() { + // run with only 1 worker thread; this would deadlock if we couldn't make progress + let mut result = None; + ThreadPool::new(Configuration::new().num_threads(1)) + .unwrap() + .install( + || { + scope( + |s| { + use std::sync::mpsc::channel; + let (tx, rx) = channel(); + let a = s.spawn_future(lazy(move || Ok::<usize, ()>(rx.recv().unwrap()))); + // ^^^^ FIXME: why is this needed? + let b = s.spawn_future(a.map(|v| v + 1)); + let c = s.spawn_future(b.map(|v| v + 1)); + s.spawn(move |_| tx.send(20).unwrap()); + result = Some(c.rayon_wait().unwrap()); + }, + ); + }, + ); + assert_eq!(result, Some(22)); +} + +// #1494 +impl Cursor { + fn foo() { + self.cur_type() + .num_template_args() + .or_else(|| { + let n: c_int = unsafe { clang_Cursor_getNumTemplateArguments(self.x) }; + + if n >= 0 { + Some(n as u32) + } else { + debug_assert_eq!(n, -1); + None + } + }) + .or_else(|| { + let canonical = self.canonical(); + if canonical != *self { + canonical.num_template_args() + } else { + None + } + }); + } +} + +fn issue1581() { + bootstrap.checks.register( + "PERSISTED_LOCATIONS", + move || if locations2.0.inner_mut.lock().poisoned { + Check::new( + State::Error, + "Persisted location storage is poisoned due to a write failure", + ) + } else { + Check::new(State::Healthy, "Persisted location storage is healthy") + }, + ); +} + +fn issue1651() { + { + let type_list: Vec<_> = try_opt!(types.iter().map(|ty| ty.rewrite(context, shape)).collect()); + } +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/block_chain.rs b/src/tools/rustfmt/tests/source/configs/indent_style/block_chain.rs new file mode 100644 index 000000000..41d914691 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/block_chain.rs @@ -0,0 +1,6 @@ +// rustfmt-indent_style: Block +// Chain indent + +fn main() { + let lorem = ipsum.dolor().sit().amet().consectetur().adipiscing().elite(); +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/block_generic.rs b/src/tools/rustfmt/tests/source/configs/indent_style/block_generic.rs new file mode 100644 index 000000000..2cf17be56 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/block_generic.rs @@ -0,0 +1,6 @@ +// rustfmt-indent_style: Block +// Generics indent + +fn lorem<Ipsum: Eq = usize, Dolor: Eq = usize, Sit: Eq = usize, Amet: Eq = usize, Adipiscing: Eq = usize, Consectetur: Eq = usize, Elit: Eq = usize>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, adipiscing: Adipiscing, consectetur: Consectetur, elit: Elit) -> T { + // body +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/block_struct_lit.rs b/src/tools/rustfmt/tests/source/configs/indent_style/block_struct_lit.rs new file mode 100644 index 000000000..47a6994f4 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/block_struct_lit.rs @@ -0,0 +1,6 @@ +// rustfmt-indent_style: Block +// Struct literal-style + +fn main() { + let lorem = Lorem { ipsum: dolor, sit: amet }; +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/block_trailing_comma_call/one.rs b/src/tools/rustfmt/tests/source/configs/indent_style/block_trailing_comma_call/one.rs new file mode 100644 index 000000000..6d48ea742 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/block_trailing_comma_call/one.rs @@ -0,0 +1,9 @@ +// rustfmt-version: One +// rustfmt-error_on_line_overflow: false +// rustfmt-indent_style: Block + +// rustfmt should not add trailing comma when rewriting macro. See #1528. +fn a() { + panic!("this is a long string that goes past the maximum line length causing rustfmt to insert a comma here:"); + foo(a, oooptoptoptoptptooptoptoptoptptooptoptoptoptptoptoptoptoptpt()); +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/block_trailing_comma_call/two.rs b/src/tools/rustfmt/tests/source/configs/indent_style/block_trailing_comma_call/two.rs new file mode 100644 index 000000000..7a62d722c --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/block_trailing_comma_call/two.rs @@ -0,0 +1,9 @@ +// rustfmt-version: Two +// rustfmt-error_on_line_overflow: false +// rustfmt-indent_style: Block + +// rustfmt should not add trailing comma when rewriting macro. See #1528. +fn a() { + panic!("this is a long string that goes past the maximum line length causing rustfmt to insert a comma here:"); + foo(a, oooptoptoptoptptooptoptoptoptptooptoptoptoptptoptoptoptoptpt()); +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/block_where_pred.rs b/src/tools/rustfmt/tests/source/configs/indent_style/block_where_pred.rs new file mode 100644 index 000000000..450491f02 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/block_where_pred.rs @@ -0,0 +1,6 @@ +// rustfmt-indent_style: Block +// Where predicate indent + +fn lorem<Ipsum, Dolor, Sit, Amet>() -> T where Ipsum: Eq, Dolor: Eq, Sit: Eq, Amet: Eq { + // body +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/default.rs b/src/tools/rustfmt/tests/source/configs/indent_style/default.rs new file mode 100644 index 000000000..f08f5c644 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/default.rs @@ -0,0 +1,6 @@ +// rustfmt-indent_style: Visual +// Where style + +fn lorem<Ipsum, Dolor, Sit, Amet>() -> T where Ipsum: Eq, Dolor: Eq, Sit: Eq, Amet: Eq { + // body +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/rfc_where.rs b/src/tools/rustfmt/tests/source/configs/indent_style/rfc_where.rs new file mode 100644 index 000000000..012840be2 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/rfc_where.rs @@ -0,0 +1,6 @@ +// rustfmt-indent_style: Block +// Where style + +fn lorem<Ipsum, Dolor, Sit, Amet>() -> T where Ipsum: Eq, Dolor: Eq, Sit: Eq, Amet: Eq { + // body +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/visual_args.rs b/src/tools/rustfmt/tests/source/configs/indent_style/visual_args.rs new file mode 100644 index 000000000..5aa28a62b --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/visual_args.rs @@ -0,0 +1,32 @@ +// rustfmt-indent_style: Visual +// Function arguments layout + +fn lorem() {} + +fn lorem(ipsum: usize) {} + +fn lorem(ipsum: usize, dolor: usize, sit: usize, amet: usize, consectetur: usize, adipiscing: usize, elit: usize) { + // body +} + +// #1922 +extern "C" { + pub fn LAPACKE_csytrs_rook_work(matrix_layout: c_int, + uplo: c_char, + n: lapack_int, + nrhs: lapack_int, + a: *const lapack_complex_float, + lda: lapack_int, ipiv: *const lapack_int, + b: *mut lapack_complex_float, + ldb: lapack_int + )-> lapack_int; + + pub fn LAPACKE_csytrs_rook_work(matrix_layout: c_int, + uplo: c_char, + n: lapack_int, + nrhs: lapack_int, + lda: lapack_int, ipiv: *const lapack_int, + b: *mut lapack_complex_float, + ldb: lapack_int + ) -> lapack_int; +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/visual_array.rs b/src/tools/rustfmt/tests/source/configs/indent_style/visual_array.rs new file mode 100644 index 000000000..05bbf00b1 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/visual_array.rs @@ -0,0 +1,6 @@ +// rustfmt-indent_style: Visual +// Array layout + +fn main() { + let lorem = vec!["ipsum","dolor","sit","amet","consectetur","adipiscing","elit"]; +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/visual_call.rs b/src/tools/rustfmt/tests/source/configs/indent_style/visual_call.rs new file mode 100644 index 000000000..9a679d6bb --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/visual_call.rs @@ -0,0 +1,6 @@ +// rustfmt-indent_style: Visual +// Function call style + +fn main() { + lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit"); +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/visual_chain.rs b/src/tools/rustfmt/tests/source/configs/indent_style/visual_chain.rs new file mode 100644 index 000000000..b74948753 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/visual_chain.rs @@ -0,0 +1,6 @@ +// rustfmt-indent_style: Visual +// Chain indent + +fn main() { + let lorem = ipsum.dolor().sit().amet().consectetur().adipiscing().elite(); +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/visual_generics.rs b/src/tools/rustfmt/tests/source/configs/indent_style/visual_generics.rs new file mode 100644 index 000000000..1f910d32d --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/visual_generics.rs @@ -0,0 +1,6 @@ +// rustfmt-indent_style: Visual +// Generics indent + +fn lorem<Ipsum: Eq = usize, Dolor: Eq = usize, Sit: Eq = usize, Amet: Eq = usize, Adipiscing: Eq = usize, Consectetur: Eq = usize, Elit: Eq = usize>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, adipiscing: Adipiscing, consectetur: Consectetur, elit: Elit) -> T { + // body +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/visual_struct_lit.rs b/src/tools/rustfmt/tests/source/configs/indent_style/visual_struct_lit.rs new file mode 100644 index 000000000..45538e704 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/visual_struct_lit.rs @@ -0,0 +1,6 @@ +// rustfmt-indent_style: Visual +// Struct literal-style + +fn main() { + let lorem = Lorem { ipsum: dolor, sit: amet }; +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/visual_trailing_comma.rs b/src/tools/rustfmt/tests/source/configs/indent_style/visual_trailing_comma.rs new file mode 100644 index 000000000..9738d397d --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/visual_trailing_comma.rs @@ -0,0 +1,7 @@ +// rustfmt-error_on_line_overflow: false +// rustfmt-indent_style: Visual + +// rustfmt should not add trailing comma when rewriting macro. See #1528. +fn a() { + panic!("this is a long string that goes past the maximum line length causing rustfmt to insert a comma here:"); +} diff --git a/src/tools/rustfmt/tests/source/configs/indent_style/visual_where_pred.rs b/src/tools/rustfmt/tests/source/configs/indent_style/visual_where_pred.rs new file mode 100644 index 000000000..055806b68 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/indent_style/visual_where_pred.rs @@ -0,0 +1,6 @@ +// rustfmt-indent_style: Visual +// Where predicate indent + +fn lorem<Ipsum, Dolor, Sit, Amet>() -> T where Ipsum: Eq, Dolor: Eq, Sit: Eq, Amet: Eq { + // body +} diff --git a/src/tools/rustfmt/tests/source/configs/match_arm_blocks/false.rs b/src/tools/rustfmt/tests/source/configs/match_arm_blocks/false.rs new file mode 100644 index 000000000..53e37e13c --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/match_arm_blocks/false.rs @@ -0,0 +1,11 @@ +// rustfmt-match_arm_blocks: false +// Wrap match-arms + +fn main() { + match lorem { + true => foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x), + false => { + println!("{}", sit) + } + } +} diff --git a/src/tools/rustfmt/tests/source/configs/match_arm_blocks/true.rs b/src/tools/rustfmt/tests/source/configs/match_arm_blocks/true.rs new file mode 100644 index 000000000..a452b13cd --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/match_arm_blocks/true.rs @@ -0,0 +1,11 @@ +// rustfmt-match_arm_blocks: true +// Wrap match-arms + +fn main() { + match lorem { + true => foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(x), + false => { + println!("{}", sit) + } + } +} diff --git a/src/tools/rustfmt/tests/source/configs/match_arm_leading_pipes/always.rs b/src/tools/rustfmt/tests/source/configs/match_arm_leading_pipes/always.rs new file mode 100644 index 000000000..162d812d8 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/match_arm_leading_pipes/always.rs @@ -0,0 +1,27 @@ +// rustfmt-match_arm_leading_pipes: Always + +fn foo() { + match foo { + "foo" | "bar" => {} + "baz" + | "something relatively long" + | "something really really really realllllllllllllly long" => println!("x"), + "qux" => println!("y"), + _ => {} + } +} + +fn issue_3973() { + match foo { + "foo" | "bar" => {} + _ => {} + } +} + +fn bar() { + match baz { + "qux" => {} + "foo" | "bar" => {} + _ => {} + } +} diff --git a/src/tools/rustfmt/tests/source/configs/match_arm_leading_pipes/never.rs b/src/tools/rustfmt/tests/source/configs/match_arm_leading_pipes/never.rs new file mode 100644 index 000000000..8a68fe214 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/match_arm_leading_pipes/never.rs @@ -0,0 +1,28 @@ +// rustfmt-match_arm_leading_pipes: Never + +fn foo() { + match foo { + | "foo" | "bar" => {} + | "baz" + | "something relatively long" + | "something really really really realllllllllllllly long" => println!("x"), + | "qux" => println!("y"), + _ => {} + } +} + +fn issue_3973() { + match foo { + | "foo" + | "bar" => {} + _ => {} + } +} + +fn bar() { + match baz { + "qux" => {} + "foo" | "bar" => {} + _ => {} + } +} diff --git a/src/tools/rustfmt/tests/source/configs/match_arm_leading_pipes/preserve.rs b/src/tools/rustfmt/tests/source/configs/match_arm_leading_pipes/preserve.rs new file mode 100644 index 000000000..5486877bd --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/match_arm_leading_pipes/preserve.rs @@ -0,0 +1,36 @@ +// rustfmt-match_arm_leading_pipes: Preserve + +fn foo() { + match foo { + | "foo" | "bar" => {} + | "baz" + | "something relatively long" + | "something really really really realllllllllllllly long" => println!("x"), + | "qux" => println!("y"), + _ => {} + } +} + +fn issue_3973() { + match foo { + | "foo" + | "bar" => {} + _ => {} + } +} + +fn bar() { + match baz { + "qux" => { } + "foo" | "bar" => {} + _ => {} + } +} + +fn f(x: NonAscii) -> bool { + match x { + // foo + | Éfgh => true, + _ => false, + } +}
\ No newline at end of file diff --git a/src/tools/rustfmt/tests/source/configs/match_block_trailing_comma/false.rs b/src/tools/rustfmt/tests/source/configs/match_block_trailing_comma/false.rs new file mode 100644 index 000000000..70e02955f --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/match_block_trailing_comma/false.rs @@ -0,0 +1,11 @@ +// rustfmt-match_block_trailing_comma: false +// Match block trailing comma + +fn main() { + match lorem { + Lorem::Ipsum => { + println!("ipsum"); + } + Lorem::Dolor => println!("dolor"), + } +} diff --git a/src/tools/rustfmt/tests/source/configs/match_block_trailing_comma/true.rs b/src/tools/rustfmt/tests/source/configs/match_block_trailing_comma/true.rs new file mode 100644 index 000000000..b9af3d472 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/match_block_trailing_comma/true.rs @@ -0,0 +1,11 @@ +// rustfmt-match_block_trailing_comma: true +// Match block trailing comma + +fn main() { + match lorem { + Lorem::Ipsum => { + println!("ipsum"); + } + Lorem::Dolor => println!("dolor"), + } +} diff --git a/src/tools/rustfmt/tests/source/configs/merge_derives/true.rs b/src/tools/rustfmt/tests/source/configs/merge_derives/true.rs new file mode 100644 index 000000000..18b8443f0 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/merge_derives/true.rs @@ -0,0 +1,46 @@ +// rustfmt-merge_derives: true +// Merge multiple derives to a single one. + +#[bar] +#[derive(Eq, PartialEq)] +#[foo] +#[derive(Debug)] +#[foobar] +#[derive(Copy, Clone)] +pub enum Foo {} + +#[derive(Eq, PartialEq)] +#[derive(Debug)] +#[foobar] +#[derive(Copy, Clone)] +pub enum Bar {} + +#[derive(Eq, PartialEq)] +#[derive(Debug)] +#[derive(Copy, Clone)] +pub enum FooBar {} + +mod foo { +#[bar] +#[derive(Eq, PartialEq)] +#[foo] +#[derive(Debug)] +#[foobar] +#[derive(Copy, Clone)] +pub enum Foo {} +} + +mod bar { +#[derive(Eq, PartialEq)] +#[derive(Debug)] +#[foobar] +#[derive(Copy, Clone)] +pub enum Bar {} +} + +mod foobar { +#[derive(Eq, PartialEq)] +#[derive(Debug)] +#[derive(Copy, Clone)] +pub enum FooBar {} +} diff --git a/src/tools/rustfmt/tests/source/configs/normalize_comments/false.rs b/src/tools/rustfmt/tests/source/configs/normalize_comments/false.rs new file mode 100644 index 000000000..488962ed9 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/normalize_comments/false.rs @@ -0,0 +1,13 @@ +// rustfmt-normalize_comments: false +// Normalize comments + +// Lorem ipsum: +fn dolor() -> usize {} + +/* sit amet: */ +fn adipiscing() -> usize {} + +// #652 +//////////////////////////////////////////////////////////////////////////////// +// Basic slice extension methods +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/tools/rustfmt/tests/source/configs/normalize_comments/true.rs b/src/tools/rustfmt/tests/source/configs/normalize_comments/true.rs new file mode 100644 index 000000000..c74a9808e --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/normalize_comments/true.rs @@ -0,0 +1,13 @@ +// rustfmt-normalize_comments: true +// Normalize comments + +// Lorem ipsum: +fn dolor() -> usize {} + +/* sit amet: */ +fn adipiscing() -> usize {} + +// #652 +//////////////////////////////////////////////////////////////////////////////// +// Basic slice extension methods +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/tools/rustfmt/tests/source/configs/normalize_doc_attributes/false.rs b/src/tools/rustfmt/tests/source/configs/normalize_doc_attributes/false.rs new file mode 100644 index 000000000..f8eb64273 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/normalize_doc_attributes/false.rs @@ -0,0 +1,13 @@ +// rustfmt-normalize_doc_attributes: false +// Normalize doc attributes + +#![doc = " Example documentation"] + +#[doc = " Example item documentation"] +pub enum Foo {} + +#[doc = " Lots of space"] +pub enum Bar {} + +#[doc = "no leading space"] +pub mod FooBar {} diff --git a/src/tools/rustfmt/tests/source/configs/normalize_doc_attributes/true.rs b/src/tools/rustfmt/tests/source/configs/normalize_doc_attributes/true.rs new file mode 100644 index 000000000..894c00a4d --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/normalize_doc_attributes/true.rs @@ -0,0 +1,13 @@ +// rustfmt-normalize_doc_attributes: true +// Normalize doc attributes + +#![doc = " Example documentation"] + +#[doc = " Example item documentation"] +pub enum Foo {} + +#[doc = " Lots of space"] +pub enum Bar {} + +#[doc = "no leading space"] +pub mod FooBar {} diff --git a/src/tools/rustfmt/tests/source/configs/remove_nested_parens/remove_nested_parens.rs b/src/tools/rustfmt/tests/source/configs/remove_nested_parens/remove_nested_parens.rs new file mode 100644 index 000000000..87aed09c1 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/remove_nested_parens/remove_nested_parens.rs @@ -0,0 +1,5 @@ +// rustfmt-remove_nested_parens: true + +fn main() { + ((((((foo())))))); +} diff --git a/src/tools/rustfmt/tests/source/configs/reorder_impl_items/false.rs b/src/tools/rustfmt/tests/source/configs/reorder_impl_items/false.rs new file mode 100644 index 000000000..beb99f0fb --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/reorder_impl_items/false.rs @@ -0,0 +1,11 @@ +// rustfmt-reorder_impl_items: false + +struct Dummy; + +impl Iterator for Dummy { + fn next(&mut self) -> Option<Self::Item> { + None + } + + type Item = i32; +} diff --git a/src/tools/rustfmt/tests/source/configs/reorder_impl_items/true.rs b/src/tools/rustfmt/tests/source/configs/reorder_impl_items/true.rs new file mode 100644 index 000000000..612b1c84a --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/reorder_impl_items/true.rs @@ -0,0 +1,11 @@ +// rustfmt-reorder_impl_items: true + +struct Dummy; + +impl Iterator for Dummy { + fn next(&mut self) -> Option<Self::Item> { + None + } + + type Item = i32; +} diff --git a/src/tools/rustfmt/tests/source/configs/reorder_imports/false.rs b/src/tools/rustfmt/tests/source/configs/reorder_imports/false.rs new file mode 100644 index 000000000..4b85684dc --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/reorder_imports/false.rs @@ -0,0 +1,7 @@ +// rustfmt-reorder_imports: false +// Reorder imports + +use lorem; +use ipsum; +use dolor; +use sit; diff --git a/src/tools/rustfmt/tests/source/configs/reorder_imports/true.rs b/src/tools/rustfmt/tests/source/configs/reorder_imports/true.rs new file mode 100644 index 000000000..2a40f6d06 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/reorder_imports/true.rs @@ -0,0 +1,19 @@ +// rustfmt-reorder_imports: true +// Reorder imports + +use lorem; +use ipsum; +use dolor; +use sit; + +fn foo() { + use C; + use B; + use A; + + bar(); + + use F; + use E; + use D; +} diff --git a/src/tools/rustfmt/tests/source/configs/reorder_modules/dolor/mod.rs b/src/tools/rustfmt/tests/source/configs/reorder_modules/dolor/mod.rs new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/reorder_modules/dolor/mod.rs @@ -0,0 +1 @@ + diff --git a/src/tools/rustfmt/tests/source/configs/reorder_modules/false.rs b/src/tools/rustfmt/tests/source/configs/reorder_modules/false.rs new file mode 100644 index 000000000..56b1aa03e --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/reorder_modules/false.rs @@ -0,0 +1,7 @@ +// rustfmt-reorder_modules: false +// Reorder modules + +mod lorem; +mod ipsum; +mod dolor; +mod sit; diff --git a/src/tools/rustfmt/tests/source/configs/reorder_modules/ipsum/mod.rs b/src/tools/rustfmt/tests/source/configs/reorder_modules/ipsum/mod.rs new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/reorder_modules/ipsum/mod.rs @@ -0,0 +1 @@ + diff --git a/src/tools/rustfmt/tests/source/configs/reorder_modules/lorem/mod.rs b/src/tools/rustfmt/tests/source/configs/reorder_modules/lorem/mod.rs new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/reorder_modules/lorem/mod.rs @@ -0,0 +1 @@ + diff --git a/src/tools/rustfmt/tests/source/configs/reorder_modules/sit/mod.rs b/src/tools/rustfmt/tests/source/configs/reorder_modules/sit/mod.rs new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/reorder_modules/sit/mod.rs @@ -0,0 +1 @@ + diff --git a/src/tools/rustfmt/tests/source/configs/reorder_modules/true.rs b/src/tools/rustfmt/tests/source/configs/reorder_modules/true.rs new file mode 100644 index 000000000..79b0ab1e3 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/reorder_modules/true.rs @@ -0,0 +1,7 @@ +// rustfmt-reorder_modules: true +// Reorder modules + +mod lorem; +mod ipsum; +mod dolor; +mod sit; diff --git a/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/10.rs b/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/10.rs new file mode 100644 index 000000000..7d0d70919 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/10.rs @@ -0,0 +1,11 @@ +// rustfmt-short_array_element_width_threshold: 10 + +fn main() { + pub const FORMAT_TEST: [u64; 5] = [ + 0x0000000000000000, + 0xaaaaaaaaaaaaaaaa, + 0xbbbbbbbbbbbbbbbb, + 0xcccccccccccccccc, + 0xdddddddddddddddd, + ]; +}
\ No newline at end of file diff --git a/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/20.rs b/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/20.rs new file mode 100644 index 000000000..8a93a51d6 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/20.rs @@ -0,0 +1,11 @@ +// rustfmt-short_array_element_width_threshold: 20 + +fn main() { + pub const FORMAT_TEST: [u64; 5] = [ + 0x0000000000000000, + 0xaaaaaaaaaaaaaaaa, + 0xbbbbbbbbbbbbbbbb, + 0xcccccccccccccccc, + 0xdddddddddddddddd, + ]; +}
\ No newline at end of file diff --git a/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/greater_than_max_width.rs b/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/greater_than_max_width.rs new file mode 100644 index 000000000..710b6fe7c --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/greater_than_max_width.rs @@ -0,0 +1,12 @@ +// rustfmt-max_width: 20 +// rustfmt-short_array_element_width_threshold: 30 + +fn main() { + pub const FORMAT_TEST: [u64; 5] = [ + 0x0000000000000000, + 0xaaaaaaaaaaaaaaaa, + 0xbbbbbbbbbbbbbbbb, + 0xcccccccccccccccc, + 0xdddddddddddddddd, + ]; +} diff --git a/src/tools/rustfmt/tests/source/configs/skip_children/foo/mod.rs b/src/tools/rustfmt/tests/source/configs/skip_children/foo/mod.rs new file mode 100644 index 000000000..d7ff6cdb8 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/skip_children/foo/mod.rs @@ -0,0 +1,3 @@ +fn skip_formatting_this() { + println ! ( "Skip this" ) ; +} diff --git a/src/tools/rustfmt/tests/source/configs/skip_children/true.rs b/src/tools/rustfmt/tests/source/configs/skip_children/true.rs new file mode 100644 index 000000000..e51889dd4 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/skip_children/true.rs @@ -0,0 +1,4 @@ +// rustfmt-skip_children: true + +mod foo ; +mod void; diff --git a/src/tools/rustfmt/tests/source/configs/space_before_colon/true.rs b/src/tools/rustfmt/tests/source/configs/space_before_colon/true.rs new file mode 100644 index 000000000..0a5976025 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/space_before_colon/true.rs @@ -0,0 +1,11 @@ +// rustfmt-space_before_colon: true +// Space before colon + +fn lorem<T : Eq>(t : T) { + let ipsum: Dolor = sit; +} + +const LOREM : Lorem = Lorem { + ipsum : dolor, + sit : amet, +}; diff --git a/src/tools/rustfmt/tests/source/configs/spaces_around_ranges/false.rs b/src/tools/rustfmt/tests/source/configs/spaces_around_ranges/false.rs new file mode 100644 index 000000000..1878c68a5 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/spaces_around_ranges/false.rs @@ -0,0 +1,34 @@ +// rustfmt-spaces_around_ranges: false +// Spaces around ranges + +fn main() { + let lorem = 0 .. 10; + let ipsum = 0 ..= 10; + + match lorem { + 1 .. 5 => foo(), + _ => bar, + } + + match lorem { + 1 ..= 5 => foo(), + _ => bar, + } + + match lorem { + 1 ... 5 => foo(), + _ => bar, + } +} + +fn half_open() { + match [5 .. 4, 99 .. 105, 43 .. 44] { + [_, 99 .., _] => {} + [_, .. 105, _] => {} + _ => {} + }; + + if let ..= 5 = 0 {} + if let .. 5 = 0 {} + if let 5 .. = 0 {} +} diff --git a/src/tools/rustfmt/tests/source/configs/spaces_around_ranges/true.rs b/src/tools/rustfmt/tests/source/configs/spaces_around_ranges/true.rs new file mode 100644 index 000000000..0eadfb285 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/spaces_around_ranges/true.rs @@ -0,0 +1,34 @@ +// rustfmt-spaces_around_ranges: true +// Spaces around ranges + +fn main() { + let lorem = 0..10; + let ipsum = 0..=10; + + match lorem { + 1..5 => foo(), + _ => bar, + } + + match lorem { + 1..=5 => foo(), + _ => bar, + } + + match lorem { + 1...5 => foo(), + _ => bar, + } +} + +fn half_open() { + match [5..4, 99..105, 43..44] { + [_, 99.., _] => {} + [_, ..105, _] => {} + _ => {} + }; + + if let ..=5 = 0 {} + if let ..5 = 0 {} + if let 5.. = 0 {} +} diff --git a/src/tools/rustfmt/tests/source/configs/struct_field_align_threshold/20.rs b/src/tools/rustfmt/tests/source/configs/struct_field_align_threshold/20.rs new file mode 100644 index 000000000..81253c460 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/struct_field_align_threshold/20.rs @@ -0,0 +1,383 @@ +// rustfmt-struct_field_align_threshold: 20 +// rustfmt-normalize_comments: true +// rustfmt-wrap_comments: true +// rustfmt-error_on_line_overflow: false + +struct Foo { + x: u32, + yy: u32, // comment + zzz: u32, +} + +pub struct Bar { + x: u32, + yy: u32, + zzz: u32, + + xxxxxxx: u32, +} + +fn main() { + let foo = Foo { + x: 0, + yy: 1, + zzz: 2, + }; + + let bar = Bar { + x: 0, + yy: 1, + zzz: 2, + + xxxxxxx: 3, + }; +} + + /// A Doc comment +#[AnAttribute] +pub struct Foo { + #[rustfmt::skip] + f : SomeType, // Comment beside a field + f: SomeType, // Comment beside a field + // Comment on a field + #[AnAttribute] + g: SomeOtherType, + /// A doc comment on a field + h: AThirdType, + pub i: TypeForPublicField +} + +// #1029 +pub struct Foo { + #[doc(hidden)] + // This will NOT get deleted! + bar: String, // hi +} + +// #1029 +struct X { + // `x` is an important number. + #[allow(unused)] // TODO: use + x: u32, +} + +// #410 +#[allow(missing_docs)] +pub struct Writebatch<K: Key> { + #[allow(dead_code)] //only used for holding the internal pointer + writebatch: RawWritebatch, + marker: PhantomData<K>, +} + +struct Bar; + +struct NewType(Type, OtherType); + +struct +NewInt <T: Copy>(pub i32, SomeType /* inline comment */, T /* sup */ + + + ); + +struct Qux<'a, + N: Clone + 'a, + E: Clone + 'a, + G: Labeller<'a, N, E> + GraphWalk<'a, N, E>, + W: Write + Copy> +( + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, // Comment + BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB, + #[AnAttr] + // Comment + /// Testdoc + G, + pub W, +); + +struct Tuple(/*Comment 1*/ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, + /* Comment 2 */ BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB,); + +// With a where-clause and generics. +pub struct Foo<'a, Y: Baz> + where X: Whatever +{ + f: SomeType, // Comment beside a field +} + +struct Baz { + + a: A, // Comment A + b: B, // Comment B + c: C, // Comment C + +} + +struct Baz { + a: A, // Comment A + + b: B, // Comment B + + + + + c: C, // Comment C +} + +struct Baz { + + a: A, + + b: B, + c: C, + + + + + d: D + +} + +struct Baz +{ + // Comment A + a: A, + + // Comment B +b: B, + // Comment C + c: C,} + +// Will this be a one-liner? +struct Tuple( + A, //Comment + B +); + +pub struct State<F: FnMut() -> time::Timespec> { now: F } + +pub struct State<F: FnMut() -> ()> { now: F } + +pub struct State<F: FnMut()> { now: F } + +struct Palette { /// A map of indices in the palette to a count of pixels in approximately that color + foo: i32} + +// Splitting a single line comment into a block previously had a misalignment +// when the field had attributes +struct FieldsWithAttributes { + // Pre Comment + #[rustfmt::skip] pub host:String, // Post comment BBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBB BBBBBBBBBBB + //Another pre comment + #[attr1] + #[attr2] pub id: usize // CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCC CCCCCCCCCCCC +} + +struct Deep { + deeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeep: node::Handle<IdRef<'id, Node<K, V>>, + Type, + NodeType>, +} + +struct Foo<T>(T); +struct Foo<T>(T) where T: Copy, T: Eq; +struct Foo<T>(TTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUU); +struct Foo<T>(TTTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTT) where T: PartialEq; +struct Foo<T>(TTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTTTT) where T: PartialEq; +struct Foo<T>(TTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUUUUUUU, TTTTTTTTTTTTTTTTTTT, UUUUUUUUUUUUUUUUUUU) where T: PartialEq; +struct Foo<T>(TTTTTTTTTTTTTTTTT, // Foo + UUUUUUUUUUUUUUUUUUUUUUUU /* Bar */, + // Baz + TTTTTTTTTTTTTTTTTTT, + // Qux (FIXME #572 - doc comment) + UUUUUUUUUUUUUUUUUUU); + +mod m { + struct X<T> where T: Sized { + a: T, + } +} + +struct Foo<T>(TTTTTTTTTTTTTTTTTTT, + /// Qux + UUUUUUUUUUUUUUUUUUU); + +struct Issue677 { + pub ptr: *const libc::c_void, + pub trace: fn( obj: + *const libc::c_void, tracer : *mut JSTracer ), +} + +struct Foo {} +struct Foo { + } +struct Foo { + // comment + } +struct Foo { + // trailing space -> + + + } +struct Foo { /* comment */ } +struct Foo( /* comment */ ); + +struct LongStruct { + a: A, + the_quick_brown_fox_jumps_over_the_lazy_dog:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, +} + +struct Deep { + deeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeep: node::Handle<IdRef<'id, Node<Key, Value>>, + Type, + NodeType>, +} + +struct Foo<C=()>(String); + +// #1364 +fn foo() { + convex_shape.set_point(0, &Vector2f { x: 400.0, y: 100.0 }); + convex_shape.set_point(1, &Vector2f { x: 500.0, y: 70.0 }); + convex_shape.set_point(2, &Vector2f { x: 450.0, y: 100.0 }); + convex_shape.set_point(3, &Vector2f { x: 580.0, y: 150.0 }); +} + +fn main() { + let x = Bar; + + // Comment + let y = Foo {a: x }; + + Foo { a: foo() /* comment*/, /* comment*/ b: bar(), ..something }; + + Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: f(), b: b(), }; + + Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: f(), b: b(), }; + + Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { + // Comment + a: foo(), // Comment + // Comment + b: bar(), // Comment + }; + + Foo { a:Bar, + b:f() }; + + Quux { x: if cond { bar(); }, y: baz() }; + + A { + // Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. + first: item(), + // Praesent et diam eget libero egestas mattis sit amet vitae augue. + // Nam tincidunt congue enim, ut porta lorem lacinia consectetur. + second: Item + }; + + Some(Data::MethodCallData(MethodCallData { + span: sub_span.unwrap(), + scope: self.enclosing_scope(id), + ref_id: def_id, + decl_id: Some(decl_id), + })); + + Diagram { /* o This graph demonstrates how + * / \ significant whitespace is + * o o preserved. + * /|\ \ + * o o o o */ + graph: G, } +} + +fn matcher() { + TagTerminatedByteMatcher { + matcher: ByteMatcher { + pattern: b"<HTML", + mask: b"\xFF\xDF\xDF\xDF\xDF\xFF", + }, + }; +} + +fn issue177() { + struct Foo<T> { memb: T } + let foo = Foo::<i64> { memb: 10 }; +} + +fn issue201() { + let s = S{a:0, .. b}; +} + +fn issue201_2() { + let s = S{a: S2{ .. c}, .. b}; +} + +fn issue278() { + let s = S { + a: 0, + // + b: 0, + }; + let s1 = S { + a: 0, + // foo + // + // bar + b: 0, + }; +} + +fn struct_exprs() { + Foo + { a : 1, b:f( 2)}; + Foo{a:1,b:f(2),..g(3)}; + LoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongStruct { ..base }; + IntrinsicISizesContribution { content_intrinsic_sizes: IntrinsicISizes { minimum_inline_size: 0, }, }; +} + +fn issue123() { + Foo { a: b, c: d, e: f }; + + Foo { a: bb, c: dd, e: ff }; + + Foo { a: ddddddddddddddddddddd, b: cccccccccccccccccccccccccccccccccccccc }; +} + +fn issue491() { + Foo { + guard: None, + arm: 0, // Comment + }; + + Foo { + arm: 0, // Comment + }; + + Foo { a: aaaaaaaaaa, b: bbbbbbbb, c: cccccccccc, d: dddddddddd, /* a comment */ + e: eeeeeeeee }; +} + +fn issue698() { + Record { + ffffffffffffffffffffffffffields: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + }; + Record { + ffffffffffffffffffffffffffields: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + } +} + +fn issue835() { + MyStruct {}; + MyStruct { /* a comment */ }; + MyStruct { + // Another comment + }; + MyStruct {} +} + +fn field_init_shorthand() { + MyStruct { x, y, z }; + MyStruct { x, y, z, .. base }; + Foo { aaaaaaaaaa, bbbbbbbb, cccccccccc, dddddddddd, /* a comment */ + eeeeeeeee }; + Record { ffffffffffffffffffffffffffieldsaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa }; +} diff --git a/src/tools/rustfmt/tests/source/configs/struct_lit_single_line/false.rs b/src/tools/rustfmt/tests/source/configs/struct_lit_single_line/false.rs new file mode 100644 index 000000000..17cad8dde --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/struct_lit_single_line/false.rs @@ -0,0 +1,6 @@ +// rustfmt-struct_lit_single_line: false +// Struct literal multiline-style + +fn main() { + let lorem = Lorem { ipsum: dolor, sit: amet }; +} diff --git a/src/tools/rustfmt/tests/source/configs/tab_spaces/2.rs b/src/tools/rustfmt/tests/source/configs/tab_spaces/2.rs new file mode 100644 index 000000000..5c2667bc2 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/tab_spaces/2.rs @@ -0,0 +1,11 @@ +// rustfmt-tab_spaces: 2 +// rustfmt-max_width: 30 +// rustfmt-indent_style: Block +// Tab spaces + +fn lorem() { +let ipsum = dolor(); +let sit = vec![ +"amet", "consectetur", "adipiscing", "elit." +]; +} diff --git a/src/tools/rustfmt/tests/source/configs/tab_spaces/4.rs b/src/tools/rustfmt/tests/source/configs/tab_spaces/4.rs new file mode 100644 index 000000000..da61bbd42 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/tab_spaces/4.rs @@ -0,0 +1,11 @@ +// rustfmt-tab_spaces: 4 +// rustfmt-max_width: 30 +// rustfmt-indent_style: Block +// Tab spaces + +fn lorem() { +let ipsum = dolor(); +let sit = vec![ +"amet", "consectetur", "adipiscing", "elit." +]; +} diff --git a/src/tools/rustfmt/tests/source/configs/trailing_comma/always.rs b/src/tools/rustfmt/tests/source/configs/trailing_comma/always.rs new file mode 100644 index 000000000..57e874cd8 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/trailing_comma/always.rs @@ -0,0 +1,7 @@ +// rustfmt-trailing_comma: Always +// Trailing comma + +fn main() { + let Lorem { ipsum, dolor, sit, } = amet; + let Lorem { ipsum, dolor, sit, amet, consectetur, adipiscing } = elit; +} diff --git a/src/tools/rustfmt/tests/source/configs/trailing_comma/never.rs b/src/tools/rustfmt/tests/source/configs/trailing_comma/never.rs new file mode 100644 index 000000000..4da3b996f --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/trailing_comma/never.rs @@ -0,0 +1,23 @@ +// rustfmt-trailing_comma: Never +// Trailing comma + +fn main() { + let Lorem { ipsum, dolor, sit, } = amet; + let Lorem { ipsum, dolor, sit, amet, consectetur, adipiscing } = elit; + + // #1544 + if let VrMsg::ClientReply {request_num: reply_req_num, value, ..} = msg { + let _ = safe_assert_eq!(reply_req_num, request_num, op); + return Ok((request_num, op, value)); + } + + // #1710 + pub struct FileInput { + input: StringInput, + file_name: OsString, + } + match len { + Some(len) => Ok(new(self.input, self.pos + len)), + None => Err(self), + } +} diff --git a/src/tools/rustfmt/tests/source/configs/trailing_comma/vertical.rs b/src/tools/rustfmt/tests/source/configs/trailing_comma/vertical.rs new file mode 100644 index 000000000..c903e8221 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/trailing_comma/vertical.rs @@ -0,0 +1,7 @@ +// rustfmt-trailing_comma: Vertical +// Trailing comma + +fn main() { + let Lorem { ipsum, dolor, sit, } = amet; + let Lorem { ipsum, dolor, sit, amet, consectetur, adipiscing } = elit; +} diff --git a/src/tools/rustfmt/tests/source/configs/type_punctuation_density/compressed.rs b/src/tools/rustfmt/tests/source/configs/type_punctuation_density/compressed.rs new file mode 100644 index 000000000..223b9a2f0 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/type_punctuation_density/compressed.rs @@ -0,0 +1,37 @@ +// rustfmt-type_punctuation_density: Compressed +// Type punctuation density + +fn lorem<Ipsum:Dolor+Sit=Amet>() { + // body +} + +struct Foo<T: Eq + Clone, U> +where U: Eq + Clone { + // body +} + +trait Foo<'a, T = usize> +where T: 'a + Eq + Clone +{ + type Bar: Eq + Clone; +} + +trait Foo: Eq + Clone { + // body +} + +impl<T> Foo<'a> for Bar +where for<'a> T: 'a + Eq + Clone +{ + // body +} + +fn foo<'a, 'b, 'c>() +where 'a: 'b + 'c +{ + // body +} + +fn Foo<T = Foo, Output = Expr<'tcx> + Foo>() { + let i = 6; +} diff --git a/src/tools/rustfmt/tests/source/configs/type_punctuation_density/wide.rs b/src/tools/rustfmt/tests/source/configs/type_punctuation_density/wide.rs new file mode 100644 index 000000000..fe0c08167 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/type_punctuation_density/wide.rs @@ -0,0 +1,37 @@ +// rustfmt-type_punctuation_density: Wide +// Type punctuation density + +fn lorem<Ipsum:Dolor+Sit=Amet>() { + // body +} + +struct Foo<T: Eq + Clone, U> +where U: Eq + Clone { + // body +} + +trait Foo<'a, T = usize> +where T: 'a + Eq + Clone +{ + type Bar: Eq + Clone; +} + +trait Foo: Eq + Clone { + // body +} + +impl<T> Foo<'a> for Bar +where for<'a> T: 'a + Eq + Clone +{ + // body +} + +fn foo<'a, 'b, 'c>() +where 'a: 'b + 'c +{ + // body +} + +fn Foo<T = Foo, Output = Expr<'tcx> + Foo>() { + let i = 6; +} diff --git a/src/tools/rustfmt/tests/source/configs/use_field_init_shorthand/false.rs b/src/tools/rustfmt/tests/source/configs/use_field_init_shorthand/false.rs new file mode 100644 index 000000000..4c2eb1de1 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/use_field_init_shorthand/false.rs @@ -0,0 +1,19 @@ +// rustfmt-use_field_init_shorthand: false +// Use field initialization shorthand if possible. + +fn main() { + let a = Foo { + x: x, + y: y, + z: z, + }; + + let b = Bar { + x: x, + y: y, + #[attr] + z: z, + #[rustfmt::skip] + skipped: skipped, + }; +} diff --git a/src/tools/rustfmt/tests/source/configs/use_field_init_shorthand/true.rs b/src/tools/rustfmt/tests/source/configs/use_field_init_shorthand/true.rs new file mode 100644 index 000000000..dcde28d74 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/use_field_init_shorthand/true.rs @@ -0,0 +1,19 @@ +// rustfmt-use_field_init_shorthand: true +// Use field initialization shorthand if possible. + +fn main() { + let a = Foo { + x: x, + y: y, + z: z, + }; + + let b = Bar { + x: x, + y: y, + #[attr] + z: z, + #[rustfmt::skip] + skipped: skipped, + }; +} diff --git a/src/tools/rustfmt/tests/source/configs/use_small_heuristics/default.rs b/src/tools/rustfmt/tests/source/configs/use_small_heuristics/default.rs new file mode 100644 index 000000000..68bc40271 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/use_small_heuristics/default.rs @@ -0,0 +1,25 @@ +// rustfmt-use_small_heuristics: Default + +enum Lorem { + Ipsum, + Dolor(bool), + Sit { + amet: Consectetur, + adipiscing: Elit, + }, +} + +fn main() { + lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing"); + + let lorem = Lorem { + ipsum: dolor, + sit: amet, + }; + + let lorem = if ipsum { + dolor + } else { + sit + }; +} diff --git a/src/tools/rustfmt/tests/source/configs/use_small_heuristics/max.rs b/src/tools/rustfmt/tests/source/configs/use_small_heuristics/max.rs new file mode 100644 index 000000000..8d30932e2 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/use_small_heuristics/max.rs @@ -0,0 +1,25 @@ +// rustfmt-use_small_heuristics: Max + +enum Lorem { + Ipsum, + Dolor(bool), + Sit { + amet: Consectetur, + adipiscing: Elit, + }, +} + +fn main() { + lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing"); + + let lorem = Lorem { + ipsum: dolor, + sit: amet, + }; + + let lorem = if ipsum { + dolor + } else { + sit + }; +} diff --git a/src/tools/rustfmt/tests/source/configs/use_small_heuristics/off.rs b/src/tools/rustfmt/tests/source/configs/use_small_heuristics/off.rs new file mode 100644 index 000000000..f76392d24 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/use_small_heuristics/off.rs @@ -0,0 +1,25 @@ +// rustfmt-use_small_heuristics: Off + +enum Lorem { + Ipsum, + Dolor(bool), + Sit { + amet: Consectetur, + adipiscing: Elit, + }, +} + +fn main() { + lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing"); + + let lorem = Lorem { + ipsum: dolor, + sit: amet, + }; + + let lorem = if ipsum { + dolor + } else { + sit + }; +} diff --git a/src/tools/rustfmt/tests/source/configs/use_try_shorthand/false.rs b/src/tools/rustfmt/tests/source/configs/use_try_shorthand/false.rs new file mode 100644 index 000000000..de7f8b4a5 --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/use_try_shorthand/false.rs @@ -0,0 +1,6 @@ +// rustfmt-use_try_shorthand: false +// Use try! shorthand + +fn main() { + let lorem = try!(ipsum.map(|dolor| dolor.sit())); +} diff --git a/src/tools/rustfmt/tests/source/configs/use_try_shorthand/true.rs b/src/tools/rustfmt/tests/source/configs/use_try_shorthand/true.rs new file mode 100644 index 000000000..9015ec41e --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/use_try_shorthand/true.rs @@ -0,0 +1,6 @@ +// rustfmt-use_try_shorthand: true +// Use try! shorthand + +fn main() { + let lorem = try!(ipsum.map(|dolor| dolor.sit())); +} diff --git a/src/tools/rustfmt/tests/source/configs/where_single_line/true.rs b/src/tools/rustfmt/tests/source/configs/where_single_line/true.rs new file mode 100644 index 000000000..9de98283b --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/where_single_line/true.rs @@ -0,0 +1,26 @@ +// rustfmt-where_single_line: true +// Where style + + +fn lorem_two_items<Ipsum, Dolor, Sit, Amet>() -> T where Ipsum: Eq, Lorem: Eq { + // body +} + +fn lorem_multi_line<Ipsum, Dolor, Sit, Amet>( + a: Aaaaaaaaaaaaaaa, + b: Bbbbbbbbbbbbbbbb, + c: Ccccccccccccccccc, + d: Ddddddddddddddddddddddddd, + e: Eeeeeeeeeeeeeeeeeee, +) -> T +where + Ipsum: Eq, +{ + // body +} + +fn lorem<Ipsum, Dolor, Sit, Amet>() -> T where Ipsum: Eq { + // body +} + +unsafe impl Sync for Foo where (): Send {} diff --git a/src/tools/rustfmt/tests/source/configs/wrap_comments/false.rs b/src/tools/rustfmt/tests/source/configs/wrap_comments/false.rs new file mode 100644 index 000000000..48ecd88ac --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/wrap_comments/false.rs @@ -0,0 +1,8 @@ +// rustfmt-wrap_comments: false +// rustfmt-max_width: 50 +// rustfmt-error_on_line_overflow: false +// Wrap comments + +fn main() { + // Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +} diff --git a/src/tools/rustfmt/tests/source/configs/wrap_comments/true.rs b/src/tools/rustfmt/tests/source/configs/wrap_comments/true.rs new file mode 100644 index 000000000..39a79a4ca --- /dev/null +++ b/src/tools/rustfmt/tests/source/configs/wrap_comments/true.rs @@ -0,0 +1,15 @@ +// rustfmt-wrap_comments: true +// rustfmt-max_width: 50 +// Wrap comments + +fn main() { + // Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +} + +fn code_block() { + // ```rust + // let x = 3; + // + // println!("x = {}", x); + // ``` +} |