Commit Graph

3614 Commits

Author SHA1 Message Date
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
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
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
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