-
Notifications
You must be signed in to change notification settings - Fork 901
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
normalize_doc_attributes
sometimes comments out code
#3988
Comments
An other example that triggers this: This original (generated) code: pub mod zwp_fullscreen_shell_v1 { impl ZwpFullscreenShellV1 { # [ doc = "present surface for display at a particular mode\n\nIf the value of wl_output.scale differs from wl_surface.buffer_scale,\nthen the compositor may choose a mode that matches either the buffer\nsize or the surface size. In either case, the surface will fill the\noutput." ] pub fn present_surface_for_mode < F > () where F : FnOnce () -> super :: zwp_fullscreen_shell_mode_feedback_v1 :: ZwpFullscreenShellModeFeedbackV1 { } } } gets formatted as pub mod zwp_fullscreen_shell_v1 {
impl ZwpFullscreenShellV1 {
///present surface for display at a particular mode
///
///If the value of wl_output.scale differs from
/// wl_surface.buffer_scale, then the compositor may choose a
/// mode that matches either the buffer size or the surface
/// size. In either case, the surface will fill the output.pub fn present_surface_for_mode < F > () where F : FnOnce () -> super :: zwp_fullscreen_shell_mode_feedback_v1 :: ZwpFullscreenShellModeFeedbackV1{
}
}
} when run using these rustfmt options:
As seen, this comments part of the code. |
Looks like this issue not in "normalize_doc_attributes" but in "max_width" mod a {
mod b {
#[doc = "test"] fn foo() -> (){
}
}
} instead of to add newline mod a {
#[myattr]fn foo() -> () { }
} with mod a {
#[myattr]
fn foo(
) -> (
)
{
}
} But with mod a {
#[myattr] fn foo() -> (){
}
} |
Without attributes mod a {
fn foo() -> () { }
} Output with mod a {
fn foo(
) -> ()
{
}
} Output with mod a {
fn foo(
) -> (
)
{
}
} Output with mod a {
fn foo() -> (){
}
} 6 can be calculated as 4 (result indent of first line) + 2 |
confirming this is still reproducible with |
I hit this today as well: input: impl Client {
#[doc = "comment"] pub async fn key_changes_survey_response_education_organization_target_associations < 'a > (& 'a self , limit : Option < i64 > , max_change_version : Option < i64 > , min_change_version : Option < i64 > , offset : Option < i32 > , total_count : Option < bool > , snapshot_identifier : Option < & 'a str >) -> Result < ResponseValue < Vec < types :: TrackedChangesEdFiSurveyResponseEducationOrganizationTargetAssociationKeyChange > > , Error < () > , >{
todo!()
}
} output: impl Client {
///comment pub async fn key_changes_survey_response_education_organization_target_associations < 'a > (& 'a self , limit : Option < i64 > , max_change_version : Option < i64 > , min_change_version : Option < i64 > , offset : Option < i32 > , total_count : Option < bool > , snapshot_identifier : Option < & 'a str >) -> Result < ResponseValue < Vec < types :: TrackedChangesEdFiSurveyResponseEducationOrganizationTargetAssociationKeyChange > > , Error < () > , >{
todo!()
}
} |
The simplest test case I've been able to come up with so far is this:
with config
This example gets reformatted to the following, although it does report an error because the line exceeds the maximum width.
I'm still not sure exactly what triggers this bug, but have found a lot of variants for this example which don't trigger it. Here are a few that might be significant:
In these examples, removing
max_width=10
fixes the issue, but I encountered this originally in a situation where rustfmt was inexplicably being run on autogenerated files in the target directory that were part of the wayland-protocol crate. I haven't figured out what was causing rustfmt to process those files in the first place, but in that case I did havemax_width=80
instead.I have no clue what's happening or how to fix it at this point, but I'm pretty sure it has to do with formatting lines that are longer than
max_width
combined with some unknown other requirement. I'll try to look into this more soon and see if I can figure out how to fix it.The text was updated successfully, but these errors were encountered: