rust-lang / rust-lang/rustfmt

New option to style `+` in `where` bounds

Open
#4,979 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request P-low
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Coming from #4941. In that issue I suggested that binop_separator be used to control situations such as the following:

pub async fn retrieve_views<'err, E, L, O, P>() -> DynResult<'err, Vec<EmployeeView>>
where
	<E as EmployeeAdapter>::Error: 'err
		+ From<<L as LocationAdapter>::Error>
		+ From<<O as OrganizationAdapter>::Error>
		+ From<<P as PersonAdapter>::Error>
		+ Send,
{

On the above, @calebcartwright said:

Thanks for sharing this observation but binop_separator is by design only applicable to binary expressions, and does not apply to compound constraints regardless of the fact that the latter utilizes one of the same symbols.

[…] If you'd like to have a new config option that could be used to control that behavior in bounds then please open a new issue and we'll take that through the standard process to consider new options.

…which makes sense. However, it leaves rustfmt without a way to configure how constraints are formatted, whereas there are similar options for other contexts (i.e. binop_separator). I personally think this should be configurable, as setting binop_separator to "Back" in a project leaves +-signs at the front in only this case.

I would propose that this new option have the same "Front" and "Back" values available in order to maintain a consistent style across projects.

Thanks for your consideration!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the context in issue #4941 and the existing binop_separator option first. Determine where rustfmt formats compound constraints and how a new Front/Back setting would fit the configuration process; done means the placement of + signs in where bounds can be controlled consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.