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

Off-by-one error wrapping comments on struct field #6180

Open
ia0 opened this issue Jun 1, 2024 · 2 comments
Open

Off-by-one error wrapping comments on struct field #6180

ia0 opened this issue Jun 1, 2024 · 2 comments
Labels
a-comments only-with-option requires a non-default option value to reproduce

Comments

@ia0
Copy link

ia0 commented Jun 1, 2024

% rustfmt --version
rustfmt 1.7.0-nightly (8679004 2024-05-23)

Content of src/lib.rs:

/*
0         1         2         3         4         5         6         7         8         9
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
*/

// This line has 100 characters ...................................................................9
pub struct Foo {
    // This line has 100 characters ...............................................................9
    pub foo: u8,
}

pub mod foo {
    // This line has 100 characters ...............................................................9
    pub fn foo() {}
}

Content of rustfmt.toml:

comment_width = 100
wrap_comments = true

Expected formatting is that nothing changes. The file is already correctly formatted.

Actual formatting is the following (the line on the foo field of the Foo struct is wrapped):

/*
0         1         2         3         4         5         6         7         8         9
0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
*/

// This line has 100 characters ...................................................................9
pub struct Foo {
    // This line has 100 characters
    // ...............................................................9
    pub foo: u8,
}

pub mod foo {
    // This line has 100 characters ...............................................................9
    pub fn foo() {}
}

This is probably a minimum reproduction example of #4929, indicating that this is an old issue, and probably not a regression but an off-by-one since the introduction of this feature.

Also I observed that comment_width seems to be capped by max_width although this doesn't seem to be documented. Using comment_width = 200 produces the same off-by-one behavior.

@ia0
Copy link
Author

ia0 commented Jun 1, 2024

Same behavior with variants and with documentation instead of comments. It works correctly with associated items. So this looks specific to structs, enums, and unions. It doesn't apply to traits.

ia0 added a commit to ia0/wasefire that referenced this issue Jun 1, 2024
Note that there is a lot of off-by-one errors because of
rust-lang/rustfmt#6180.
ia0 added a commit to google/wasefire that referenced this issue Jun 1, 2024
Note that there is a lot of off-by-one errors because of
rust-lang/rustfmt#6180.
@ytmimi ytmimi added a-comments only-with-option requires a non-default option value to reproduce labels Jun 4, 2024
@ytmimi
Copy link
Contributor

ytmimi commented Jun 4, 2024

Thanks for the report. Linking the tracking issue for wrap_comments #3347

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments only-with-option requires a non-default option value to reproduce
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants