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

rustfmt should value internal consistency in trait method signatures #4555

Closed
HeroicKatora opened this issue Nov 25, 2020 · 1 comment
Closed
Labels

Comments

@HeroicKatora
Copy link

Input

trait Sample {
    fn bytelen(width: u32, height: u32, samples: u32)
        -> ImageResult<usize>;

    fn from_bytes(bytes: &mut [u8], width: u32, height: u32, samples: u32)
        -> ImageResult<Vec<u8>>;

    fn from_ascii(reader: &mut dyn Read, width: u32, height: u32, samples: u32)
        -> ImageResult<Vec<u8>>;
}

Output

trait Sample {
    fn bytelen(width: u32, height: u32, samples: u32) -> ImageResult<usize>;

    fn from_bytes(mbytes: &mut [u8], width: u32, height: u32, samples: u32)
        -> ImageResult<Vec<u8>>;

    fn from_ascii(
        reader: &mut dyn Read,
        width: u32,
        height: u32,
        samples: u32,
    ) -> ImageResult<Vec<u8>>;
}

Expected output

None of the lines in the Input violate the line length requirements. Thus, I would expect that code is most legible if it has a consistent style and function parameters and return types are placed similarly. Instead, it changes the output to have all three different styles. Another acceptable output would be to change all or at least the second and third method to the fully expanded style.

trait Sample {
    fn bytelen(width: u32, height: u32, samples: u32)
        -> ImageResult<usize>;

    fn from_bytes(bytes: &mut [u8], width: u32, height: u32, samples: u32)
        -> ImageResult<Vec<u8>>;

    fn from_ascii(reader: &mut dyn Read, width: u32, height: u32, samples: u32)
        -> ImageResult<Vec<u8>>;
}

Meta

@HeroicKatora HeroicKatora changed the title rustfmt should value internal consistency rustfmt should value internal consistency in trait method signatures Nov 25, 2020
@calebcartwright
Copy link
Member

Thank you for reaching out @HeroicKatora, however, this is working as designed. The formatting emitted by rustfmt is governed by the Rust Style Guide which prescribes specific formatting guidelines for all code constructs. All of the formatting rules are applied consistently to each node in the AST, and by design those rules are not conditionally applied/broken based on original formatting nor the formatted result of other/"related" elements.

The request here runs counter to the formatting approach of the style guide and thus rustfmt, so going to close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants