-
Notifications
You must be signed in to change notification settings - Fork 888
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
Use of incorrect width when rewriting nested doc comment can lead to doc comment exceeding the max width #5531
Comments
@laralove143 could you please post the code snippet to help us try and reproduce the issue. |
I really can't reproduce this, it's weird I'll just send the file which still triggers this |
@laralove143 - please keep working at it and try to identify a minimal reproducible example yourself. We really don't like have to work with arbitrary archive files, and the video in the issue description doesn't work. |
What do you mean by doesn't work? And here, it's barely any different than the file with a few unused items removed pub struct Request {
required_permissions: u8,
method: u8,
endpoint: String,
}
impl Request {
/// Creates a new `Request` from the given fields
#[must_use]
pub const fn new(required_permissions: u8, method: u8, endpoint: String) -> Self {
Self {
required_permissions,
method,
endpoint,
}
}
}
struct Foo;
impl Foo {
/// ```rust
/// #[derive(Clone)]
/// struct Bar;
///
/// impl Bar {
/// fn exec(self, guild_id: u8, auto_moderation_rule_id: u8) {
/// Foo.request_with_params(
/// Request::new(
/// 1,
/// 1,
/// format!("/guilds/{guild_id}/auto-moderation/rules/{auto_moderation_rule_id}"),
/// ),
/// self,
/// )
/// }
/// }
/// ```
fn foo(request: Request, params: impl Clone) {}
} |
Thank you! Inline code snippets are always significantly more useful and appreciated than media.
The video doesn't work, doesn't play/shows an error when trying to play, doesn't provide any utility in its current form, etc. It's moot now though, the code snippet is all that matters.
For awareness, there's a decent amount of subtext that comes across in choices of wording like this in the thread. That may be unintentional, but I just wanted to make note of it so that we can keep the conversation constructive and focused on technical aspects. The error you are seeing is due to your usage of the still unstable option error_on_line_overflow, and quoting the docs for that option:
So yes, there's a likely bug here (perhaps two actually), and that's surfacing because you've opted to use this unstable option. Many options remain unstable because there's known (or presumed bugs), so bug reports relating to unstable options are always helpful, thank you! For anyone that wants to have a go at digging into this, I feel like there are at least two items worth exploring:
|
It could also be related to Also is there a way to enable error_on_line_overflow for every line, to force the comments, docs and strings to fit into width as aell |
I took a look at this, and I believe the issue is that we're not setting the correct Lines 733 to 736 in ee2bed9
In this case, rustfmt is just doing what it's designed to do. The issue is that rustfmt doesn't have 100 characters of width to use. It only has 92 (max_width(100) - indent(4) - "/// "(4)).
We can force the doc comment to be written with a max width of 92 in this case by setting using impl Foo {
/// ```rust
/// #[derive(Clone)]
/// struct Bar;
///
/// impl Bar {
/// fn exec(self, guild_id: u8, auto_moderation_rule_id: u8) {
/// Foo.request_with_params(
/// Request::new(
/// 1,
/// 1,
/// format!("/guilds/{guild_id}/auto-moderation/rules/{auto_moderation_rule_id}"),
/// ),
/// self,
/// )
/// }
/// }
/// ```
fn foo(request: Request, params: impl Clone) {}
} output impl Foo {
/// ```rust
/// #[derive(Clone)]
/// struct Bar;
///
/// impl Bar {
/// fn exec(self, guild_id: u8, auto_moderation_rule_id: u8) {
/// Foo.request_with_params(
/// Request::new(
/// 1,
/// 1,
/// format!(
/// "/guilds/{guild_id}/auto-moderation/rules/\
/// {auto_moderation_rule_id}"
/// ),
/// ),
/// self,
/// )
/// }
/// }
/// ```
fn foo(request: Request, params: impl Clone) {}
} This probably brings up a larger question about whether |
My config:
Version:
rustfmt 1.5.1-nightly (84f0c3f7 2022-09-03)
Hard to explain with text so here's a recording:
https://user-images.githubusercontent.com/82576556/188334072-8fb46dd0-e76c-46ce-8f03-8db6a08eb096.mov
It even "fixes" the string being split with
\
The text was updated successfully, but these errors were encountered: