Converting Type Constraints
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Apologies if this has been brought up before but I took a brief look and didn't see anything.
It would be useful if Rustfmt had an option for normalizing type constraints on functions to use where instead of inline. Perhaps it could go the other way too, converting where clauses into inline clauses if it is possible. (not everything that can be done with the where syntax can be done inline, but everything done inline can be done in where clauses)
The idea would be to convert between instances of:
pub fn some_fn<S: AsRef<str>>(arg: S) {}
and:
pub fn some_fn<S>(arg: S)
where
S: AsRef<str>,
{
}
Here is a relevant SO question with an answer that sums up the differences nicely: https://stackoverflow.com/questions/28405621/what-is-the-syntax-and-semantics-of-the-where-keyword
As the SO discussion mentions, the inline syntax is commonly used just because it's more convenient, but the where syntax is more readable. This seems like a perfect use case for Rustfmt to make code more readable, without sacrificing convenience.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing Rustfmt's existing configuration options and handling of function type constraints. Define how normalization should work in both directions, including cases where inline syntax cannot represent a where clause. Done means the behavior is specified, configurable, and covered for the examples and edge cases described in the issue.
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
- 25/100