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

Tracking Issue: Fixing broken lint suggestions #3630

Closed
38 of 39 tasks
phansch opened this issue Jan 4, 2019 · 17 comments · Fixed by #4575
Closed
38 of 39 tasks

Tracking Issue: Fixing broken lint suggestions #3630

phansch opened this issue Jan 4, 2019 · 17 comments · Fixed by #4575
Labels
C-tracking-issue Category: Tracking Issue I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@phansch
Copy link
Member

phansch commented Jan 4, 2019

Now that we have rustfix integrated in our testsuite, we can use it to make sure that the suggestions we provide are valid rust code. This will also be useful once cargo fix --clippy is available to users.

This tracking issue is meant to give an overview of how many lints currently provide incorrect suggestions.

Below is the list of tests that include MachineApplicable but incorrect suggestions. For this issue to be closed, we need to add // run-rustfix to all of them and have the tests execute successfully.

If you want to help out with this, feel free to select one file that is not fixed and leave a comment below. Smaller files are most likely easier to fix.

  1. Once you added // run-rustfix to the .rs file run cargo test && tests/ui/update-all-references.sh && cargo test. The tests for your file should fail and it should have generated a *.fixed file
  2. Run rustc tests/ui/<your_test_file>.fixed to see the exact compilation error
  3. Fix the issue (Follow CONTRIBUTING.md and feel free to ask questions)

Files that test lints which need to be fixed

  • tests/ui/assign_ops.rs
  • tests/ui/assign_ops2.rs
  • tests/ui/cmp_owned.rs
  • tests/ui/deref_addrof_double_trigger.rs
  • tests/ui/entry.rs
  • tests/ui/eq_op.rs
  • tests/ui/float_cmp.rs
  • tests/ui/float_cmp_const.rs
  • tests/ui/for_loop.rs
  • tests/ui/identity_conversion.rs
  • tests/ui/implicit_return.rs
  • tests/ui/inline_fn_without_body.rs
  • tests/ui/int_plus_one.rs
  • tests/ui/literals.rs
  • tests/ui/map_flatten.rs
  • tests/ui/mem_discriminant.rs
  • tests/ui/needless_borrow.rs
  • tests/ui/needless_borrowed_ref.rs
  • tests/ui/needless_collect.rs
  • tests/ui/needless_return.rs
  • tests/ui/non_copy_const.rs
  • tests/ui/op_ref.rs (op_ref false positive with deref coercions when comparing #2597)
  • tests/ui/option_map_unit_fn.rs
  • tests/ui/or_fun_call.rs
  • tests/ui/outer_expn_data.rs
  • tests/ui/range_plus_minus_one.rs
  • tests/ui/redundant_closure_call.rs
  • tests/ui/redundant_pattern_matching.rs
  • tests/ui/rename.rs
  • tests/ui/renamed_builtin_attr.rs
  • tests/ui/redundant_static_lifetimes.rs
  • tests/ui/result_map_unit_fn.rs Add run-rustfix for result_map_unit_fn lint #4571
  • tests/ui/short_circuit_statement.rs
  • tests/ui/strings.rs
  • tests/ui/toplevel_ref_arg.rs Add run-rustfix for toplevel_ref_arg lint #4567
  • tests/ui/unnecessary_clone.rs
  • tests/ui/unnecessary_operation.rs
  • tests/ui/wildcard_enum_match_arm.rs Add run-rustfix for wildcard_enum_match_arm lint #4562
  • tests/ui/useless_attribute.rs
@phansch phansch added L-suggestion Lint: Improving, adding or fixing lint suggestions C-tracking-issue Category: Tracking Issue I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Jan 4, 2019
@detrumi
Copy link
Member

detrumi commented Jan 13, 2019

I'm currently going through the list, writing down why each test doesn't work with run-rustfix yet, and fixing the easy ones.

@flip1995
Copy link
Member

Could you share what you write down here, for lints which you don't get to fix, so that future contributors have an easier start?

@detrumi
Copy link
Member

detrumi commented Jan 13, 2019

@flip1995 Was already doing that, but I guess I can just edit my comment while I'm working through the list.

Fixing this myself (PR: #3658)

  • cfg_attr_rustfmt: Custom inner attributes are unstable. Let's disable the lint for inner attributes until #54726 stabilizes
  • collapsible_if: unrelated cyclomatic_complexity warning that can be ignored
  • duration_subsec: Simply needed #![allow(dead_code)]
  • excessive_precision: Fixed by #!allow(dead_code,unused_variables)
  • explicit_write: Fixed by #![allow(unused_imports)]
  • inconsistent_digit_grouping: Triggered unrelated clippy::excessive_precision lint
  • infallible_destructuring_match: Fixed by #![allow(dead_code, unreachable_code, unused_variables)]
  • into_iter_on_ref: Triggered unrelated clippy::useless_vec lint
  • large_digit_groups: Triggered clippy::excessive_precision lint
  • map_clone: Fixed by #![allow(clippy::iter_cloned_collect)]
  • mem_replace: Suggestion causes import to be unused, fixed by #![allow(unused_imports)]
  • precedence: Allow some unrelated lints, and change out-of-range 0b1111_1111i8 literal
  • redundant_field_names: Allow dead code, and remove stabilized feature toggles
  • replace_consts: Fixed by #![allow(unused_variables)]
  • starts_ends_with: Fixed by #![allow(unused_must_use)]
  • types: Fixed by #![allow(dead_code, unused_variables)]
  • unit_arg: Fixed by #[allow(unused_must_use)]
  • unnecessary_fold: Fixed by adding type annotations and adding #![allow(dead_code)]

Not yet fixed

  • bytecount: Suggestions use bytecount crate which probably isn't imported
  • cast: Only cast-lossless is machine-applicable, others like cast_precision_loss aren't. Split the tests?
  • decimal_literal_representation: 4_042_322_160 is out of range for i32, but using 4_042_322_160_u32 leads to a suggestion of 0xF0F0_F0F0, without the _u32
  • expect_fun_call: Excess ) (this suggestion), but fixing that leads to a borrowed value does not live long enough error here
  • fn_to_numeric_cast: The suggestion changes the type (to usize in a function that returns i32)
  • for_loop: Suggests invalid .... Also several other invalid suggestions that result in syntax errors or iterating over ()
  • len_zero: The len_without_is_empty lint triggers because the test defines its own len() function. len_without_is_empty should probably not trigger here.
  • literals: rustfix panics with error Cannot replace slice of data that was already replaced.
  • matches: The suggestions don't seem to be applied (or update-references.sh isn't working)
  • methods: This test does #![warn(clippy::all)] and then whitelists some, but several other lints are triggered that are not in the whitelist. This test needs to be rewritten to trigger less lints, or it should use a blacklist instead
  • needless_bool: Needs #![allow(clippy::no_effect, path_statements, unused_must_use)], and some lint warnings don't have suggestions, such as this if-then-else expression will always return true
  • reference: The test is designed to trigger new lints after applying the suggestions, so it can't use the current run-rustfix (unless you can specify that a line will trigger a lint after applying the suggestion)
  • strings: clippy::string_add currently doesn't give suggestions in all cases yet
  • unnecessary_operation: [42, 55][get_number() as usize]; gets replaced by [42, 55];get_number() as usize;, but that triggers the lint again to replace get_number() as usize; with get_number();
  • use_self: See Clippy recommends use of unstable Self constructors, which cause an ICE #3567
  • useless_asref: It replaces foo_rrrrmr((&&&&MoreRef).as_ref()) with foo_rrrrmr((&&&&MoreRef)), which triggers the unused_parens lint. The lint should probably remove those parens
  • while_loop: This lint makes suggestions like while let Some(_x) = y { .. }, which aren't meant to be machine-applicable (run-rustfix literally places .. there, instead of the code block)

Notes on the process

That's the whole list! Some of these are tricky cases:

  • Suggestions that trigger another lint afterwards. Would it be better to avoid doing that in tests, or should we be able to annotate that it's intended somehow? Maybe common cases like removing extra braces should still be included.
  • Maybe a special case of the above, but what if a lint needs a new import, or removes the last usage of the import? Should the lint be able to add/remove imports?

bors added a commit that referenced this issue Jan 14, 2019
…phansch

Add several run rustfix annotations

Adds `run-rustfix` to 18 of the tests from the tracking issue #3630.
Each test has its own commit, to make reviewing easier (hopefully this is easier to review than 18 separate PRs).

## Changes
- `cfg_attr_rustfmt`: Custom inner attributes are unstable. Let's disable the lint for inner attributes until [#54726](rust-lang/rust#54726) stabilizes
- `collapsible_if`: unrelated cyclomatic_complexity warning that can be ignored
- `duration_subsec`: Simply needed `#![allow(dead_code)]`
- `excessive_precision`: Fixed by `#!allow(dead_code,unused_variables)`
- `explicit_write`: Fixed by `#![allow(unused_imports)]`
- `inconsistent_digit_grouping`: Avoid triggering `clippy::excessive_precision` lint
- `infallible_destructuring_match`: Fixed by `#![allow(dead_code, unreachable_code, unused_variables)]`
- `into_iter_on_ref`: Triggered unrelated `clippy::useless_vec` lint
- `large_digit_groups`: Avoid triggering `clippy::excessive_precision` lint
- `map_clone`: Fixed by `#![allow(clippy::iter_cloned_collect)]`
- `mem_replace`: Suggestion causes import to be unused, fixed by `#![allow(unused_imports)]`
- `precedence`: Allow some unrelated lints, and change out-of-range `0b1111_1111i8` literal
- `redundant_field_names`: Allow dead code, and remove stabilized feature toggles
- `replace_consts`: Fixed by `#![allow(unused_variables)]`
- `starts_ends_with`: Fixed by `#![allow(unused_must_use)]`
- `types`: Fixed by `#![allow(dead_code, unused_variables)]`
- `unit_arg`: Fixed by `#[allow(unused_must_use)]`
- `unnecessary_fold`: Fixed by adding type annotations and adding `#![allow(dead_code)]`
@flip1995
Copy link
Member

Suggestions that trigger another lint afterwards

Sometimes this is unavoidable. If it is somehow possible we should maybe set all Clippy lints to warn/allow in the second pass, where the *.rustfix files are checked.

but what if a lint needs a new import, or removes the last usage of the import? Should the lint be able to add/remove imports

If that's the case, the lint shouldn't be MachineApplicable but MaybeIncorrect.

bors added a commit that referenced this issue Jan 26, 2019
Fix `expect_fun_call` lint suggestions

This commit corrects some bad suggestions produced by the
`expect_fun_call` lint and enables `rust-fix` checking on the tests.

Addresses #3630
g-bartoszek pushed a commit to g-bartoszek/rust-clippy that referenced this issue Feb 5, 2019
This commit corrects some bad suggestions produced by the
`expect_fun_call` lint and enables `rust-fix` checking on the tests.

Addresses rust-lang#3630
g-bartoszek pushed a commit to g-bartoszek/rust-clippy that referenced this issue Feb 7, 2019
This commit corrects some bad suggestions produced by the
`expect_fun_call` lint and enables `rust-fix` checking on the tests.

Addresses rust-lang#3630
@ghost
Copy link

ghost commented Mar 7, 2019

Just a note. If the .fixed file fails to compile due a Clippy warning, you can run

CLIPPY_TESTS=true cargo run --bin clippy-driver tests/ui/<test>.fixed

to see.

bors added a commit that referenced this issue Mar 15, 2019
Enable rustfix for `useless_asref` lint tests

cc #3630
phansch added a commit to phansch/rust-clippy that referenced this issue Apr 10, 2019
@flip1995 flip1995 pinned this issue Apr 10, 2019
bors added a commit that referenced this issue Apr 10, 2019
Add // run-rustfix for eta.rs test

cc #3071, #3630
bors added a commit that referenced this issue Apr 17, 2019
Change while_let_loop applicability to HasPlaceholders

The suggestion has been changed at some point to use `..` in the suggested code.
Due to that we can't make the lint MachineApplicable anymore.

cc #3630
bors added a commit that referenced this issue Apr 17, 2019
Add run-rustfix for deref_addrof lint

* renames `tests/ui/reference.{rs,stderr}` to
  `tests/ui/deref_addrof.{rs,stderr}
* Moves small part of the testfile to a separate file as the lint
  triggered again on the fixed code (as intended)
* Adds `// run-rustfix` to `tests/ui/deref_addrof.rs`

cc #3630
bors added a commit that referenced this issue Apr 17, 2019
@Manishearth
Copy link
Member

Posted #4558, will make more progress tomorrow on the plane.

bors added a commit that referenced this issue Sep 20, 2019
Make more tests rustfixable

Progress towards #3630

r? @phansch
bors added a commit that referenced this issue Sep 20, 2019
Make more tests rustfixable

changelog: Fix various lint suggestions

Progress towards #3630

r? @phansch
bors added a commit that referenced this issue Sep 21, 2019
Make more tests rustfixable

changelog: Fix various lint suggestions

Progress towards #3630

r? @phansch
bors added a commit that referenced this issue Sep 21, 2019
Make more tests rustfixable

changelog: Fix various lint suggestions

Progress towards #3630

r? @phansch
bors added a commit that referenced this issue Sep 21, 2019
Add run-rustfix for wildcard_enum_match_arm lint

cc #3630
bors added a commit that referenced this issue Sep 21, 2019
Add run-rustfix for wildcard_enum_match_arm lint

changelog: none

cc #3630
bors added a commit that referenced this issue Sep 23, 2019
Add run-rustfix for toplevel_ref_arg lint

cc #3630
bors added a commit that referenced this issue Sep 23, 2019
Add run-rustfix for toplevel_ref_arg lint

changelog: none

cc #3630
@Manishearth
Copy link
Member

Manishearth commented Sep 25, 2019

More in #4575

With this and #4571 we have nine left to go!

@Manishearth
Copy link
Member

#4575 contains everything except op_ref.

bors added a commit that referenced this issue Sep 25, 2019
Make more tests rustfixable

Burning through #3630

changelog: Improve suggestions for many lints in preparation for `cargo fix --clippy`

r? @phansch @yaahc
bors added a commit that referenced this issue Sep 25, 2019
Make more tests rustfixable

Burning through #3630

changelog: Improve suggestions for many lints in preparation for `cargo fix --clippy`

r? @phansch @yaahc
bors added a commit that referenced this issue Sep 25, 2019
Make more tests rustfixable

Burning through #3630

changelog: Improve suggestions for many lints in preparation for `cargo fix --clippy`

r? @phansch @yaahc
bors added a commit that referenced this issue Sep 25, 2019
Make more tests rustfixable

Burning through #3630

changelog: Improve suggestions for many lints in preparation for `cargo fix --clippy`

r? @phansch @yaahc
bors added a commit that referenced this issue Sep 25, 2019
Make more tests rustfixable

Burning through #3630

changelog: Improve suggestions for many lints in preparation for `cargo fix --clippy`

r? @phansch @yaahc
@Manishearth
Copy link
Member

I updated #4575 to just mark op_ref as MaybeIncorrect for now. We're done!

@bors bors closed this as completed in 1366629 Sep 25, 2019
@phansch
Copy link
Member Author

phansch commented Sep 26, 2019

Awesome! thanks @Manishearth for finishing this up 🎉

@phansch
Copy link
Member Author

phansch commented Sep 26, 2019

Oh, as a next step, we could probably use the compiletest-rs rustfix coverage tracking to make sure all new MachineApplicable diagnostics have a test file. I'll file a new issue later today.

@Manishearth
Copy link
Member

It would be nice if compiletest had a mode that didn't force you to split files into rustfixable and non-rustfixable, where it tries to fix the code and then rechecks the file, only looking for errors which aren't fixable. We can also check in the .fixed-stderr file in that case. This way we could run-rustfix by default.

@phansch phansch unpinned this issue Oct 2, 2019
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: Tracking Issue I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants