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

rustfmt silently removes code it can't parse #4315

Closed
fogti opened this issue Jul 10, 2020 · 2 comments · Fixed by #4317
Closed

rustfmt silently removes code it can't parse #4315

fogti opened this issue Jul 10, 2020 · 2 comments · Fixed by #4317
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@fogti
Copy link

fogti commented Jul 10, 2020

Describe the bug

Currently, when rustfmt tries to format code which e.g. uses feature(generic_associated_types), rustfmt produces no error messages, but removes code which causes previously working examples to fail compiling after formatting using rustfmt.

To Reproduce

The following diff describes the change currently performed by rustfmt:

 /// Helper trait for "stripping indention" from an object reference
 pub trait AsUnindented {
-    type Output<'ast> where Self: 'ast;
+    type Output<'ast>;
 
     /// Returns a reference to the unindented part of `Self`
     fn as_unindented<'ast>(&'ast self) -> Self::Output<'ast>;
 }

Expected behavior

Rustfmt should fail with either "Error writing files: failed to resolve mod ...: cannot parse /...rs", or a more concise error message;
and skip the offending modules (not modifying them, except maybe removing simple stuff like trailing whitespace and double-newlines, which don't require fully parsed code) and all submodules of them.

Meta

  • rustfmt version: rustfmt 1.4.18-nightly (c1e9b7b 2020-06-13)
  • From where did you install rustfmt?: rustup
  • How do you run rustfmt: cargo fmt
@fogti fogti added the bug Panic, non-idempotency, invalid code, etc. label Jul 10, 2020
@ayazhafiz
Copy link
Contributor

ayazhafiz commented Jul 10, 2020

rustfmt should bail on non-parseable inputs today; for example,

fn f( {
}

fails quickly with a number of rustc parser error messages. The problem here is probably that rustfmt just isn't try to format the generic bound of the associated type.

@ayazhafiz
Copy link
Contributor

ayazhafiz commented Jul 10, 2020

I think this was fixed (but not yet released) in https://github.com/rust-lang/rustfmt/pull/4106/files#diff-d5afe6fbd84797013d4e4b0fc11d83e9R540-R541 but we don't seem to have any tests for it

ayazhafiz added a commit to ayazhafiz/rustfmt that referenced this issue Jul 10, 2020
This was fixed in 1e9af9f but it seems
that a test was never added.

Closes rust-lang#4315
calebcartwright pushed a commit that referenced this issue Jul 10, 2020
This was fixed in 1e9af9f but it seems
that a test was never added.

Closes #4315
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants