Skip to content
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

Cargo expand fails to format code with documentation comments #111

Closed
Robbepop opened this issue Jun 14, 2021 · 2 comments
Closed

Cargo expand fails to format code with documentation comments #111

Robbepop opened this issue Jun 14, 2021 · 2 comments

Comments

@Robbepop
Copy link

Robbepop commented Jun 14, 2021

I encountered a problem with documentation comments in Rust code that cause cargo expand to have unformatted blobs of code in its output.
2021-06-14-132407_1436x644_scrot

In the picture above you can clearly see the entirely unformatted section of code next to some properly fomatted sections of code.
The whole things got fixed by manually converting some /// doc comments into normal comments // basically removing them.

I don't yet know whether this also happens with other attributes, however, note that the code does contain other attributes should as #[inline] or certain derives which got expanded properly.

Also note that cargo expand in fact seems to use rustfmt since cargo expand --ugly produces very different output that does not contain these entirely unformatted sections of code. However, code with cargo expand --ugly tends to look more ... ugly in general so it is also not a serious work around for me for now.

You can reproduce the problem with:

const _: () = {
    /// Breaks cargo-expand's formatting
    struct A;
};

This issue seems to be similar to #71.

@dtolnay
Copy link
Owner

dtolnay commented Jun 14, 2021

I would be shocked if this were a cargo-expand issue. Could you report to rustfmt instead, with a minimized repro? Cargo-expand does not control what parts of the file rustfmt would run on.

@Robbepop
Copy link
Author

Robbepop commented Jul 6, 2021

@dtolnay The following minimal code snippet can be reproduced with cargo-expand tool but not with rustfmt tool.

const _: () = {
    /// Breaks cargo-expand's formatting
    struct A;
};

What do you think this could be the reason for this? I opened an issue for the rustfmt tool and the problem is that this code snippet really only works for reproducability with cargo-expand but not rustfmt.

Why cannot we handle this similar to #72 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants