Skip to content

Update Clippy #75405

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

Merged
merged 156 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
156 commits
Select commit Hold shift + click to select a range
442c8ae
Fix FP for `suspicious_arithmetic_impl` from `suspicious_trait_impl` …
ThibsG Jul 18, 2020
51f2a6f
Add documentation for basic Clippy hacking
flip1995 Jul 22, 2020
17903f6
Mention lint naming guidelines earlier
flip1995 Jul 24, 2020
3a4cc9f
Address review comments
flip1995 Jul 24, 2020
b375f1d
Add suggestion for `iter_skip_next` lint
dima74 Jul 25, 2020
d164ab6
Merge commit 'da5a6fb1b65ec6581a67e942a3850f6bc15a552c' into clippyup
flip1995 Jul 26, 2020
f5d429c
Auto merge of #5820 - ThibsG:FixSuspiciousArithmeticImpl, r=flip1995
bors Jul 26, 2020
5a64496
run cargo dev new_lint
Ryan1729 Jul 27, 2020
fc20ee6
move derive_ord_xor_partial_ord into derive mod so we can reuse deriv…
Ryan1729 Jul 27, 2020
0722991
add test for derive_ord_xor_partial_ord based on test for derive_hash…
Ryan1729 Jul 27, 2020
068acbd
initial implementation based on code for `derive_hash_xor_partial_eq`…
Ryan1729 Jul 27, 2020
a8d6eda
use get_trait_def_id to check for Ord trait
Ryan1729 Jul 27, 2020
6c3e459
update reference since we see the expected four errors
Ryan1729 Jul 27, 2020
7dc9748
remove is_local check since getting the def_id directly makes it unne…
Ryan1729 Jul 27, 2020
431924c
add description for derive_ord_xor_partial_ord
Ryan1729 Jul 27, 2020
668b747
run cargo dev fmt and fix overly long line
Ryan1729 Jul 27, 2020
ca03f2b
s/pord/partial_ord/ to fix dogfood failure
Ryan1729 Jul 27, 2020
12a6eee
fill in lint description for DERIVE_ORD_XOR_PARTIAL_ORD
Ryan1729 Jul 27, 2020
94b10a6
run cargo dev update_lints
Ryan1729 Jul 27, 2020
3a9ccff
`chmod` 644 `clippy_lints/src/utils/ast_utils.rs`
giraffate Jul 27, 2020
d3e9db7
Auto merge of #5850 - giraffate:chmod_utils_ats_utils, r=flip1995
bors Jul 27, 2020
dfa1af2
clippy
lcnr Jun 19, 2020
8878708
this might be unqualified, but at least it's now quantified
lcnr Jun 24, 2020
6ce37fa
introduce PredicateAtom
lcnr Jul 8, 2020
133e1d6
clippy
lcnr Jul 27, 2020
94c50bc
Lint duplicate methods of trait bounds
wiomoc Jul 28, 2020
04f4471
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Jul 29, 2020
61eab6e
Auto merge of #5853 - flip1995:rustup, r=flip1995
bors Jul 29, 2020
73764ab
Auto merge of #5840 - flip1995:basics, r=phansch
bors Jul 29, 2020
2e0f8b6
Auto merge of #5843 - dima74:iter_skip_next.add-suggestion, r=phansch
bors Jul 29, 2020
2b7fde6
typo fix
wiomoc Jul 29, 2020
98f3c79
Update clippy ui test.
oli-obk Jul 29, 2020
a427c99
Handle mapping to Option in `map_flatten` lint
dima74 Jul 25, 2020
d4ba561
Review fixes
dima74 Jul 30, 2020
aa3d9ca
Rename HAIR to THIR (Typed HIR).
Lezzz Jul 21, 2020
cb00cdf
Remove old Symbol reexport
phansch Aug 2, 2020
bb6e857
fmt
phansch Aug 2, 2020
24a6130
fix typos
Aug 2, 2020
e336fe8
manual_async_fn: take input lifetimes into account
ebroto Aug 2, 2020
05bb6e6
Create test for wanted behavior
JarredAllen Jul 20, 2020
3ee6137
Write the lint and write tests
JarredAllen Jul 23, 2020
3657c92
Check for other things which can be used indirectly
JarredAllen Jul 23, 2020
c86f410
Split indirect collects into their own test case
JarredAllen Jul 23, 2020
a849483
Fix formatting and dogfood fallout
JarredAllen Jul 23, 2020
bb2c14e
Fix a bug causing it to be too trigger-happy
JarredAllen Jul 23, 2020
5e10b03
Implement review suggestions
JarredAllen Aug 3, 2020
e521c67
early return on empty parameters/where clause
wiomoc Aug 3, 2020
0e44ed5
Fix ui-cargo tests in CI
flip1995 Aug 3, 2020
bbbc973
Auto merge of #5864 - rust-lang:ci_debug, r=Manishearth
bors Aug 3, 2020
25abd7a
Create stable_sort_primitive lint
JarredAllen Jul 9, 2020
e967710
try_err: Consider Try impl for Poll when generating suggestions
tmiasko Aug 2, 2020
0ccdf29
Remove obsolete known problems unnecessary_fold
camsteffen Aug 3, 2020
52a9c15
rustc_ast: `(Nested)MetaItem::check_name` -> `has_name`
petrochenkov Aug 2, 2020
1968aed
Auto merge of #5867 - flip1995:rustup, r=flip1995
bors Aug 4, 2020
ca2a25d
Rollup merge of #5837 - JarredAllen:needless_collect, r=phansch
flip1995 Aug 4, 2020
378ba2e
Rollup merge of #5846 - dima74:map_flatten.map_to_option, r=flip1995
flip1995 Aug 4, 2020
888067c
Rollup merge of #5848 - Ryan1729:add-derive_ord_xor_partial_ord-lint,…
flip1995 Aug 4, 2020
84455b2
Rollup merge of #5852 - wiomoc:feature/lint-duplicate-trait, r=Manish…
flip1995 Aug 4, 2020
fb7ad95
Rollup merge of #5856 - phansch:remove-symbol-reexport, r=flip1995
flip1995 Aug 4, 2020
8012178
Auto merge of #5868 - flip1995:rollup-5g8vft5, r=flip1995
bors Aug 4, 2020
2ceb8c6
Auto merge of #5865 - camsteffen:unnecessary-fold-known-probs, r=Mani…
bors Aug 4, 2020
542740c
Run cargo dev fmt
JarredAllen Aug 5, 2020
3d7e3fd
Auto merge of #5857 - tmiasko:try-err-poll, r=matthiaskrgr
bors Aug 5, 2020
1e8ada3
Add lint `same_item_push`
giraffate Jul 18, 2020
161f475
Add test case for `same_item_push`
giraffate Jul 19, 2020
2beb909
Rename TypeckTables to TypeckResults
giraffate Jul 20, 2020
1543e11
cargo dev update_lints
giraffate Jul 20, 2020
14a4e3b
Fix a lint message
giraffate Jul 20, 2020
b7ceb4d
rustfmt
giraffate Jul 20, 2020
228f668
Use `mutated_variables`
giraffate Jul 22, 2020
e48685e
Just check if it contains `_` in `for pat`
giraffate Jul 22, 2020
610d4e3
rustfmt
giraffate Aug 5, 2020
2eab060
Auto merge of #5859 - ebroto:5765_manual_async_fn_fp, r=yaahc
bors Aug 5, 2020
2d4c337
Auto merge of #5809 - JarredAllen:stable_sort_primitive, r=Manishearth
bors Aug 5, 2020
50a86d4
enable #[allow(clippy::unsafe_derive_deserialize)]
ebroto Aug 5, 2020
0abc483
Lint .min(x).max(y) with x < y
wiomoc Aug 6, 2020
5e84b8c
run cargo dev new_lint then move transmutes_expressible_as_ptr_casts …
Ryan1729 Aug 3, 2020
069f851
initial compiling version of TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS
Ryan1729 Aug 3, 2020
46ef4e8
write currently failing test for transmutes_expressible_as_ptr_casts
Ryan1729 Aug 3, 2020
34d3a00
accidentally cause an ICE by putting the TRANSMUTES_EXPRESSIBLE_AS_PT…
Ryan1729 Aug 3, 2020
de05212
try putting the can_be_expressed_as_pointer_cast at the top and find …
Ryan1729 Aug 3, 2020
ccc4747
get the expected number of errors by acknowledging that other lints a…
Ryan1729 Aug 3, 2020
d38766e
address some review comments
Ryan1729 Aug 4, 2020
19f36bc
add description to assert
Ryan1729 Aug 4, 2020
94340d6
add documentation to functions that call `do_check` and add a test ag…
Ryan1729 Aug 6, 2020
ded2d6c
add extra error message to the expected stderr for transmutes_express…
Ryan1729 Aug 6, 2020
8997c55
change filter to assert, and update comments
Ryan1729 Aug 6, 2020
b0c8c7a
add newline to transmutes_expressible_as_ptr_casts.rs
Ryan1729 Aug 6, 2020
0d2a378
run clippy_dev update_lints
Ryan1729 Aug 6, 2020
42f3d39
run clippy_dev fmt
Ryan1729 Aug 6, 2020
49c7e39
Apply suggestions from code review
Ryan1729 Aug 6, 2020
d642c3b
Fix clippy
petrochenkov Jul 22, 2020
a285b58
Add some comments for magic numbers + Add tests
petrochenkov Aug 4, 2020
fe9ad57
copy over *.fixed file
Ryan1729 Aug 7, 2020
a7fa264
Auto merge of #74821 - oli-obk:const_eval_read_uninit_fast_path, r=we…
bors Aug 7, 2020
e0a4988
Lint against `Self` as an arbitrary self type
wiomoc Aug 4, 2020
737f62c
fix doc
wiomoc Aug 4, 2020
d635b76
adopt comments from review
wiomoc Aug 5, 2020
c87d999
fix ui tests
wiomoc Aug 5, 2020
e03f73e
fix nits
wiomoc Aug 5, 2020
bfe610c
ignore mutable self reference parameters
wiomoc Aug 7, 2020
87e7409
check impl Ord / is_float
wiomoc Aug 7, 2020
bd71b01
Make the docs clearer for new contributors
camelid Aug 7, 2020
01bba2c
Eliminate the `SessionGlobals` from `librustc_ast`.
nnethercote Jul 30, 2020
888657e
Fix ICE in `loops` module
ebroto Aug 8, 2020
fd87cdb
Run fmt
flip1995 Aug 8, 2020
3899d60
Auto merge of #5878 - flip1995:rustup, r=flip1995
bors Aug 8, 2020
70c46de
Auto merge of #5877 - ebroto:5872_loops_ice, r=Manishearth
bors Aug 8, 2020
a1ca125
update stderr for transmutes_expressible_as_ptr_casts
Ryan1729 Aug 9, 2020
84db238
add a test example of where transmutes_expressible_as_ptr_casts shoul…
Ryan1729 Aug 9, 2020
bc8d32d
fix unary minus on usize and unused variable errors in .fixed file
Ryan1729 Aug 9, 2020
873e5f5
add allow unused_unsafe and allow dead_code
Ryan1729 Aug 9, 2020
6af9693
Prevent compile parts of rustc when using `cargo dev ra-setup`
dima74 Aug 9, 2020
7228368
Auto merge of #5882 - dima74:ra_setup-prevent-compile-rustc, r=Manish…
bors Aug 9, 2020
9da5b6d
Rollup merge of #5825 - giraffate:same_item_push, r=Manishearth
flip1995 Aug 10, 2020
8ee57ee
Rollup merge of #5869 - wiomoc:feature/implicit-self, r=ebroto,flip1995
flip1995 Aug 10, 2020
08ab29b
Rollup merge of #5870 - ebroto:5789_allow_unsafe_derive_deserialize, …
flip1995 Aug 10, 2020
ee8db50
Rollup merge of #5871 - wiomoc:feature/methodcall-minmax, r=flip1995
flip1995 Aug 10, 2020
7f6897c
Rollup merge of #5874 - camelid:patch-1, r=flip1995
flip1995 Aug 10, 2020
c576bed
Auto merge of #5883 - flip1995:rollup-x9mftxe, r=flip1995
bors Aug 10, 2020
82c816e
Fix CHANGELOG's commit range links
robojumper Aug 10, 2020
4113453
Auto merge of #5887 - robojumper:patch-1, r=flip1995
bors Aug 10, 2020
e57aafe
too-many-lines: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
0876f17
bool-comparison: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
fd379a8
builtin-type-shadow: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
40416c0
naive_bytecount: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
5d66bd7
Avoid or_fun_call for const_fn with no args
ebroto Aug 10, 2020
9b7ab1d
checked-conversions: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
8679dd3
unnecessary_unwrap, panicking_unwrap: make lints adhere to lint messa…
matthiaskrgr Jul 23, 2020
3d592b5
cmp_null: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
6b0a6a7
default-trait-access: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
ba7a01a
double-comparisons: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
590b91d
double-parens: make lint adhere to lint message convention and do min…
matthiaskrgr Jul 23, 2020
0db5cb1
drop_bounds: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
2792260
empty-liner-after-outer-attr: make lint adhere to lint message conven…
matthiaskrgr Jul 23, 2020
4418ff1
unneeded-field-pattern: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
b36a6c9
ref_in_deref: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
7954c22
unknown: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
fe37ddb
suspicious-arithmetic-impl: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
5d69ca5
also change "deprecated-attribute" message
matthiaskrgr Jul 23, 2020
3e1e0c9
redundant-static-lifetimes: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
81f77a4
range-zip-with-len: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
9178363
path-buf-push-overwrite: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
e519bb3
overflow-check-conditional: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
178da9b
neg-multiply: make lint adhere to lint message convention
matthiaskrgr Jul 23, 2020
dabf989
neg-cmp-op-on-partial-ord: make lint adhere to lint message convention
matthiaskrgr Jul 28, 2020
c514ff0
Update clippy_lints/src/neg_cmp_op_on_partial_ord.rs
matthiaskrgr Aug 10, 2020
1b46e48
Update clippy_lints/src/unwrap.rs
matthiaskrgr Aug 10, 2020
f59ec19
run cargo dev update-lints
matthiaskrgr Aug 10, 2020
1683189
Auto merge of #5889 - ebroto:5886_or_fun_call_const_0_args, r=Manishe…
bors Aug 10, 2020
6d0b5e2
update test stderr
matthiaskrgr Aug 10, 2020
cc5bfd4
Auto merge of #5888 - matthiaskrgr:lints, r=yaahc
bors Aug 10, 2020
9e73d33
Rollup merge of #75098 - Ryan1729:clippy-pointer-cast-lint-experiment…
Dylan-DPC Aug 10, 2020
9311c11
Fix sync fallout
flip1995 Aug 11, 2020
09bd400
Auto merge of #5891 - flip1995:rustup, r=flip1995
bors Aug 11, 2020
d6b991d
Merge commit '09bd400243ed6f7059fedc0c1623aae3792521d6' into clippyup
flip1995 Aug 11, 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
9 changes: 7 additions & 2 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ document.

## Unreleased / In Rust Nightly

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

## Rust 1.46

Current beta, release 2020-08-27

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

### New lints

Expand Down Expand Up @@ -1454,6 +1454,7 @@ Released 2018-09-13
[`deprecated_semver`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_semver
[`deref_addrof`]: https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof
[`derive_hash_xor_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq
[`derive_ord_xor_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord
[`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
[`doc_markdown`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
[`double_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_comparisons
Expand Down Expand Up @@ -1615,6 +1616,7 @@ Released 2018-09-13
[`mutex_atomic`]: https://rust-lang.github.io/rust-clippy/master/index.html#mutex_atomic
[`mutex_integer`]: https://rust-lang.github.io/rust-clippy/master/index.html#mutex_integer
[`naive_bytecount`]: https://rust-lang.github.io/rust-clippy/master/index.html#naive_bytecount
[`needless_arbitrary_self_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_arbitrary_self_type
[`needless_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_bool
[`needless_borrow`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
[`needless_borrowed_reference`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrowed_reference
Expand Down Expand Up @@ -1686,6 +1688,7 @@ Released 2018-09-13
[`result_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unit_fn
[`reversed_empty_ranges`]: https://rust-lang.github.io/rust-clippy/master/index.html#reversed_empty_ranges
[`same_functions_in_if_condition`]: https://rust-lang.github.io/rust-clippy/master/index.html#same_functions_in_if_condition
[`same_item_push`]: https://rust-lang.github.io/rust-clippy/master/index.html#same_item_push
[`search_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#search_is_some
[`serde_api_misuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#serde_api_misuse
[`shadow_reuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_reuse
Expand All @@ -1701,6 +1704,7 @@ Released 2018-09-13
[`single_match_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else
[`skip_while_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#skip_while_next
[`slow_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#slow_vector_initialization
[`stable_sort_primitive`]: https://rust-lang.github.io/rust-clippy/master/index.html#stable_sort_primitive
[`str_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#str_to_string
[`string_add`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_add
[`string_add_assign`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_add_assign
Expand All @@ -1723,6 +1727,7 @@ Released 2018-09-13
[`too_many_arguments`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments
[`too_many_lines`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_lines
[`toplevel_ref_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#toplevel_ref_arg
[`trait_duplication_in_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#trait_duplication_in_bounds
[`transmute_bytes_to_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_bytes_to_str
[`transmute_float_to_int`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_float_to_int
[`transmute_int_to_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_bool
Expand Down
27 changes: 15 additions & 12 deletions src/tools/clippy/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ All contributors are expected to follow the [Rust Code of Conduct].

## Getting started

High level approach:
**Note: If this is your first time contributing to Clippy, you should
first read the [Basics docs](doc/basics.md).**

### High level approach

1. Find something to fix/improve
2. Change code (likely some file in `clippy_lints/src/`)
3. Follow the instructions in the [docs for writing lints](doc/adding_lints.md) such as running the `setup-toolchain.sh` script
3. Follow the instructions in the [Basics docs](doc/basics.md) to get set up
4. Run `cargo test` in the root directory and wiggle code until it passes
5. Open a PR (also can be done after 2. if you run into problems)

Expand Down Expand Up @@ -95,16 +98,16 @@ quick read.

## 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
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!

Expand Down
3 changes: 2 additions & 1 deletion src/tools/clippy/clippy_dev/src/ra_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ fn inject_deps_into_manifest(
});

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

// replace "[dependencies]" with
// [dependencies]
Expand Down
5 changes: 2 additions & 3 deletions src/tools/clippy/clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! checks for attributes

use crate::reexport::Name;
use crate::utils::{
first_line_of_span, is_present_in_source, match_def_path, paths, snippet_opt, span_lint, span_lint_and_help,
span_lint_and_sugg, span_lint_and_then, without_block_comments,
Expand Down Expand Up @@ -517,7 +516,7 @@ fn is_relevant_expr(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>
}
}

fn check_attrs(cx: &LateContext<'_>, span: Span, name: Name, attrs: &[Attribute]) {
fn check_attrs(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Attribute]) {
if span.from_expansion() {
return;
}
Expand Down Expand Up @@ -606,7 +605,7 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::as
cx,
EMPTY_LINE_AFTER_OUTER_ATTR,
begin_of_attr_to_item,
"Found an empty line after an outer attribute. \
"found an empty line after an outer attribute. \
Perhaps you forgot to add a `!` to make it an inner attribute?",
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/bytecount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
cx,
NAIVE_BYTECOUNT,
expr.span,
"You appear to be counting bytes the naive way",
"Consider using the bytecount crate",
"you appear to be counting bytes the naive way",
"consider using the bytecount crate",
format!("bytecount::count({}, {})",
snippet_with_applicability(cx, haystack.span, "..", &mut applicability),
snippet_with_applicability(cx, needle.span, "..", &mut applicability)),
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/checked_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for CheckedConversions {
cx,
CHECKED_CONVERSIONS,
item.span,
"Checked cast can be simplified.",
"checked cast can be simplified",
"try",
format!("{}::try_from({}).is_ok()", to_type, snippet),
applicability,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/default_trait_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultTraitAccess {
cx,
DEFAULT_TRAIT_ACCESS,
expr.span,
&format!("Calling `{}` is more clear than this expression", replacement),
&format!("calling `{}` is more clear than this expression", replacement),
"try",
replacement,
Applicability::Unspecified, // First resolve the TODO above
Expand Down
120 changes: 117 additions & 3 deletions src/tools/clippy/clippy_lints/src/derive.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::utils::paths;
use crate::utils::{
is_automatically_derived, is_copy, match_path, span_lint_and_help, span_lint_and_note, span_lint_and_then,
get_trait_def_id, is_allowed, is_automatically_derived, is_copy, match_path, span_lint_and_help,
span_lint_and_note, span_lint_and_then,
};
use if_chain::if_chain;
use rustc_hir::def_id::DefId;
Expand Down Expand Up @@ -43,6 +44,57 @@ declare_clippy_lint! {
"deriving `Hash` but implementing `PartialEq` explicitly"
}

declare_clippy_lint! {
/// **What it does:** Checks for deriving `Ord` but implementing `PartialOrd`
/// explicitly or vice versa.
///
/// **Why is this bad?** The implementation of these traits must agree (for
/// example for use with `sort`) so it’s probably a bad idea to use a
/// default-generated `Ord` implementation with an explicitly defined
/// `PartialOrd`. In particular, the following must hold for any type
/// implementing `Ord`:
///
/// ```text
/// k1.cmp(&k2) == k1.partial_cmp(&k2).unwrap()
/// ```
///
/// **Known problems:** None.
///
/// **Example:**
///
/// ```rust,ignore
/// #[derive(Ord, PartialEq, Eq)]
/// struct Foo;
///
/// impl PartialOrd for Foo {
/// ...
/// }
/// ```
/// Use instead:
/// ```rust,ignore
/// #[derive(PartialEq, Eq)]
/// struct Foo;
///
/// impl PartialOrd for Foo {
/// fn partial_cmp(&self, other: &Foo) -> Option<Ordering> {
/// Some(self.cmp(other))
/// }
/// }
///
/// impl Ord for Foo {
/// ...
/// }
/// ```
/// or, if you don't need a custom ordering:
/// ```rust,ignore
/// #[derive(Ord, PartialOrd, PartialEq, Eq)]
/// struct Foo;
/// ```
pub DERIVE_ORD_XOR_PARTIAL_ORD,
correctness,
"deriving `Ord` but implementing `PartialOrd` explicitly"
}

declare_clippy_lint! {
/// **What it does:** Checks for explicit `Clone` implementations for `Copy`
/// types.
Expand Down Expand Up @@ -103,7 +155,12 @@ declare_clippy_lint! {
"deriving `serde::Deserialize` on a type that has methods using `unsafe`"
}

declare_lint_pass!(Derive => [EXPL_IMPL_CLONE_ON_COPY, DERIVE_HASH_XOR_EQ, UNSAFE_DERIVE_DESERIALIZE]);
declare_lint_pass!(Derive => [
EXPL_IMPL_CLONE_ON_COPY,
DERIVE_HASH_XOR_EQ,
DERIVE_ORD_XOR_PARTIAL_ORD,
UNSAFE_DERIVE_DESERIALIZE
]);

impl<'tcx> LateLintPass<'tcx> for Derive {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
Expand All @@ -116,6 +173,7 @@ impl<'tcx> LateLintPass<'tcx> for Derive {
let is_automatically_derived = is_automatically_derived(&*item.attrs);

check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);
check_ord_partial_ord(cx, item.span, trait_ref, ty, is_automatically_derived);

if is_automatically_derived {
check_unsafe_derive_deserialize(cx, item, trait_ref, ty);
Expand Down Expand Up @@ -180,6 +238,60 @@ fn check_hash_peq<'tcx>(
}
}

/// Implementation of the `DERIVE_ORD_XOR_PARTIAL_ORD` lint.
fn check_ord_partial_ord<'tcx>(
cx: &LateContext<'tcx>,
span: Span,
trait_ref: &TraitRef<'_>,
ty: Ty<'tcx>,
ord_is_automatically_derived: bool,
) {
if_chain! {
if let Some(ord_trait_def_id) = get_trait_def_id(cx, &paths::ORD);
if let Some(partial_ord_trait_def_id) = cx.tcx.lang_items().partial_ord_trait();
if let Some(def_id) = &trait_ref.trait_def_id();
if *def_id == ord_trait_def_id;
then {
// Look for the PartialOrd implementations for `ty`
cx.tcx.for_each_relevant_impl(partial_ord_trait_def_id, ty, |impl_id| {
let partial_ord_is_automatically_derived = is_automatically_derived(&cx.tcx.get_attrs(impl_id));

if partial_ord_is_automatically_derived == ord_is_automatically_derived {
return;
}

let trait_ref = cx.tcx.impl_trait_ref(impl_id).expect("must be a trait implementation");

// Only care about `impl PartialOrd<Foo> for Foo`
// For `impl PartialOrd<B> for A, input_types is [A, B]
if trait_ref.substs.type_at(1) == ty {
let mess = if partial_ord_is_automatically_derived {
"you are implementing `Ord` explicitly but have derived `PartialOrd`"
} else {
"you are deriving `Ord` but have implemented `PartialOrd` explicitly"
};

span_lint_and_then(
cx,
DERIVE_ORD_XOR_PARTIAL_ORD,
span,
mess,
|diag| {
if let Some(local_def_id) = impl_id.as_local() {
let hir_id = cx.tcx.hir().as_local_hir_id(local_def_id);
diag.span_note(
cx.tcx.hir().span(hir_id),
"`PartialOrd` implemented here"
);
}
}
);
}
});
}
}
}

/// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint.
fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &TraitRef<'_>, ty: Ty<'tcx>) {
if match_path(&trait_ref.path, &paths::CLONE_TRAIT) {
Expand Down Expand Up @@ -242,7 +354,9 @@ fn check_unsafe_derive_deserialize<'tcx>(
if_chain! {
if match_path(&trait_ref.path, &paths::SERDE_DESERIALIZE);
if let ty::Adt(def, _) = ty.kind;
if def.did.is_local();
if let Some(local_def_id) = def.did.as_local();
let adt_hir_id = cx.tcx.hir().as_local_hir_id(local_def_id);
if !is_allowed(cx, UNSAFE_DERIVE_DESERIALIZE, adt_hir_id);
if cx.tcx.inherent_impls(def.did)
.iter()
.map(|imp_did| item_from_def_id(cx, *imp_did))
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/double_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<'tcx> DoubleComparisons {
cx,
DOUBLE_COMPARISONS,
span,
"This binary expression can be simplified",
"this binary expression can be simplified",
"try",
sugg,
applicability,
Expand Down
23 changes: 5 additions & 18 deletions src/tools/clippy/clippy_lints/src/double_parens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,28 @@ impl EarlyLintPass for DoubleParens {
return;
}

let msg: &str = "consider removing unnecessary double parentheses";

match expr.kind {
ExprKind::Paren(ref in_paren) => match in_paren.kind {
ExprKind::Paren(_) | ExprKind::Tup(_) => {
span_lint(
cx,
DOUBLE_PARENS,
expr.span,
"Consider removing unnecessary double parentheses",
);
span_lint(cx, DOUBLE_PARENS, expr.span, &msg);
},
_ => {},
},
ExprKind::Call(_, ref params) => {
if params.len() == 1 {
let param = &params[0];
if let ExprKind::Paren(_) = param.kind {
span_lint(
cx,
DOUBLE_PARENS,
param.span,
"Consider removing unnecessary double parentheses",
);
span_lint(cx, DOUBLE_PARENS, param.span, &msg);
}
}
},
ExprKind::MethodCall(_, ref params, _) => {
if params.len() == 2 {
let param = &params[1];
if let ExprKind::Paren(_) = param.kind {
span_lint(
cx,
DOUBLE_PARENS,
param.span,
"Consider removing unnecessary double parentheses",
);
span_lint(cx, DOUBLE_PARENS, param.span, &msg);
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/clippy_lints/src/drop_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ declare_clippy_lint! {
/// ```
pub DROP_BOUNDS,
correctness,
"Bounds of the form `T: Drop` are useless"
"bounds of the form `T: Drop` are useless"
}

const DROP_BOUNDS_SUMMARY: &str = "Bounds of the form `T: Drop` are useless. \
Use `std::mem::needs_drop` to detect if a type has drop glue.";
const DROP_BOUNDS_SUMMARY: &str = "bounds of the form `T: Drop` are useless, \
use `std::mem::needs_drop` to detect if a type has drop glue";

declare_lint_pass!(DropBounds => [DROP_BOUNDS]);

Expand Down
Loading