Commit Graph

4981 Commits

Author SHA1 Message Date
flip1995
b05aeaa9bc
Run fmt 2020-10-06 23:32:38 +02:00
Ivan Tham
7021d70d2e
Use more concrete explanation for methods
Show some code rather than "a single method call".
2020-10-06 23:58:32 +08:00
Philipp Hansch
da57a16872
clippy_lints: Replace lazy_static with SyncLazy 2020-10-06 14:39:04 +02:00
Matthew Jasper
adb7fc6283 Fix tools 2020-10-06 11:19:30 +01:00
Yuki Okushi
22c5e0c347 Rollup merge of #77560 - rschoon:fix-litkind-rc-bytebuf, r=lcnr
Fix LitKind's byte buffer to use refcounted slice

While working on adding a new lint for clippy (see https://github.com/rust-lang/rust-clippy/pull/6044) for avoiding shared ownership of "mutable buffer" types (such as using `Rc<Vec<T>>` instead of `Rc<[T]>`), I noticed a type exported from rustc_ast and used by clippy gets caught by the lint. This PR fixes the exported type.

This PR includes the actual change to clippy too, but I will open a PR directly against clippy for that part (although it will currently fail to build there).
2020-10-06 16:26:11 +09:00
bors
c9fdeef643 Auto merge of #6078 - ebroto:unnecessary_sort_by_take_2, r=phansch
unnecessary sort by: avoid dereferencing the suggested closure parameter

This change tries to simplify the solution for problematic cases but is less restrictive than  #6006.

* We can't dereference shared references to non-Copy types, so the new suggestion does not do that. Note that this implies that the suggested closure parameter will be a reference.
* We can't take a reference to the closure parameter in the returned key, so we don't lint in those cases. This can happen either because the key borrows from the parameter (e.g. `|a| a.borrows()`), or because we suggest `|a| Reverse(a)`. If we did we would hit this error:
```
error: lifetime may not live long enough
  --> /home/ebroto/src/ebroto-clippy/tests/ui/unnecessary_sort_by.fixed:19:25
   |
19 |     vec.sort_by_key(|b| Reverse(b));
   |                      -- ^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
   |                      ||
   |                      |return type of closure is Reverse<&'2 isize>
   |                      has type `&'1 isize`

error: aborting due to previous error
```

Note that Clippy does not currently have the (MIR-based) machinery necessary to check that what is borrowed is actually the closure parameter.

changelog: [`unnecessary_sort_by`]: avoid dereferencing the suggested closure parameter

Fixes #6001
2020-10-06 06:59:33 +00:00
bors
3239b46e92 Auto merge of #6114 - FliegendeWurst:no-mistyped-fraction, r=Manishearth
Do not lint float fractions in `mistyped_literal_suffixes`

As suggested in https://github.com/rust-lang/rust-clippy/issues/4706#issuecomment-544797928, the fractional part is now ignored (the integer part is checked instead).

Fixes: #4706

changelog: `mistyped_literal_suffixes` no longer warns on the fractional part of a float (e.g. 713.23_64)
2020-10-05 21:17:37 +00:00
Eduardo Broto
5554641fce Fix rustup fallout 2020-10-05 22:32:04 +02:00
Eduardo Broto
5f492490a3 Merge remote-tracking branch 'upstream/master' into rustup 2020-10-05 22:13:44 +02:00
FliegendeWurst
78695bd496
Do not lint float fractions in mistyped_literal_suffixes (fixes #4706) 2020-10-05 12:09:21 +02:00
Dylan MacKenzie
29d43f63bd clippy: (Body, DefId) -> Body 2020-10-04 16:07:03 -07:00
Robin Schoonover
f34f4a7327 Change clippy's Constant back to refcount clone byte strings 2020-10-04 15:53:37 -06:00
bors
2ed5143c0e Auto merge of #6111 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: Deprecate [`drop_bounds`] lint. This lint was uplifted to rustc with the same name.
2020-10-04 12:04:31 +00:00
rail
f58a1695a6 fix a FP in interior_mutable_const
fix a false positive in two `interior_mutable_const` lints where a constant with enums gets linted
even if it uses a clearly unfrozen variant. Note that the code uses the MIR interpreter, which
the author of #3962 thought unlikely to be a solution. This might be over-engineering;
but, I think it's important to be able to work with the 'http' crate (#3825).
2020-10-04 18:15:28 +13:00
bors
9408c68c1d Auto merge of #6105 - bugadani:sus-char, r=ebroto
Lint for invisible Unicode characters other than ZWSP

This PR extends the existing `zero_width_space` lint to look for other invisible characters as well (in this case, `\\u{ad}` soft hyphen.

I feel like this lint is the logical place to add the check, but I also realize the lint name is not particularly flexible, but I also understand that it shouldn't be renamed for compatibility reasons.

Open questions:
 - What other characters should trigger the lint?
 - What should be done with the lint name?
 - How to indicate the change in functionality?

Motivation behind this PR: https://github.com/rust-lang/rust/issues/77417 - I managed to shoot myself in the foot by an invisible character pasted into my test case.

changelog: rename [`zero_width_space`] to [`invisible_characters`] and add SHY and WJ to the list.
2020-10-02 22:22:37 +00:00
Dániel Buga
572e4c4837 Add WJ 2020-10-03 00:07:56 +02:00
Dániel Buga
998bd3b6b4 Rename lint to invisible_characters 2020-10-03 00:03:33 +02:00
Long Louis Bui
8b8c63f568 changed non_copy_const lints to warn by default 2020-10-02 23:12:40 +02:00
nahuakang
f302af33bc Add doc comment issue of #5834 to known problems of lint doc_markdown 2020-10-02 22:05:40 +02:00
Michael Howell
840f7daaad Deprecate clippy lint 2020-10-02 11:34:14 -07:00
rail
b541884294 remove the explicit return value of print_limit 2020-10-02 23:38:10 +13:00
Dániel Buga
515ca93123 Look for soft hyphens as well 2020-10-02 11:56:21 +02:00
rail
2a0e45b8db supress clippy::filter_map 2020-10-02 21:38:50 +13:00
rail
41a0ccbc57 add comments around loop_counters 2020-10-02 21:38:50 +13:00
rail
1402d8ae4f fix a FN where incr exprs with no semicolon at ends 2020-10-02 21:18:37 +13:00
Michael Wright
e91202cf68 Allow exponent separator
Fixes #6096
2020-10-02 07:02:58 +02:00
rail
94d7b82340 simplify the code 2020-10-02 14:04:46 +13:00
rail
388384177e document MinifyingSugg and Offset
...and also swap their position
2020-10-02 13:30:50 +13:00
bors
8c9800a3a9 Auto merge of #6102 - giraffate:no_lint_when_invalid_suggestion_in_needless_range_loop, r=flip1995
Don't emit a lint for the suggestion leading to errors in `needless_range_loop`

Fix #5945

changelog: Don't emit a lint for the suggestion leading to errors in `needless_range_loop`
2020-10-01 16:29:08 +00:00
Takayuki Nakata
0a91fe7016 Don't emit a lint for the suggestion leading to errors in needless_range_loop 2020-10-02 00:49:05 +09:00
bors
d4313737d8 Auto merge of #5978 - montrivo:needless-lifetime, r=ebroto
needless-lifetime - nested elision sites

Closes #2944

changelog: fix needless-lifetime nested elision site FPs
2020-10-01 13:43:24 +00:00
bors
abce9e7c9f Auto merge of #6092 - jethrogb:jb/inline-asm-syntax-lint, r=ebroto
Add lint for inline assembly syntax style preference

changelog: Add lint for inline assembly syntax style preference
2020-09-30 21:44:29 +00:00
Jethro Beekman
0690f9c5d5 Add lint for inline assembly syntax style preference 2020-09-30 09:43:46 +02:00
Tim Nielens
cb2be6f9db needless-lifetime / pr remarks 2020-09-30 00:33:46 +02:00
Tim Nielens
aa2ac38fa7 needless-lifetime / add known problem item 2020-09-30 00:08:19 +02:00
Tim Nielens
7cfe3dc2eb Merge branch 'master' into needless-lifetime 2020-09-29 22:51:59 +02:00
Eduardo Broto
101e76f117 needless arbitrary self: handle macros 2020-09-28 19:17:22 +02:00
rail
9725f00f4d Use the From trait to make MinifyingSugg 2020-09-28 02:27:55 +13:00
Eduardo Broto
8bf27c5e92 Fix dogfood 2020-09-27 15:22:33 +02:00
Eduardo Broto
cd4706413f Run cargo dev fmt 2020-09-27 15:17:13 +02:00
Eduardo Broto
798a5cf5bc Merge remote-tracking branch 'upstream/master' into rustup 2020-09-27 15:09:52 +02:00
rail
99aceebf1c Use the spans of the entire for loops for suggestions 2020-09-27 16:38:41 +13:00
rail
5c71352b18 Prevent unnecessary lints from triggering 2020-09-27 14:54:20 +13:00
rail
4918e7ad62 Replace snippet_opt + unwrap_or_else with snippet 2020-09-27 14:19:43 +13:00
Jeremiah Senkpiel
00e641b914 lints: clarify rc_buffer and add caveats
This didn't display some types properly in the docs due the lack of code formatting.

Also, refs for the caveat:
https://github.com/rust-lang/rust-clippy/pull/6044#issuecomment-699559082
https://github.com/http-rs/surf/pull/242
2020-09-26 17:19:12 -07:00
bors
ea079eb8a4 Auto merge of #6081 - ilknarf:master, r=matthiaskrgr
New Lint: disallowed_method

Fixes https://github.com/rust-lang/rust-clippy/issues/6073

I added a `disallowed_method` lint that works similar to `blacklisted_name`, e.g allows config-defined disallowed method calls.

This lint allows advanced users to patch in undesired method calls for specific projects. It basically uses the DefId of method calls and matches it to parsed strings. Is there an alternative approach that could use more easily digestible configuration strings?

All tests pass as expected except for a linting error on `ui/redundant_pattern_matching_option`, which I am not sure how to resolve since I don't think I changed anything affecting it.

changelog: Add disallowed_method lint to warn on user-defined method calls
2020-09-26 20:55:53 +00:00
bors
b64d21d980 Auto merge of #6079 - giraffate:print_stdout_in_build_rs, r=ebroto
Fix FP in `print_stdout`

Fix #6041

This lint shouldn't be emitted in `build.rs` as `println!` and `print!` are used for the build script.

changelog: none
2020-09-26 20:34:35 +00:00
Oliver Scherer
7072e45c6c Remove all unstable feature support in the missing_const_for_fn lint 2020-09-26 16:23:56 +02:00
Takayuki Nakata
83294f894d Some small fixes 2020-09-26 23:10:25 +09:00
Oliver Scherer
a6fda14394 Move qualify_min_const_fn out of rustc into clippy 2020-09-26 16:08:24 +02:00
Frank
d18653158d remove useless test, update disallowed_method description 2020-09-25 11:09:04 -05:00
Frank
f9da2946d8 update error message, refactor disallowed_method 2020-09-25 11:09:04 -05:00
Frank
3886edb05a fix error message 2020-09-25 11:09:04 -05:00
Frank
725a0ef8b1 change config variables to reference, remove wildcard import 2020-09-25 11:09:04 -05:00
Frank
e1b3f85e98 run cargo dev fmt 2020-09-25 11:09:04 -05:00
Frank
12e5637f75 update unused variable 2020-09-25 11:09:04 -05:00
Frank
1479c18396 add disallowed_method lint 2020-09-25 11:09:04 -05:00
Takayuki Nakata
5b484b4057 Fix the detection of build scripts 2020-09-25 23:32:18 +09:00
bors
6273be6fc2 Auto merge of #77144 - flip1995:clippyup, r=Manishearth
Update Clippy

Bi-weekly Clippy update.

This includes a `Cargo.lock` update (d445493479), so probably needs `rollup=never`.

r? `@Manishearth`
2020-09-25 06:23:55 +00:00
Jonas Schievink
a8c6073278 Rollup merge of #76724 - ecstatic-morse:dataflow-pass-names, r=lcnr
Allow a unique name to be assigned to dataflow graphviz output

Previously, if the same analysis were invoked multiple times in a single compilation session, the graphviz output for later runs would overwrite that of previous runs. Allow callers to add a unique identifier to each run so this can be avoided.
2020-09-25 02:29:31 +02:00
rail
e855fe3620 Reflect the changes that has been made and fmt 2020-09-25 09:02:05 +12:00
rail
ce653d65a8 use #[derive] instead of the manual implementation 2020-09-25 09:02:05 +12:00
rail
f410df3c48 make clippy happy (needless_pass_by_value, filter_map and find_map) 2020-09-25 09:02:05 +12:00
rail
44187383f4 Use operator overloading instead of direct calls of make_binop 2020-09-25 09:02:05 +12:00
rail
10d7a18f72 fmt 2020-09-25 09:02:05 +12:00
rail
eb3ffe6ed2 make use of macros in operator overloading 2020-09-25 09:02:05 +12:00
rail
d9a88be0b0 Rename get_offset and its private items 2020-09-25 09:02:05 +12:00
rail
8da6cfd17b fmt 2020-09-25 09:02:05 +12:00
rail
de56279cd9 Implement building the manual_memcpy sugggestion with loop counters 2020-09-25 09:02:05 +12:00
rail
720f19f2ec Implement detecting manual_memcpy with loop counters 2020-09-25 09:02:05 +12:00
rail
b4b4da162f Introduce Start and StartKind 2020-09-25 09:02:05 +12:00
rail
1026b42f06 Rename a struct and variables 2020-09-25 09:02:05 +12:00
rail
9573a0d378 Rename variables 2020-09-25 09:02:05 +12:00
rail
13c207d375 Generalise InitializeVisitor 2020-09-25 09:02:05 +12:00
rail
c599e2fcfa Split VarState 2020-09-25 09:02:05 +12:00
rail
31cb110964 add concinient methods to Increment/InitializeVisitor 2020-09-25 08:59:14 +12:00
rail
b2d5b89a1d Check if it's after the loop earlier 2020-09-25 08:59:14 +12:00
rail
116f30dc33 Use else blocks instead of return statements in Increment/InitializeVisitor 2020-09-25 08:59:14 +12:00
rail
dc89bb1135 Use if_chain in Increment/InitializeVisitor 2020-09-25 08:59:14 +12:00
Takayuki Nakata
2892a2b0f5 Fix FP in print_stdout
This lint shouldn't be emitted in `build.rs` as `println!` and `print!` are used for the build script.
2020-09-24 23:22:54 +09:00
bors
cc1998f7b3 Auto merge of #6077 - ebroto:revert_or_fun_call_const, r=matthiaskrgr
Revert: or_fun_call should lint calls to `const fn`s with no args

The changes in #5889 and #5984 were done under the incorrect assumption that a `const fn` with no args was guaranteed to be evaluated at compile time.  A `const fn` is only guaranteed to be evaluated at compile time if it's inside a const context (the initializer of a `const` or a `static`).

See this [zulip conversation](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/Common.20misconception.3A.20.60const.20fn.60.20and.20its.20effect.20on.20codegen/near/208059113) for more details on this common misconception.

Given that none of the linted methods by `or_fun_call` can be called in const contexts, the lint should make no exceptions.

changelog: [`or_fun_call`] lints again calls to `const fn` with no args
2020-09-24 14:14:53 +00:00
bors
019c0d5f7f Auto merge of #6076 - rail-rain:fix_fp_explicit_counter_loop, r=matthiaskrgr
Fix a FP in `explicit_counter_loop`

Fixes #4677 and #6074

Fix a false positive in `explicit_counter_loop` where the loop counter is used after incremented, adjust the test so that counters are incremented at the end of the loop and add the test for this false positive.

---

changelog: Fix a false positive in `explicit_counter_loop` where the loop counter is used after incremented
2020-09-24 13:45:24 +00:00
flip1995
d1f9cad102 Merge commit 'e636b88aa180e8cab9e28802aac90adbc984234d' into clippyup 2020-09-24 14:49:22 +02:00
Eduardo Broto
9365660a2f unnecessary sort by: avoid dereferencing closure param 2020-09-23 23:33:50 +02:00
bors
e636b88aa1 Auto merge of #6044 - rschoon:rc-buffer, r=yaahc
Add `rc_buffer` lint for checking Rc<String> and friends

Fixes #2623

This is a bit different from the original PR attempting to implement this type of lint.   Rather than linting against converting into the unwanted types, this PR lints against declaring the unwanted type in a struct or function definition.

I'm reasonably happy with what I have here, although I used the fully qualified type names for the Path and OsString suggestions, and I'm not sure if I should have just used the short versions instead, even if they might not have been declared via use.

Also, I don't know if "buffer type" is the best way to put it or not.  Alternatively I could call it a "growable type" or "growable buffer type", but I was thinking of PathBuf when I started making the lint.

changelog: Add `rc_buffer` lint
2020-09-23 18:35:08 +00:00
Robin Schoonover
6c056d3465 Satisfy rc_buffer lint in Constant::Binary byte string by copying data
We can avoid the data copy again by fixing rustc_ast::ast::LitKind
later.
2020-09-22 20:35:54 -06:00
Eduardo Broto
ce83d8d4d1 Revert "Avoid or_fun_call for const_fn with no args"
This reverts commit 5d66bd7bb3.
2020-09-23 00:39:00 +02:00
Eduardo Broto
3e294b22a4 Revert "or_fn_call: ignore nullary associated const fns"
This reverts commit 7a66e6502d.
2020-09-23 00:34:56 +02:00
rail
5e393c7747 Fix a FP in explicit_counter_loop
Fix a false positive in `explicit_counter_loop` where the loop counter is used after incremented,
adjust the test so that counters are incremented at the end of the loop
and add the test for this false positive.
2020-09-23 08:15:44 +12:00
Aleksei Latyshev
d4f158fa5c
Forbid redundant_pattern_matching triggering in macros
- remove ice-2636 test
2020-09-21 20:49:42 +03:00
Eduardo Broto
6e07247578 Merge remote-tracking branch 'upstream/master' into rustup 2020-09-21 15:11:24 +02:00
Christiaan Dirkx
141b9c2890 Remove can_suggest from Clippy.
Removes `can_suggest` from as it is no longer used.
Reverts rust-clippy#5724.
2020-09-21 00:00:33 +02:00
bors
a334ae658b Auto merge of #76136 - CDirkx:const-result, r=dtolnay
Stabilize some Result methods as const

Stabilize the following methods of Result as const:
 - `is_ok`
 - `is_err`
 - `as_ref`

A test is also included, analogous to the test for `const_option`.

These methods are currently const under the unstable feature `const_result` (tracking issue: #67520).
I believe these methods to be eligible for stabilization because of the stabilization of #49146 (Allow if and match in constants) and the trivial implementations, see also: [PR#75463](https://github.com/rust-lang/rust/pull/75463) and [PR#76135](https://github.com/rust-lang/rust/pull/76135).

Note: these methods are the only methods currently under the `const_result` feature, thus this PR results in the removal of the feature.

Related: #76225
2020-09-20 13:07:11 +00:00
CDirkx
ac0d069616 Update src/tools/clippy/clippy_lints/src/matches.rs
Co-authored-by: Ralf Jung <post@ralfj.de>
2020-09-20 12:21:23 +02:00
Christiaan Dirkx
292e2f71a7 Remove can_suggest check for is_ok and is_err.
`is_ok` and `is_err` are stabilized as const and can thus always be suggested.
2020-09-20 10:46:30 +02:00
rail
2fc9064921 rewrite the test and fix a minor fp
* rewrite the test for `declare_interior_mutable_const from scratch`

* fix a minor false positive where `Cell<"const T>` gets linted twice
2020-09-17 19:48:40 +12:00
rail
d655c0a938 Change the criteria of interior_mutable_const
* stop linting associated types and generic type parameters
* start linting ones in trait impls
  whose corresponding definitions in the traits are generic
* remove the `is_copy` check
  as presumably the only purpose of it is to allow
  generics with `Copy` bounds as `Freeze` is internal
  and generics are no longer linted
* remove the term 'copy' from the tests
  as being `Copy` no longer have meaning
2020-09-17 19:38:37 +12:00
Robin Schoonover
27200855c3 Move rc_buffer lint into perf category 2020-09-16 17:20:36 -06:00
rail
ce06472246 replace walk_ptrs_ty with peel_refs 2020-09-17 10:11:59 +12:00
rail
2ce2d6b40e fix a FP in indexing_slicing
treat refs to arrays the same as arrays
in `indexing_slicing` and `out_of_bounds_indexing`
2020-09-17 10:11:10 +12:00
bors
06f1902878 Auto merge of #5937 - montrivo:option_if_let_else, r=flip1995
option_if_let_else - distinguish pure from impure else expressions

Addresses partially #5821.

changelog: improve the lint `option_if_let_else`. Suggest `map_or` or `map_or_else` based on the else expression purity.
2020-09-16 19:36:49 +00:00
bors
44d6439bfd Auto merge of #6025 - thomcc:compare_exchange_atomics, r=flip1995
Extend invalid_atomic_ordering for compare_exchange{,_weak} and fetch_update

changelog: The invalid_atomic_ordering lint can now detect misuse of `compare_exchange`, `compare_exchange_weak`, and `fetch_update`.

---

I was surprised not to find an issue or existing support here, since these are the functions which are always hardest to get the ordering right on for me (as the allowed orderings for `fail` depend on the `success` parameter).

I believe this lint now covers all atomic methods which care about their ordering now, but I could be wrong.

Hopefully I didn't forget to do anything for the PR!
2020-09-16 18:33:38 +00:00
bors
5e60497fb8 Auto merge of #6038 - mikerite:lint-5734, r=matthiaskrgr
Add `manual-strip` lint

Add `manual-strip` lint.

changelog: Add `manual-strip` lint
2020-09-16 18:13:36 +00:00
bors
b08bbe50ea Auto merge of #6048 - giraffate:add_note_to_shadow_unrelated, r=matthiaskrgr
Add note to `shadow_unrelated`

Fix #5455.

This lint can be disabled at function level.

changelog: none
2020-09-16 17:52:40 +00:00
bors
61dd007536 Auto merge of #6042 - euclio:println-empty, r=flip1995
{print,write}-with-newline: do not suggest empty format string

changelog: do not suggest empty format strings in `print-with-newline` and `write-with-newline`
2020-09-16 17:16:07 +00:00
Andy Russell
0261e341fd
{print,write}-with-newline: do not suggest empty format string 2020-09-16 11:25:53 -04:00
Lzu Tao
ad6f8c6354 bump pulldown-cmark v0.8 2020-09-16 12:09:57 +07:00
Tim Nielens
6ba36bcfd3 option_if_let_else - distinguish pure from impure else expressions 2020-09-16 01:30:50 +02:00
Michael Wright
79a0e5110a manual-strip: Fix formatting 2020-09-15 21:32:27 +02:00
Michael Wright
8b04c2d6e8 Merge branch 'master' into lint-5734 2020-09-15 21:21:35 +02:00
bors
0695f21994 Auto merge of #6043 - HaramanJohal:margin_of_error, r=matthiaskrgr
clarify margin of error in wording of float comparison operator lint messages

fixes #6040

changelog: change wording of float comparison operator to make margin of error less ambiguous
2020-09-15 17:17:31 +00:00
bors
190c6ea369 Auto merge of #6049 - flip1995:rustup, r=flip1995
Fix clippy hard-code slice::Iter path

r? `@ghost`

changelog: none
2020-09-15 16:46:41 +00:00
Haraman Johal
16b6cebaa6 update lint docs 2020-09-15 17:29:41 +01:00
Takayuki Nakata
44eb66d947 Add note to shadow_unrelated
This lint can be disabled at function level.
2020-09-16 01:01:31 +09:00
bors
9f0f035fe0 Auto merge of #6045 - giraffate:remove_extra_blank_line, r=flip1995
Remove an extra blank line in `shadow_same`

It seems to be an extra blank line in doc example.

changelog: none

<img width="1143" alt="スクリーンショット 2020-09-15 8 50 30" src="https://user-images.githubusercontent.com/17407489/93149409-369df080-f731-11ea-9a39-d8bbc72b61ee.png">
2020-09-15 12:26:25 +00:00
Lzu Tao
78f9ea5431 Fix clippy hard-code slice::Iter path 2020-09-15 10:21:40 +00:00
Eduardo Broto
d0b5663d30 Fix usage of backquotes in suggestion 2020-09-15 10:45:57 +02:00
Eduardo Broto
c86a7e5f38 Misc doc updates 2020-09-15 10:29:53 +02:00
Eduardo Broto
332c2dcb4d Fix dogfood after MatchTypeOnDiagItem 2020-09-15 10:29:53 +02:00
Eduardo Broto
8afa7ed6ae Add internal lint MatchTypeOnDiagItem 2020-09-15 10:29:53 +02:00
Dylan MacKenzie
72b402ed38 Add pass names to some common dataflow analyses 2020-09-14 17:56:39 -07:00
Takayuki Nakata
fd151f5135 Remove an extra blank line in shadow_same 2020-09-15 08:51:52 +09:00
Haraman Johal
4d73ccaa94 clarify margin of error in wording of float comparison operator lint messages 2020-09-15 00:20:31 +01:00
Robin Schoonover
2dd7175d60 Apply rc_buffer lint to Arc<T> 2020-09-14 17:08:14 -06:00
Robin Schoonover
1b5317f68b Add rc_buffer lint for Rc<String> and other buffer types 2020-09-14 17:08:14 -06:00
bors
f82e84c894 Auto merge of #5998 - deg4uss3r:master, r=yaahc
Add map_err_ignore lint

In a large code base a lot of times errors are ignored by using something like:

```rust
foo.map_err(|_| Some::Enum)?;
```

This drops the original error in favor of a enum that will not have the original error's context. This lint helps catch throwing away the original error in favor of an enum without its context.

---

*Please keep the line below*
changelog: Added map_err_ignore lint
2020-09-14 19:56:47 +00:00
Michael Wright
15244a88df Fix manual-strip dogfood errors 2020-09-14 06:11:35 +02:00
Michael Wright
d1f0f04a48 New lint: manual-strip
Add a new lint, `manual-strip`, that suggests using the `str::strip_prefix`
and `str::strip_suffix` methods introduced in Rust 1.45 when the same
functionality is performed 'manually'.

Closes #5734
2020-09-14 06:11:35 +02:00
bors
231444d989 Auto merge of #6035 - matthiaskrgr:try_into_show_type, r=flip1995
useless_conversion: show type in error message.

changelog: useless_conversion: show type in error message.
2020-09-13 18:57:55 +00:00
Takayuki Nakata
9ff7e5d984 Downgrade verbose_bit_mask to pedantic 2020-09-13 23:23:45 +09:00
Matthias Krüger
7ba1a8fec4 useless_conversion: show type in error message.
changelog: useless_conversion: show type in error message.
2020-09-13 12:50:39 +02:00
bors
21c351867a Auto merge of #6032 - matthiaskrgr:move_consume, r=flip1995
into_iter_on_ref: rephrase lint message: will not move the x -> will not consume the x

imo that's a bit clearer.

changelog: none
2020-09-13 08:10:12 +00:00
bors
c057621527 Auto merge of #6030 - rail-rain:fix_use_snippet_in_types, r=matthiaskrgr
fix some use of `snippet` in `types.rs`

changelog: none
2020-09-13 07:37:40 +00:00
flip1995
4df2069fc4
Merge remote-tracking branch 'upstream/master' into rustup 2020-09-12 15:58:41 +02:00
Matthias Krüger
2487f8f461 into_iter_on_ref: rephrase lint message: will not move the x -> will not consume the x
imo that's a bit clearer.
2020-09-11 16:52:25 +02:00
bors
519799f099 Auto merge of #75800 - Aaron1011:feature/full-nt-tokens, r=petrochenkov
Attach tokens to all AST types used in `Nonterminal`

We perform token capturing when we have outer attributes (for nonterminals that support attributes - e.g. `Stmt`), or when we parse a `Nonterminal` for a `macro_rules!` argument. The full list of `Nonterminals` affected by this PR is:

* `NtBlock`
* `NtStmt`
* `NtTy`
* `NtMeta`
* `NtPath`
* `NtVis`
* `NtLiteral`

Of these nonterminals, only `NtStmt` and `NtLiteral` (which is actually just an `Expr`), support outer attributes - the rest only ever have token capturing perform when they match a `macro_rules!` argument.

This makes progress towards solving https://github.com/rust-lang/rust/issues/43081 - we now collect tokens for everything that might need them. However, we still need to handle `#[cfg]`, inner attributes, and misc pretty-printing issues (e.g. #75734)

I've separated the changes into (mostly) independent commits, which could be split into individual PRs for each `Nonterminal` variant. The purpose of having them all in one PR is to do a single Crater run for all of them.

Most of the changes in this PR are trivial (adding `tokens: None` everywhere we construct the various AST structs). The significant changes are:

* `ast::Visibility` is changed from `type Visibility = Spanned<VisibilityKind>` to a `struct Visibility { kind, span, tokens }`.
* `maybe_collect_tokens` is made generic, and used for both `ast::Expr` and `ast::Stmt`.
* Some of the statement-parsing functions are refactored so that we can capture the trailing semicolon.
* `Nonterminal` and `Expr` both grew by 8 bytes, as some of the structs which are stored inline (rather than behind a `P`) now have an `Option<TokenStream>` field. Hopefully the performance impact of doing this is negligible.
2020-09-11 02:35:01 +00:00
Aaron Hill
8808dc6abf Fully integrate token collection for additional AST structs
This commit contains miscellaneous changes that don't fit into any of
the other commits in this PR
2020-09-10 17:58:14 -04:00
Thom Chiovoloni
09f7a377a6 Add comments to the invalid_atomic_ordering example 2020-09-10 14:50:10 -07:00
bors
0ab75c37b6 Auto merge of #5977 - xvschneider:AddLintPanicInResult, r=matthiaskrgr
Add lint panic in result

### Change
Adding a new "restriction" lint that will emit a warning when using "panic", "unimplemented" or "unreachable" in a function of type option/result.

### Motivation
Some codebases must avoid crashes at all costs, and hence functions of type option/result must return an error instead of crashing.

### Test plan
Running:
TESTNAME=panic_in_result cargo uitest ---

changelog: none
2020-09-10 16:22:20 +00:00
flip1995
a12828a80a Merge commit '5034d47f721ff4c3a3ff2aca9ef2ef3e1d067f9f' into clippyup 2020-09-10 17:47:07 +02:00
bors
df6d7bfbef Auto merge of #6028 - giraffate:fix_typo, r=flip1995
Fix typo

changelog: none
2020-09-10 15:41:29 +00:00
bors
99374ae136 Auto merge of #6019 - rail-rain:improve_known_probs_mut_key, r=flip1995
Improve the "known problems" section of `interior_mutable_key`

* Remove the mention to `Rc` and `Arc` as these are `Freeze` (despite my intuition) so the lint correctly handles already.
* Instead, explain what could cause a false positive, and mention `bytes` as an example.

---

changelog: Improved the "known problems" section of `interior_mutable_key`
2020-09-10 15:17:09 +00:00
Philipp Krones
36a864854f
Fix spelling of "Known problems section" of interior_mutable_key 2020-09-10 17:08:10 +02:00
bors
5034d47f72 Auto merge of #5980 - matsujika:create-dir, r=flip1995
Add a lint to prevent `create_dir` from being used

This closes #5950
changelog: none
2020-09-10 14:34:22 +00:00
bors
55efa96659 Auto merge of #5931 - montrivo:unit-arg, r=flip1995
improve the suggestion of the lint `unit-arg`

Fixes #5823
Fixes #6015

Changes
```
help: move the expression in front of the call...
  |
3 |     g();
  |
help: ...and use a unit literal instead
  |
3 |     o.map_or((), |i| f(i))
  |
```
into
```
help: move the expression in front of the call and replace it with the unit literal `()`
  |
3 |     g();
  |     o.map_or((), |i| f(i))
  |
```
changelog: improve the suggestion of the lint `unit-arg`
2020-09-10 14:11:27 +00:00
bors
0e9769e787 Auto merge of #6023 - matthiaskrgr:box, r=flip1995
link to the Box docs in related lint documentation.

changelog: link to the box docs in lint docs
2020-09-10 13:49:50 +00:00
Takayuki Nakata
f1775f05b7 Fix typo 2020-09-10 22:41:08 +09:00
bors
87a4495b5d Auto merge of #6027 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2020-09-10 13:25:39 +00:00
flip1995
2d56512580
Cleanup of rustup 2020-09-10 15:23:38 +02:00
rail
f3489d4a5e fix some use of snippet in types.rs 2020-09-10 19:31:43 +12:00
Thom Chiovoloni
4b5326b0d6 Address small review comments 2020-09-09 23:12:57 -07:00
bors
961f18317d Auto merge of #75573 - Aaron1011:feature/const-mutation-lint, r=oli-obk
Add CONST_ITEM_MUTATION lint

Fixes #74053
Fixes #55721

This PR adds a new lint `CONST_ITEM_MUTATION`.
Given an item `const FOO: SomeType = ..`, this lint fires on:

* Attempting to write directly to a field (`FOO.field = some_val`) or
  array entry (`FOO.array_field[0] = val`)
* Taking a mutable reference to the `const` item (`&mut FOO`), including
  through an autoderef `FOO.some_mut_self_method()`

The lint message explains that since each use of a constant creates a
new temporary, the original `const` item will not be modified.
2020-09-10 05:54:26 +00:00
Thom Chiovoloni
b65745545f Use AtomicU8 in ordering example so all operations can be demonstrated 2020-09-09 14:40:43 -07:00
Thom Chiovoloni
61671a2268 Detect fetch_update misuse in invalid_atomic_ordering too 2020-09-09 14:15:54 -07:00
Thom Chiovoloni
6211599cca Extend invalid_atomic_ordering to detect misuse of compare_exchange{,_weak} 2020-09-09 14:15:54 -07:00
Vali Schneider
3550568a54 removing if chain and renaming lint 2020-09-09 14:02:34 -07:00
Matthias Krüger
de195f2d3d print the unit type () in related lint messages. 2020-09-09 17:59:13 +02:00
Matthias Krüger
4db10297c1 link to the Box docs in related lint documentation. 2020-09-09 16:54:24 +02:00
rail
d712d7f700 Improve "known problems" of interior_mutable_key
* Remove the mention to `Rc` and `Arc` as these are `Freeze`
  so the lint correctly handles already.

* Instead, explain what could cause a false positive,
  and mention `bytes` as an example.
2020-09-09 14:18:19 +12:00
Ricky
d719b48543 Move map_err_ignore from style to pedantic 2020-09-08 19:37:14 -04:00
Aaron Hill
f23670ed68 Adjust Clippy for CONST_ITEM_MUTATION lint
We no longer lint assignments to const item fields in the
`temporary_assignment` lint, since this is now covered by the
`CONST_ITEM_MUTATION` lint.

Additionally, we `#![allow(const_item_mutation)]` in the
`borrow_interior_mutable_const.rs` test. Clippy UI tests are run with
`-D warnings`, which seems to cause builtin lints to prevent Clippy
lints from running.
2020-09-08 17:59:56 -04:00
bors
8b54f1e2d9 Auto merge of #6016 - giraffate:restrict_same_item_push, r=ebroto
Restrict `same_item_push` to suppress false positives

It only emits a lint when the pushed item is a literal, a constant and an immutable binding that are initialized with those, as discussed in https://github.com/rust-lang/rust-clippy/pull/5997#pullrequestreview-483005186.

Fix https://github.com/rust-lang/rust-clippy/issues/5985

changelog: Restrict `same_item_push` to literals, constants and immutable bindings that are initialized with those.

r? `@ebroto`
2020-09-08 21:34:55 +00:00
Eduardo Broto
e83190bdd4 Merge remote-tracking branch 'upstream/master' into rustup 2020-09-08 22:26:31 +02:00
Ricky
4f1c4a99d4 Fixed typo in lint and test 2020-09-08 12:05:18 -04:00
Hirochika Matsumoto
a899ad2e12 Change suggestion to create_dir_all({}) from std::fs::create_dir_all({}) 2020-09-08 23:35:19 +09:00
Takayuki Nakata
1d8ae3aa12 Address items_after_statement 2020-09-08 23:12:04 +09:00
Tim Nielens
a60e5de90c needless-lifetime / nested elision sites / PR remarks 2020-09-08 02:41:38 +02:00
Takayuki Nakata
5d085ad011 Some refactoring 2020-09-08 08:34:51 +09:00
Takayuki Nakata
619ca76731 Refactoring: use inner function 2020-09-08 08:25:31 +09:00
bors
3ffe9f843c Auto merge of #76044 - ecstatic-morse:dataflow-lattice, r=oli-obk
Support dataflow problems on arbitrary lattices

This PR implements last of the proposed extensions I mentioned in the design meeting for the original dataflow refactor. It extends the current dataflow framework to work with arbitrary lattices, not just `BitSet`s. This is a prerequisite for dataflow-enabled MIR const-propagation. Personally, I am skeptical of the usefulness of doing const-propagation pre-monomorphization, since many useful constants only become known after monomorphization (e.g. `size_of::<T>()`) and users have a natural tendency to hand-optimize the rest. It's probably worth exprimenting with, however, and others have shown interest cc `@rust-lang/wg-mir-opt.`

The `Idx` associated type is moved from `AnalysisDomain` to `GenKillAnalysis` and replaced with an associated `Domain` type that must implement `JoinSemiLattice`. Like before, each `Analysis` defines the "bottom value" for its domain, but can no longer override the dataflow join operator. Analyses that want to use set intersection must now use the `lattice::Dual` newtype. `GenKillAnalysis` impls have an additional requirement that `Self::Domain: BorrowMut<BitSet<Self::Idx>>`, which effectively means that they must use `BitSet<Self::Idx>` or `lattice::Dual<BitSet<Self::Idx>>` as their domain.

Most of these changes were mechanical. However, because a `Domain` is no longer always a powerset of some index type, we can no longer use an `IndexVec<BasicBlock, GenKillSet<A::Idx>>>` to store cached block transfer functions. Instead, we use a boxed `dyn Fn` trait object. I discuss a few alternatives to the current approach in a commit message.

The majority of new lines of code are to preserve existing Graphviz diagrams for those unlucky enough to have to debug dataflow analyses. I find these diagrams incredibly useful when things are going wrong and considered regressing them unacceptable, especially the pretty-printing of `MovePathIndex`s, which are used in many dataflow analyses. This required a parallel `fmt` trait used only for printing dataflow domains, as well as a refactoring of the `graphviz` module now that we cannot expect the domain to be a `BitSet`. Some features did have to be removed, such as the gen/kill display mode (which I didn't use but existed to mirror the output of the old dataflow framework) and line wrapping. Since I had to rewrite much of it anyway, I took the opportunity to switch to a `Visitor` for printing dataflow state diffs instead of using cursors, which are error prone for code that must be generic over both forward and backward analyses. As a side-effect of this change, we no longer have quadratic behavior when writing graphviz diagrams for backward dataflow analyses.

r? `@pnkfelix`
2020-09-07 21:29:43 +00:00
Takayuki Nakata
3d30ef7818 Restrict same_item_push to suppress false positives
It emits a lint when the pushed item is a literal, a constant and an immutable binding that are initialized with those.
2020-09-07 23:46:43 +09:00
Eduardo Broto
9fa9208bd5 Restrict unnecessary_sort_by to non-ref copy types 2020-09-07 00:19:17 +02:00
Tim Nielens
390a13b06c needless-lifetime - fix nested elision site FPs 2020-09-06 23:06:58 +02:00
bors
e9440cbcde Auto merge of #5997 - giraffate:fix_fp_about_clone_in_same_item_push, r=ebroto
Fix FP in `same_item_push`

Don't emit a lint when the pushed item doesn't have Clone trait

Fix #5979

changelog: Fix FP in `same_item_push` not to emit a lint when the pushed item doesn't have Clone trait
2020-09-05 20:27:17 +00:00
Takayuki Nakata
96b31a5b36 Fix FP when coercion kicks in 2020-09-06 00:02:35 +09:00
Ryan1729
04ba07bdc3 add line_count and max_lines to too_many_lines lint message 2020-09-04 19:26:35 -06:00
Jane Lusby
c31d4730b0 update example to be more idiomatic 2020-09-04 15:55:13 -07:00
Eduardo Broto
2905fff936 Run cargo dev fmt 2020-09-04 23:30:55 +02:00
Eduardo Broto
7bcf40a13d Fix fallout from rustup 2020-09-04 23:30:06 +02:00
Eduardo Broto
23646e6583 Merge remote-tracking branch 'upstream/master' into sync-from-rust 2020-09-04 23:27:01 +02:00
LeSeulArtichaut
4286d9c87a ty.flags -> ty.flags() 2020-09-04 18:28:20 +02:00
LeSeulArtichaut
28f9b84042 ty.kind -> ty.kind() in rustdoc and clippy 2020-09-04 18:27:33 +02:00
Michael Wright
cf1cc7c449 Simplify clippy::default_trait_access
Remove repeated matching on the same QPath.
2020-09-04 05:15:31 +02:00
bors
8829214764 Auto merge of #5994 - taiki-e:useless_attribute, r=phansch
useless_attribute: Permit wildcard_imports and enum_glob_use

Fixes #5918

changelog: `useless_attribute`: Permit `wildcard_imports` and `enum_glob_use` on `use` items
2020-09-03 05:33:03 +00:00
Ricky
2387f68e43 Removed map_err suggestion in lint, and updated lint documentation example 2020-09-02 19:21:34 -04:00
Tim Nielens
b220ddf146 unit-arg - pr remarks 2020-09-02 23:30:40 +02:00
Tim Nielens
b1f0e019fe Merge branch 'master' into unit-arg 2020-09-02 19:39:54 +02:00
bors
7f27b12288 Auto merge of #5996 - Koxiaet:master, r=ebroto
Allow GraphQL in docs without backticks

changelog: Allow "GraphQL" in [`doc_markdown`] without backticks.
2020-09-02 12:24:31 +00:00
Eduardo Broto
a5754a1fad Run cargo dev fmt 2020-09-02 08:57:00 +02:00
Eduardo Broto
da86067775 Merge remote-tracking branch 'upstream/master' into sync-from-rust 2020-09-02 08:53:29 +02:00
Ricky
337729137b Ran cargo dev update_lints 2020-09-01 17:05:40 -04:00
Ricky
202a80c927 Added tests for map_err, ignored map_err lint on drop_ref tests 2020-09-01 16:59:37 -04:00
Ricky
e49a29933b Working map_err_ignore lint 2020-09-01 16:26:59 -04:00
Takayuki Nakata
aa7ffa5257 Fix FP in same_item_push
Don't emit a lint when the pushed item doesn't have Clone trait
2020-09-01 22:39:09 +09:00
Koxiaet
b30422114e
Allow GraphQL in doc without backticks 2020-09-01 14:05:19 +01:00
Taiki Endo
2e4b4cebbb useless_attribute: Permit wildcard_imports and enum_glob_use 2020-09-01 12:09:32 +09:00
rail
afeb917fca Fix a fp in transmute_ptr_to_ptr
Avoid firing the lint when `transmute` in const contexts
as dereferencing raw pointers in consts is unstable. cc #5959
2020-09-01 11:51:32 +12:00
bors
67e18c2d5c Auto merge of #5993 - taiki-e:default_trait_access, r=phansch
default_trait_access: Fix wrong suggestion

https://github.com/rust-lang/rust-clippy/issues/5975#issuecomment-683751131
> I think the underlying problem is clippy suggests code with complete parameters, not clippy triggers this lint even for complex types. AFAIK, If code compiles with `Default::default`, it doesn't need to specify any parameters, as type inference is working. (So, in this case, `default_trait_access` should suggest `RefCell::default`.)

Fixes #5975 Fixes #5990

changelog: `default_trait_access`: fixed wrong suggestion
2020-09-01 15:05:16 +00:00
Vali Schneider
f9fcbbea03 fixed bug 2020-08-31 13:32:05 -07:00
bors
066f105d67 Auto merge of #5992 - giraffate:fix_wrong_seggestion_in_collapsible_if, r=yaahc
Fix the wrong suggestion when using macro in `collapsible_if`

Fix #5962

changelog: Fix the wrong suggestion when using macro in `collapsible_if`
2020-08-31 19:41:13 +00:00
bors
8334a58c2f Auto merge of #5909 - khuey:async_yields_async, r=yaahc
Add a lint for an async block/closure that yields a type that is itself awaitable.

This catches bugs of the form

tokio::spawn(async move {
    let f = some_async_thing();
    f // Oh no I forgot to await f so that work will never complete.
});

See the two XXXkhuey comments and the unfixed `_l` structure for things that need more thought.

*Please keep the line below*
changelog: none
2020-08-31 19:20:30 +00:00
Taiki Endo
8b0aa6a00b default_trait_access: Fix wrong suggestion 2020-09-01 00:31:53 +09:00
Takayuki Nakata
001f9e45f2 Fix the wrong suggestion when using macro in collapsible_if 2020-09-01 00:05:53 +09:00
Hirochika Matsumoto
451ef78803 Use match_def_path instead of match_qpath 2020-08-31 22:40:47 +09:00
bors
001c1c51d2 Auto merge of #5984 - ebroto:5693_const_assoc_fn, r=flip1995
or_fn_call: ignore nullary associated const fns

The fix in #5889 was missing associated functions.

changelog: Ignore also `const fn` methods in [`or_fun_call`]

Fixes #5693
2020-08-31 10:43:58 +00:00
Aaron Hill
fdc48fb90c Fix clippy 2020-08-30 19:17:17 -04:00
Camelid
17b2ba5ded Syntax-highlight single_char_push_str lint 2020-08-30 11:29:17 -07:00
Dylan MacKenzie
1c5b0fbe53 Update dataflow analyses to use new interface 2020-08-30 11:15:25 -07:00
Vali Schneider
73a3288282 uncommented fn 2020-08-29 16:22:15 -07:00
Vali Schneider
a424a2c167 changed check_impl_item to check_fn and added a few more test cases 2020-08-29 16:17:53 -07:00
Kyle Huey
04912ca115 Formatting changes requested by ThibsG. 2020-08-29 15:33:54 -07:00
Kyle Huey
4972989b61 Add a lint for an async block/closure that yields a type that is itself awaitable.
This catches bugs of the form

tokio::spawn(async move {
    let f = some_async_thing();
    f // Oh no I forgot to await f so that work will never complete.
});
2020-08-29 15:33:54 -07:00
Hirochika Matsumoto
5b7590f841 Downgrade applicability of create_dir 2020-08-29 14:20:01 +09:00
Eduardo Broto
7a66e6502d or_fn_call: ignore nullary associated const fns 2020-08-29 01:20:49 +02:00
flip1995
282c59820b Merge commit '3d0b0e66afdfaa519d8855b338b35b4605775945' into clippyup 2020-08-28 18:43:25 +02:00
bors
3d0b0e66af Auto merge of #5774 - ThibsG:FixNewRetNoSelf, r=ebroto
Fix FP in `new_ret_no_self`: trigger in trait def instead of impl block

Lint in trait def instead of impl block.

Fixes: #5435

changelog: none
2020-08-28 11:54:07 +00:00
Hirochika Matsumoto
eebd248365 Fix errors 2020-08-28 19:56:19 +09:00
Hirochika Matsumoto
34e302e67c Fix clippy error 2020-08-28 19:35:04 +09:00
Hirochika Matsumoto
607905d126 Add STD_FS_CREATE_DIR into paths 2020-08-28 18:53:15 +09:00
Hirochika Matsumoto
5574182b4d Add a new lint to prevent create_dir from being used 2020-08-28 18:45:28 +09:00
Thibaud
73b1ee1a61
Update clippy_lints/src/methods/mod.rs
Co-authored-by: Eduardo Broto <ebroto@tutanota.com>
2020-08-28 09:33:05 +02:00
Thibaud
ffaadae8e4
Update clippy_lints/src/utils/mod.rs
Co-authored-by: Eduardo Broto <ebroto@tutanota.com>
2020-08-28 09:31:29 +02:00
Thibaud
e8be047c5b
Update clippy_lints/src/utils/mod.rs
Co-authored-by: Eduardo Broto <ebroto@tutanota.com>
2020-08-28 09:31:12 +02:00
Vali Schneider
b006522393 added lint for todo and removed option 2020-08-27 16:55:23 -07:00
bors
07c5e9edb5 Auto merge of #5971 - giraffate:fix_fp_in_to_string_in_display, r=ebroto
Fix FP in `to_string_in_display`

Don't emit a lint when `.to_string()` on anything that is not `self`

Fix #5967

changelog: Fix FP in `to_string_in_display` when calling `.to_string()` on anything that is not `self`
2020-08-27 23:26:52 +00:00
Vali Schneider
8462cce960 edited documentation 2020-08-27 16:22:37 -07:00
Vali Schneider
ceab1a9167 removed unnecessary comment 2020-08-27 16:19:24 -07:00
Vali Schneider
459969f88f added restriction lint that prohibits the usage of unimplemented, unreachable or panic in a function of type result or option 2020-08-27 16:18:05 -07:00
Tim Nielens
f3ccbef2af unit-arg - pr comments 2020-08-27 19:36:28 +02:00
ThibsG
504612622f Merge logic of looking for Self type 2020-08-27 18:31:31 +02:00
ThibsG
3cb75c2e5c Remove expansion restriction + fix doc and tests naming 2020-08-27 18:25:38 +02:00
ThibsG
2a3ee5fa85 Fix FP in new_ret_no_self: trigger in trait def instead of impl block 2020-08-27 18:25:38 +02:00
Takayuki Nakata
04bff17668 Fix FP in to_string_in_display
Don't emit a lint when `.to_string()` on anything that is not `self`
2020-08-27 23:37:47 +09:00
Jane Lusby
91024f1fde Add new lint to prevent usage of unwrap in fns that return result 2020-08-26 16:31:49 -07:00
rail
edc05da57d Fix the wrong use of snippet_with_applicability
This includes a workaround of the issue #5822,
the cause of this little mistake.
2020-08-27 10:24:16 +12:00
bors
64c4bb0d2b Auto merge of #5966 - 1c3t3a:1c3t3a-dev-5819-fix, r=Manishearth
Corrects the float_equality_without_abs lint

Fixes an issue in the `float_equality_without_abs` lint. The lint suggestion was configured in a way that it lints the whole error and not just the subtraction part. In the current configuration the lint would suggest to change the expression in a wrong way, e.g.
```rust
let _ = (a - b) < f32::EPSILON; // before
let _ = (a - b).abs(); // after
```
This was dicovered by @flip1995. (See discussion of PR #5952).

Also the suggestion is now formatted via `utils::sugg`.
changelog: none
2020-08-26 18:15:42 +00:00
Bastian
2d853148d7 Changed the location of the suggestion as well as the way the suggestion is assembled 2020-08-26 16:39:30 +02:00
bors
894581b872 Auto merge of #5946 - mikerite:fix-5729, r=flip1995
Fix `let_and_return` bad suggestion

Add a cast to the suggestion when the return expression has adjustments.
These adjustments are lost when the suggestion is applied.

This is similar to the problem in issue #4437.

Closes #5729

changelog: Fix `let_and_return` bad suggestion
2020-08-26 12:01:32 +00:00
bors
9ef44799bf Auto merge of #5949 - rail-rain:fix_fp_borrow_interior_mutable_const, r=oli-obk
Fix fp in `borrow_interior_mutable_const`

fixes #5796

changelog: fix false positive in `borrow_interior_mutable_const` when referencing a field behind a pointer.
2020-08-26 11:06:37 +00:00
Hirochika Matsumoto
9d18c24b56 Fix typo 2020-08-26 16:03:35 +09:00
bors
ad7a03cbaa Auto merge of #5951 - ThibsG:FixMacroCloneOnRefPtr2076, r=ebroto
Fix incorrect suggestion when `clone_on_ref_ptr` is triggered in macros

In the lint `clone_on_ref_ptr`, if the `span` is in a macro, don't expand it for suggestion.

Fixes: #2076

changelog: none

r? @ebroto
2020-08-25 21:48:19 +00:00
Thibaud
370fc45a0a
Update clippy_lints/src/methods/mod.rs
Co-authored-by: Eduardo Broto <ebroto@tutanota.com>
2020-08-25 22:20:35 +02:00
Scott McMurray
3b1e5d6ff7 Re-enable len_zero for ranges now that is_empty is stable on them 2020-08-25 12:17:03 -07:00
bors
f9015592f3 Auto merge of #5952 - 1c3t3a:1c3t3a-dev-5819, r=Manishearth
Added a lint which corrects expressions like (a - b) < f32::EPSILON, according to #5819

Fixes #5819
changelog: none
2020-08-25 16:54:48 +00:00
Bastian
179df0bd15 Added F32::EPSILON and F64::EPSILON to paths.rs 2020-08-25 13:41:39 +02:00
bors
64b53f3877 Auto merge of #5920 - giraffate:fix_fp_for_redundant_closure_call, r=mikerite
Fix FP for `redundant_closure_call`

Fix #5916

changelog: Fix FP for `redundant_closure_call` when called in function body
2020-08-25 03:29:59 +00:00
Matthias Krüger
e9964f2e8a stable_sort_primitive: print the type that is being sorted in the lint message 2020-08-24 20:06:43 +02:00
Bastian
680c68153b Added a lint which corrects expressions like (a - b) < f32::EPSILON 2020-08-24 16:31:51 +02:00
ThibsG
3d820f71fe Fix incorrect suggestion when clone_on_ref_ptr is triggered in macros 2020-08-24 14:05:49 +02:00
Takayuki Nakata
9fe0ac36a5 Avoid period in lint message according to convention 2020-08-24 10:11:53 +09:00
Takayuki Nakata
b2c2266792 Fix FP for redundant_closure_call
Visit the nested things like function body when checking closure call.
2020-08-24 09:43:16 +09:00
rail
91b200c62b Fix fp in borrow_interior_mutable_const
Fix false positive when referencing a field behind a pointer.
2020-08-23 22:49:08 +12:00
Eduardo Broto
8776db9f6d Fix ICE in repeat_once lint 2020-08-23 12:05:34 +02:00
Michael Wright
e8d33d73dc Fix let_and_return bad suggestion
Add a cast to the suggestion when the return expression has adjustments.
These adjustments are lost when the suggestion is applied.

This is similar to the problem in issue #4437.

Closes #5729
2020-08-23 07:50:59 +02:00
bors
dd07860b83 Auto merge of #5941 - ThibsG:InlineInCopyPassByRef, r=yaahc
Don't lint if it has always inline attribute

Don't trigger the lint `trivially_copy_pass_by_ref` if it has `#[inline(always)]` attribute.

Note: I am not particularly familiar with `inline` impacts, so I implemented this the way that if only `#[inline]` attribute is here (without `always`), the lint will still trigger. Also, it will still trigger if it has `#[inline(never)]`.
Just tell me if it sounds too much conservative.

Fixes: #5876

changelog: none
2020-08-22 18:30:39 +00:00
Christian Stefanescu
e615a26ae4 Use more elegant way to check for prelude string 2020-08-22 14:22:02 +02:00
Christian Stefanescu
5b07b9ed61 Widen understanding of prelude import
Prelude imports are exempt from wildcard import warnings. Until now only
imports of the form

```
use ...::prelude::*;
```

were considered. This change makes it so that the segment `prelude` can
show up anywhere, for instance:

```
use ...::prelude::v1::*;
```

Fixes #5917
2020-08-22 14:22:02 +02:00
ThibsG
191b6c798f Don't lint if it has always inline attribute 2020-08-22 12:58:35 +02:00
bors
b57ef14290 Auto merge of #5926 - giraffate:improve_lint_message_in_to_string_in_display, r=yaahc
Improve lint message in `to_string_in_display`

This is a follow-up of https://github.com/rust-lang/rust-clippy/pull/5831.

changelog: none
2020-08-22 04:51:38 +00:00
bors
aa3b04ff74 Auto merge of #5933 - mikerite:fix-5927, r=matthiaskrgr
Fix false negative in `option_as_ref_deref`

Closes #5927

changelog: Fix false negative in `option_as_ref_deref`
2020-08-21 23:43:20 +00:00
Eduardo Broto
146e352db4 run cargo dev fmt 2020-08-22 00:59:42 +02:00
Eduardo Broto
c2799c861d Merge remote-tracking branch 'upstream/master' into sync-from-rust 2020-08-22 00:53:03 +02:00
Michael Wright
11efd75aeb Fix false negative in option_as_ref_deref 2020-08-21 07:23:04 +02:00
Tim Nielens
2ecc2ac864 unit-arg - improve suggestion 2020-08-21 00:42:11 +02:00
bors
4104611913 Auto merge of #5928 - mikerite:fix-5924, r=ebroto
Fix false positive in `PRECEDENCE` lint

Extend the lint to handle chains of methods combined with unary negation.

Closes #5924

changelog: Fix false negative in `PRECEDENCE` lint
2020-08-20 22:09:27 +00:00
Aaron Hill
191b0806d2 Capture tokens for Pat used in macro_rules! argument
This extends PR #73293 to handle patterns (Pat). Unlike expressions,
patterns do not support custom attributes, so we only need to capture
tokens during macro_rules! argument parsing.
2020-08-20 02:45:28 -04:00
Michael Wright
c236c0fb56 Fix false positive in PRECEDENCE lint
Extend the lint to handle chains of methods combined with unary negation.

Closes #5924
2020-08-20 06:34:48 +02:00
Takayuki Nakata
902b28275e Improve lint message in to_string_in_display 2020-08-19 22:31:34 +09:00
Eduardo Broto
6a12bae194 no from/to bits in const: add tests cases for f64 2020-08-18 22:19:30 +02:00
Eduardo Broto
df4d42fc2d transmute: avoid suggesting from/to bits in const 2020-08-18 21:55:56 +02:00
flip1995
c680602005
Merge remote-tracking branch 'upstream/master' into rustup 2020-08-18 19:50:23 +02:00
bors
4b0e6d5b90 Auto merge of #75120 - JulianKnodt:rm_reps, r=oli-obk
rust_ast::ast => rustc_ast

Rework of #71199 which is a rework #70621

Still working on this but just made the PR to track progress

r? @Dylan-DPC
2020-08-17 23:16:08 +00:00
Ujjwal Sharma
ae0eb390b0 rust_ast::ast => rustc_ast 2020-08-17 20:32:32 +00:00
bors
9360ca6dc2 Auto merge of #5908 - giraffate:fix_fp_for_same_item_push, r=flip1995
Fix FP for `same_item_push`

Fixes https://github.com/rust-lang/rust-clippy/issues/5902

changelog: Fix FP for `same_item_push` where the pushed variable is mutated.
2020-08-17 16:49:03 +00:00
David Wood
f13d2bfd9b clippy: support QPath::LangItem
This commit updates clippy with the introduction of `QPath::LangItem` so
that it still compiles.

Signed-off-by: David Wood <david@davidtw.co>
2020-08-17 13:55:05 +01:00
bors
838c201af9 Auto merge of #5915 - matthiaskrgr:deps_, r=Manishearth
deps: bump cargo_metadata and semver

cargo_metadata 0.9.1 -> 0.11.1
semver 0.9.0 -> 0.10.0

changelog: none
2020-08-17 12:23:44 +00:00
Matthias Krüger
262db3b5e6 deps: bump cargo_metadata and semver
cargo_metadata 0.9.1 -> 0.11.1
semver 0.9.0 -> 0.10.0
2020-08-17 12:19:32 +02:00
Takayuki Nakata
99ba290a14 Improve code style 2020-08-17 08:36:02 +09:00
Tomasz Miąsko
4f4abf4e06 Warn about explicit self-assignment
Warn about assignments where left-hand side place expression is the same
as right-hand side value expression. For example, warn about assignment in:

```rust
pub struct Event {
    id: usize,
    x: i32,
    y: i32,
}

pub fn copy_position(a: &mut Event, b: &Event) {
    a.x = b.x;
    a.y = a.y;
}
```
2020-08-16 23:31:36 +02:00
Tomasz Miąsko
d1dbf7913a Expresions with Assign / AssignOp have side effects 2020-08-16 23:31:27 +02:00
Tomasz Miąsko
9b800b1e92 Rename SpanlessEq::ignore_fn to deny_side_effects
No functional changes intended.
2020-08-16 23:30:33 +02:00
Tomasz Miąsko
6afa4ef60f Introduce function for comparing expression values
Introduce `eq_expr_value(cx, a, b)` as a shortcut for
`SpanlessEq::new(cx).ignore_fn().eq_expr(cx, a, b)`.

No functional changes intended.
2020-08-16 23:30:33 +02:00
bors
8d0d89adc8 Auto merge of #5720 - bugadani:new-lint, r=flip1995,yaahc
Add unnecessary lazy evaluation lint

changelog: Add [`unnecessary_lazy_evaluations`] lint that checks for usages of `unwrap_or_else` and similar functions that can be simplified.

Closes #5715
2020-08-16 20:27:43 +00:00
Dániel Buga
fc1e07e0c1 Rename lint to use plural form 2020-08-16 22:16:39 +02:00
Dániel Buga
b7ee8685ac Fix dogfooding test errors 2020-08-16 21:04:02 +02:00
Dániel Buga
3b52d7f780 run cargo dev fmt 2020-08-16 20:51:16 +02:00
Dániel Buga
8a14c11536 Cleanup, explain return value 2020-08-16 20:50:30 +02:00
Dániel Buga
d71b418ac5 Moved to submodule, don't trigger if map_unwrap_or does 2020-08-16 20:47:50 +02:00
Hactar
d8f0a14da1
Fix typo in description of unnecessary_mut_passed 2020-08-16 14:43:34 -04:00
Dániel Buga
9c41822d34 Apply suggested change
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-08-16 20:27:54 +02:00
Dániel Buga
94cf90e5a5 Apply suggested change
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-08-16 20:27:54 +02:00
Dániel Buga
a7083eea1c Removed the extra lifetime parameter 2020-08-16 20:27:54 +02:00
Dániel Buga
75637c1eda Catch function calls in argument lists, add tests that tuples don't get linted 2020-08-16 20:27:54 +02:00
Dániel Buga
d7220dbd91 Run cargo dev update_lints 2020-08-16 20:27:54 +02:00
Dániel Buga
a7cc5d4068 Also simplify if the closure body is an index expression 2020-08-16 20:27:54 +02:00
Dániel Buga
848af39310 Add note to or_fun_call, list checked methods 2020-08-16 20:27:54 +02:00
Dániel Buga
a3ea65c2d9 Implement new lint 2020-08-16 20:27:22 +02:00
bors
3bd98895f1 Auto merge of #5725 - montrivo:should-impl-trait, r=flip1995
should_impl_trait - ignore methods with lifetime params

Fixes: #5617

changelog: don't lint should_implement_trait when an `Iterator::next` case has explicit parameters
2020-08-16 17:51:18 +00:00
bors
78857cc9d3 Auto merge of #5907 - wiomoc:feature/useless-vec-max-size, r=flip1995
appreciative too_large_for_stack in useless `vec!`

Fixes: #5847
changelog: Add `too_large_for_stack ` configuration option for `USELESS_VEC`
2020-08-16 17:30:12 +00:00
bors
dff7e74b27 Auto merge of #5903 - jrqc:needless_return, r=ebroto,flip1995
Needless return

Fixes #5858
changelog: fix false positive [`needless_return`]
2020-08-16 17:08:45 +00:00
bors
c8e05fc1c6 Auto merge of #5881 - wiomoc:feature/single-char-push_str, r=ebroto,flip1995
Lint `push_str` with a single-character string literal

Fixes #5875
changelog:  `* [single_char_push_str]`
2020-08-16 16:41:57 +00:00
bors
e522ca3c8d Auto merge of #5831 - chansuke:to_string_in_display, r=flip1995
Don't use `to_string` in impl Display

fixes #3876

this PR is derived from [Toxyxer's implementation](https://github.com/rust-lang/rust-clippy/pull/5574).
changelog: add [`to_string_in_display`] lint
2020-08-16 16:21:37 +00:00
Eduardo Broto
1a140dcc1c Improve needless_doctest_main by using the parser 2020-08-16 00:25:54 +02:00
jrqc
baa4cb1cdd early return removed 2020-08-16 00:24:27 +03:00
jrqc
96efaee552 cargo dev update_lints 2020-08-16 00:24:27 +03:00
jrqc
a7d5c2f967 Modifications according to the code review 2020-08-16 00:24:27 +03:00
jrqc
cd6ca72e0e Known problems changed 2020-08-16 00:24:27 +03:00
jrqc
65d10c7abf Borrow checker added 2020-08-16 00:24:27 +03:00
jrqc
85f4ef0fbd Visitor added 2020-08-16 00:24:27 +03:00
jrqc
6d18fe730e Make needless_return a late lint pass 2020-08-16 00:24:27 +03:00
bors
f0cc006964 Auto merge of #5910 - flip1995:rustup, r=flip1995
Rustup

r? @ghost

changelog: none
2020-08-15 12:05:11 +00:00
Christoph Walcher
b381ade179
elide lifetimes 2020-08-15 01:40:55 +02:00
Christoph Walcher
ae56e988a2
Merge lint with single_char_pattern 2020-08-15 01:40:55 +02:00
Christoph Walcher
72d2c2eab4
Lint push_str with a single-character string literal
Fixes #5875
2020-08-15 01:40:55 +02:00
Takayuki Nakata
f98ffa271d Fix FP for same_item_push
Don't emit a lint when `pushed_item` was declared as mutable variable.
2020-08-14 22:54:12 +09:00
chansuke
8e549978e5 Don't use to_string in impl Display 2020-08-14 21:38:11 +09:00
Christoph Walcher
8514b8407a
appreciative too_large_for_stack in useless vec!
Fixes: #5847
2020-08-14 14:29:16 +02:00
Erich Gubler
48a142559d
docs: typo in temporary_cstring_as_ptr: s/point/&s 2020-08-13 13:52:21 -06:00
Bastian Kauschke
429a1cedfa merge as_local_hir_id with local_def_id_to_hir_id 2020-08-13 16:55:16 +02:00
bors
d5f5487252 Auto merge of #5899 - JarredAllen:rc-box-suggestion, r=yaahc
Change Rc<Box<T>> recommendation to be Rc<T> instead of Box<T>

Fixes #5722

changelog: Suggest `Rc<Box<T>>` -> `Rc<T>` in [`redundant_allocation`] lint
2020-08-13 13:31:55 +00:00
bors
fc4fd91914 Auto merge of #5900 - ThibsG:ParensUselessConversion4750, r=phansch
Fix: keep parenthesis for suggestion in `useless_conversion` lint

Note: this lint was previously named `identity_conversion`.

fixes: #4750

changelog: fix parenthesis for `useless_conversion` lint suggestion
2020-08-13 05:27:29 +00:00
JarredAllen
4e28d99f41 Replace panics with early returns 2020-08-12 13:24:55 -07:00
ThibsG
5634c8da02 Fix: keep parenthesis for suggestion in useless_conversion lint 2020-08-12 21:44:02 +02:00
bors
dc1e09bdc1 Auto merge of #5897 - matthiaskrgr:no_clone_tts, r=flip1995
write.rs: don't clone TokenStream

changelog: none
2020-08-12 17:36:23 +00:00
JarredAllen
480ccc3dbe Change Rc<Box<T>> recommendation to be Rc<T> instead of Box<T> 2020-08-12 10:35:08 -07:00
bors
439bae62a4 Auto merge of #5884 - Ryan1729:patch-1, r=flip1995
Add the other overloadable operations to suspicious_arithmetic_impl

In #2268 I idly mused that the other user-overloadable operations could be added to this lint. Knowing that the lint was arguably incomplete was gnawing at the back of my mind, so I figured that I might as well make this PR, particularly given the change needed was so small.

changelog: Start warning on suspicious implementations of the `BitAnd`, `BitOr`, `BitXor`, `Rem`, `Shl`, and `Shr` traits.
2020-08-12 17:00:48 +00:00
bors
c73cf9f387 Auto merge of #5893 - matthiaskrgr:lint_msg, r=yaahc
fix remaining lint messages

r? @yaahc

changelog:  make remaining lint messages adhere to rustc dev guide lint message convention.
2020-08-12 16:33:57 +00:00
Ryan Wiedemann
c70581732d trailing comma
Should have actually ran rustfmt on it, rather than attempting to fix it manually
2020-08-12 10:33:16 -06:00
Ryan Wiedemann
616682deb7 formatting 2020-08-12 10:33:16 -06:00
Ryan Wiedemann
0fc61becb5 Add the other overloadable operations to suspicious_arithmetic_impl
In #2268 I idly mused that the other user-overloadable operations could be added to this lint. Knowing that the lint was arguably incomplete was gnawing at the back of my mind, so I figured that I might as well make this PR, particularly given the change needed was so small.
2020-08-12 10:33:16 -06:00
bors
2f4de2fc75 Auto merge of #5885 - Ryan1729:patch-2, r=flip1995
Add example of false positive to PTR_ARG docs.

Addresses #214

changelog: Add example of false positive to `ptr_arg` docs.
2020-08-12 15:51:39 +00:00
flip1995
318c74af2b
Merge remote-tracking branch 'upstream/master' into rustup 2020-08-12 17:03:54 +02:00
Ryan Wiedemann
7d2e42daec
fix typo pointed out in review comment
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-08-12 08:54:32 -06:00
Matthias Krüger
8a96b9cdfe write.rs: don't clone TokenStream 2020-08-12 14:35:31 +02:00
bors
fdc2f879f1 Auto merge of #75405 - flip1995:clippyup, r=Manishearth
Update Clippy

Biweekly Clippy update (2 days late, since I wanted to wait for https://github.com/rust-lang/rust/pull/75098)

r? @Manishearth
2020-08-12 00:34:19 +00:00
flip1995
027780ca2c Merge commit '09bd400243ed6f7059fedc0c1623aae3792521d6' into clippyup 2020-08-11 17:50:45 +02:00
Matthias Krüger
be3e695b60 if_not_else: make lint adhere to lint message convention 2020-08-11 16:43:53 +02:00
Matthias Krüger
605e027fda if_let_some_result: make lint adhere to lint message convention 2020-08-11 16:40:45 +02:00
Matthias Krüger
89591a78b8 enum-variant-names: make lint adhere to lint message convention 2020-08-11 16:38:20 +02:00
Matthias Krüger
db390f5e6a enum-clike-unportable-variant: tweak message a bit (Clike -> C-like) 2020-08-11 16:35:09 +02:00
Matthias Krüger
2de290d5c5 duration-subsec: make lint adhere to lint message convention 2020-08-11 16:31:02 +02:00
Matthias Krüger
423615693b pub-enum-variant-names: make lint adhere to lint message convention 2020-08-11 16:28:05 +02:00
Matthias Krüger
1f17c3b02b multiple_inherent_impl: make lint adhere to lint message convention 2020-08-11 15:28:51 +02:00
Matthias Krüger
bdf4dc3abd implicit-saturating-sub: make lint adhere to lint message convention 2020-08-11 15:22:59 +02:00
Matthias Krüger
f171f89aed int_plus_one: make lint adhere to lint message convention 2020-08-11 15:15:26 +02:00
Matthias Krüger
6af297f80e iter-next-slice: make lint adhere to lint message convention 2020-08-11 15:15:26 +02:00
Matthias Krüger
04867e004e mutex-atomic: make lint adhere to lint message convention 2020-08-11 15:15:26 +02:00
Matthias Krüger
ac194cafc1 map_clone: make lint adhere to lint message convention 2020-08-11 15:15:26 +02:00
Matthias Krüger
c0a9d64818 stable-sort-primitive: make lint adhere to lint message convention 2020-08-11 15:15:26 +02:00
bors
3337f7956c Auto merge of #5892 - matthiaskrgr:redundant_mut, r=flip1995
unnecessary-mut-passed: make lint message say if fn is a function or a method

changelog: refine "unnecessary-mut-passed" lint message
2020-08-11 12:52:41 +00:00