You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To the best of my knowledge we don't have this info captured anywhere in a single place, but it's something we should have. Unfortunately I think the only way to pull this together will be scanning through the source code and trying to reproduce associated snippets with respective constructs.
@ytmimi - if you have bandwidth and are willing to look into it that'd be most appreciated, but no worries if not
@calebcartwright I'm happy to help look into this 😁. Would we want to add a Version Two section to each configuration's documentation or did you have something else in mind in regards to how we'd document the V1 vs V2 formatting differences?
Thanks! The most immediate need is really just an enumeration of the differences in one place, as succinctly as possible. Even something as simple as comments posted on this issue would help in the short term.
Sure! I'll take a look through the codebase to look for all the places where we special case the formatting for Version One or Version Two. I like the idea of compiling all the differences here, and then moving them over to the docs once we've got them mostly listed out. @jmj0502 would there be any interest on your end in helping me work on this?
@ytmimi I'm up for it 🚀! Thanks for taking me into consideration. It would be cool if we can define the structure we'll use to describe each V2 feature as a starting point (the simplest that comes to mind would be title -> snippet). What do you think?
hard_tabs (Indentation for generics on impl blocks)
V2
The examples are taken out of the different test cases available on the master branch (the examples of this change are applied over the generics of impl blocks at top and module levels).
@ytmimi@calebcartwright Please, let me know if there's something else you would like me to add to this code sample (a detailed description, more code, etc.). I plan to use this sample as a template for further examples.
@jmj0502 I like it! This is similar to the approach that I was going to take. I think maybe the only addition that would be nice is a reference to where in the codebase we conditionally check for v2 / v1 formatting.
Indentation for generics on impl blocks (No additional options)
V2
The examples for this particular feature are taken out of the different test cases available on the main branch. The feature is tested on top and module level impl blocks.
The examples for this feature are taken out of different test cases available on the master branch. Such test cases contain long line comments after different const and variable declarations.
pubconstIFF_MULTICAST:::c_int = 0x0000000800;// Supports multicast// Multicast using broadcst. add.pubconstSQ_CRETAB:u16 = 0x000e;// CREATE TABLEpubconstSQ_DRPTAB:u16 = 0x000f;// DROP TABLEpubconstSQ_CREIDX:u16 = 0x0010;// CREATE INDEX//const SQ_DRPIDX: u16 = 0x0011; // DROP INDEX//const SQ_GRANT: u16 = 0x0012; // GRANT//const SQ_REVOKE: u16 = 0x0013; // REVOKEfnfoo(){let f = bar();// Donec consequat mi. Quisque vitae dolor. Integer lobortis. Maecenas id nulla. Lorem.// Id turpis. Nam posuere lectus vitae nibh. Etiam tortor orci, sagittis// malesuada, rhoncus quis, hendrerit eget, libero. Quisque commodo nulla at// nunc. Mauris consequat, enim vitae venenatis sollicitudin, dolor orci// bibendum enim, a sagittis nulla nunc quis elit. Phasellus augue. Nunc// suscipit, magna tincidunt lacinia faucibus, lacus tellus ornare purus, a// pulvinar lacus orci eget nibh. Maecenas sed nibh non lacus tempor faucibus.// In hac habitasse platea dictumst. Vivamus a orci at nulla tristique// condimentum. Donec arcu quam, dictum accumsan, convallis accumsan, cursus sit// amet, ipsum. In pharetra sagittis nunc.let b = baz();let normalized = self.ctfont.all_traits().normalized_weight();// [-1.0, 1.0]// TODO(emilio): It may make sense to make this range [.01, 10.0], to align// with css-fonts-4's range of [1, 1000].}
Original V1 format
pubconstIFF_MULTICAST:::c_int = 0x0000000800;// Supports multicast// Multicast using broadcst. add.pubconstSQ_CRETAB:u16 = 0x000e;// CREATE TABLEpubconstSQ_DRPTAB:u16 = 0x000f;// DROP TABLEpubconstSQ_CREIDX:u16 = 0x0010;// CREATE INDEX//const SQ_DRPIDX: u16 = 0x0011; // DROP INDEX//const SQ_GRANT: u16 = 0x0012; // GRANT//const SQ_REVOKE: u16 = 0x0013; // REVOKEfnfoo(){let f = bar();// Donec consequat mi. Quisque vitae dolor. Integer lobortis. Maecenas id nulla.// Lorem. Id turpis. Nam posuere lectus vitae nibh. Etiam// tortor orci, sagittis malesuada, rhoncus quis, hendrerit eget, libero.// Quisque commodo nulla at nunc. Mauris consequat, enim vitae venenatis// sollicitudin, dolor orci bibendum enim, a sagittis nulla nunc quis elit.// Phasellus augue. Nunc suscipit, magna tincidunt lacinia faucibus, lacus// tellus ornare purus, a pulvinar lacus orci eget nibh. Maecenas sed nibh non// lacus tempor faucibus. In hac habitasse platea dictumst. Vivamus a orci at// nulla tristique condimentum. Donec arcu quam, dictum accumsan, convallis// accumsan, cursus sit amet, ipsum. In pharetra sagittis nunc.let b = baz();let normalized = self.ctfont.all_traits().normalized_weight();// [-1.0, 1.0]// TODO(emilio): It may make sense to make this range [.01, 10.0], to align// with css-fonts-4's range of [1, 1000].}
Came up with a little script to help us find all the Version::One and Version::Two uses throughout the codebase:
regex="Version::One|Version::Two"forfilein$(rg "$regex" --files-with-matches src);doecho"Version Usage in $file"
git --no-pager blame -- $file| rg "$regex" -A 3 -B 3
echo""done
Here's the output with some annotations and references to PRs where the version gates were added. Hoping that the links to PRs can help us get some context for the version gates (and maybe some examples):
efb68ee21 (Seiichi Uchida 2017-12-12 13:48:24 +0900 246) let indent_str = self.block_indent.to_string(self.config);
efb68ee21 (Seiichi Uchida 2017-12-12 13:48:24 +0900 247) self.push_str(&indent_str);
984ac100a (topecongiro 2017-12-22 12:00:24 +0900 248) self.block_indent
fb01dc857 (Stéphane Campinas 2019-10-04 17:22:01 +0200 249) } else if self.config.version() == Version::Two && !snippet.starts_with('\n') {
fb01dc857 (Stéphane Campinas 2019-10-04 17:22:01 +0200 250) // The comment appears on the same line as the previous formatted code.
fb01dc857 (Stéphane Campinas 2019-10-04 17:22:01 +0200 251) // Assuming that comment is logically associated with that code, we want to keep it on
fb01dc857 (Stéphane Campinas 2019-10-04 17:22:01 +0200 252) // the same level and avoid mixing it with possible other comment.
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
There was some version gates that were also associated with indent_style=Visual that were added in #3731 so I thought it might be worth adding the version config in combination with indent_style=Visual.
fnmain(){trace!("get some longer length in here yes yes {} {}","hello","world");debug!("get some longer length in here yes yes {} {}","hello","world");}
V1
The trace! macro is not special cased.
fnmain(){trace!("get some longer length in here yes yes {} {}","hello","world");debug!("get some longer length in here yes yes {} {}","hello","world");}
Note to future selves that #5577 (comment) is the one the style team decided we didn't want to keep for 2024 style edition
Important
Edit(ytmimi) We tried to defer these changes to style_edition=2027 with #6362, but we failed to get r-l/rustfmt synced with r-l/rust in time for the 2024 release so the change made it into the stable style_edition=2024. #6595 reverts #6362.
Activity
ytmimi commentedon Oct 29, 2022
@calebcartwright I'm happy to help look into this 😁. Would we want to add a
Version Two
section to each configuration's documentation or did you have something else in mind in regards to how we'd document theV1
vsV2
formatting differences?calebcartwright commentedon Oct 29, 2022
Thanks! The most immediate need is really just an enumeration of the differences in one place, as succinctly as possible. Even something as simple as comments posted on this issue would help in the short term.
ytmimi commentedon Oct 31, 2022
Sure! I'll take a look through the codebase to look for all the places where we special case the formatting for
Version One
orVersion Two
. I like the idea of compiling all the differences here, and then moving them over to the docs once we've got them mostly listed out. @jmj0502 would there be any interest on your end in helping me work on this?jmj0502 commentedon Oct 31, 2022
@ytmimi I'm up for it 🚀! Thanks for taking me into consideration. It would be cool if we can define the structure we'll use to describe each
V2
feature as a starting point (the simplest that comes to mind would be title -> snippet). What do you think?jmj0502 commentedon Nov 7, 2022
hard_tabs (Indentation for generics on impl blocks)
V2
The examples are taken out of the different test cases available on the master branch (the examples of this change are applied over the generics of
impl
blocks at top and module levels).Reference in code base
items.rs/format_impl_ref_and_type
.rustfmt/src/items.rs
Lines 830 to 838 in ad9fb89
Original
V1
format@ytmimi @calebcartwright Please, let me know if there's something else you would like me to add to this code sample (a detailed description, more code, etc.). I plan to use this sample as a template for further examples.
ytmimi commentedon Nov 7, 2022
@jmj0502 I like it! This is similar to the approach that I was going to take. I think maybe the only addition that would be nice is a reference to where in the codebase we conditionally check for
v2
/v1
formatting.jmj0502 commentedon Nov 7, 2022
@ytmimi Cool! That would be awesome. I'll modify the example, in order to add such reference as soon as I can!
jmj0502 commentedon Nov 7, 2022
Indentation for generics on impl blocks (No additional options)
V2
The examples for this particular feature are taken out of the different test cases available on the main branch. The feature is tested on top and module level
impl
blocks.Reference in codebase
items.rs/format_impl_ref_and_type
.rustfmt/src/items.rs
Lines 830 to 838 in ad9fb89
Original
V1
formatjmj0502 commentedon Nov 15, 2022
Don't align unrelated trailing comments after items or at the end of blocks
Reference in codebase
missed_spans::process_comment
visitor::FmtVisitor::close_block
V2
The examples for this feature are taken out of different test cases available on the
master
branch. Such test cases contain long line comments after differentconst
andvariable
declarations.Original
V1
formatytmimi commentedon Nov 20, 2022
Came up with a little script to help us find all the
Version::One
andVersion::Two
uses throughout the codebase:Here's the output with some annotations and references to PRs where the version gates were added. Hoping that the links to PRs can help us get some context for the version gates (and maybe some examples):
Version Usage in src/visitor.rs
Version gate added in #3833
Version Usage in src/utils.rs
Version gate added in #3326
Version gate added in #3284
Version gate added in #5201
Version Usage in src/missed_spans.rs
Version gate added in #3833
Version Usage in src/expr.rs
Version gate added in #3556
Version Usage in src/items.rs
Version gate added in #3856
Version gate added in #3731
Version gate(s) added in #3294
Version gate(s) added in #3731
Version gate(s) added (#3731) / updated (#3803 some renaming)
Version Usage in src/chains.rs
Version gate(s) added #4503 commit 63f172d
Version Usage in src/matches.rs
Version gate added (#3250) / updated (#3756)
Version Usage in src/patterns.rs
Version gate added in #4994
Version Usage in src/stmt.rs
Version gate added in #3631
Version Usage in src/overflow.rs
Version gates both added in #3298
Version Usage in src/types.rs
Version gates both added in #3731
Version Usage in src/closures.rs
Version gate added in #3334
Version Usage in src/imports.rs
Version gates added in backport PR #5384
ytmimi commentedon Nov 20, 2022
Table of what I found above. Might be useful to track which examples we've already added.
Version Usage in src/visitor.rs
None
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)Version Usage in src/utils.rs
None
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)None
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)Version Usage in src/missed_spans.rs
None
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)Version Usage in src/expr.rs
format_strings=false (default)
-- Examples added in CatalogVersion=Two
formatting differences #5577 (comment)Version Usage in src/items.rs
hard_tabs=true
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)None
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)None
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)None
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)Version Usage in src/chains.rs
None
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)Version Usage in src/matches.rs
None
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)Version Usage in src/patterns.rs
None
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)Version Usage in src/stmt.rs
None
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)Version Usage in src/overflow.rs
None
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)None
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)Version Usage in src/types.rs
None
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)Version Usage in src/closures.rs
None
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)Version Usage in src/imports.rs
reorder_imports=true (default)
-- Example added in CatalogVersion=Two
formatting differences #5577 (comment)ytmimi commentedon Nov 20, 2022
Imports with raw identifiers
reorder_imports=true
(default)Reference in codebase:
impl Ord for UseSegment
V2
V1
Back to table
ytmimi commentedon Nov 21, 2022
Force block closures for closures with a single
loop
body.Reference in codebase:
closures::is_block_closure_forced_inner
V2
loop
s are written with a block closures.V1
loop
s are not forced to be written in a block closures.Back to table
ytmimi commentedon Nov 21, 2022
Use correct indent when formatting complex fn type
Reference in codebase:
impl Rewrite for ast::Ty (ast::TyKindParen)
impl Rewrite for ast::Ty (ast::TyKindImplTrait)
impl Rewrite for ast::FnRetTy (ast::FnRetTy::Ty)
items::rewrite_fn_base
return type indentV2
V1
There was some version gates that were also associated with
indent_style=Visual
that were added in #3731 so I thought it might be worth adding the version config in combination withindent_style=Visual
.V2 (
indent_style=Visual
)V1 (
indent_style=Visual
)Back to table
17 remaining items
ytmimi commentedon Dec 24, 2023
Consistent handling of macros from the
log
crate.Reference in codebase: overflow::OverflowableItem::special_cases
Added in PR #5989
V2
All of the macros are formatted consistently.
V1
The
trace!
macro is not special cased.Back to table
ytmimi commentedon Jan 8, 2024
TODO: Document #6000
ytmimi commentedon Jan 29, 2024
TODO: Document #5582
ytmimi commentedon Mar 12, 2024
TODO: Document #6092
ytmimi commentedon Apr 26, 2024
TODO: Document #6147 / #6148
trailing_semicolon = "Preserve"
#6149calebcartwright commentedon May 4, 2024
Note to future selves that #5577 (comment) is the one the style team decided we didn't want to keep for 2024 style edition
Important
Edit(ytmimi) We tried to defer these changes to
style_edition=2027
with #6362, but we failed to getr-l/rustfmt
synced withr-l/rust
in time for the 2024 release so the change made it into the stablestyle_edition=2024
. #6595 reverts #6362.ytmimi commentedon Sep 3, 2024
TODO: Document #6284 (version sort for imports)
style_edition=2027
#6362