Commit graph

11970 commits

Author SHA1 Message Date
flip1995
b98e2ec527
Fix ICE in redundant_pattern_matching 2021-07-16 10:45:28 +02:00
bors
78ffcd9959 Auto merge of #7460 - camsteffen:run-from-source, r=Manishearth
Add instructions to run from source

changelog: none

We often get messages on Zulip asking how to install and run Clippy from source. This adds instructions to the readme. I also added a note explaining that `cargo install --path . --force` is bad, which I just decided after some investigating. I use macOS. It would be nice to get some tests on other platforms to see if this is correct.
2021-07-15 21:53:17 +00:00
Cameron Steffen
6ef0cd7a71 Add instructions to run from source 2021-07-15 16:07:18 -05:00
bors
54a20a02ec Auto merge of #7468 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2021-07-15 08:37:36 +00:00
flip1995
43b0121fa7
Bump nightly version -> 2021-07-15 2021-07-15 10:32:21 +02:00
flip1995
69fbd64e2a
Merge remote-tracking branch 'upstream/master' into rustup 2021-07-15 10:32:06 +02:00
bors
09f5f15d8b Auto merge of #7308 - lengyijun:redundant_allocation_arc, r=xFrednet,flip1995
add Arc to `redundant_allocation`

 fixes #7303
changelog:  add Arc to `redundant_allocation`
2021-07-15 07:20:37 +00:00
lyj
e575610fb3 redundant_allocation: add Arc; some refractoring. 2021-07-15 07:10:55 +08:00
bors
2b193e247f Auto merge of #7462 - xFrednet:7369-branches-sharing-code-else-expr-fp, r=camsteffen
FP fix and documentation for `branches_sharing_code` lint

Closes rust-lang/rust-clippy#7369

Related rust-lang/rust-clippy#7452 I'm still thinking about the best way to fix this. I could simply add another visitor to ensure that the moved expressions don't modify values being used in the condition, but I'm not totally happy with this due to the complexity. I therefore only documented it for now

changelog: [`branches_sharing_code`] fixed false positive where block expressions would sometimes be ignored.
2021-07-14 20:29:56 +00:00
xFrednet
61e280863f Fixed branches_sharing_code FP with block expressions in else
And added `branches_sharing_code` PF note to lint doc for `rust-clippy#7452`
2021-07-14 21:37:17 +02:00
bors
4acbff9eb0 Auto merge of #7437 - ebobrow:redundant-closure-move, r=flip1995
suggest `&mut` for redundant FnMut closures

fixes #6903

changelog: suggest `&mut` for redundant FnMut closures
2021-07-14 15:15:28 +00:00
Elliot Bobrow
4c398e07e0 suggest &mut for redundant FnMut closures 2021-07-14 07:56:27 -07:00
bors
f07feca40c Auto merge of #7346 - lengyijun:redundant_clone_5707, r=oli-obk
fix 5707

changelog: ``[`redundant_clone`]``, fix #5707

# Root problem of #5707 :
```
&2:&mut HashMap = &mut _4;
&3:&str = & _5;
_1 = HashMap::insert(move _2,move _3, _);
```

generate PossibleBorrower(_2,_1) and PossibleBorrower(_3,_1).

However, it misses PossibleBorrower(_3,_2).

# My solution to #5707 :

When meet a function call, we should:
1. build PossibleBorrower between borrow parameters and return value (currently)
2. build PossibleBorrower between immutable borrow parameters and mutable borrow parameters (*add*)
3. build PossibleBorrower inside mutable borrow parameters (*add*)

For example:
```
_2: &mut _22;
_3: &mut _;
_4: & _;
_5: & _;
_1 = call(move _2, move _3, move _4, move _5);
```
we need to build
1. return value with parameter(current implementataion)
 PossibleBorrower(_2,_1)
 PossibleBorrower(_3,_1)
 PossibleBorrower(_4,_1)
 PossibleBorrower(_5,_1)

2. between mutable borrow and immutable borrow
PossibleBorrower(_4,_2)
PossibleBorrower(_5,_2)
PossibleBorrower(_4,_3)
PossibleBorrower(_5,_3)

3. between mutable borrow and mutable borrow
PossibleBorrower(_3,_2)
PossibleBorrower(_2,_3)

  But that's not enough.
 Modification to _2 actually apply to _22.
  So I write a `PossibleBorrowed` visitor, which tracks (borrower => possible borrowed) relation.
  For example (_2 => _22).
  However, a lot of problems exist here.

## Known Problems:
  1. not sure all `&mut`'s origin are collected.
  I'm not sure how to deal with `&mut` when meet a function call, so I didn't do it currently.
  Also, my implement is not flow sensitive, so it's not accurate.

```
foo(_2:&mut _, _3: &_)
```
This pr doesn't count _3 as origin of _2.

 2. introduce false negative
`foo(_2, _3)` will  emit PossibleBorrower(_3,_2) in this pr, but _3 and _2 may not have relation.
Clippy may feel that _3 is still in use because of _2, but actually, _3 is on longer needed and can be moved.

## Insight
  The key problem is determine where every `&mut` come from accurately.
  I think Polonius is an elegant solution to it. Polonius is flow sensitive and accurate.
  But I'm uncertain about whether we can import Polonius in rust-clippy currently.
  This pr actually is part of Polonius' functionality, I think.

# TODO
1. `cargo test` can't pass yet due to similar variable name
2021-07-14 10:10:14 +00:00
lyj
10910020ec rename possible_borrowed to possible_origin; pass dogfood 2021-07-14 13:46:33 +08:00
lyj
251c3b64da fix 5707 2021-07-14 10:57:47 +08:00
bors
2fd8dbc8af Auto merge of #86827 - camsteffen:hash-lint-resolved, r=oli-obk
Fix internal `default_hash_types` lint to use resolved path

I run into false positives now and then (mostly in Clippy) when I want to name some util after HashMap.
2021-07-13 15:06:10 +00:00
bors
8131445e53 Auto merge of #7446 - Y-Nak:fix-7445, r=xFrednet,flip1995
`default_numeric_fallback`: Fix FP with floating literal

Fix #7445

changelog: `default_numeric_fallback`: Fix FP with floating literal
2021-07-13 14:31:02 +00:00
Yoshitomo Nakanishi
25e4c7d73f default_numeric_fallback: Add rustfix tests 2021-07-13 23:18:31 +09:00
bors
bf4512ef57 Auto merge of #7442 - camsteffen:format-args, r=xFrednet
Refactor `format_args!` expansion parsing

Introduces `FormatExpn::parse` and `FormatArgsExpn::parse`. Motivated by rust-lang/rust#83302, so I only have to change Clippy in one place. Fixed an FP along the way.

I also allowed `needless_bool` in macros because I often want to do `if_chain! { .. then { true } else { false } }`.

changelog: Fix false positive in `useless_format` when some text is appended or prepended to a single string with some useless formatting params
changelog: Allow `needless_bool` in macros
2021-07-13 13:58:38 +00:00
Cameron Steffen
306f9e843d Split a lint message into help 2021-07-13 08:57:16 -05:00
Cameron Steffen
73ffae6ea1 Reduce redundant code 2021-07-13 08:57:16 -05:00
Cameron Steffen
e6ab222b81 Refactor format macro parsing 2021-07-13 08:57:16 -05:00
Cameron Steffen
20dbb277cf Fix useless_format false positive 2021-07-13 08:57:16 -05:00
Cameron Steffen
3fc8dae46c Allow needless_bool in macro 2021-07-13 08:57:16 -05:00
Yoshitomo Nakanishi
4e8cd4d346 Fix NumericLiteral::format that may produce a invalid literal 2021-07-13 22:57:02 +09:00
bors
94d6be4c0a Auto merge of #7458 - flip1995:unused_unit-doc, r=giraffate
Add fixed example to unused_unit documentation

changelog: none

(don't think this is worth a changelog mention)
2021-07-13 13:43:12 +00:00
flip1995
f05949f9ce
Add fixed example to unused_unit documentation 2021-07-13 10:54:29 +02:00
Vadim Petrochenkov
075a28996c rustc_span: Revert addition of proc_macro field to ExpnKind::Macro
The flag has a vague meaning and is used for a single diagnostic change that is low benefit and appears only under `-Z macro_backtrace`.
2021-07-10 23:03:35 +03:00
Cameron Steffen
dce274024e clippy: allow default_hash_types on bootstrap 2021-07-09 09:10:45 -05:00
bors
cb16543b3a Auto merge of #7449 - flip1995:remove-lints_enabled, r=camsteffen
Remove lints_enabled

r? `@camsteffen`

cc https://github.com/rust-lang/rust-clippy/pull/7448#issuecomment-876497862

I haven't added a variant with `last_node_with_lint_attrs` yet, since I didn't see a usecase for this. Also this field is not documented, so I'm wondering how it behaves with command line lints and so on.

changelog: none
2021-07-09 14:00:52 +00:00
flip1995
d2c8f50bbe
Rename is_allowed -> is_lint_allowed 2021-07-09 15:06:12 +02:00
flip1995
5add651223
Remove lints_enabled function
This function was redundant with the is_allowed function. Now is_allowed
is used everywhere lints_enabled was used before.
2021-07-09 15:00:24 +02:00
Yoshitomo Nakanishi
04aa3f7e9b default_numeric_fallback: Add more tests for floating literal 2021-07-09 18:24:23 +09:00
bors
8da39e66ac Auto merge of #7448 - flip1995:run_lints-rename, r=llogiq
Rename run_lints -> lints_enabled

Just a quick rename of a utilities function. `run_lints` kinda suggested that the lints were run by this function. But the only thing this function does is to check if the lints are enabled in the context of the `hir_id`

changelog: none
2021-07-09 06:39:56 +00:00
Guillaume Gomez
3fc34455f4 Rework SESSION_GLOBALS API to prevent overwriting it 2021-07-08 16:16:28 +02:00
flip1995
795868dd88
Rename run_lints -> lints_enabled 2021-07-08 15:45:19 +02:00
Yoshitomo Nakanishi
3bc5abef62 default_numeric_fallback: Fix FP with floating literal 2021-07-08 11:37:12 +09:00
bors
7de1efa02e Auto merge of #86920 - JohnTitor:rollup-buvzpkr, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #80918 (Add Integer::log variants)
 - #86717 (Rename some Rust 2021 lints to better names )
 - #86819 (Clean up rustdoc IDs)
 - #86880 (Test ManuallyDrop::clone_from.)
 - #86906 (Replace deprecated compare_and_swap and fix typo in core::sync::atomic::{fence, compiler_fence} docs)
 - #86907 (Migrate `cpu-usage-over-time.py` to Python 3)
 - #86916 (rewrote documentation for thread::yield_now())
 - #86919 (Update books)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-07-07 03:31:23 +00:00
Aman Arora
f0f3b3acf8 Make type_implements_trait not a query 2021-07-06 14:38:10 -04:00
Ryan Levick
30c5c2ff03 Add s to non_fmt_panic 2021-07-06 20:12:56 +02:00
bors
28e769951f Auto merge of #7439 - iobtl:assert_msg_panic_fp, r=flip1995
Fix false-positive `assert` in `panic`

This PR fixes a false-positive in `clippy::panic` when using the `assert` macro with its optional message parameter.

Fixes: #7433

changelog: `panic_unimplemented.rs`: added condition to exclude `assert` macro, similar to `debug_assert`
changelog: `panicking_macros.rs`: relevant tests to check for `assert` usage.
2021-07-06 08:22:57 +00:00
iobtl
eeefbb7617 fix false positive (panic message) with assert macro using message parameter 2021-07-06 15:14:53 +08:00
bors
64d74df19c Auto merge of #7243 - mgacek8:issue7145_strlen_on_c_strings, r=giraffate
Add new lint: `strlen_on_c_strings`

~~This is WIP, linting in case of `CString` has been added, but for `CStr`, its diagnostic item needs to be available for clippy.
[PR that adds diagnostic item for CStr on rust repo](https://github.com/rust-lang/rust/pull/85439).~~
Ready for the review. Please take a look.
fixes #7145
changelog: Add new lint: `strlen_on_c_strings`, that lints on `libc::strlen(some_cstring.as_ptr())`
2021-07-05 13:12:43 +00:00
Mateusz Gacek
59a164e86c Add new lint: strlen_on_c_strings 2021-07-05 11:10:45 +02:00
Niko Matsakis
26e57f05cc revert broken formatting 2021-07-04 12:50:41 -04:00
bors
3cc6778512 Auto merge of #7431 - DevinR528:fix-macro-brace, r=llogiq
Fix emitting in nested (proc_)macros for nonstandard_macro_braces lint

fixes #7422

changelog: fixes false positives in [`nonstandard_macro_braces`]
2021-07-04 16:47:11 +00:00
Niko Matsakis
89f6c4cfe2 allow inference vars in type_implements_trait 2021-07-04 11:28:20 -04:00
Devin Ragotzy
1d110f8c2e Fix emitting in nested (proc_)macros for nonstandard_macro_braces lint 2021-07-04 07:06:23 -04:00
bors
0a59c24e8a Auto merge of #7428 - camsteffen:use-self-ice, r=flip1995
Fix use_self ICE

changelog: Fix ICE #7423

r? `@flip1995`
2021-07-03 19:09:05 +00:00
Cameron Steffen
cb4670deb3 Fix use_self ICE 2021-07-03 12:40:50 -05:00