Alignment of let bindings
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Hi!
I really like what rustfmt is doing, however, one thing hurts me strongly here. It allows the vertical alignment of struct fields, but does not allow for such alignment of let bindings. Consider the following code:
impl Scene {
fn new() -> Result<Scene, Error> {
let doc = document()?;
let canvas = doc.get_element_by_id("canvas").ok_or(DOMError::missing("canvas"))?;
let data = Rc::new(SceneData { canvas, context });
let data_weak = Rc::downgrade(&data);
....
}
}
I believe it is much nicer to read the following code:
impl Scene {
fn new() -> Result<Scene, Error> {
let doc = document()?;
let canvas = doc.get_element_by_id("canvas").ok_or(DOMError::missing("canvas"))?;
let data = Rc::new(SceneData { canvas, context });
let data_weak = Rc::downgrade(&data);
....
}
}
Would it be possible to add some treshold option to rustfmt for such a style? :)
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 vertical alignment behavior for struct fields and how formatting options are defined. Determine the scope and semantics of an option for aligning let bindings, including the proposed threshold. Done means the option’s behavior is specified and implemented consistently for the example shown.
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