Commit graph

4039 commits

Author SHA1 Message Date
Piti the little Light
e320dd3042
Improve: error message 2020-11-03 16:44:23 +01:00
Piti the little Light
0ab96ba2c0
Allow lint 2020-11-03 16:44:23 +01:00
Piti the little Light
8906040445
Improvements from PR feedback 2020-11-03 16:44:21 +01:00
Piti the little Light
a85670652a
Update: stderr message format 2020-11-03 16:42:30 +01:00
Piti the little Light
1b117f4629
Add tests for from_iter_instead_of_collect 2020-11-03 16:42:30 +01:00
bors
3ee9c2e1a0 Auto merge of #6037 - matthiaskrgr:single_char_insert, r=flip1995
single_char_insert_str: lint using insert_str() on single-char literals and suggest insert()

Fixes #6026

changelog: add single_char_insert_str lint which lints using string.insert_str() with single char literals and suggests string.insert() with a char
2020-11-03 15:36:33 +00:00
Cameron Steffen
b2332a7357 Change lint to use const sym 2020-11-02 11:52:17 -06:00
ThibsG
ce98468158 Fix incorrect suggestion when from expansion in try_err lint 2020-11-02 18:08:38 +01:00
ThibsG
343bdb3364 Give better suggestion by working on span on deref_addrof lint 2020-11-02 18:08:38 +01:00
ThibsG
158bf9aa44 Fix incorrect suggestion for macro expansion in deref_addrof lint 2020-11-02 18:08:38 +01:00
Henri Lunnikivi
7b203f3da6 Implement field_reassign_with_default
- Implement `field_reassign_with_default` as a `LateLintPass`
- Avoid triggering `default_trait_access` on a span already linted by
`field_reassigned_with_default`
- Merge `default_trait_access` and `field_reassign_with_default` into
`Default`
- Co-authored-by: Eduardo Broto <ebroto@tutanota.com>
- Fixes #568
2020-10-31 15:49:58 +02:00
Eduardo Broto
f8ac1f99ef Address suggestions in PR review 2020-10-30 23:47:22 +01:00
Eduardo Broto
d958269fe5 Rename single_char_push_str to single_char_add_str 2020-10-30 23:29:44 +01:00
Matthias Krüger
c1eb8ceede get_hint_if_single_char_arg: fix bug where multi-char letters are not detected properly 2020-10-30 23:29:44 +01:00
Matthias Krüger
c6412aeebc handle macros returning Strings in single_char_push_str and single_char_insert_str 2020-10-30 23:29:38 +01:00
Matthias Krüger
2350ee75b2 single_char_push_str lint using insert_str() on single-char literals and suggest insert()
changelog: single_char_push_str: lint using string.insert_str() with single char literals and suggests string.insert() with a char

Fixes #6026
2020-10-30 23:28:17 +01:00
bors
084b203988 Auto merge of #6260 - matthiaskrgr:ices, r=ebroto
add a couple of ICE testcases

Fixes #6250
Fixes #6251
Fixes #6252
Fixes #6255
Fixes #6256

changelog: none
2020-10-30 22:19:11 +00:00
bors
7387b87bb9 Auto merge of #6197 - ThibsG:ImproveFilterNext, r=ebroto
Improve suggestions for several lints

This PR is a follow-up of this [Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/filter_next.20lint).

It unifies placeholders for `methods` module and improves several suggestions for `filter_next`, `filter_map_next` and `map_unwrap_or` lints.

changelog: none
2020-10-30 21:58:09 +00:00
Cameron Steffen
c0d1002d93 Fix unnecessary_lazy_eval suggestion applicability
Fixes #6240
2020-10-30 16:10:01 -05:00
Cameron Steffen
7c74d870b5 Fix vec_box scope error
Fixes #6236
2020-10-30 13:09:27 -05:00
bors
0be654482c Auto merge of #6229 - henil:improve-integer-division-lint, r=phansch
Update the existing arithmetic lint

re: #6209

Updates the lint to not the error message if RHS of binary operation `/` of `%` is a literal/constant that is not `0` or `-1`, as suggested [here](https://github.com/rust-lang/rust-clippy/issues/6209#issuecomment-715624354)

changelog: Expand [`integer_arithmetic`] to work with RHS literals and constants
2020-10-30 12:37:46 +00:00
henil
fa0a78b130 removed lint for division/modulo for literal 0 2020-10-30 17:31:10 +05:30
bors
74d8fbb7a4 Auto merge of #6200 - rail-rain:borrowed_box_invalid_sugg, r=phansch
fix the error-causing suggestion of 'borrowed_box'

Fixes #3128

Fix the suggestion of 'borrowed_box', which causes a syntax error because it misses necessary parentheses.

---

changelog: Fix the error-causing suggestion of 'borrowed_box'
2020-10-30 10:40:44 +00:00
dvermd
7b065dba84 clippy: update reference file to match suggested change 2020-10-29 17:38:46 +01:00
bors
c57d8ae515 Auto merge of #6227 - HMPerson1:collect_map, r=phansch
Add lint for replacing `.map().collect()` with `.try_for_each()`

Fixes #6208

changelog: Add `map_collect_result_unit`
2020-10-29 15:34:15 +00:00
bors
e1a2845558 Auto merge of #6226 - Urcra:master, r=flip1995
Add lint for comparing to empty slices instead of using .is_empty()

Hey first time making a clippy lint

I added the implementation of the lint the `len_zero` since it shared a lot of the code, I would otherwise have to rewrite. Just tell me if the lint should use it's own file instead

changelog: Add lint for comparing to empty slices

Fixes #6217
2020-10-29 15:12:24 +00:00
bors
ee9da9a194 Auto merge of #6176 - achris:issues/578, r=phansch
Lint items after statements in local macro expansions

The items_after_statements lint was skipping all expansions.  Instead
we should still lint local macros.

Fixes #578

---

*Please keep the line below*
changelog: The items_after_statements now applies to local macro expansions
2020-10-29 14:51:41 +00:00
bors
e8de57c20d Auto merge of #6212 - ThibsG:MacroTopLevelRefArg, r=flip1995
No lint in macro for `toplevel_ref_arg`

Do not lint when the span is from a macro.

Question: shouldn't we extend this for external macros also ?

Fixes: #5849

changelog: none
2020-10-29 14:29:30 +00:00
henil
e97602e482 Update existing arithmetic lint and add new tests related to it. 2020-10-29 19:08:52 +05:30
Eduardo Broto
50419118b4 Merge commit '645ef505da378b6f810b1567806d1bcc2856395f' into clippyup 2020-10-28 23:36:07 +01:00
Matthias Krüger
abd64d7c05 add a couple of ICE testcases
Fixes #6250
Fixes #6251
Fixes #6252
Fixes #6255
Fixes #6256
2020-10-28 23:35:11 +01:00
Eduardo Broto
a50d9e7af6 Deprecate temporary_cstr_as_ptr 2020-10-28 22:34:45 +01:00
Takayuki Nakata
8e988e1c66 Merge remote-tracking branch 'upstream/master' into sync-from-rust 2020-10-28 14:14:09 +09:00
Takayuki Nakata
4c58860cbf Fix suggestion to add unneeded space in unused_unit 2020-10-28 12:40:47 +09:00
Aleksei Latyshev
2b7dd31368
improve MATCH_LIKE_MATCHES_MACRO lint
- add tests
- refactor match_same_arms lint
- prioritize match_expr_like_matches_macro over match_same_arms
2020-10-27 23:45:58 +03:00
Michael Wright
66d56fefc5 Add invalid_paths internal lint 2020-10-27 07:42:13 +02:00
Tim Nielens
111b9023da add manual_ok_or lint 2020-10-27 01:57:04 +01:00
rail
e568a328f9 fix the error-causing suggestion of 'borrowed_box'
fix the error-causing suggestion of 'borrowed_box',
which missed parentheses and was ambiguous.
2020-10-27 12:11:09 +13:00
Nathan Whitaker
a1bb10e9b8 Remove lint from clippy 2020-10-26 18:19:48 -04:00
dvermd
6212950ceb Explain why 'run-rustfix' is not defined 2020-10-26 23:00:10 +01:00
dvermd
2270ff4d16 clippy_lint: Add test cases 2020-10-26 22:34:43 +01:00
dvermd
bdd76a9d1c clippy_lint: Allow 'ref_option_ref' for 'option_if_let_else' 2020-10-26 22:34:42 +01:00
dvermd
469b2fc781 clippy_lint: Add 'ref_option_ref' move to check_ty and add type alias test 2020-10-26 22:34:42 +01:00
dvermd
213dbf7aac clippy_lint: Add 'ref_option_ref' 2020-10-26 22:34:40 +01:00
ThibsG
c0dd1f9f76 Fix tests for map_unwrap_or* 2020-10-26 11:15:01 +01:00
ThibsG
e2d86b5b80 Move fixable filter_next and filter_map_next cases to rustfixed tests 2020-10-26 11:02:07 +01:00
ThibsG
2a3ae11485 Move fixable map_unwrap_or cases to rustfixed test 2020-10-26 11:02:07 +01:00
ThibsG
3fec6f568d Improve some suggestions for filter_map_next, filter_next and map_unwrap_or lints 2020-10-26 11:02:07 +01:00
ThibsG
2911d9c7de Use better placeholders for some methods lint messages 2020-10-26 11:02:07 +01:00
ThibsG
bab338685f No lint in external macro for toplevel_ref_arg 2020-10-26 10:14:03 +01:00
HMPerson1
f0cf3bdca1
Add lint for replacing .map().collect() with .try_for_each() 2020-10-25 21:20:57 -04:00
Urcra
de5a6d3420 Initial implementation of comparison_to_empty 2020-10-26 00:31:25 +01:00
bors
83bb5ecec8 Auto merge of #6202 - giraffate:fix_invalid_suggestion_in_needless_collect_test, r=flip1995
Fix an invalid suggestion in `needless_collect` test

A test, https://github.com/rust-lang/rust-clippy/blob/master/tests/ui/needless_collect_indirect.rs#L11-L12, suggests following codes, but the suggested codes don't work. An example is here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6947d9f2806a83f41cc5eb8e39b09d0b.
```
error: avoid using `collect()` when not needed
  --> $DIR/needless_collect_indirect.rs:11:5
   |
LL | /     let indirect_contains = sample.iter().collect::<VecDeque<_>>();
LL | |     indirect_contains.contains(&&5);
   | |____^
   |
help: Check if the original Iterator contains an element instead of collecting then checking
   |
LL |
LL |     sample.iter().any(|x| x == &&5);
```

changelog: none
2020-10-25 17:35:33 +00:00
cgm616
312bbff696
Integrate suggestions from code review 2020-10-25 11:31:24 -04:00
Takayuki Nakata
2f5d418011 Add test case 2020-10-26 00:01:20 +09:00
Takayuki Nakata
3ce820bf83 Fix an invalid suggestion in needless_collect test 2020-10-25 23:58:14 +09:00
cgm616
0c0f8db347 Remove accidental test inclusion 2020-10-25 09:19:58 -04:00
Florian Hartwig
db8380c4a0 Add lint for unusually-grouped hex/binary literals 2020-10-25 09:18:38 -04:00
bors
718bb28f68 Auto merge of #6211 - ThibsG:NeedlessBoolCfg, r=flip1995
No lint with `cfg!` and fix sugg for macro in `needless_bool` lint

Don't lint if `cfg!` macro is one of the operand.
Fix suggestion when the span originated from a macro, using `hir_with_macro_callsite`.

Fixes: #3973

changelog: none
2020-10-25 11:37:18 +00:00
bors
38be214724 Auto merge of #6198 - montrivo:needless-lifetime, r=flip1995
needless-lifetime / multiple where clause predicates regression

Closes #6159.

changelog: fix regression in needless-lifetimes
2020-10-25 11:15:01 +00:00
bors
90cb25d3f6 Auto merge of #6177 - rust-lang:manual-range-contains, r=flip1995
New lint: manual-range-contains

This fixes #1110, at least for the contains-suggesting part.

- \[x] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`
---

changelog: new lint: manual-range-contains
2020-10-25 10:35:46 +00:00
bors
399732bf79 Auto merge of #6103 - FrancisMurillo:mut_mutex_lock, r=flip1995
Add lint for `&mut Mutex::lock`

Fixes #1765

changelog: Add lint [`mut_mutex_lock`] for `&mut Mutex::lock` and suggests using `&mut Mutex::get_mut` instead.
2020-10-25 10:16:23 +00:00
bors
fd62c180fe Auto merge of #6162 - josephlr:empty-loop-no-std, r=flip1995
Update empty_loop documentation/message.

Originally part of #6161, but now this PR only deals with `std` crates

This change:
  - Updates the `std` message .
  - Updates the docs to mention how the busy loops should be fixed
    - Gives examples of how to do this for `no_std` targets
  - Updates the tests/stderr files to test this change.

changelog: Update `empty_loop` lint documentation
2020-10-25 09:56:16 +00:00
Francis Murillo
292cb9bfb6 Use sugg_lint_and_help 2020-10-25 17:41:30 +08:00
Francis Murillo
fb8a9cb38d Change lint doc test 2020-10-25 17:41:24 +08:00
bors
6b01c39e64 Auto merge of #6181 - cgm616:undropped-manually-drops, r=flip1995
Add new lint for undropped ManuallyDrop values

Adds a new lint for the following code:

```rust
struct S;

impl Drop for S {
    fn drop(&mut self) {
        println!("drip drop");
    }
}

fn main() {
    // This will not drop the `S`!!!
    drop(std::mem::ManuallyDrop::new(S));
    unsafe {
        // This will.
        std::mem::ManuallyDrop::drop(&mut std::mem::ManuallyDrop::new(S));
    }
}
```

The inner value of a `ManuallyDrop` will not be dropped unless the proper, unsafe drop function is called on it. This lint makes sure that a user does not accidently use the wrong function and forget to drop a `ManuallyDrop` value.

Fixes #5581.

---

*Please keep the line below*
changelog: none
2020-10-25 09:37:09 +00:00
Francis Murillo
f82f9c2c55 Add lint for &mut Mutex::lock 2020-10-25 17:18:52 +08:00
bors
e0e617adaa Auto merge of #6109 - patrickelectric:single_element_for_check, r=flip1995
Add linter for a single element for loop

changelog: Fixes #1540, check for vectors that contain a single element in a for loop
2020-10-25 09:15:55 +00:00
bors
a675778cfb Auto merge of #6029 - Daniel-B-Smith:refcell_ref_await, r=flip1995
Add lint for holding RefCell Ref across an await

Fixes #6008

This introduces the lint await_holding_refcell_ref. For async functions, we iterate
over all types in generator_interior_types and look for `core::cell::Ref` or `core::cell::RefMut`. If we find one then we emit a lint.

Heavily cribs from: https://github.com/rust-lang/rust-clippy/pull/5439

changelog: introduce the await_holding_refcell_ref lint
2020-10-25 08:54:27 +00:00
bors
b06856eae0 Auto merge of #6187 - geoffreycopin:master, r=ebroto
Lint unnecessary int-to-int and float-to-float casts

This is an implementation of a lint that detects unnecessary casts of number literals, as discussed here:
https://github.com/rust-lang/rust-clippy/issues/6116

---

changelog: lint unnecessary as-casts of literals when they could be written using literal syntax.
2020-10-24 23:29:49 +00:00
bors
29979ad043 Auto merge of #6190 - montrivo:manual_result_unwrap_or, r=ebroto
manual_unwrap_or / support Result::unwrap_or

Implements partially #5923.

changelog: support Result::unwrap_or in manual_unwrap_or
2020-10-24 23:09:14 +00:00
Cauê Baasch de Souza
e8731a926c Add large_types_passed_by_value lint
Refactor trivially_copy_pass_by_ref and the new lint into pass_by_ref_or_value module

Update stderr of conf_unknown_key test

Rename lint to large_types_passed_by_value

Increase `pass_by_value_size_limit` default value to 256

Improve rules for `large_types_passed_by_value`

Improve tests for `large_types_passed_by_value`

Improve documentation for `large_types_passed_by_value`

Make minor corrections to pass_by_ref_or_value.rs suggested by clippy itself

Fix `large_types_passed_by_value` example and improve docs

pass_by_ref_or_value: Tweak check for mut annotation in params

large_types_passed_by_value: add tests for pub trait, trait impl and inline attributes
2020-10-24 14:46:56 -03:00
Geoffrey Copin
71ac0c0be8 Keep separators in cast_size_32bits stderr 2020-10-24 14:08:53 +02:00
Tim Nielens
0d21ae0e19 manual-unwrap-or / pr remarks, round 3 2020-10-24 11:35:05 +02:00
ThibsG
62f60e1ae5 No lint with cfg! and fix sugg for macro in needless_bool lint 2020-10-24 09:37:23 +02:00
Geoffrey Copin
d46edd9966 Keep sign in int-to-float casts 2020-10-24 00:04:37 +02:00
Eduardo Broto
cdb555f4fc Merge commit 'bf1c6f9871f430e284b17aa44059e0d0395e28a6' into clippyup 2020-10-23 22:16:59 +02:00
Eduardo Broto
d17edaa152 Merge remote-tracking branch 'upstream/master' into rustup 2020-10-23 14:37:17 +02:00
Joe Richey
3807634a47
clippy_lints: Update empty_loop lint
We also update the documentation to note that the remediations are
different for `std` and `no_std` crates.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-10-22 22:03:13 -07:00
Geoffrey Copin
30f80c3b8c Fix test file 2020-10-23 00:33:15 +02:00
Geoffrey Copin
02f01104bf Add test case for negative literals 2020-10-23 00:04:27 +02:00
Geoffrey Copin
e8f12d2f02 Address review comments 2020-10-22 23:56:49 +02:00
Tim Nielens
6533d8becf manual-unwrap-or / pr remarks, round 2 2020-10-22 23:39:59 +02:00
Tim Nielens
f2da0c701e manual-unwrap-or / pr remarks 2020-10-22 22:46:10 +02:00
varkor
fcde7683fe Fix clippy tests 2020-10-22 13:23:14 +01:00
Andre Bogus
c693de350a New lint: manual-range-contains 2020-10-22 08:45:21 +02:00
cgm616
e70817e712 Update tests and add known problems to docs 2020-10-21 21:21:11 -04:00
cgm616
4a4f998c39 Add new lint for undropped ManuallyDrop values 2020-10-21 21:21:11 -04:00
Daniel Smith
4d3322525d Separate tests for each lint 2020-10-21 11:04:26 -04:00
Daniel Smith
ee20ebadaf Move refcell lint into shared module 2020-10-21 11:04:26 -04:00
Daniel Smith
3ed69cdb13 Move existing lint into shared file 2020-10-21 11:04:26 -04:00
Daniel Smith
b3a427d873 Add another test case 2020-10-21 11:04:26 -04:00
Daniel Smith
0f4abbf99a Better naming post copy/paste 2020-10-21 11:04:26 -04:00
Daniel Smith
8727169f72 fmt 2020-10-21 11:04:26 -04:00
Daniel Smith
57bf80f776 Add lint for holding RefCell Ref across an await 2020-10-21 11:04:26 -04:00
Tim Nielens
65b52d84f8 needless-lifetime / multiple where clause predicates regression 2020-10-20 00:42:00 +02:00
bors
eaffd0e418 Auto merge of #6167 - ThibsG:IdenticalArgumentsAssertEq3574, r=ebroto
Identical arguments on assert macro family

Lint when identical args are used on `assert_eq!`, `debug_assert_eq!`, `assert_ne!` and `debug_assert_ne!` macros.

Added to the lint `eq_op`.

Common functions added to `utils/higher.rs`

Fixes: #3574
Fixes: #4694

changelog: Lint on identical args when calling `assert_eq!`, `debug_assert_eq!`, `assert_ne!` and `debug_assert_ne!` macros
2020-10-19 19:50:12 +00:00
ThibsG
16b5f37b5a Split eq_op ui tests to avoid file limit error in CI 2020-10-19 17:36:48 +02:00
Patrick José Pereira
ba1ca19c3b tests: if_same_then_else2: Ignore single_element_loop lint
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2020-10-19 09:53:35 -03:00
Patrick José Pereira
ec23db9496 Add linter for a single element for loop
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2020-10-19 09:53:35 -03:00
Tim Nielens
915ce36087 manual_unwrap_or / support Result::unwrap_or 2020-10-18 01:18:59 +02:00
Geoffrey Copin
bb0ce32423 Lint unnecessary int-to-int and float-to-float casts 2020-10-17 16:12:51 +02:00
bors
4e83a38618 Auto merge of #6123 - montrivo:less_concise_than, r=ebroto
add lint manual_unwrap_or

Implements partially #5923.

changelog: add lint manual_unwrap_or
2020-10-16 20:43:45 +00:00
bors
a771557ee9 Auto merge of #6178 - josephlr:sync-from-rust, r=phansch
Sync from rust

Fix rustc breakage by running:
```rust
git subtree push -P src/tools/clippy git@github.com:josephlr/rust-clippy sync-from-rust
```
and then adding a commit that runs `cargo dev fmt`

---

changelog: none
2020-10-16 07:45:42 +00:00
Dylan DPC
d2feccc1ef Rollup merge of #77493 - hosseind88:ICEs_should_always_print_the_top_of_the_query_stack, r=oli-obk
ICEs should always print the top of the query stack

see #76920
2020-10-16 02:10:09 +02:00
Chris Ayoup
32e2021b75 Lint items after statements in macro expansions
The items_after_statements lint was skipping all expansions.  Instead
we should still lint local macros.

Fixes #578
2020-10-14 23:49:48 -04:00
Tim Nielens
690a6a6c0e manual-unwrap-or / remove unwrap_or_else suggestion due to ownership issues 2020-10-14 22:52:07 +02:00
Tim Nielens
fc846c37fc manual_unwrap_or / use consts::constant_simple helper 2020-10-14 22:16:48 +02:00
Tim Nielens
6d4eeeabcd manual-unwrap-or / pr remarks 2020-10-14 22:16:48 +02:00
Tim Nielens
07b2da884c add lint less_concise_than_option_unwrap_or 2020-10-14 22:16:48 +02:00
ThibsG
71c29b5be8 Add iterator test case for eq_op lint 2020-10-14 21:29:53 +02:00
hosseind88
ab0fc477b8 fix stderr file of clippy/custom_ice_message test 2020-10-14 18:19:26 +03:30
ThibsG
121a047645 Move linting of assert macros from early to late pass 2020-10-13 23:57:22 +02:00
bors
0b77c35965 Auto merge of #6169 - ThibsG:SameFunctionsInIfConditionIgnoreMacro, r=ebroto
Fix FP in `same_functions_in_if_condition` lint about condition as macro

Ignore expr that originate from a macro.

Fixes: #6168

changelog: none
2020-10-13 16:01:11 +00:00
ThibsG
e2124086b8 Fix FP in same_functions_in_if_condition lint about condition as macro 2020-10-13 11:31:13 +02:00
ThibsG
a3e0446afe Extend to the assert macro family 2020-10-13 09:31:53 +02:00
ThibsG
32fdb8fb0c Lint on identical variable used as args in assert_eq! macro call 2020-10-12 23:38:31 +02:00
bors
18ffea01ee Auto merge of #6158 - giraffate:improve_updating_references, r=phansch
Remove the generated files by `update-references.sh` if they are empty

An empty file may be generated by `update-references.sh` and committed as is when creating a patch like https://github.com/rust-lang/rust-clippy/pull/6101#issuecomment-702076508 and https://github.com/rust-lang/rust-clippy/pull/6079#pullrequestreview-496502721. So, I think it would be helpful to add documentation, and automatically remove the generated file if it's empty.

changelog: none
2020-10-12 13:49:19 +00:00
Eduardo Broto
74ae116131 Use lowercase in error messages 2020-10-11 22:28:55 +02:00
Andre Bogus
6021c23159 New lint: result-unit-err 2020-10-11 22:04:59 +02:00
Takayuki Nakata
377d1fab1f Remove the generated files by update-references.sh if they are empty 2020-10-11 22:57:22 +09:00
flip1995
52e650ae88
Add test for ICE #6153 2020-10-10 15:12:20 +02:00
bors
dbc02854fc Auto merge of #5727 - rail-rain:manual_memcpy_with_counter, r=flip1995
Expands `manual_memcpy` to lint ones with loop counters

Closes #1670

This PR expands `manual_memcpy` to lint ones with loop counters as described in https://github.com/rust-lang/rust-clippy/issues/1670#issuecomment-293280204

Although the current code is working, I have a couple of questions and concerns.

~~Firstly, I manually implemented `Clone` for `Sugg` because `AssocOp` lacks `Clone`. As `AssocOp` only holds an enum, which is `Copy`, as a value, it seems `AssocOp` can be `Clone`; but, I was not sure where to ask it. Should I make a PR to `rustc`?~~ The [PR]( https://github.com/rust-lang/rust/pull/73629) was made.

Secondly, manual copying with loop counters are likely to trigger `needless_range_loop` and `explicit_counter_loop` along with `manual_memcpy`; in fact, I explicitly allowed them in the tests. Is there any way to disable these two lints when a code triggers `manual_memcpy`?

And, another thing I'd like to note is that `Sugg` adds unnecessary parentheses when expressions with parentheses passed to its `hir` function, as seen here:

```
error: it looks like you're manually copying between slices
  --> $DIR/manual_memcpy.rs:145:14
   |
LL |     for i in 3..(3 + src.len()) {
   |              ^^^^^^^^^^^^^^^^^^ help: try replacing the loop by: `dst[3..((3 + src.len()))].clone_from_slice(&src[..((3 + src.len()) - 3)])
```

However, using the `hir` function is needed to prevent the suggestion causing  errors when users use bitwise operations; and also this have already existed, for example: `verbose_bit_mask`. Thus, I think this is fine.

changelog: Expands `manual_memcpy` to lint ones with loop counters
2020-10-10 06:32:32 +00:00
bors
2bdadd8e7d Auto merge of #6151 - bofh69:master, r=ebroto
Preserve raw strs for: format!(s) to s.to_string() lint

fixes #6142

clippy::useless_format will keep the source's string (after converting {{ and }} to { and }) when suggesting a change from format!() to .to_string() usage. Ie:
|     let s = format!(r#""hello {{}}""#);
|             ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `r#""hello {}""#.to_string()`

changelog: [`useless_format`]: preserve raw string literals when no arguments to `format!()` are provided.
2020-10-09 23:14:58 +00:00
bors
0b86340999 Auto merge of #6144 - rust-lang:float-cmp-ref, r=ebroto
allow refs in our constant folder

This helps with #3804 (but won't completely fix it).

---

changelog: none
2020-10-09 22:28:00 +00:00
bors
08bd3f0b0d Auto merge of #6152 - flip1995:ice_6139, r=ebroto
Fixes ICE 6139

Fixes #6139

Kind of hacky, but this should be fine.

changelog: none
2020-10-09 20:39:26 +00:00
flip1995
6d88803a1c
Add regression test for ICE 6139 2020-10-09 22:21:47 +02:00
Andre Bogus
26e4de9557 allow refs in our constant handling 2020-10-09 21:37:50 +02:00
Sebastian Andersson
7b7ddfa55d Preserve raw strs for: format!(s) to s.to_string() lint
Ie:
|     let s = format!(r#""hello""#);
|             ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `r#""hello""#.to_string()`
2020-10-09 20:23:03 +02:00
hosseind75
7f07577e6f add new line 2020-10-09 20:57:45 +03:30
hosseind75
49bc85e947 fix clippy custom_ice_message test 2020-10-09 20:57:45 +03:30
bors
947516f018 Auto merge of #6130 - Ambroisie:lint-ptr-eq, r=Manishearth
New lint: Recommend using `ptr::eq` when possible

This is based almost entirely on the code available in the previous PR #4596. I merely updated the code to make it compile.

Fixes #3661.

- [ ] I'm not sure about the lint name, but it was the one used in the original PR.
- [X] Added passing UI tests (including committed `.stderr` file)
- [X] `cargo test` passes locally
- [X] Executed `cargo dev update_lints`
- [X] Added lint documentation
- [X] Run `cargo dev fmt`

---

changelog: none
2020-10-09 16:46:09 +00:00
flip1995
fbf2430f02 Merge commit '2f6439ae6a6803d030cceb3ee14c9150e91b328b' into clippyup 2020-10-09 12:45:29 +02:00
bors
e651a04fab Auto merge of #6133 - JPTIZ:no-box-for-c-ffi, r=ebroto
clippy_lints: Do not warn against Box parameter in C FFI

changelog: [`boxed_local`]: don't lint in `extern fn` arguments

Fixes #5542.

When using C FFI, to handle pointers in parameters it is needed to
declare them as `Box` in its Rust-side signature. However, the current
linter warns against the usage of Box stating that "local variable
doesn't need to be boxed here".

This commit fixes it by ignoring functions whose Abi is C.
2020-10-08 22:50:29 +00:00
João Paulo Taylor Ienczak Zanette
b709b87363 tests: Add test function that does not specify ABI 2020-10-08 18:50:52 -03:00
João Paulo Taylor Ienczak Zanette
5ae0f2644d clippy_lint: extern definition is in Rust, not C 2020-10-08 09:07:24 -03:00
João Paulo Taylor Ienczak Zanette
418cde0389 clippy_lint: Fix typo (now -> not) 2020-10-08 09:06:19 -03:00
João Paulo Taylor Ienczak Zanette
15150c07ea clippy_lint: Test for BoxedLocal false-positive in C-FFI and fix C-FFI Abi comparison. 2020-10-07 22:49:50 -03:00
Andre Bogus
11672577de Fix unicode regexen with bytes::Regex
fixes #6005
2020-10-08 01:07:00 +02:00
Bruno BELANYI
5bad9175fb New lint: Recommend using ptr::eq when possible
This is based almost entirely on the code available in the previous PR #4596.
2020-10-07 11:48:06 +02:00
bors
277191890b Auto merge of #6120 - phansch:replace-lazy-static, r=Manishearth
Replace some lazy_static usage with once_cell feature

This replaces some `lazy_static` usage with [`SyncLazy`](https://doc.rust-lang.org/nightly/std/lazy/struct.SyncLazy.html) of the unstable `once_cell` feature.

changelog: none
2020-10-07 04:58:13 +00:00
Eduardo Broto
6c3611bdef Reinstate test for forbid blanket restriction 2020-10-07 00:02:28 +02:00
bors
1a4175bcec Auto merge of #6126 - flip1995:rustup, r=flip1995
Rustup

Supersedes #6121. There was another breakage.

r? `@ghost`

changelog: none
2020-10-06 21:34:50 +00: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
Philipp Hansch
9b4ceee593
integration tests: Replace lazy_static with SyncLazy 2020-10-06 08:20:18 +02:00
FliegendeWurst
428ef362d6 Fix test formatting 2020-10-05 12:23:01 +02:00
FliegendeWurst
78695bd496
Do not lint float fractions in mistyped_literal_suffixes (fixes #4706) 2020-10-05 12:09:21 +02:00
Felix S. Klock II
5747c15961 Prevent forbid from being ignored if overriden at the same level.
That is, this changes `#[forbid(foo)] #[allow(foo)]` from allowing foo to
forbidding foo.
2020-10-04 13:14:01 -04: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
rail
be8160878a split interior_mutable_const tests and clean it
* remove a 'ERROR' comment from `borrow`
   `Vec<AtomicUsize>` itself is `Freeze` as it holds the atomic in heap
* remove `ONCE_INIT` from `declare`
   it seems like an artifact from previous spliting
2020-10-04 18:12:53 +13: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
Michael Howell
840f7daaad Deprecate clippy lint 2020-10-02 11:34:14 -07:00
rail
7820cb1442 Add tests for
* `dst.len()` as the end of the range with loop counters
* the increment of the loop counter at the top of the loop
2020-10-02 23:21:24 +13:00
Dániel Buga
515ca93123 Look for soft hyphens as well 2020-10-02 11:56:21 +02: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
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
Eduardo Broto
507561ecfc
Update tests/ui/asm_syntax.rs
Use a single `only` header command in asm_syntax test
2020-09-30 23:30:49 +02: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
124420f920 needless-lifetime / fix master merge 2020-09-29 23:06:08 +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
ec94bd6cb4 split up the manual_memcpy test 2020-09-28 02:43:45 +13: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
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
Takayuki Nakata
83294f894d Some small fixes 2020-09-26 23:10:25 +09: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
9eb52d2eb6 update toml_unknown_key test 2020-09-25 11:09:04 -05:00
Frank
e1b3f85e98 run cargo dev fmt 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
6e5306dcc3 Auto merge of #6084 - ebroto:ui_tests_cleanup, r=flip1995
UI tests cleanup

`@matthiaskrgr` noticed some `run-pass` annotations in some crash tests that were added in #3922. At that moment they seemed to be necessary to make the tests fail in case of an ICE, but they do not seem to be needed anymore. To test this I forced an ICE in a file with and without annotations, with and without stderr files, and the ICE makes the test fail every time.

In addition, I've applied a suggestion from `@ehuss` and `@jyn514` to add `emit=metadata` to the rustc flags for the UI tests. In my machine this improved the run time from ~17 to ~12 seconds.

changelog: none
2020-09-25 14:14:25 +00:00
Eduardo Broto
1cb3c00cba Use emit=link for auxiliary proc macro crates 2020-09-25 15:46:32 +02:00
Eduardo Broto
fd0656109f Add emit=metadata to UI tests build flags
This should improve the performance by avoiding codegen
2020-09-25 15:20:04 +02:00
Eduardo Broto
6b59675449 Remove run-pass annotations from crash tests
It does not seem to be necessary
2020-09-25 15:19:36 +02:00
rail
174065fc98 fix the multiple counters test 2020-09-25 09:02:05 +12:00
rail
4ea4a97250 Add tests for bitwise operations 2020-09-25 09:02:05 +12:00
rail
9aad38bf61 Update manual_memcpy.stderr to reflect additional parentheses 2020-09-25 09:02:05 +12:00
rail
774e82a566 Add the tests for manual_memcpy with loop counters 2020-09-25 09:02:05 +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
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
4117ae1175 Split redundant_pattern_matching tests
This is to avoid the 200 lines stderr file limit
2020-09-21 15:32:26 +02:00
Eduardo Broto
6e07247578 Merge remote-tracking branch 'upstream/master' into rustup 2020-09-21 15:11:24 +02:00
Christiaan Dirkx
ed43385cab Update Clippy testcases
Update the test `redundant_pattern_matching`: check if `is_some` and `is_none` are suggested within const contexts.
2020-09-20 23:59:34 +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
Christiaan Dirkx
10d272b2e2 Update Clippy testcases
Update the test `redundant_pattern_matching`: check if `is_ok` and `is_err` are suggested within const contexts.
Also removes the `redundant_pattern_matching_const_result` test, as it is no longer needed.
2020-09-20 03:32:36 +02:00
rail
d5af360bb2 add WRAPPED_SELF: Option<Self> in the test 2020-09-17 21:14:14 +12: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
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
Tim Nielens
79da7474b1 option_if_let_else - change misleading test file section 2020-09-16 19:59:51 +02: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
Robin Schoonover
d0ddbb9d0d Extend testing of rc_buffer lint 2020-09-15 21:11:28 -06:00
Tim Nielens
6ba36bcfd3 option_if_let_else - distinguish pure from impure else expressions 2020-09-16 01:30:50 +02:00
Michael Wright
ecbe9ac0e9 manual-strip: Add additional test 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
Eduardo Broto
d0b5663d30 Fix usage of backquotes in suggestion 2020-09-15 10:45:57 +02:00
Eduardo Broto
8afa7ed6ae Add internal lint MatchTypeOnDiagItem 2020-09-15 10:29:53 +02: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
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
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
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
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
Thom Chiovoloni
3a072131da Ah, right, rerun the scripts 2020-09-09 23:22:01 -07:00
Thom Chiovoloni
159178e5d4 Separate compare_exchange and compare_exchange_weak uitests 2020-09-09 14:32:38 -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
Tim Nielens
c8e9e52303 needless-lifetime / add test cases for nested elision sites 2020-09-09 10:08:45 +02: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
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
952c04674e Refactoring: tests in same_item_push 2020-09-08 23:03:15 +09:00
Takayuki Nakata
2c9f82e7d2 Add some tests to same_item_push
Add tests in which the variable is initialized with a match expression and function call
2020-09-08 22:45:27 +09:00
Tim Nielens
a60e5de90c needless-lifetime / nested elision sites / PR remarks 2020-09-08 02:41:38 +02: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
9e7ce9d385 run the specific script suggested by the error message
```
./tests/ui-toml/update-references.sh './target/debug/test_build_base' 'functions_maxlines/test.rs'
```
2020-09-04 21:12:16 -06:00
Ryan1729
db16fa26ce run tests/ui/update-all-references.sh 2020-09-04 20:16:02 -06:00
Eduardo Broto
23646e6583 Merge remote-tracking branch 'upstream/master' into sync-from-rust 2020-09-04 23:27:01 +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
Michael Wright
93ce686b5d Update ui stderr with improved rustc output
Related rust pull request: rust-lang/rust#76160
2020-09-03 04:58:14 +02:00
Ricky
2387f68e43 Removed map_err suggestion in lint, and updated lint documentation example 2020-09-02 19:21:34 -04: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
Koxiaet
22c9940613 Add tests for allowed non-backticked identifiers in doc 2020-09-02 12:51:44 +01:00
Sasha
246f1f8a8e Improve recovery on malformed format call
If a comma in a format call is replaced with a similar token, then we
emit an error and continue parsing, instead of stopping at this point.
2020-09-02 13:18:19 +02:00
Ricky
202a80c927 Added tests for map_err, ignored map_err lint on drop_ref tests 2020-09-01 16:59:37 -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
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
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
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
c1d2b9376a Add a test for an async function. 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
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
5574182b4d Add a new lint to prevent create_dir from being used 2020-08-28 18:45:28 +09: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
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
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
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
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
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
f326668577 Auto merge of #5958 - mikerite:fix-fmt-20200825, r=flip1995
Various fmt test improvements

Various fmt test improvements.

changelog: none
2020-08-25 17:15:51 +00: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
bors
5ef345a853 Auto merge of #5960 - flip1995:rustup, r=flip1995
Rustup

r? @ghost

changelog: none
2020-08-25 16:11:17 +00:00
Philipp Krones
acc6b6ce07
Fix typo 2020-08-25 18:01:08 +02:00