Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to format include! files #3619

Open
JP-Ellis opened this issue Jun 11, 2019 · 1 comment
Open

Unable to format include! files #3619

JP-Ellis opened this issue Jun 11, 2019 · 1 comment

Comments

@JP-Ellis
Copy link

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?

@topecongiro
Copy link
Contributor

Is there any way that rustfmt could format func.inc.rs?

It's not possible with the current implementation for several reasons.

  1. func.inc.rs is not visible to cargo fmt as it's not part of the ast.
  2. If somehow cargo fmt can find it, rustfmt cannot format it because it is not a valid code on its own.

Or could this be implemented in the future?

It's possible, though the priority is low.

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

No branches or pull requests

4 participants