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

cargo fmt --all completely stops formatting when failing on a single file #3008

Open
matthiaskrgr opened this issue Sep 10, 2018 · 16 comments
Open
Labels
bug Panic, non-idempotency, invalid code, etc. needs-mcve needs a Minimal Complete and Verifiable Example

Comments

@matthiaskrgr
Copy link
Member

meta:
rustc 1.30.0-nightly (2d4e34ca8 2018-09-09)

cargo fmt --version: rustfmt 0.99.4-nightly (1c40881 2018-08-27)
rustfmt --version: rustfmt 0.99.4-nightly (1c40881 2018-08-27)

example crate: clippy

cd clippy_lints
cargo fmt --all

changed files:

    modified:   src/assign_ops.rs
    modified:   src/attrs.rs
cd clippy_lints
fd \.rs  -x rustfmt

changed files:

    modified:   src/assign_ops.rs
    modified:   src/attrs.rs
    modified:   src/blacklisted_name.rs
    modified:   src/block_in_if_condition.rs
    modified:   src/booleans.rs
    modified:   src/bytecount.rs
    modified:   src/const_static_lifetime.rs
    modified:   src/consts.rs
    modified:   src/cyclomatic_complexity.rs
    modified:   src/default_trait_access.rs
    modified:   src/deprecated_lints.rs
    modified:   src/doc.rs
    modified:   src/double_comparison.rs
    modified:   src/double_parens.rs
    modified:   src/drop_forget_ref.rs
    modified:   src/duration_subsec.rs
    modified:   src/else_if_without_else.rs
    modified:   src/empty_enum.rs
    modified:   src/entry.rs
    modified:   src/enum_clike.rs
    modified:   src/enum_glob_use.rs
    modified:   src/enum_variants.rs
    modified:   src/eq_op.rs
    modified:   src/erasing_op.rs
    modified:   src/escape.rs
    modified:   src/eta_reduction.rs
    modified:   src/eval_order_dependence.rs
    modified:   src/excessive_precision.rs
    modified:   src/explicit_write.rs
    modified:   src/fallible_impl_from.rs
    modified:   src/format.rs
    modified:   src/formatting.rs
    modified:   src/functions.rs
    modified:   src/identity_conversion.rs
    modified:   src/identity_op.rs
    modified:   src/if_let_redundant_pattern_matching.rs
    modified:   src/if_not_else.rs
    modified:   src/indexing_slicing.rs
    modified:   src/infallible_destructuring_match.rs
    modified:   src/infinite_iter.rs
    modified:   src/inherent_impl.rs
    modified:   src/inline_fn_without_body.rs
    modified:   src/int_plus_one.rs
    modified:   src/invalid_ref.rs
    modified:   src/items_after_statements.rs
    modified:   src/large_enum_variant.rs
    modified:   src/len_zero.rs
    modified:   src/let_if_seq.rs
    modified:   src/lifetimes.rs
    modified:   src/literal_representation.rs
    modified:   src/loops.rs
    modified:   src/map_clone.rs
    modified:   src/map_unit_fn.rs
    modified:   src/matches.rs
    modified:   src/misc.rs
    modified:   src/misc_early.rs
    modified:   src/missing_doc.rs
    modified:   src/missing_inline.rs
    modified:   src/multiple_crate_versions.rs
    modified:   src/mut_mut.rs
    modified:   src/mut_reference.rs
    modified:   src/mutex_atomic.rs
    modified:   src/needless_bool.rs
    modified:   src/needless_borrow.rs
    modified:   src/needless_borrowed_ref.rs
    modified:   src/needless_pass_by_value.rs
    modified:   src/needless_update.rs
    modified:   src/neg_cmp_op_on_partial_ord.rs
    modified:   src/neg_multiply.rs
    modified:   src/new_without_default.rs
    modified:   src/no_effect.rs
    modified:   src/non_copy_const.rs
    modified:   src/non_expressive_names.rs
    modified:   src/ok_if_let.rs
    modified:   src/open_options.rs
    modified:   src/overflow_check_conditional.rs
    modified:   src/panic_unimplemented.rs
    modified:   src/partialeq_ne_impl.rs
    modified:   src/precedence.rs
    modified:   src/ptr.rs
    modified:   src/ptr_offset_with_cast.rs
    modified:   src/question_mark.rs
    modified:   src/ranges.rs
    modified:   src/redundant_field_names.rs
    modified:   src/reference.rs
    modified:   src/regex.rs
    modified:   src/replace_consts.rs
    modified:   src/returns.rs
    modified:   src/serde_api.rs
    modified:   src/shadow.rs
    modified:   src/strings.rs
    modified:   src/suspicious_trait_impl.rs
    modified:   src/swap.rs
    modified:   src/temporary_assignment.rs
    modified:   src/transmute.rs
    modified:   src/trivially_copy_pass_by_ref.rs
    modified:   src/types.rs
    modified:   src/unicode.rs
    modified:   src/unsafe_removed_from_name.rs
    modified:   src/unused_io_amount.rs
    modified:   src/unused_label.rs
    modified:   src/unwrap.rs
    modified:   src/use_self.rs
    modified:   src/utils/author.rs
    modified:   src/utils/camel_case.rs
    modified:   src/utils/conf.rs
    modified:   src/utils/constants.rs
    modified:   src/utils/higher.rs
    modified:   src/utils/hir_utils.rs
    modified:   src/utils/internal_lints.rs
    modified:   src/utils/ptr.rs
    modified:   src/utils/sugg.rs
    modified:   src/vec.rs
    modified:   src/zero_div_zero.rs

What is going on here?

@topecongiro
Copy link
Contributor

It seems to me that in the latter case rustfmt is not using the expected rustfmt.toml. Could you please try without rustfmt.toml and see if those two still format differently?

@matthiaskrgr
Copy link
Member Author

cargo fmt --all and cargo fmt --all -- --config-path ../rustfmt.toml seem to behave identical
and
fd \.rs -x rustfmt and fd \.rs -x rustfmt --config-path ../rustfmt.toml ; seem to behave identical

@matthiaskrgr
Copy link
Member Author

For the record, I also get the different formatting behavior between cargo fmt --all and rustfmt <file> after removing the rustfmt.toml.

@matthiaskrgr
Copy link
Member Author

I tried to understand how cargo fmt works.

It seems that rustfmt file1 file2 file3 file4 (the cargo fmt strategy) behaves differently from

for i in `find . | grep "\.rs$"`; do
   rustfmt $i
; done

@matthiaskrgr
Copy link
Member Author

When formatting clippy_lints, it seems that rustfmt throws a bad exit status on bit_mask.rs (theres no output in -verbose unfortunately).
I assume what happens is that when formatting everything at once, it fails formatting that file and then stops processing all other files afterwards.

@matthiaskrgr matthiaskrgr changed the title cargo fmt --all and rustfmt format differently cargo fmt --all silently terminates when erroring on a file Sep 12, 2018
@matthiaskrgr matthiaskrgr changed the title cargo fmt --all silently terminates when erroring on a file cargo fmt --all completely stops formatting when failing on a single file Sep 12, 2018
@otavio
Copy link
Contributor

otavio commented Sep 25, 2018

I have the same issue using:

https://github.com/otavio/updatehub

It fails with 101 exit status. Running it on all files does format them but using cargo fmt --all is failing badly.

@otavio
Copy link
Contributor

otavio commented Sep 26, 2018

I found that the option which, in our case, triggers the issue is the wrap_comments[1] and dropping the documentation comments[2] "solve" the problem.

  1. https://github.com/otavio/updatehub/blob/fa057c3956472f850455b2012c262638c37ba08c/.rustfmt.toml#L7
  2. https://github.com/otavio/updatehub/blob/fa057c3956472f850455b2012c262638c37ba08c/src/states/mod.rs#L99-L129

@scampi
Copy link
Contributor

scampi commented Sep 27, 2018

@otavio checking what's wrong with your example, looks like it is the code block.

@otavio
Copy link
Contributor

otavio commented Sep 27, 2018

@otavio checking what's wrong with your example, looks like it is the code block.

Do you mean the diagram?

@scampi
Copy link
Contributor

scampi commented Sep 27, 2018

yes

@otavio
Copy link
Contributor

otavio commented Sep 27, 2018

But why it would abort rustfmt? and more important ... silently?

@otavio
Copy link
Contributor

otavio commented Sep 27, 2018

I reported #3055 with a small test case for the issue.

@otavio
Copy link
Contributor

otavio commented Oct 8, 2018

I'd like to mention that as #3055 has been fixed, this does not happen to me anymore. However, this issue seems to be a general issue which rustfmt may die, and just abort the formatting of the rest of files.

It would be good if it at least prints something on the stderr so the user knows it is stopping the formatting without completing.

@Sytten
Copy link

Sytten commented Apr 15, 2022

This is a very old issue, but I started seeing this problem in tests folders (when using a lib.rs) when the line ending is mixed-up.
I will investigate, but it basically fails silently.
EDIT: It seems to happen when you use very long strings

@hbina
Copy link

hbina commented Jun 11, 2022

Is there a way around this yet? I have a very long and descriptive name like update_transaction_from_database_after_bla_bla plus even more arguments to this function. I suspect this is what causing cargo fmt to just bail out. Is there any reason why this even happen?

@ytmimi
Copy link
Contributor

ytmimi commented Jul 20, 2022

Can anyone provide a link to a repo where this still happens?

@ytmimi ytmimi added bug Panic, non-idempotency, invalid code, etc. needs-mcve needs a Minimal Complete and Verifiable Example labels Jul 20, 2022
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. needs-mcve needs a Minimal Complete and Verifiable Example
Projects
None yet
Development

No branches or pull requests

7 participants