Skip to content

stdin formatting fails if mod file not found #562

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

Closed
johannhof opened this issue Nov 4, 2015 · 6 comments
Closed

stdin formatting fails if mod file not found #562

johannhof opened this issue Nov 4, 2015 · 6 comments
Labels
bug Panic, non-idempotency, invalid code, etc. p-high

Comments

@johannhof
Copy link
Contributor

echo "mod abc; fn main(){let a =1\n; \n let b = 2;}" | rustfmt

result:

stdin:1:5: 1:8 error: file not found for module `abc`
stdin:1 mod abc; fn main(){let a =1
            ^~~

For file formatting it's quite okay since you have a location to search modules in, but obviously this behavior is not ideal when piping from stdin.

The error is generated by syntex_syntax. Maybe we can parse syntax items more granularly and ignore this kind of error.

@nrc nrc added the bug Panic, non-idempotency, invalid code, etc. label Nov 4, 2015
@nrc nrc removed the bug Panic, non-idempotency, invalid code, etc. label Jan 28, 2016
@matthew-piziak
Copy link

Yeah, this is a problem when fmting files over Emacs TRAMP, for example.

@vadixidav
Copy link

vadixidav commented Mar 31, 2017

Is there a temporary solution to this? For instance, in VS Code can we pass an argument to RLS that will tell it to look in the source directory for the modules?

@vadixidav
Copy link

Also, in VS Code, it automatically switches to the output panel from the problems panel whenever it outputs this error. So every time I save the file, I have to switch panels. Is there a workaround to this as well?

@nrc
Copy link
Member

nrc commented Apr 2, 2017

Hmm, I'm not really sure how to fix this. Even if we get the info from VSCode or emacs or whatever, the hard part is how to communicate that to the parser (and actually if we are getting in to changing the parser, then just stopping at mod statements is probably the easiest and best thing to do). I think the best fix here is just to add a flag to the parser to not parse out of line modules. That doesn't feel like it should be too hard to do. If anyone wants a good first rustc bug, I'd be happy to mentor.

@nrc nrc added bug Panic, non-idempotency, invalid code, etc. p-high labels Apr 5, 2017
@nrc
Copy link
Member

nrc commented May 17, 2017

I have a PR to libsyntax that should fix this, at least on the libsyntax branch - rust-lang/rust#42071

@nrc
Copy link
Member

nrc commented May 28, 2017

This is fixed on the libsyntax branch now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc. p-high
Projects
None yet
Development

No branches or pull requests

4 participants