Commit Graph

2335 Commits

Author SHA1 Message Date
Michael Wright
9185c8d996 Format 2019-02-18 08:32:53 +02:00
Michael Wright
6e7a813ed2 Improve iter_cloned_collect suggestions
Fixes #3704
2019-02-18 07:30:50 +02:00
flip1995
f204b7ec76
Fix ICE #3717
Restore the old `TypeckTables` in visit_body after walking the body
2019-02-17 01:50:13 +01:00
flip1995
10811d5d89
Fix breakage from rust-lang/rust#58296 2019-02-14 14:01:43 +01:00
Michael Wright
533dd360d7 Fix breakage due to rust-lang/rust#58167 2019-02-14 08:55:50 +02:00
flip1995
5a3cd31c9e
Rustup
cc rust-lang/rust#58137
2019-02-13 22:08:17 +01:00
bors
db13e6fa34 Auto merge of #3756 - g-bartoszek:redundant-closure-for-methods, r=oli-obk
Redundant closure for methods

fixes  #3469
2019-02-12 13:31:44 +00:00
bors
ed3287605d Auto merge of #3757 - mikerite:fix-2542, r=oli-obk
Fix `needless_range_loop` bad suggestion

Detect if the index variable is used inside a closure.

Fixes #2542
2019-02-12 10:27:18 +00:00
bors
2066368583 Auto merge of #3758 - phansch:document_macro, r=flip1995
Document `declare_clippy_lint` macro

Split up from my work on updating CONTRIBUTING.md, which is slowly
making progress.

cc #2666
2019-02-11 23:52:52 +00:00
Philipp Hansch
a14247b500
Update comment regarding crate level cfg_attr 2019-02-11 22:32:54 +01:00
Philipp Hansch
7d3983216f
Document some more core functions 2019-02-11 08:34:37 +01:00
Philipp Hansch
a27022e0dc
Document declare_clippy_lint macro
Split up from my work on updating CONTRIBUTING.md, which is slowly
making progress.

cc #2666
2019-02-11 08:34:37 +01:00
Michael Wright
217965e855 Fix needless_range_loop bad suggestion
Detect if the index variable is used inside a closure.

Fixes #2542
2019-02-11 07:03:12 +02:00
bors
2755d12fa6 Auto merge of #3744 - phansch:fix3144, r=oli-obk
Fix ICE in needless_pass_by_value lint

If I understand it correctly, we were first creating a type with a
`RegionKind::ReErased` region and then deleted it again in
`util::implements_trait` with:

    cx.tcx.erase_regions(&ty);

causing the type query to fail.

It looks like using `ReEmpty` works around that deletion.

Fixes #3144
2019-02-10 13:39:46 +00:00
bors
af43950143 Auto merge of #3740 - flip1995:const_assert_macro, r=oli-obk
Macro check for assertion_on_constants lint

The `assertion_on_constants` lint currently has following output for this code [Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6f2c9df6fc50baf847212d3b5136ee97):
```rust
macro_rules! assert_const {
    ($len:expr) => {
        assert!($len > 0);
    }
}

fn main() {
    assert_const!(3);
    assert_const!(-1);
}
```
```
warning: assert!(const: true) will be optimized out by the compiler
 --> src/main.rs:3:9
  |
3 |         assert!($len > 0);
  |         ^^^^^^^^^^^^^^^^^^
...
8 |     assert_const!(3);
  |     ---------------- in this macro invocation
  |
  = note: #[warn(clippy::assertions_on_constants)] on by default
  = help: remove it
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants

warning: assert!(const: false) should probably be replaced
 --> src/main.rs:3:9
  |
3 |         assert!($len > 0);
  |         ^^^^^^^^^^^^^^^^^^
...
9 |     assert_const!(-1);
  |     ----------------- in this macro invocation
  |
  = help: use panic!() or unreachable!()
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants
```

This is contradictory. This lint should not trigger if the `assert!` is in a macro itself.
2019-02-10 12:47:16 +00:00
Grzegorz
16881390e1 removing redundant closures in the whole project 2019-02-10 13:35:44 +01:00
Grzegorz
b38c587b98 redundant closure implemented for closures containing method calls 2019-02-10 12:58:51 +01:00
bors
5725726345 Auto merge of #3751 - h-michael:opt-def-id, r=phansch
Use Hir::Def opt_def_id

related with: https://github.com/rust-lang/rust-clippy/pull/3750#issuecomment-462010225

Using `def.opt_def_id` in `opt_def_id` before replacing all all at once.
2019-02-09 12:01:45 +00:00
Hirokazu Hata
71dfbe2072 Use Hir::Def opt_def_id 2019-02-09 13:28:21 +09:00
bors
77435f9938 Auto merge of #3748 - phansch:uitest, r=oli-obk
Add a uitest subcommand to simplify UI test invocation

This makes running single tests a lot easier.

It's now

`TESTNAME=xxx cargo uitest`

instead of

`TESTNAME=xxx cargo test --test compile-test`
2019-02-09 04:09:25 +00:00
Hirokazu Hata
66f8fa320b Add new Def type ConstParam 2019-02-09 11:42:13 +09:00
Philipp Hansch
f934f98111
Add a uitest subcommand to simplify UI test invocation
This allows to run

`TESTNAME=xxx cargo uitest`

instead of

`TESTNAME=xxx cargo test --test-compile-test`
2019-02-08 08:09:37 +01:00
bors
e176324fc5 Auto merge of #3665 - jsgf:master, r=oli-obk
Start making clippy easier to invoke in non-cargo contexts

Clippy (clippy-driver) currently has a couple of strong but unnecessary couplings with cargo. This series:
1. makes detection of check builds more robust, and
2. make clippy-driver use the --sysroot specified on the command line as its internal sysroot.
2019-02-06 15:43:07 +00:00
Philipp Hansch
f3cd81980d
Fix ICE in needless_pass_by_value lint
If I understand it correctly, we were first creating a type with a
`RegionKind::ReErased` region and then deleted it again in
`util::implements_trait` with:

    cx.tcx.erase_regions(&ty);

causing the type query to fail.

It looks like using `ReEmpty` works around that deletion.
2019-02-06 09:18:35 +01:00
flip1995
446e2ecfb7
Don't warn about const assertions when assert is in a macro itself 2019-02-05 19:37:50 +01:00
bors
4259377ea6 Auto merge of #3725 - mikerite:fix-2728, r=phansch
Fix `cast_sign_loss` false positive

This checks if the value is a non-negative constant before linting about
losing the sign.

Because the `constant` function doesn't handle const functions, we check if
the value is from a call to a `max_value` function directly. A utility method
called `get_def_path` was added to make checking for the function paths
easier.

Fixes #2728
2019-02-04 05:52:44 +00:00
Michael Wright
f3ee53d225 Document get_def_path 2019-02-04 07:30:24 +02:00
rhysd
83d620b824 run util/dev update_lints and cargo fmt --all 2019-02-03 21:56:24 +09:00
rhysd
4b736ff29b Merge branch 'master' into issue3721 2019-02-03 21:27:23 +09:00
rhysd
60f723fba4 prefer if to match 2019-02-03 18:50:00 +09:00
rhysd
3100fecb99 use snippet for making a suggestion if possible 2019-02-03 18:28:42 +09:00
Michael Wright
c02367c4e9 Fix breakage due to rust-lang/rust#58079
The rustc change added HirId to a few nodes. As I understand it, the plan is
to remove the NodeId from these nodes eventually. Where the NodeId was
not being matched, I used `..` to try and avoid further breakage. Where it
was, I used `_` to make the fix easier when NodeId is removed.
2019-02-03 09:12:07 +02:00
Jeremy Fitzhardinge
86c513e605 Let CLIPPY_CONF_DIR be used to start search for config, and fall back to
CARGO_MANIFEST_DIR if it isn't set. If CARGO_MANIFEST_DIR isn't set, fall back
"." rather than panicing.

Issue #3663
2019-02-02 11:43:21 -08:00
bors
27b5dd8886 Auto merge of #2857 - avborhanian:master, r=phansch
Adding lint test for excessive LOC.

This is a WIP for #2377. Just wanted to pull in because I had a few questions:

1. Is it okay that I'm approaching this via counting by looking at each line in the snippet instead of looking at the AST tree? If there's another way to do it, I want to make sure I'm doing the correct way, but I wasn't sure since the output AST JSON doesn't seem to contain whitespace.

2. My function is definitely going to trigger the lint, so also wanted to see if there was something obvious I could do to reduce it.

3. Are the two tests fine, or is there something obvious I'm missing?

4. Obviously bigger question - am I approaching the line count correctly. Current strategy is count a line if it contains some code, so skip if it's just comments or empty.
2019-02-02 08:32:27 +00:00
rhysd
54d49af3ff add more test cases for dbg_macro rule 2019-02-02 04:54:51 +09:00
Philipp Hansch
ac9472d16e
Update clippy_lints/src/types.rs
Co-Authored-By: avborhanian <avborhanian@gmail.com>
2019-02-01 14:53:15 -05:00
Philipp Hansch
a022d47a6b
Update clippy_lints/src/types.rs
Co-Authored-By: avborhanian <avborhanian@gmail.com>
2019-02-01 14:52:56 -05:00
rhysd
268ff85326 use span_help_and_lint() instead of span_lint_and_sugg() 2019-02-02 04:52:21 +09:00
Unknown
93a856e9d5 Changing single character string to a character match. 2019-02-01 13:21:19 -05:00
Unknown
6931b0f5a1 rustfmt 2019-02-01 13:21:19 -05:00
Araam Borhanian
5e10809ac3 Adding lint for too many lines. 2019-02-01 13:21:19 -05:00
Unknown
44c835feea Skipping check if in external macro. 2019-02-01 13:21:19 -05:00
Unknown
c1f4e18453 Adding back tests, but also reducing threshold by 1 2019-02-01 13:21:19 -05:00
Unknown
e583f35b3a rustfmt 2019-02-01 13:21:19 -05:00
Unknown
7fbd55c329 Reworking function logic, and adding doc example.
This should fix line count logic issues that the previous code had, with assumptions it would make.
2019-02-01 13:21:19 -05:00
Araam Borhanian
1169066a0b Adding lint for too many lines. 2019-02-01 13:21:19 -05:00
Philipp Hansch
38347bad38
Make vec_box MachineApplicable 2019-02-01 18:18:45 +01:00
Philipp Hansch
4aff8711f0
Fix ICE in vec_box lint and add run-rustfix
`hir::Ty` doesn't seem to know anything about type bounds and
`cx.tcx.type_of(def_id)` caused an ICE when it was passed a generic type
with a bound:

```
src/librustc_typeck/collect.rs:1311: unexpected non-type Node::GenericParam: Type { default: None, synthetic: None }
```

Converting it to a proper `Ty` fixes the ICE and catches a few more
places where the lint applies.
2019-02-01 18:18:45 +01:00
bors
5176a5c4b7 Auto merge of #3726 - phansch:some_renaming, r=oli-obk
Some renamings: s/ast_ty/hir_ty and s/StructField/hir::StructField

I think in both cases the new names make the code more understandable.
For `StructField` specifically because there's one in
[`syntax::ast`][ast] and one in [`rustc::hir`][hir].

[ast]: https://doc.rust-lang.org/nightly/nightly-rustc/syntax/ast/struct.StructField.html
[hir]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/hir/struct.StructField.html
2019-02-01 08:36:11 +00:00
Michael Wright
b6c3a6a09f Move max_value handling to consts module 2019-02-01 06:32:16 +02:00