Rustfmt: stdin formatting fails if mod file not found

Created on 4 Nov 2015  路  6Comments  路  Source: rust-lang/rustfmt

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.

bug p-high

Most helpful comment

This is fixed on the libsyntax branch now

All 6 comments

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

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?

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?

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.

I have a PR to libsyntax that should fix this, at least on the libsyntax branch - https://github.com/rust-lang/rust/pull/42071

This is fixed on the libsyntax branch now

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thomaseizinger picture thomaseizinger  路  3Comments

cramertj picture cramertj  路  4Comments

fuine picture fuine  路  3Comments

jonhoo picture jonhoo  路  4Comments

gnzlbg picture gnzlbg  路  3Comments