Commit graph

9011 commits

Author SHA1 Message Date
bors
7228368953 Auto merge of #5882 - dima74:ra_setup-prevent-compile-rustc, r=Manishearth
Prevent compile parts of rustc when using `cargo dev ra-setup`

Currently after running `cargo dev ra-setup` the following lines are added to `Cargo.toml`:

```toml
[target]
rustc_data_structures = { path = ".../rust/src/librustc_data_structures" }
rustc_driver = { path = ".../rust/src/librustc_driver" }
rustc_errors = { path = ".../rust/src/librustc_errors" }
rustc_interface = { path = ".../rust/src/librustc_interface" }
rustc_middle = { path = ".../rust/src/librustc_middle" }
```

This pull request adds dependencies for `rustc` crates under `cfg(NOT_A_PLATFORM)`, thus preventing them from compiling together with clippy:

```toml
[target.'cfg(NOT_A_PLATFORM)'.dependencies]
rustc_data_structures = { path = ".../rust/src/librustc_data_structures" }
rustc_driver = { path = ".../rust/src/librustc_driver" }
rustc_errors = { path = ".../rust/src/librustc_errors" }
rustc_interface = { path = ".../rust/src/librustc_interface" }
rustc_middle = { path = ".../rust/src/librustc_middle" }
```

---

This approach was [originally proposed for IntelliJ Rust](https://github.com/intellij-rust/intellij-rust/issues/1618#issuecomment-459098749), and looks like it works for rust-analyzer too.

changelog: none
2020-08-09 19:18:01 +00:00
Dmitry Murzin
6af969379e
Prevent compile parts of rustc when using cargo dev ra-setup 2020-08-09 22:21:09 +05: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
bors
a7fa264ae7 Auto merge of #74821 - oli-obk:const_eval_read_uninit_fast_path, r=wesleywiser
Check whether locals are too large instead of whether accesses into them are too large

Essentially this stops const prop from attempting to optimize

```rust
let mut x = [0_u8; 5000];
x[42] = 3;
```

I don't expect this to be a perf improvement without #73656 (which is also where the lack of this PR will be a perf regression).

r? @wesleywiser
2020-08-07 15:28:07 +00: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
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
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
bors
80121781a3 Auto merge of #5868 - flip1995:rollup-5g8vft5, r=flip1995
Rollup of 5 pull requests

Successful merges:

 - #5837 (needless_collect: catch x: Vec<_> = iter.collect(); x.into_iter() ...)
 - #5846 (Handle mapping to Option in `map_flatten` lint)
 - #5848 (Add derive_ord_xor_partial_ord lint)
 - #5852 (Add lint for duplicate methods of trait bounds)
 - #5856 (Remove old Symbol reexport)

Failed merges:

r? @ghost

changelog: rollup
2020-08-04 10:07:47 +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
bors
bbbc973a84 Auto merge of #5864 - rust-lang:ci_debug, r=Manishearth
Fix ui-cargo tests in CI

r? @ebroto

The `ui-toml` tests set the `CARGO_MANIFEST_DIR` var, but never reset it, so the `ui-cargo` tests used it also and then found a faulty `clippy.toml` file

changelog: none
2020-08-03 17:53:35 +00:00
flip1995
0e44ed5ca9
Fix ui-cargo tests in CI 2020-08-03 18:18:11 +02: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
c86f4109fd Split indirect collects into their own test case 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
JarredAllen
05bb6e6bdb Create test for wanted behavior 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
liuzhenyu
24a6130da2 fix typos 2020-08-02 23:20:00 +08:00
Philipp Hansch
bb6e857980
fmt 2020-08-02 14:22:54 +02:00
Philipp Hansch
cb00cdf0d7
Remove old Symbol reexport
I couldn't really tell what it was meant to improve. It seems more clear
without the renaming to `Name`?
2020-08-02 11:25:03 +02:00
Valentin Lazureanu
aa3d9ca0e9 Rename HAIR to THIR (Typed HIR). 2020-07-31 22:15:12 +00:00
Dmitry Murzin
d4ba561aaf
Review fixes 2020-07-31 00:28:21 +03:00
Dmitry Murzin
a427c99f3d
Handle mapping to Option in map_flatten lint 2020-07-30 23:23:33 +03:00
Oliver Scherer
98f3c79385 Update clippy ui test.
The reason we do not trigger these lints anymore is that clippy sets the mir-opt-level to 0, and the recent changes subtly changed how the const propagator works.
2020-07-29 22:14:19 +02:00
Christoph Walcher
2b7fde6a4b
typo fix 2020-07-29 16:10:15 +02:00
bors
2e0f8b6cc6 Auto merge of #5843 - dima74:iter_skip_next.add-suggestion, r=phansch
Add suggestion for `iter_skip_next` lint

changelog: Add suggestion for [`iter_skip_next`](https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_next) lint
2020-07-29 06:10:55 +00:00
bors
73764ab8cd Auto merge of #5840 - flip1995:basics, r=phansch
Basic instruction for new contributors

While answering a few questions to @AB1908, I realized, that our documentation could use some love. Especially the "Getting Started" part for new contributors. So I wrote together some instruction on how to get the toolchain and how to build and test Clippy.

[Rendered](https://github.com/flip1995/rust-clippy/blob/basics/doc/basics.md)

r? @phansch

changelog: none
2020-07-29 05:43:02 +00:00
bors
61eab6e8f9 Auto merge of #5853 - flip1995:rustup, r=flip1995
Rustup

r? @ghost

changelog: none
2020-07-29 01:18:35 +00:00
flip1995
04f4471761
Merge remote-tracking branch 'upstream/master' into rustup 2020-07-29 03:17:23 +02:00
Christoph Walcher
94c50bc8c9
Lint duplicate methods of trait bounds
Fixes #5777
2020-07-28 16:42:26 +02:00