Unable to format include! files
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
I have a use-case in which I have sometimes very large mathematical expressions which, for the sake of code clarity, are contained in a separate file and included into the code with the include! macro.
It would be nice if rustfmt could format these included files as well. Currently it is unable to do so as they are not valid rust code on their own.
A very simple example would be:
func.inc.rs
(((8.11757) + ((x) * ((4.49504) + ((x) * ((5.99194) + ((x) * ((6.65951) + ((x) * ((6.32449) + ((x) * ((9.07255) + ((x) * ((9.9719) + ((x) * ((2.7438) + ((x) * ((7.59082) + ((4.21836) * (x))))))))))))))))))).powi(-1)) * ((5.78209) + ((x) * ((4.60331) + ((x) * ((1.60796) + ((x) * ((1.5818) + ((x) * ((5.72673) + ((x) * ((0.879603) + ((x) * ((2.03822) + ((x) * ((5.84432) + ((x) * ((7.51743) + ((5.4175) * (x)))))))))))))))))))
main.rs
fn main() {
let f = |x| include!("func.inc.rs");
// Do something with f
}
Is there any way that rustfmt could format func.inc.rs? Or could this be implemented in the future?
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 reproducing the example with main.rs and func.inc.rs, then inspect how rustfmt handles the include! macro and included source fragments. Define completion as rustfmt formatting func.inc.rs through the include! use case without breaking ordinary Rust formatting, with coverage for the shown example.
Written by the indexing model from the issue text.
Assessment
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100