Commit graph

4278 commits

Author SHA1 Message Date
Philipp Krones
ee8db50e13
Rollup merge of #5871 - wiomoc:feature/methodcall-minmax, r=flip1995
Lint .min(x).max(y) with x < y

Fixes  #5854

changelog: Also lint `ord.min(a).max(b)`, where `a < b` in [`min_max`] lint
2020-08-10 14:56:29 +02:00
Philipp Krones
08ab29bed1
Rollup merge of #5870 - ebroto:5789_allow_unsafe_derive_deserialize, r=flip1995
enable #[allow(clippy::unsafe_derive_deserialize)]

Before this change this lint could not be allowed as the code we are checking is automatically generated.

changelog: Enable using the `allow` attribute on top of an ADT linted by [`unsafe_derive_deserialize`].

Fixes: #5789
2020-08-10 14:56:27 +02:00
Philipp Krones
8ee57eed79
Rollup merge of #5869 - wiomoc:feature/implicit-self, r=ebroto,flip1995
New lint against `Self` as an arbitrary self type

Fixes #5861

changelog: * [`needless_arbitrary_self_type`] [#5869](https://github.com/rust-lang/rust-clippy/pull/5869)
2020-08-10 14:56:26 +02:00
Philipp Krones
9da5b6d1d0
Rollup merge of #5825 - giraffate:same_item_push, r=Manishearth
Add the new lint `same_item_push`

changelog: Add the new lint `same_item_push`

Fixed #4078. As I said in https://github.com/rust-lang/rust-clippy/issues/4078#issuecomment-658184195, I referrerd to https://github.com/rust-lang/rust-clippy/pull/4647.
2020-08-10 14:56:25 +02:00
bors
70c46de012 Auto merge of #5877 - ebroto:5872_loops_ice, r=Manishearth
Fix ICE in `loops` module

changelog: Fix ICE related to `needless_collect` when a call to `iter()` was not present.

I went for restoring the old suggestion of `next().is_some()` over `get(0).is_some()` given that `iter()` is not necessarily present (could be e.g. `into_iter()` or `iter_mut()`)  and that the old suggestion could change semantics, e.g. a call to `filter()` could be present between `iter()` and the collect part.

Fixes #5872
2020-08-08 18:44:48 +00:00
bors
3899d6001c Auto merge of #5878 - flip1995:rustup, r=flip1995
Rustup

r? @ghost

changelog: none
2020-08-08 17:28:34 +00:00
flip1995
fd87cdb357
Run fmt 2020-08-08 19:20:34 +02:00
Eduardo Broto
888657e09a Fix ICE in loops module 2020-08-08 18:13:43 +02:00
Nicholas Nethercote
01bba2c532 Eliminate the SessionGlobals from librustc_ast.
By moving `{known,used}_attrs` from `SessionGlobals` to `Session`. This
means they are accessed via the `Session`, rather than via TLS. A few
`Attr` methods and `librustc_ast` functions are now methods of
`Session`.

All of this required passing a `Session` to lots of functions that didn't
already have one. Some of these functions also had arguments removed, because
those arguments could be accessed directly via the `Session` argument.

`contains_feature_attr()` was dead, and is removed.

Some functions were moved from `librustc_ast` elsewhere because they now need
to access `Session`, which isn't available in that crate.
- `entry_point_type()` --> `librustc_builtin_macros`
- `global_allocator_spans()` --> `librustc_metadata`
- `is_proc_macro_attr()` --> `Session`
2020-08-08 12:03:42 +10:00
Christoph Walcher
87e740921a
check impl Ord / is_float 2020-08-07 18:30:20 +02:00
Christoph Walcher
bfe610cc8d
ignore mutable self reference parameters 2020-08-07 18:08:51 +02:00
Christoph Walcher
e03f73e627
fix nits 2020-08-07 18:08:51 +02:00
Christoph Walcher
d635b76eaf
adopt comments from review 2020-08-07 18:08:51 +02:00
Christoph Walcher
737f62cb6e
fix doc 2020-08-07 18:08:51 +02:00
Christoph Walcher
e0a4988fcc
Lint against Self as an arbitrary self type
Fixes #5861
2020-08-07 18:08:51 +02:00
Vadim Petrochenkov
a285b58368 Add some comments for magic numbers + Add tests 2020-08-06 22:55:26 +03:00
Vadim Petrochenkov
d642c3b6f8 Fix clippy 2020-08-06 22:13:11 +03:00
Christoph Walcher
0abc4833e5
Lint .min(x).max(y) with x < y
Fixes #5854
2020-08-06 02:56:07 +02:00
Eduardo Broto
50a86d4927 enable #[allow(clippy::unsafe_derive_deserialize)] 2020-08-06 00:45:30 +02:00
bors
2d4c3379d3 Auto merge of #5809 - JarredAllen:stable_sort_primitive, r=Manishearth
Stable sort primitive

changelog: Implements #5762
2020-08-05 20:41:21 +00:00
bors
2eab060ab7 Auto merge of #5859 - ebroto:5765_manual_async_fn_fp, r=yaahc
manual_async_fn: take input lifetimes into account

The anonymous future returned from an `async fn` captures all input
lifetimes. This was not being taken into account.

See https://github.com/rust-lang/rfcs/blob/master/text/2394-async_await.md#lifetime-capture-in-the-anonymous-future

changelog: Take input lifetimes into account in [`manual_async_fn`].

Fixes #5765
2020-08-05 17:52:28 +00:00
Takayuki Nakata
610d4e3c8b rustfmt 2020-08-05 23:10:30 +09:00
Takayuki Nakata
e48685edef Just check if it contains _ in for pat 2020-08-05 23:00:03 +09:00
Takayuki Nakata
228f668282 Use mutated_variables 2020-08-05 23:00:03 +09:00
Takayuki Nakata
b7ceb4d3d7 rustfmt 2020-08-05 23:00:03 +09:00
Takayuki Nakata
14a4e3bcc8 Fix a lint message 2020-08-05 22:59:12 +09:00
Takayuki Nakata
1543e117cc cargo dev update_lints 2020-08-05 22:51:38 +09:00
Takayuki Nakata
2beb9090d1 Rename TypeckTables to TypeckResults 2020-08-05 22:51:38 +09:00
Takayuki Nakata
161f475100 Add test case for same_item_push 2020-08-05 22:51:38 +09:00
Takayuki Nakata
1e8ada3cab Add lint same_item_push 2020-08-05 22:51:38 +09:00
bors
3d7e3fdffd Auto merge of #5857 - tmiasko:try-err-poll, r=matthiaskrgr
try_err: Consider Try impl for Poll when generating suggestions

There are two different implementation of `Try` trait for `Poll` type:
`Poll<Result<T, E>>` and `Poll<Option<Result<T, E>>>`. Take them into
account when generating suggestions.

For example, for `Err(e)?` suggest either `return Poll::Ready(Err(e))` or
`return Poll::Ready(Some(Err(e)))` as appropriate.

Fixes #5855

changelog: try_err: Consider Try impl for Poll when generating suggestions
2020-08-05 08:43:37 +00:00
JarredAllen
542740c2ec Run cargo dev fmt 2020-08-04 17:53:29 -07:00
bors
2ceb8c6c2d Auto merge of #5865 - camsteffen:unnecessary-fold-known-probs, r=Manishearth
Remove obsolete known problems unnecessary_fold

The known problems looks to be obsolete since NLL is stable.

changelog: none
2020-08-04 23:09:35 +00:00
Philipp Krones
fb7ad956f6
Rollup merge of #5856 - phansch:remove-symbol-reexport, r=flip1995
Remove old Symbol reexport

I couldn't really tell what it was meant to improve. It seems more clear
without the renaming to `Name`?

changelog: none
2020-08-04 12:06:43 +02:00
Philipp Krones
84455b211f
Rollup merge of #5852 - wiomoc:feature/lint-duplicate-trait, r=Manishearth
Add lint for duplicate methods of trait bounds

rel: #5777

changelog: Add [`trait_duplication_in_bounds`] lint
2020-08-04 12:06:41 +02:00
Philipp Krones
888067c623
Rollup merge of #5848 - Ryan1729:add-derive_ord_xor_partial_ord-lint, r=matthiaskrgr
Add derive_ord_xor_partial_ord lint

Fix #1621

Some remarks:
This PR follows the example of the analogous derive_hash_xor_partial_eq lint where possible.
I initially tried using the `match_path` function to identify `Ord` implementation like the derive_hash_xor_partial_eq lint currently does, for `Hash` implementations but that didn't work.

Specifically, the structs at the top level were getting paths that matched `&["$crate", "cmp", "Ord"]` instead of `&["std", "cmp", "Ord"]`. While trying to figure out what to do instead I saw the comment at the top of [clippy_lints/src/utils/paths.rs](f5d429cd76/clippy_lints/src/utils/paths.rs (L5)) that mentioned [this issue](https://github.com/rust-lang/rust-clippy/issues/5393) and suggested to use diagnostic items instead of hardcoded paths whenever possible. I looked for a way to identify `Ord` implementations with diagnostic items, but (possibly because this was the first time I had heard of diagnostic items,) I was unable to find one.

Eventually I tried using `get_trait_def_id` and comparing `DefId` values directly and that seems to work as expected. Maybe there's a better approach however?

changelog: new lint: derive_ord_xor_partial_ord
2020-08-04 12:06:40 +02:00
Philipp Krones
378ba2e03e
Rollup merge of #5846 - dima74:map_flatten.map_to_option, r=flip1995
Handle mapping to Option in `map_flatten` lint

Fixes #4496

The existing [`map_flatten`](https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten) lint suggests changing `expr.map(...).flatten()` to `expr.flat_map(...)` when `expr` is `Iterator`. This PR changes suggestion to `filter_map` instead of `flat_map` when mapping to `Option`, because it is more natural

Also here are some questions:
* If expression has type which implements `Iterator` trait (`match_trait_method(cx, expr, &paths::ITERATOR) == true`), how can I get type of iterator elements? Currently I use return type of closure inside `map`, but probably it is not good way
* I would like to change suggestion range to cover only `.map(...).flatten()`, that is from:
```
    let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect();
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `flat_map` instead: `vec![5_i8; 6].into_iter().flat_map
```
to
```
    let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect();
                                             ^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `flat_map` instead: `.flat_map(|x| 0..x)`
```
Is it ok?
* Is `map_flatten` lint intentionally in `pedantic` category, or could it be moved to `complexity`?

changelog: Handle mapping to Option in [`map_flatten`](https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten) lint
2020-08-04 12:06:39 +02:00
Philipp Krones
ca2a25d966
Rollup merge of #5837 - JarredAllen:needless_collect, r=phansch
needless_collect: catch x: Vec<_> = iter.collect(); x.into_iter() ...

changelog: Expand the needless_collect lint as suggested in #5627 (WIP).

This PR is WIP because I can't figure out how to make the multi-part suggestion include its changes in the source code (the fixed is identical to the source, despite the lint making suggestions). Aside from that one issue, I think this should be good.
2020-08-04 12:06:38 +02:00
bors
1968aede0f Auto merge of #5867 - flip1995:rustup, r=flip1995
Rustup

r? @ghost

changelog: none
2020-08-04 09:25:05 +00:00
Vadim Petrochenkov
52a9c157d0 rustc_ast: (Nested)MetaItem::check_name -> has_name
For consistency with `Attribute::has_name` which doesn't mark the attribute as used either.

Replace all uses of `check_name` with `has_name` outside of rustc
2020-08-04 00:34:11 +03:00
Cameron Steffen
0ccdf2913a
Remove obsolete known problems unnecessary_fold 2020-08-03 16:23:20 -05:00
Tomasz Miąsko
e9677105bf try_err: Consider Try impl for Poll when generating suggestions
There are two different implementation of Try trait for Poll type;
Poll<Result<T, E>> and Poll<Option<Result<T, E>>>. Take them into
account when generating suggestions.

For example, for Err(e)? suggest either return Poll::Ready(Err(e)) or
return Poll::Ready(Some(Err(e))) as appropriate.
2020-08-03 20:48:18 +02:00
JarredAllen
25abd7ae76 Create stable_sort_primitive lint 2020-08-03 11:17:43 -07:00
Christoph Walcher
e521c67e5f
early return on empty parameters/where clause 2020-08-03 12:32:23 +02:00
JarredAllen
5e10b039a3 Implement review suggestions 2020-08-02 21:46:18 -07:00
JarredAllen
bb2c14e92b Fix a bug causing it to be too trigger-happy 2020-08-02 21:34:17 -07:00
JarredAllen
a849483294 Fix formatting and dogfood fallout 2020-08-02 21:34:17 -07:00
JarredAllen
3657c92ac9 Check for other things which can be used indirectly 2020-08-02 21:34:17 -07:00
JarredAllen
3ee61373fe Write the lint and write tests 2020-08-02 21:34:17 -07:00
Eduardo Broto
e336fe80d2 manual_async_fn: take input lifetimes into account
The anonymous future returned from an `async fn` captures all input
lifetimes. This was not being taken into account.

See https://github.com/rust-lang/rfcs/blob/master/text/2394-async_await.md#lifetime-capture-in-the-anonymous-future
2020-08-03 00:36:28 +02:00