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
{{ message }}
Repository navigation
Doc comments on use declarations are limited to 5 characters less than max_width #5914
If wrap_comments is true, doc comments on use declarations are wrapped to 5 characters less than max_width (or comment_width, if it is less than max_width - 5). This makes it impossible to wrap such comments to the same value as max_width.
Example:
test.rs:
/// a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
/// aa a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
pub use u32;
/// a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
/// aa a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
pub struct X;
After running rustfmt --config wrap_comments=true,comment_width=79,max_width=79 test.rs:
/// a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
/// a a a a a a a a a a aa a a a a a a a a a a a a a a a a a a a a a a a a
/// a a a a a a a a a a a a a a a a a a a a
pub use u32;
/// a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
/// a a a a a a a aa a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
/// a a a a a a a a a a a a a a a
pub struct X;
The comment on the use declaration is wrapped to 74 characters, exactly 5 less than 79. This five-character difference persists across different values of comment_width and max_width, except if comment_width is more than 5 characters less than max_width, both doc comments will be limited to that value.
Thanks for reaching out. #5890 only applies to multi-line block comments so it's unrelated.
The issue here is that we're passing the nested_shape to UseTree::rewrite_top_level, and that shape gets used to rewrite both the import and the attributes.
The use declaration is only 49 characters but gets wrapped anyway. This also happens with the default max_width of 100 (use declarations > 98 characters get wrapped).
@taylordotfish It's possible, though my guess is that they're not related since your original issue describes doc comments on imports wrapping too early when using warp_comments=true, while this second case is about rustfmt wrapping nested use declarations too early when close to the max_width boundary.
I very much appreciate you taking the time to check other edge cases 🙏🏼. Probably best to create a new issue so we can track that separately.
Activity
taylordotfish commentedon Sep 17, 2023
This issue presents similarly to #5890, but I don't know if the cause is similar—I would expect both doc comments to have the same internal shape.
ytmimi commentedon Sep 20, 2023
Thanks for reaching out. #5890 only applies to multi-line block comments so it's unrelated.
The issue here is that we're passing the
nested_shapetoUseTree::rewrite_top_level, and that shape gets used to rewrite both the import and the attributes.rustfmt/src/reorder.rs
Lines 126 to 141 in da7f678
I can think of two possible approaches to fixes this:
nested_shapederivation intoUseTree::rewrite_top_level(which might also obviate the need for Use the same shape to rewrite import when reordering them or not #5307)nested_shapefor rewriting imports and the originalshapefor rewriting attributes toUseTree::rewrite_top_levelytmimi commentedon Sep 20, 2023
linking the tracking issue for
wrap_comments(#3347)taylordotfish commentedon Sep 21, 2023
Is this bug related then?
After
rustfmt --config max_width=50:The
usedeclaration is only 49 characters but gets wrapped anyway. This also happens with the defaultmax_widthof 100 (usedeclarations > 98 characters get wrapped).ytmimi commentedon Sep 22, 2023
@taylordotfish It's possible, though my guess is that they're not related since your original issue describes doc comments on imports wrapping too early when using
warp_comments=true, while this second case is about rustfmt wrapping nested use declarations too early when close to themax_widthboundary.I very much appreciate you taking the time to check other edge cases 🙏🏼. Probably best to create a new issue so we can track that separately.
taylordotfish commentedon Sep 28, 2023
@ytmimi Sure, created #5927.