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

enum variant doc comments are wrapped before comment_width #5801

Closed
InsertCreativityHere opened this issue Jun 27, 2023 · 4 comments · Fixed by #6000
Closed

enum variant doc comments are wrapped before comment_width #5801

InsertCreativityHere opened this issue Jun 27, 2023 · 4 comments · Fixed by #6000
Assignees
Labels
a-comments fixed-with-v2 The issue is resolved by setting `version = "Two"` in your projects rustfmt.toml

Comments

@InsertCreativityHere
Copy link

InsertCreativityHere commented Jun 27, 2023

Using rustfmt 1.5.3-nightly (5ea66686 2023-06-27), with the following configuration options:

comment_width = 120
wrap_comments = true
unstable_features = true
max_width = 120

Sometimes comments are wrapped after 119 columns instead of the 120 columns I'd expect. It also seems context dependent.

For example, both of these lines are 120 columns, and neither get wrapped.

/// This function is 120 columns wide and is left alone. This comment is 120 columns wide and the formatter is also fine
fn my_super_cool_function_name(my_very_cool_argument_name: String, my_other_very_cool_argument_name: String) -> String {
    unimplemented!()
}

But this comment's line is 120 columns long, and does get wrapped:

pub enum Severity {
    /// But here, this comment is 120 columns wide and the formatter wants to split it up onto two separate lines still.
    Error,
}

I have a little repository demonstrating this: https://github.com/InsertCreativityHere/rustfmt-comment-width-weirdness

@ytmimi
Copy link
Contributor

ytmimi commented Jun 27, 2023

@InsertCreativityHere Thanks for reaching out!

Looks like we're reducing the shape by 1 prematurely in preparation for rewriting the enum variant when we should use the entire shape to rewrite the doc comment (and all other attributes).

@HarrisonHemstreet any interest in taking this one on? Any changes would likely need to be version gated.

rustfmt/src/items.rs

Lines 635 to 637 in 9386b32

// 1 = ','
let shape = self.shape().sub_width(1)?;
let attrs_str = field.attrs.rewrite(&context, shape)?;

@ytmimi ytmimi changed the title comment_width will wrap comments one column early sometimes enum variant doc comments are wrapped before comment_width Jun 27, 2023
@HarrisonHemstreet
Copy link

@rustbot claim

@ytmimi
Copy link
Contributor

ytmimi commented Dec 29, 2023

@IVIURRAY I think this would be a good one to get started with. The issue is that we're using the wrong Shape. This should involve minimal code changes to fix. As I mentioned #5801 (comment), this change needs to be version gated.

@IVIURRAY
Copy link
Contributor

Hey, @ytmimi, thanks for picking this one out, I've started to take a look but I'm finding it rather difficult to get the debugger working for this project. I'm obviously doing something wrong, I posted in Rust's Zulip streams, so hopefully I will get some help there.

At the minute I'm spraying println!() statements everywhere which is not really a great use of my time 😆

@rustbot claim

@ytmimi ytmimi added fixed-with-v2 The issue is resolved by setting `version = "Two"` in your projects rustfmt.toml and removed p-low labels Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments fixed-with-v2 The issue is resolved by setting `version = "Two"` in your projects rustfmt.toml
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants