Skip to content

Clarify internal programming style #49567

Closed

Description

@varkor

Every so often someone will submit a pull request that is the result of running rustfmt on a particular file, or set of files (examples: #49360, #38567, #30684).

Presumably we want to encourage fixing mistakes in the code style, though at the moment rustfmt can produce undesirable changes (e.g. see the comments in #37349). Without guidelines, these can either be merged directly, or it left up to the individual reviewer to decide which changes are preferred.

It seems to me it would be better to do one of two things:

  • Add rustfmt to tidy and ensure code always adheres to one style.
  • Explicate style guidelines, and then only allow PRs fixing mistakes that haven't been spotted from earlier changes (for example, if rustfmt is too strict or not good enough). I.e. not changing style choices that were the original intention of the author if they're not specified by the style guide.

At the moment, I think style changes are being made, through blind use of rustfmt, that leave the code in a worse state than before. I think it'd be preferable if we could avoid this; does anyone else have thoughts?

Activity

  1. steveklabnik commented on Apr 2, 2018

    @steveklabnik
    Contributor

    The intention has always been that, when rustfmt is ready, projects by the Rust team will use rustfmt with no configuration for its projects. However, rustfmt isn't ready yet, so we haven't gotten there yet.

    I think it'd be preferable if we could avoid this; does anyone else have thoughts?

    Generally, discussions are best had on https://internals.rust-lang.org/ rather than the issue tracker; I'll leave @rust-lang/compiler to decide if this should be moved there, though.

  2. varkor commented on Apr 2, 2018

    @varkor
    ContributorAuthor

    However, rustfmt isn't ready yet, so we haven't gotten there yet.

    In this case, it would seem sensible to discourage "Run rustfmt on [X]"-style PRs in general.

    Generally, discussions are best had on internals.rust-lang.org rather than the issue tracker

    Ah, that's true. I was thinking of it more as a "contribution documentation" omission (i.e. that this should be made clearer somewhere in the repository), but more nuanced discussions (if anyone would be opposed to stating that these kinds of PRs are discouraged until rustfmt better fits rustc's use cases) would best be taken elsewhere.

  3. steveklabnik commented on Apr 2, 2018

    @steveklabnik
    Contributor

    In this case, it would seem sensible to discourage "Run rustfmt on [X]"-style PRs in general.

    Historically, this has been helpful to point out issues in rustfmt to get it to be good enough to get to 1.0 :)

    I was thinking of it more as a "contribution documentation" omission (i.e. that this should be made clearer somewhere in the repository),

    Yes, this is exactly why I didn't close it; if the team wants to document some kind of policy, this is totally a bug, but if there's more disagreement about the policy than I'm aware of (as I'm not on the team) and it needs to be discussed before documenting it, then it'd better be on internals. We'll see!

  4. ehuss commented on Apr 2, 2018

    @ehuss
    Contributor

    Cargo recently attempted this, but just today it was disabled (rust-lang/cargo#5278). It can cause friction with PRs since most people aren't used to running rustfmt all the time.

  5. oli-obk commented on Apr 2, 2018

    @oli-obk
    Contributor

    Clippy tried it a while back, but we disabled it out of the same reason that cargo did so.

    Options that I see:

    • have a bot that pushes a rustfmt commit after every not formatted commit (on open PRs )
    • have bors rustfmt before test
    • run rustfmt regularly with a bot and open rustfmt PRs
  6. nrc commented on Apr 4, 2018

    @nrc
    Member

    We might also be able to solve this on the rustfmt side by pinning to a version number.

  7. nrc commented on Apr 4, 2018

    @nrc
    Member

    At this stage I think that rustfmt formatting is stable enough that re-formatting crates is unlikely to cause much churn, therefore it is fine to land formatting PRs. However, I wouldn't go so far as to encourage it because reviewing and landing them can be a pain.

  8. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
    on Jun 29, 2018
  9. nikomatsakis commented on Oct 30, 2018

    @nikomatsakis
    Contributor

    Closing in favor of discussing on internals

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions