-
Notifications
You must be signed in to change notification settings - Fork 898
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
Fix doc of generic items formmating error #5124
Conversation
TBH I've personally always found the usage of doc comments within generics as odd, but agreed we don't want to have the current rustfmt behavior. The test failures look legitimate so you'll need to address when you get a chance. This doesn't seem like something that should be tracked globally on the rewrite context though, and which should be handled as part of the processing of each param. |
@calebcartwright Thanks for you review. I used doc comments in generic params where there are a few const params representing some configs. Yet in stable rust, I cannot put consts with user-defined types into generics, and instead I used separate const bool or int types as the generic params, which may help the compiler opt out some These const params in generics, I think, is necessary to have some doc comments for their usages. BTW, for this PR, there is still a unresolved problem, that I have precluded the duplicated doc comments of const generic params before rewriting pre-comments of the I could not figure out why Lines 737 to 742 in 8da8371
Here Lines 589 to 600 in 8da8371
Then I read the code in None of them include the attributes. Are there other places where the spans of |
Thanks for the follow up. Wanted to acknowledge having seen the update and that it's on my list to circle back to, though going to be a bit busy for the next week or two so it may be a little while |
Thanks again, and sorry for the delay @frank-king !
You've definitely found an existing issue while working on the original one, and that stems from the Spanned impl for You can find (and if you're still willing) fix that here: https://github.com/rust-lang/rustfmt/blob/master/src/spanned.rs#L114-L127 Where we basically need to account for the presence of attributes what that kind variant too. Also, feel free to adjust the assignment of The other change you have is fine, so once the span issue is adjusted this should be good to go. The last thing to note is that there's no need to include both |
@calebcartwright I have revised the // Non-doc pre-comment of Foo
/// doc of Foo
// Non-doc post-comment of Foo
struct Foo<
// Non-doc pre-comment of 'a
/// doc of 'a
// Non-doc post-comment of 'a
'a,
// Non-doc pre-comment of T
/// doc of T
// Non-doc post-comment of T
T,
// Non-doc pre-comment of N
/// doc of N
// Non-doc post-comment of N
const N: item,
>; becomes // Non-doc pre-comment of Foo
/// doc of Foo
// Non-doc post-comment of Foo
struct Foo<
// Non-doc pre-comment of 'a
/// doc of 'a
'a,
// Non-doc pre-comment of T
/// doc of T
T,
// Non-doc pre-comment of N
/// doc of N
const N: item,
>; I didn't include the post-comments (after their doc-comments) of the generic items because of the above reason. I think this might have lower priority to fix, since only part of the comments are affected, is it? |
Yikes. This is a bit of a mess isn't it. These issues already exist so I don't think we need to block the changes here which do provide some fixes and improvements. If you'd be willing and interested in working on the post comment fix in a follow up PR that'd be most appreciated! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Fixes #5122
The issue has two problems to fix:
The span of a const generic param need to contains its attributes.EDIT: specifically for const generic params, the doc commenta are duplicated twice, because for a const generic param, all of its attributes including the doc comment are treated as part of its pre-comments.