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

Pull changes from rust-lang/rust-clippy #72972

Merged
merged 111 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
318b8b6
Add hint for collect type
Mark-Simulacrum May 11, 2020
d4092ac
Merge pull request #5584 from Mark-Simulacrum/beta-next
flip1995 May 11, 2020
221c482
Stabilize str_strip feature
tesuji May 22, 2020
e820a03
iterate List by value
lcnr May 23, 2020
64a05f5
len_zero: skip ranges if feature `range_is_empty` is not enabled
ebroto May 27, 2020
7b49090
clippy_dev: add ra_setup
matthiaskrgr May 27, 2020
a0e9f9b
Merge commit '7ea7cd165ad6705603852771bf82cc2fd6560db5' into clippyup2
flip1995 May 28, 2020
b6c58f0
Temp fix: don't run cargo lint tests in rustc test suite
flip1995 May 28, 2020
28c690e
Rollup merge of #72466 - lzutao:stabilize_str-strip, r=dtolnay
Dylan-DPC May 29, 2020
fcc0e8f
Auto merge of #72671 - flip1995:clippyup, r=Xanewok
bors May 29, 2020
b92cc8a
add testcase that no longer ICEs
matthiaskrgr May 29, 2020
9fd8e10
Return early to avoid ICE
JohnTitor May 30, 2020
5faab87
new lint: vec_resize_to_zero
tnielens May 22, 2020
e6f5dd5
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 May 31, 2020
37381d3
Fix sync fallout
flip1995 May 31, 2020
5713574
Auto merge of #5665 - flip1995:rustup, r=matthiaskrgr
bors May 31, 2020
871f3ed
Auto merge of #5655 - matthiaskrgr:source_mod, r=flip1995
bors May 31, 2020
0fff522
Rollup merge of #5637 - montrivo:feature/vec_resize_to_zero, r=yaahc,…
flip1995 May 31, 2020
873c9fc
Rollup merge of #5656 - ebroto:len_zero_ranges, r=matthiaskrgr
flip1995 May 31, 2020
00c656d
Rollup merge of #5663 - matthiaskrgr:crash_test_3969, r=Manishearth
flip1995 May 31, 2020
0bcfae9
moved cast_ptr_alignment to pedantic and expanded documentation
djugei May 31, 2020
8b191b5
Auto merge of #5666 - flip1995:rollup-yjyvvbg, r=flip1995
bors May 31, 2020
18b5cee
ran update_lints
djugei May 31, 2020
8aa8f42
Auto merge of #5667 - djugei:master, r=flip1995
bors May 31, 2020
6122612
Increase cargo_metadata version to 0.9.1
May 31, 2020
0ab823c
Rework suggestion generation of `unit_arg` lint
flip1995 Aug 26, 2019
380d941
Adapt stderr and fixed files
flip1995 Aug 26, 2019
a1a1a4b
Use multiple span_suggestions instead of multipart_suggestion
flip1995 Aug 26, 2019
0f69caf
Rework suggestion generation and use multipart_suggestion again
flip1995 Feb 17, 2020
f9c325f
Suggest to remove the semicolon of the last stmt in a block
flip1995 Feb 17, 2020
4c9cefa
Move linting out in its own function
flip1995 Feb 18, 2020
6d15a14
Update test files
flip1995 Feb 17, 2020
a9cde3a
Don't suggest to move empty blocks
flip1995 May 31, 2020
77dd0ea
Add tests for empty blocks
flip1995 May 31, 2020
fcc3ed2
Auto merge of #5669 - mikerite:fix-cargo_metadata-0.9, r=phansch
bors May 31, 2020
9fdcb13
Auto merge of #4455 - flip1995:unit_arg_appl, r=phansch
bors May 31, 2020
14e9100
cargo-ui tests: check that <dir>/src exists before processing test
ebroto May 24, 2020
7e84351
Created lint
JarredAllen May 14, 2020
24847ea
Attempted start at sort_by_key_reverse lint
JarredAllen May 16, 2020
8590ab4
More progress towards sort_by_key_reverse lint
JarredAllen May 19, 2020
943cb94
Passes all tests now!
JarredAllen May 20, 2020
955a25e
Added negative test cases and ran cargo dev fmt
JarredAllen May 20, 2020
059e8ed
Detect also a non-reversed comparison
JarredAllen May 25, 2020
07886a9
Detect also when works
JarredAllen May 25, 2020
015ab9f
Renamed to
JarredAllen May 29, 2020
20cb512
Updated test cases and formatted
JarredAllen May 31, 2020
9f9877c
Auto merge of #5662 - ebroto:cargo_tests_invalid_crate, r=flip1995
bors May 31, 2020
32fde0b
New lint: iter_next_slice
esamudera May 25, 2020
7727c4a
CONTRIBUTING: explain how to use cargo dev ra-setup
matthiaskrgr May 28, 2020
6c008d7
Auto merge of #5661 - matthiaskrgr:explain_ra_setup, r=phansch
bors May 31, 2020
9a5baed
Implement suggestions from phansch
JarredAllen May 31, 2020
b89880a
Ran update_lints
JarredAllen May 31, 2020
6955420
Update changelog for stable:1.44 beta:1.45
ebroto May 31, 2020
bee0608
Auto merge of #5623 - JarredAllen:sort_by_key_reverse, r=phansch
bors Jun 1, 2020
ae0ce22
Add regression test for string_lit_as_bytes issue
phansch Jun 1, 2020
861b897
Add regression test for endless loop
phansch Jun 1, 2020
61587c9
Fix some code examples in doc
ThibsG May 27, 2020
262c9dc
Fix more code examples
ThibsG May 29, 2020
1933933
Give more corrected code examples in doc
ThibsG May 31, 2020
9893254
Add more corrected code for doc
ThibsG May 31, 2020
137a3b4
Corrected doc PR fixes
ThibsG Jun 1, 2020
9e89ba9
Add doc for checking if type defines certain method
ThibsG May 31, 2020
bfafb8e
Auto merge of #5673 - phansch:endless-loop, r=Manishearth
bors Jun 1, 2020
a44fa38
Update documentation on changelog updates
ebroto Jun 1, 2020
ea06c72
Call `skip_binder` or `no_bound_vars` before `self_ty`
ecstatic-morse May 23, 2020
f760d77
Auto merge of #5597 - esamudera:slice_iter_next, r=flip1995
bors Jun 2, 2020
5cb9ef3
Auto merge of #5664 - ThibsG:GiveCorrectedCode, r=flip1995
bors Jun 2, 2020
153ef1c
Auto merge of #5672 - phansch:regression-test-env, r=yaahc
bors Jun 2, 2020
fbf0b84
Make use of slice pattern
tesuji Jun 2, 2020
6c833df
Auto merge of #5678 - lzutao:slice, r=flip1995
bors Jun 2, 2020
2b79413
Rename the crates in source code
petrochenkov Jun 2, 2020
dcd4806
Apply suggestions from PR review
ebroto Jun 2, 2020
bd3fc11
Update fulldeps tests and clippy
petrochenkov Jun 2, 2020
b39fd5f
Fix false negative of checked_conversion lint
tesuji Jun 3, 2020
e2fdeec
Auto merge of #5677 - lzutao:checked_conv, r=matthiaskrgr
bors Jun 3, 2020
0c470b3
Bump to 1.46
Mark-Simulacrum Jun 3, 2020
7654125
match_wildcard_for_single_variants: remove empty line at start of lin…
matthiaskrgr Jun 4, 2020
a8957ac
Auto merge of #5681 - matthiaskrgr:empty_line, r=phansch
bors Jun 4, 2020
17bdc96
Merge remote-tracking branch 'upstream/beta' into backport_remerge
flip1995 Jun 5, 2020
f61840d
Auto merge of #5685 - flip1995:backport_remerge, r=flip1995
bors Jun 5, 2020
9ef15ae
Reorder sections of release documentation
flip1995 Jun 5, 2020
af9a094
Auto merge of #5686 - flip1995:release_doc, r=phansch
bors Jun 5, 2020
6fc9939
Auto merge of #5671 - ebroto:changelog_144_145, r=flip1995
bors Jun 5, 2020
6b9e2e9
Replace all remaining occurrences of submodule with subtree
flip1995 Jun 5, 2020
b16d101
Auto merge of #5687 - flip1995:release_doc, r=phansch
bors Jun 5, 2020
413713c
Add error info when cargo metadata fails to run
ebroto Jun 5, 2020
c325c12
Fix cargo ui tests when running inside rust repo
ebroto Jun 5, 2020
ea7066a
Auto merge of #5688 - ebroto:fix_cargo_tests_in_rustc, r=flip1995
bors Jun 5, 2020
b059c0a
Auto merge of #72927 - petrochenkov:rustc, r=Mark-Simulacrum
bors Jun 6, 2020
623faac
Cleanup: Use rustc's `same_types` instead of our `same_tys`
phansch Jun 6, 2020
e6f05ad
Auto merge of #5528 - phansch:same-tys, r=flip1995
bors Jun 6, 2020
5699672
Auto merge of #5674 - ThibsG:DocTypeDefinesMethod, r=yaahc,phansch,fl…
bors Jun 6, 2020
161474b
Rollup merge of #72508 - ecstatic-morse:poly-self-ty, r=nikomatsakis
RalfJung Jun 6, 2020
1a8a69d
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Jun 7, 2020
5bdbc45
Rustup to rust-lang/rust#71796
flip1995 Jun 7, 2020
d9aa26a
Temporarily disable RLS integration test
flip1995 Jun 7, 2020
67ec96c
Auto merge of #5691 - flip1995:rustup, r=matthiaskrgr
bors Jun 7, 2020
dc13016
Make let_and_return a late lint pass
ebroto Jun 2, 2020
9c205d7
Rename let_and_return test for consistency with the lint name
ebroto Jun 6, 2020
dac8a3c
let_and_return: do not lint if last statement borrows
ebroto Jun 6, 2020
ebfc1da
reversed_empty_ranges: don't lint N..N except in for loop arg
ebroto Jun 7, 2020
7b6dc7b
add `unnested_or_patterns` lint
Centril Mar 19, 2020
a664ce7
Remove unnecessary lifetime parameter
ebroto Jun 7, 2020
78f158e
dogfood unnested_or_patterns
Centril Mar 28, 2020
d6136b9
split unnested_or_patterns test
Centril Mar 28, 2020
ecabed6
Apply self-review by Centril
flip1995 Jun 7, 2020
a9ca832
Fix rebase fallout
flip1995 Jun 7, 2020
08b84b3
Auto merge of #5378 - Centril:unnested-or-pats, r=flip1995,phansch
bors Jun 8, 2020
f947644
Auto merge of #5680 - ebroto:3792_let_return, r=Manishearth
bors Jun 8, 2020
ff0993c
Auto merge of #5692 - ebroto:5689_N_dotdot_N, r=yaahc
bors Jun 8, 2020
41c845e
Merge commit 'ff0993c5e9162ddaea78e83d0f0161e68bd4ea73' into clippy
tesuji Jun 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/tools/clippy/.github/workflows/clippy_bors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ jobs:
matrix:
integration:
- 'rust-lang/cargo'
- 'rust-lang/rls'
# FIXME: re-enable once fmt_macros is renamed in RLS
# - 'rust-lang/rls'
- 'rust-lang/chalk'
- 'rust-lang/rustfmt'
- 'Marwes/combine'
Expand Down
87 changes: 84 additions & 3 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,88 @@ document.

## Unreleased / In Rust Nightly

[891e1a8...master](https://github.com/rust-lang/rust-clippy/compare/891e1a8...master)
[7ea7cd1...master](https://github.com/rust-lang/rust-clippy/compare/7ea7cd1...master)

## Rust 1.45

Current beta, release 2020-07-16

[891e1a8...7ea7cd1](https://github.com/rust-lang/rust-clippy/compare/891e1a8...7ea7cd1)

### New lints

* [`match_wildcard_for_single_variants`] [#5582](https://github.com/rust-lang/rust-clippy/pull/5582)
* [`unsafe_derive_deserialize`] [#5493](https://github.com/rust-lang/rust-clippy/pull/5493)
* [`if_let_mutex`] [#5332](https://github.com/rust-lang/rust-clippy/pull/5332)
* [`mismatched_target_os`] [#5506](https://github.com/rust-lang/rust-clippy/pull/5506)
* [`await_holding_lock`] [#5439](https://github.com/rust-lang/rust-clippy/pull/5439)
* [`match_on_vec_items`] [#5522](https://github.com/rust-lang/rust-clippy/pull/5522)
* [`manual_async_fn`] [#5576](https://github.com/rust-lang/rust-clippy/pull/5576)
* [`reversed_empty_ranges`] [#5583](https://github.com/rust-lang/rust-clippy/pull/5583)
* [`manual_non_exhaustive`] [#5550](https://github.com/rust-lang/rust-clippy/pull/5550)

### Moves and Deprecations

* Downgrade [`match_bool`] to pedantic [#5408](https://github.com/rust-lang/rust-clippy/pull/5408)
* Downgrade [`match_wild_err_arm`] to pedantic and update help messages. [#5622](https://github.com/rust-lang/rust-clippy/pull/5622)
* Downgrade [`useless_let_if_seq`] to nursery. [#5599](https://github.com/rust-lang/rust-clippy/pull/5599)
* Generalize `option_and_then_some` and rename to [`bind_instead_of_map`]. [#5529](https://github.com/rust-lang/rust-clippy/pull/5529)
* Rename `identity_conversion` to [`useless_conversion`]. [#5568](https://github.com/rust-lang/rust-clippy/pull/5568)
* Merge `block_in_if_condition_expr` and `block_in_if_condition_stmt` into [`blocks_in_if_conditions`].
[#5563](https://github.com/rust-lang/rust-clippy/pull/5563)
* Merge `option_map_unwrap_or`, `option_map_unwrap_or_else` and `result_map_unwrap_or_else` into [`map_unwrap_or`].
[#5563](https://github.com/rust-lang/rust-clippy/pull/5563)
* Merge `option_unwrap_used` and `result_unwrap_used` into [`unwrap_used`].
[#5563](https://github.com/rust-lang/rust-clippy/pull/5563)
* Merge `option_expect_used` and `result_expect_used` into [`expect_used`].
[#5563](https://github.com/rust-lang/rust-clippy/pull/5563)
* Merge `for_loop_over_option` and `for_loop_over_result` into [`for_loops_over_fallibles`].
[#5563](https://github.com/rust-lang/rust-clippy/pull/5563)

### Enhancements

* Avoid running cargo lints when not enabled to improve performance. [#5505](https://github.com/rust-lang/rust-clippy/pull/5505)
* Extend [`useless_conversion`] with `TryFrom` and `TryInto`. [#5631](https://github.com/rust-lang/rust-clippy/pull/5631)
* Lint also in type parameters and where clauses in [`unused_unit`]. [#5592](https://github.com/rust-lang/rust-clippy/pull/5592)
* Do not suggest deriving `Default` in [`new_without_default`]. [#5616](https://github.com/rust-lang/rust-clippy/pull/5616)

### False Positive Fixes

* [`while_let_on_iterator`] [#5525](https://github.com/rust-lang/rust-clippy/pull/5525)
* [`empty_line_after_outer_attr`] [#5609](https://github.com/rust-lang/rust-clippy/pull/5609)
* [`unnecessary_unwrap`] [#5558](https://github.com/rust-lang/rust-clippy/pull/5558)
* [`comparison_chain`] [#5596](https://github.com/rust-lang/rust-clippy/pull/5596)
* Don't trigger [`used_underscore_binding`] in await desugaring. [#5535](https://github.com/rust-lang/rust-clippy/pull/5535)
* Don't trigger [`borrowed_box`] on mutable references. [#5491](https://github.com/rust-lang/rust-clippy/pull/5491)
* Allow `1 << 0` in [`identity_op`]. [#5602](https://github.com/rust-lang/rust-clippy/pull/5602)
* Allow `use super::*;` glob imports in [`wildcard_imports`]. [#5564](https://github.com/rust-lang/rust-clippy/pull/5564)
* Whitelist more words in [`doc_markdown`]. [#5611](https://github.com/rust-lang/rust-clippy/pull/5611)
* Skip dev and build deps in [`multiple_crate_versions`]. [#5636](https://github.com/rust-lang/rust-clippy/pull/5636)
* Honor `allow` attribute on arguments in [`ptr_arg`]. [#5647](https://github.com/rust-lang/rust-clippy/pull/5647)
* Honor lint level attributes for [`redundant_field_names`], [`just_underscores_and_digits`], [`many_single_char_names`]
and [`similar_names`]. [#5651](https://github.com/rust-lang/rust-clippy/pull/5651)
* Ignore calls to `len` in [`or_fun_call`]. [#4429](https://github.com/rust-lang/rust-clippy/pull/4429)

### Suggestion Improvements

* Simplify suggestions in [`manual_memcpy`]. [#5536](https://github.com/rust-lang/rust-clippy/pull/5536)
* Fix suggestion in [`redundant_pattern_matching`] for macros. [#5511](https://github.com/rust-lang/rust-clippy/pull/5511)
* Avoid suggesting `copied()` for mutable references in [`map_clone`]. [#5530](https://github.com/rust-lang/rust-clippy/pull/5530)
* Improve help message for [`clone_double_ref`]. [#5547](https://github.com/rust-lang/rust-clippy/pull/5547)

### ICE Fixes

* Fix ICE caused in unwrap module. [#5590](https://github.com/rust-lang/rust-clippy/pull/5590)
* Fix ICE on rustc test issue-69020-assoc-const-arith-overflow.rs [#5499](https://github.com/rust-lang/rust-clippy/pull/5499)

### Documentation

* Clarify the documentation of [`unnecessary_mut_passed`]. [#5639](https://github.com/rust-lang/rust-clippy/pull/5639)
* Extend example for [`unneeded_field_pattern`]. [#5541](https://github.com/rust-lang/rust-clippy/pull/5541)

## Rust 1.44

Current beta, release 2020-06-04
Current stable, released 2020-06-04

[204bb9b...891e1a8](https://github.com/rust-lang/rust-clippy/compare/204bb9b...891e1a8)

Expand Down Expand Up @@ -93,7 +170,7 @@ Current beta, release 2020-06-04

## Rust 1.43

Current stable, released 2020-04-23
Released 2020-04-23

[4ee1206...204bb9b](https://github.com/rust-lang/rust-clippy/compare/4ee1206...204bb9b)

Expand Down Expand Up @@ -1401,6 +1478,7 @@ Released 2018-09-13
[`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements
[`iter_cloned_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_cloned_collect
[`iter_next_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_loop
[`iter_next_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_slice
[`iter_nth`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth
[`iter_nth_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth_zero
[`iter_skip_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_next
Expand Down Expand Up @@ -1601,9 +1679,11 @@ Released 2018-09-13
[`unnecessary_fold`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_fold
[`unnecessary_mut_passed`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed
[`unnecessary_operation`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_operation
[`unnecessary_sort_by`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_sort_by
[`unnecessary_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_unwrap
[`unneeded_field_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_field_pattern
[`unneeded_wildcard_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_wildcard_pattern
[`unnested_or_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns
[`unreachable`]: https://rust-lang.github.io/rust-clippy/master/index.html#unreachable
[`unreadable_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#unreadable_literal
[`unsafe_derive_deserialize`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_derive_deserialize
Expand All @@ -1630,6 +1710,7 @@ Released 2018-09-13
[`useless_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_transmute
[`useless_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_vec
[`vec_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#vec_box
[`vec_resize_to_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#vec_resize_to_zero
[`verbose_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#verbose_bit_mask
[`verbose_file_reads`]: https://rust-lang.github.io/rust-clippy/master/index.html#verbose_file_reads
[`vtable_address_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#vtable_address_comparisons
Expand Down
36 changes: 28 additions & 8 deletions src/tools/clippy/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ anything, feel free to ask questions on issues or visit the `#clippy` on [Discor

All contributors are expected to follow the [Rust Code of Conduct].

* [Getting started](#getting-started)
* [Finding something to fix/improve](#finding-something-to-fiximprove)
* [Writing code](#writing-code)
* [How Clippy works](#how-clippy-works)
* [Fixing nightly build failures](#fixing-build-failures-caused-by-rust)
* [Issue and PR Triage](#issue-and-pr-triage)
* [Bors and Homu](#bors-and-homu)
* [Contributions](#contributions)
- [Contributing to Clippy](#contributing-to-clippy)
- [Getting started](#getting-started)
- [Finding something to fix/improve](#finding-something-to-fiximprove)
- [Writing code](#writing-code)
- [Getting code-completion for rustc internals to work](#getting-code-completion-for-rustc-internals-to-work)
- [How Clippy works](#how-clippy-works)
- [Fixing build failures caused by Rust](#fixing-build-failures-caused-by-rust)
- [Issue and PR triage](#issue-and-pr-triage)
- [Bors and Homu](#bors-and-homu)
- [Contributions](#contributions)

[Discord]: https://discord.gg/rust-lang
[Rust Code of Conduct]: https://www.rust-lang.org/policies/code-of-conduct
Expand Down Expand Up @@ -91,6 +93,24 @@ quick read.
[rfc_stability]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#stability-guarantees
[rfc_lint_cats]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#lint-audit-and-categories

## Getting code-completion for rustc internals to work

Unfortunately, [`rust-analyzer`][ra_homepage] does not (yet?) understand how Clippy uses compiler-internals
using `extern crate` and it also needs to be able to read the source files of the rustc-compiler which are not
available via a `rustup` component at the time of writing.
To work around this, you need to have a copy of the [rustc-repo][rustc_repo] available which can be obtained via
`git clone https://github.com/rust-lang/rust/`.
Then you can run a `cargo dev` command to automatically make Clippy use the rustc-repo via path-dependencies
which rust-analyzer will be able to understand.
Run `cargo dev ra-setup --repo-path <repo-path>` where `<repo-path>` is an absolute path to the rustc repo
you just cloned.
The command will add path-dependencies pointing towards rustc-crates inside the rustc repo to
Clippys `Cargo.toml`s and should allow rust-analyzer to understand most of the types that Clippy uses.
Just make sure to remove the dependencies again before finally making a pull request!

[ra_homepage]: https://rust-analyzer.github.io/
[rustc_repo]: https://github.com/rust-lang/rust/

## How Clippy works

[`clippy_lints/src/lib.rs`][lint_crate_entry] imports all the different lint modules and registers in the [`LintStore`].
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ tempfile = { version = "3.1.0", optional = true }
lazy_static = "1.0"

[dev-dependencies]
cargo_metadata = "0.9.0"
cargo_metadata = "0.9.1"
compiletest_rs = { version = "0.5.0", features = ["tmp"] }
tester = "0.7"
lazy_static = "1.0"
Expand Down
3 changes: 2 additions & 1 deletion src/tools/clippy/clippy_dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use walkdir::WalkDir;

pub mod fmt;
pub mod new_lint;
pub mod ra_setup;
pub mod stderr_length_check;
pub mod update_lints;

Expand Down Expand Up @@ -400,7 +401,7 @@ fn test_replace_region_no_changes() {
changed: false,
new_lines: "123\n456\n789".to_string(),
};
let result = replace_region_in_text(text, r#"^\s*123$"#, r#"^\s*456"#, false, || vec![]);
let result = replace_region_in_text(text, r#"^\s*123$"#, r#"^\s*456"#, false, Vec::new);
assert_eq!(expected, result);
}

Expand Down
16 changes: 15 additions & 1 deletion src/tools/clippy/clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg_attr(feature = "deny-warnings", deny(warnings))]

use clap::{App, Arg, SubCommand};
use clippy_dev::{fmt, new_lint, stderr_length_check, update_lints};
use clippy_dev::{fmt, new_lint, ra_setup, stderr_length_check, update_lints};

fn main() {
let matches = App::new("Clippy developer tooling")
Expand Down Expand Up @@ -87,6 +87,19 @@ fn main() {
SubCommand::with_name("limit_stderr_length")
.about("Ensures that stderr files do not grow longer than a certain amount of lines."),
)
.subcommand(
SubCommand::with_name("ra-setup")
.about("Alter dependencies so rust-analyzer can find rustc internals")
.arg(
Arg::with_name("rustc-repo-path")
.long("repo-path")
.short("r")
.help("The path to a rustc repo that will be used for setting the dependencies")
.takes_value(true)
.value_name("path")
.required(true),
),
)
.get_matches();

match matches.subcommand() {
Expand Down Expand Up @@ -115,6 +128,7 @@ fn main() {
("limit_stderr_length", _) => {
stderr_length_check::check();
},
("ra-setup", Some(matches)) => ra_setup::run(matches.value_of("rustc-repo-path")),
_ => {},
}
}
2 changes: 2 additions & 0 deletions src/tools/clippy/clippy_dev/src/new_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ fn get_manifest_contents(lint_name: &str, hint: &str) -> String {
name = "{}"
version = "0.1.0"
publish = false

[workspace]
"#,
hint, lint_name
)
Expand Down
90 changes: 90 additions & 0 deletions src/tools/clippy/clippy_dev/src/ra_setup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#![allow(clippy::filter_map)]

use std::fs;
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;

// This module takes an absolute path to a rustc repo and alters the dependencies to point towards
// the respective rustc subcrates instead of using extern crate xyz.
// This allows rust analyzer to analyze rustc internals and show proper information inside clippy
// code. See https://github.com/rust-analyzer/rust-analyzer/issues/3517 and https://github.com/rust-lang/rust-clippy/issues/5514 for details

pub fn run(rustc_path: Option<&str>) {
// we can unwrap here because the arg is required here
let rustc_path = PathBuf::from(rustc_path.unwrap());
assert!(rustc_path.is_dir(), "path is not a directory");
let rustc_source_basedir = rustc_path.join("src");
assert!(
rustc_source_basedir.is_dir(),
"are you sure the path leads to a rustc repo?"
);

let clippy_root_manifest = fs::read_to_string("Cargo.toml").expect("failed to read ./Cargo.toml");
let clippy_root_lib_rs = fs::read_to_string("src/driver.rs").expect("failed to read ./src/driver.rs");
inject_deps_into_manifest(
&rustc_source_basedir,
"Cargo.toml",
&clippy_root_manifest,
&clippy_root_lib_rs,
)
.expect("Failed to inject deps into ./Cargo.toml");

let clippy_lints_manifest =
fs::read_to_string("clippy_lints/Cargo.toml").expect("failed to read ./clippy_lints/Cargo.toml");
let clippy_lints_lib_rs =
fs::read_to_string("clippy_lints/src/lib.rs").expect("failed to read ./clippy_lints/src/lib.rs");
inject_deps_into_manifest(
&rustc_source_basedir,
"clippy_lints/Cargo.toml",
&clippy_lints_manifest,
&clippy_lints_lib_rs,
)
.expect("Failed to inject deps into ./clippy_lints/Cargo.toml");
}

fn inject_deps_into_manifest(
rustc_source_dir: &PathBuf,
manifest_path: &str,
cargo_toml: &str,
lib_rs: &str,
) -> std::io::Result<()> {
let extern_crates = lib_rs
.lines()
// get the deps
.filter(|line| line.starts_with("extern crate"))
// we have something like "extern crate foo;", we only care about the "foo"
// ↓ ↓
// extern crate rustc_middle;
.map(|s| &s[13..(s.len() - 1)]);

let new_deps = extern_crates.map(|dep| {
// format the dependencies that are going to be put inside the Cargo.toml
format!(
"{dep} = {{ path = \"{source_path}/lib{dep}\" }}\n",
dep = dep,
source_path = rustc_source_dir.display()
)
});

// format a new [dependencies]-block with the new deps we need to inject
let mut all_deps = String::from("[dependencies]\n");
new_deps.for_each(|dep_line| {
all_deps.push_str(&dep_line);
});

// replace "[dependencies]" with
// [dependencies]
// dep1 = { path = ... }
// dep2 = { path = ... }
// etc
let new_manifest = cargo_toml.replacen("[dependencies]\n", &all_deps, 1);

// println!("{}", new_manifest);
let mut file = File::create(manifest_path)?;
file.write_all(new_manifest.as_bytes())?;

println!("Dependency paths injected: {}", manifest_path);

Ok(())
}
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ keywords = ["clippy", "lint", "plugin"]
edition = "2018"

[dependencies]
cargo_metadata = "0.9.0"
cargo_metadata = "0.9.1"
if_chain = "1.0.0"
itertools = "0.9"
lazy_static = "1.0.2"
pulldown-cmark = { version = "0.7", default-features = false }
pulldown-cmark = { version = "0.7.1", default-features = false }
quine-mc_cluskey = "0.2.2"
regex-syntax = "0.6"
serde = { version = "1.0", features = ["derive"] }
Expand Down
4 changes: 4 additions & 0 deletions src/tools/clippy/clippy_lints/src/assign_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ declare_clippy_lint! {
/// let mut a = 5;
/// let b = 0;
/// // ...
/// // Bad
/// a = a + b;
///
/// // Good
/// a += b;
/// ```
pub ASSIGN_OP_PATTERN,
style,
Expand Down
Loading