rustfmt
rustfmt copied to clipboard
Format trailing where clauses in type aliases
Self-explanatory. cc rust-lang/rust#114901
This implementation is probably super busted. I have no idea what most of these options in rustfmt mean, lol.
r? @ytmimi or @fee1-dead
I'd like to hold off on merging this till the next-next sync & release (assuming we are still on track to get let-chains in quickly) given the diff it'll introduce on stable.
Probably worth having common (and uncommon) comments in the test snippets too
I'd like to hold off on merging this till the next-next sync & release (assuming we are still on track to get let-chains in quickly) given the diff it'll introduce on stable.
Sounds good. I think we're still on track to get that out soon. I'll likely have that PR ready later this week. Given that I'll probably hold off on reviewing this until after the next sync.
@ytmimi do you think we should pull this in as part of the next release? I imagine this would need to be prefaced with a blog post and some associated lead time due to the intro of formatting being applied for the first time?
@ytmimi do you think we should pull this in as part of the next release? I imagine this would need to be prefaced with a blog post and some associated lead time due to the intro of formatting being applied for the first time?
@calebcartwright Yeah, I think we could pull this in for the next release. When did you want to do the sync? I'm still up for taking on the subtree push. Maybe we can talk it over on Zulip and find a time that works.
I'm expecting to see some changes now that we actually format trailing where clauses, but let's see what the Diff-Check reveals.
Edit: The job failed but includes a lot of unrelated changes. Going to rebase and run it agin.
Okay, This Diff-Check job shows the diffs I was expecting. @compiler-errors can when you have a chance, can you review the logs and double check that things are formatted here as expected based on the formatting rules you implemented.
For your convenience I'm including the diffs inline: note the output is a diff of diffs, so it might be a little noisy, by the highlighting should help identify the changes
Diff in /tmp/rust-lang-rust-f0yK2vou/library/core/src/ops/async_function.rs:73:
where
<F as FnOnce<A>>::Output: Future,
{
- type CallFuture<'a> = <F as FnOnce<A>>::Output where Self: 'a;
+ type CallFuture<'a>
+ = <F as FnOnce<A>>::Output
+ where
+ Self: 'a;
extern "rust-call" fn async_call(&self, args: A) -> Self::CallFuture<'_> {
self.call(args)
Diff in /tmp/rust-lang-rust-f0yK2vou/library/core/src/ops/async_function.rs:85:
where
<F as FnOnce<A>>::Output: Future,
{
- type CallMutFuture<'a> = <F as FnOnce<A>>::Output where Self: 'a;
+ type CallMutFuture<'a>
+ = <F as FnOnce<A>>::Output
+ where
+ Self: 'a;
extern "rust-call" fn async_call_mut(&mut self, args: A) -> Self::CallMutFuture<'_> {
self.call_mut(args)
Diff in /tmp/rust-lang-rust-f0yK2vou/compiler/rustc_query_system/src/query/caches.rs:32:
pub struct DefaultCacheSelector<K>(PhantomData<K>);
impl<'tcx, K: Eq + Hash, V: 'tcx> CacheSelector<'tcx, V> for DefaultCacheSelector<K> {
- type Cache = DefaultCache<K, V>
+ type Cache
+ = DefaultCache<K, V>
where
V: Copy;
}
Diff in /tmp/rust-lang-rust-f0yK2vou/compiler/rustc_query_system/src/query/caches.rs:84:
pub struct SingleCacheSelector;
impl<'tcx, V: 'tcx> CacheSelector<'tcx, V> for SingleCacheSelector {
- type Cache = SingleCache<V>
+ type Cache
+ = SingleCache<V>
where
V: Copy;
}
Diff in /tmp/rust-lang-rust-f0yK2vou/compiler/rustc_query_system/src/query/caches.rs:126:
pub struct VecCacheSelector<K>(PhantomData<K>);
impl<'tcx, K: Idx, V: 'tcx> CacheSelector<'tcx, V> for VecCacheSelector<K> {
- type Cache = VecCache<K, V>
+ type Cache
+ = VecCache<K, V>
where
V: Copy;
}
Diff in /tmp/rust-lang-rust-f0yK2vou/compiler/rustc_query_system/src/query/caches.rs:177:
pub struct DefIdCacheSelector;
impl<'tcx, V: 'tcx> CacheSelector<'tcx, V> for DefIdCacheSelector {
- type Cache = DefIdCache<V>
+ type Cache
+ = DefIdCache<V>
where
V: Copy;
}
Diff in /tmp/rust-lang-rust-f0yK2vou/src/librustdoc/clean/types.rs:1059:
}
impl AttributesExt for [(Cow<'_, ast::Attribute>, Option<DefId>)] {
- type AttributeIterator<'a> = impl Iterator<Item = ast::NestedMetaItem> + 'a
- where Self: 'a;
- type Attributes<'a> = impl Iterator<Item = &'a ast::Attribute> + 'a
- where Self: 'a;
+ type AttributeIterator<'a>
+ = impl Iterator<Item = ast::NestedMetaItem> + 'a
+ where
+ Self: 'a;
+ type Attributes<'a>
+ = impl Iterator<Item = &'a ast::Attribute> + 'a
+ where
+ Self: 'a;
fn lists<'a>(&'a self, name: Symbol) -> Self::AttributeIterator<'a> {
AttributesExt::iter(self)
@ -7[54](https://github.com/rust-lang/rustfmt/actions/runs/7661954853/job/20882324738#step:4:55)9,0 +7[63](https://github.com/rust-lang/rustfmt/actions/runs/7661954853/job/20882324738#step:4:64)3,7 @@ Diff in /tmp/rust-lang-rust-f0yK2vou/src/tools/rust-analyzer/crates/parser/test_
Diff in /tmp/rust-lang-rust-f0yK2vou/src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/0012_type_item_where_clause.rs:1:
-type Foo = () where Foo: Copy;
+type Foo
+ = ()
+where
+ Foo: Copy;
@ytmimi: Yes, that formatting looks correct. When there is a where clause present, there's always a line break, then = and the type, then a break, then the where clauses.
@ytmimi do you think we should pull this in as part of the next release? I imagine this would need to be prefaced with a blog post and some associated lead time due to the intro of formatting being applied for the first time?
I think all the implementation work for this is done on the rustfmt side!
@calebcartwright I missed the fact that you suggested we get a blog post together for this. I'd be happy to draft something in preparation for the release. Is the idea to have the blog post go out before the release?
@ytmimi: Yes, that formatting looks correct. When there is a where clause present, there's always a line break, then
=and the type, then a break, then the where clauses.
Awesome, thank you for confirming! I'm already anticipating someone asking for a single-line formatting option 😅
@calebcartwright @ytmimi: It's been almost a year since this PR was opened. Is there any chance we could finally get this merged? What's the plan on doing the next rustfmt->rust sync?
@ytmimi thoughts on how to label this one? it isn't technically part of the 2024 edition and can/should go before, but it is definitely something that can't slip past the 2024 edition
Agreed that this one should get in no later than the 2024 edition, and really as soon as we can. Just brainstorming here, but maybe we can label it something like pre-2024-must-have
What I think I'd like to do is get this merged such that it's timed to land with the addition of the style_edition option so that we can have a single blog post highlighting both