-
Notifications
You must be signed in to change notification settings - Fork 888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Catalog Version=Two
formatting differences
#5577
Comments
@calebcartwright I'm happy to help look into this 😁. Would we want to add a |
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 |
@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 |
|
let shape = if context.config.version() == Version::Two { | |
Shape::indented(offset + last_line_width(&result), context.config) | |
} else { | |
generics_shape_from_config( | |
context.config, | |
Shape::indented(offset + last_line_width(&result), context.config), | |
0, | |
)? | |
}; |
Original V1
format
impl<
Target: FromEvent<A> + FromEvent<B>,
A: Widget2<Ctx = C>,
B: Widget2<Ctx = C>,
C: for<'a> CtxFamily<'a>,
> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}
mod foo {
impl<
Target: FromEvent<A> + FromEvent<B>,
A: Widget2<Ctx = C>,
B: Widget2<Ctx = C>,
C: for<'a> CtxFamily<'a>,
> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}
}
@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 |
@ytmimi Cool! That would be awesome. I'll modify the example, in order to add such reference as soon as I can! |
|
let shape = if context.config.version() == Version::Two { | |
Shape::indented(offset + last_line_width(&result), context.config) | |
} else { | |
generics_shape_from_config( | |
context.config, | |
Shape::indented(offset + last_line_width(&result), context.config), | |
0, | |
)? | |
}; |
Original V1
format
impl<
Target: FromEvent<A> + FromEvent<B>,
A: Widget2<Ctx = C>,
B: Widget2<Ctx = C>,
C: for<'a> CtxFamily<'a>,
> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}
mod foo {
impl<
Target: FromEvent<A> + FromEvent<B>,
A: Widget2<Ctx = C>,
B: Widget2<Ctx = C>,
C: for<'a> CtxFamily<'a>,
> Widget2 for WidgetEventLifter<Target, A, B>
{
type Ctx = C;
type Event = Vec<Target>;
}
}
Don't align unrelated trailing comments after items or at the end of blocksReference in codebase
|
Came up with a little script to help us find all the regex="Version::One|Version::Two"
for file in $(rg "$regex" --files-with-matches src);
do
echo "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): Version Usage in src/visitor.rsVersion gate added in #3833
Version Usage in src/utils.rsVersion gate added in #3326
Version gate added in #3284
Version gate added in #5201
Version Usage in src/missed_spans.rsVersion gate added in #3833
Version Usage in src/expr.rsVersion gate added in #3556
Version Usage in src/items.rsVersion 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.rsVersion gate(s) added #4503 commit 63f172d
Version Usage in src/matches.rsVersion gate added (#3250) / updated (#3756)
Version Usage in src/patterns.rsVersion gate added in #4994
Version Usage in src/stmt.rsVersion gate added in #3631
Version Usage in src/overflow.rsVersion gates both added in #3298
Version Usage in src/types.rsVersion gates both added in #3731
Version Usage in src/closures.rsVersion gate added in #3334
Version Usage in src/imports.rsVersion gates added in backport PR #5384
|
Imports with raw identifiers
|
Force block closures for closures with a single
|
Use correct indent when formatting complex fn typeReference in codebase:
V2fn build_sorted_static_get_entry_names(
mut entries: Vec<(u8, &'static str)>,
) -> (
impl Fn(
AlphabeticalTraversal,
Box<dyn dirents_sink::Sink<AlphabeticalTraversal>>,
) -> BoxFuture<'static, Result<Box<dyn dirents_sink::Sealed>, Status>>
+ Send
+ Sync
+ 'static
) {
} V1fn build_sorted_static_get_entry_names(
mut entries: Vec<(u8, &'static str)>,
) -> (impl Fn(
AlphabeticalTraversal,
Box<dyn dirents_sink::Sink<AlphabeticalTraversal>>,
) -> BoxFuture<'static, Result<Box<dyn dirents_sink::Sealed>, Status>>
+ Send
+ Sync
+ 'static) {
} There was some version gates that were also associated with V2 (
|
Consistency between function and macro when overflowing method callsReference in codebase: V2fn main() {
assert!(
HAYSTACK
.par_iter()
.find_any(|&&x| x[0] % 1000 == 999)
.is_some()
);
assert(
HAYSTACK
.par_iter()
.find_any(|&&x| x[0] % 1000 == 999)
.is_some(),
);
} V1fn main() {
assert!(HAYSTACK
.par_iter()
.find_any(|&&x| x[0] % 1000 == 999)
.is_some());
assert(
HAYSTACK
.par_iter()
.find_any(|&&x| x[0] % 1000 == 999)
.is_some(),
);
} |
Consistency between function and macro when deciding to overflow items or keep them on the same lineReference in codebase: V2Overflow rules don't take macro context into account. macro_rules! bar {
($m:ident) => {
$m!([
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z,
]);
$m!([
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
]);
};
} V1Overflow rules do take macro context into account. macro_rules! bar {
($m:ident) => {
$m!([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z,]);
$m!([a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]);
};
} |
Wrap long arrays and slice patternsReference in codebase: V2fn main() {
let [
aaaaaaaaaaaaaaaaaaaaaaaaaa,
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
cccccccccccccccccccccccccc,
ddddddddddddddddddddddddd,
] = panic!();
} V1fn main() {
let [aaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccc, ddddddddddddddddddddddddd] =
panic!();
} |
Nested tuples access without spacesReference in codebase: V2No spaces added fn main() {
let _ = ((1,),).0.0;
} V1A space is added for the nested item access. fn main() {
let _ = ((1,),).0 .0;
} |
Don't Change multi-line string literal indentation inside macroReference in codebase: V2macro_rules! moo {
() => {
bar! {
"
"
}
};
} V1macro_rules! moo {
() => {
bar! {
"
"
}
};
} |
Don't indent strings within commentsReference in codebase: V2pub fn main() {
/* let s = String::from(
"
hello
world
",
); */
assert_eq!(s, "\nhello\nworld\n");
} V1pub fn main() {
/* let s = String::from(
"
hello
world
",
); */
assert_eq!(s, "\nhello\nworld\n");
} |
Don't wrap string literals in Option with
|
Note #6362 pushes those changes to Break function return types before
|
Trailing semicolon for return statements inside a match armReference in codebase: matches::rewrite_match_body V2match arm fn foo() {
match 0 {
0 => {
return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;
}
1 => {
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
}
_ => "",
};
} V1match arm fn foo() {
match 0 {
0 => {
return AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
}
1 => {
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
}
_ => "",
};
} |
Format the last expression-statement as expressionReference in codebase: impl<'a> Rewrite for Stmt<'a> V2fn main() {
let toto = || {
if true { 42 } else { 24 }
};
{ T }
} V1fn main() {
let toto = || {
if true {
42
} else {
24
}
};
{
T
}
} |
Proper indention of single generic bound with multiline formattingReference in codebase: types::join_bounds_inner V2pub trait PrettyPrinter<'tcx>:
Printer<
'tcx,
Error = fmt::Error,
Path = Self,
Region = Self,
Type = Self,
DynExistential = Self,
Const = Self,
>
{
//
}
pub trait PrettyPrinter<'tcx>:
Printer<
'tcx,
Error = fmt::Error,
Path = Self,
Region = Self,
Type = Self,
DynExistential = Self,
Const = Self,
> + fmt::Write
{
//
} V1pub trait PrettyPrinter<'tcx>:
Printer<
'tcx,
Error = fmt::Error,
Path = Self,
Region = Self,
Type = Self,
DynExistential = Self,
Const = Self,
>
{
//
}
pub trait PrettyPrinter<'tcx>:
Printer<
'tcx,
Error = fmt::Error,
Path = Self,
Region = Self,
Type = Self,
DynExistential = Self,
Const = Self,
> + fmt::Write
{
//
} |
TODO: Document #5867 |
TODO: Document #5902 |
TODO: Ensure #4800 is covered somewhere in a human-readable manner |
Consistent handling of macros from the
|
TODO: Document #6000 |
TODO: Document #5582 |
TODO: Document #6092 |
Note to future selves that #5577 (comment) is the one the style team decided we didn't want to keep for 2024 style edition Edit(ytmimi): #6362 pushes those changes to |
TODO: Document #6284 (version sort for imports) |
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
The text was updated successfully, but these errors were encountered: