Commit graph

2046 commits

Author SHA1 Message Date
Michael Wright
464ed58861 Ensure expect_fun_call bad suggestion is fixed
Closes #3839
2019-03-06 07:00:05 +02:00
Philipp Hansch
15cba2e956
Fix missing_const_for_fn for impl trait methods 2019-03-05 08:11:55 +01:00
Philipp Hansch
b87f5bc55a
Don't trigger missing_const_for_fn in external macros
As reported in #3841. Only fixes the part where it triggers on the
`derive`.
2019-03-04 22:56:33 +01:00
flip1995
c4eb780156
Add test for unknown Clippy attributes 2019-02-28 20:18:42 +01:00
Michael Wright
6e6e39b4a8 Add rustfmt::skip to double_parens tests 2019-02-28 08:02:45 +02:00
bors
ff2798840c Auto merge of #3666 - detrumi:map-or-on-non-copy, r=flip1995
Only suggest map_or for copy types

Fixes #2686
2019-02-27 08:28:48 +00:00
Michael Wright
11682b4cd2 Add rustfmt::skip to outer attr format tests 2019-02-27 07:41:07 +02:00
bors
6e8931c5f5 Auto merge of #3821 - g-bartoszek:redundant_closure-different-borrow-levels, r=oli-obk
do not trigger redundant_closure when there is a difference in borrow…

… level between closure parameter and "self", fixes  #3802
2019-02-26 17:30:48 +00:00
Wilco Kusee
eb70a72459
Fix false negative 2019-02-26 17:29:36 +01:00
Wilco Kusee
fec6e55d1d
Attempt to fix false negative 2019-02-26 17:27:41 +01:00
Wilco Kusee
54ab22f6db
Only suggest map_or for copy types 2019-02-26 17:27:40 +01:00
bors
0957f7d3b7 Auto merge of #3817 - rust-lang:fix-bool_comparison-on-non-bool, r=oli-obk
Fix `bool_comparison` with non-`bool` expressions

Fixes #3703.
It just moves around the type check that was already there for some comparison to all of them, because if one type isn't `bool`, none of those comparison can be simplified.
2019-02-26 15:51:40 +00:00
Grzegorz
a7f4d41a7d do not trigger redundant_closure when there is a difference in borrow level between closure parameter and "self" 2019-02-26 12:12:27 +01:00
Michael Wright
7fd0fbf435 Add [rustfmt::skip] to formatting lint tests 2019-02-26 07:49:46 +02:00
mcarton
c0c0686a65 Fix bool_comparison with non-bool expressions 2019-02-25 22:31:16 +01:00
bors
50d9473856 Auto merge of #3808 - mikerite:useless-format-suggestions, r=oli-obk
Fix `useless_format` suggestions
2019-02-25 16:21:26 +00:00
bors
1ac6f4e9ae Auto merge of #3772 - flip1995:ice-3719, r=Manishearth
Fix ICE #3719+#3718 in lint match_ref_pats

Fixes #3719
This conveniently also fixes #3718

The ICE occurs when the match expression was a macro call, where the macro was defined in another file. Since we don't have the ability to reproduce this behavior with our UI tests (AFAIK), I couldn't add a test reproducing this ICE.. However, I added a test which is related to the ICE, to show the new behavior of the lint.

I tested it with the mscheme repo locally and the ICE didn't happen anymore.

r? @matthiaskrgr
2019-02-25 12:30:35 +00:00
bors
cd29740e6e Auto merge of #3805 - martinsp:ice-3747, r=Manishearth
Fix ICE #3747

I'm not sure if this was the correct approach.

I don't know if I put tests/ui/crashses/ice-3747.rs in correct place because the test always passed when I ran it with `cargo test`, even without the fix applied.

If I run that test with `env CLIPPY_TESTS=true cargo run --bin clippy-driver -- -L ./target/debug tests/ui/crashes/ice-3747.rs` then the test correctly fails without the fix applied

fixes #3747
2019-02-25 12:08:43 +00:00
mcarton
8bcd546648 Add a test for #2526 2019-02-24 18:23:54 +01:00
Michael Wright
0182a6640e Fix useless_format suggestions 2019-02-24 07:30:08 +02:00
Martins Polakovs
391ee7987d Fix ICE #3747
[Martins Polakovs, John Firebaugh]
2019-02-23 21:38:16 +02:00
bors
36e92a521f Auto merge of #3795 - mikerite:test-rustfmt, r=phansch
Allow rustfmt to run on more tests
2019-02-22 06:54:25 +00:00
Michael Wright
7a43509cc4 rustfmt tests/ui/methods.rs 2019-02-22 08:05:21 +02:00
Michael Wright
b96c4329db Add #[rustfmt::skip] to methods tests
Many people run rustfmt automatically on save. Format-dependent tests
should be marked with `#[rustfmt::skip]` to prevent accidental
reformatting from this. As a bonus the rest of the code can the formatted.
2019-02-22 07:49:17 +02:00
bors
a5c16e5892 Auto merge of #3789 - bzzzzzz:needless_range_loop_bugfix, r=oli-obk
Make needless_range_loop not applicable to structures without iter method

Fixes https://github.com/rust-lang/rust-clippy/issues/3788

Now we will start lint indexed structure only if it has known iter or iter_mut method implemented.
2019-02-21 09:36:13 +00:00
bors
027dde92e2 Auto merge of #3781 - uniphil:write_with_newline_false_positive, r=oli-obk
Don't check [print/write]_with_newline on raw strings

Some tests for #3778 and some maybe-not-the-greatest code that passes those tests!

I didn't run `fmt` because a) it doesn't seem to install on nightly for me, and b) on stable it wanted to apply formatting to over 90 files. Happy to make any tweaks though!

I suspect this contribution may require more than just tweaks. I'm still sort of new to rust so it may not be idiomatic, and the specific approach I took feels a little heavy-handed and brittle. I'm happy to make changes with some guidance, or equally happy if this gives a starting place for someone else to do it better :)
2019-02-20 16:37:32 +00:00
bors
d5d8d7bca5 Auto merge of #3779 - mikerite:fix-3704, r=phansch
Improve `iter_cloned_collect` suggestions

Fixes #3704
2019-02-20 09:21:18 +00:00
bzzzz
f9c6682827 Make needless_range_loop not applicable to structures without iter method 2019-02-20 00:10:25 -08:00
Michael Wright
bef7c76025 Format again 2019-02-20 06:06:00 +02:00
flip1995
0ce564a7e1
Add test related to the ICE
This test doesn't reproduce the ICE since it only happens, when the macro is defined in another file.
Currently we can't add tests with multiple files AFAIK

Also using the auxiliary folder didn't help
2019-02-19 21:34:14 +01:00
bors
075c212849 Auto merge of #3776 - notriddle:drop-bounds, r=oli-obk
Add a lint to warn on `T: Drop` bounds

**What it does:** Checks for generics with `std::ops::Drop` as bounds.

**Why is this bad?** `Drop` bounds do not really accomplish anything.
A type may have compiler-generated drop glue without implementing the
`Drop` trait itself. The `Drop` trait also only has one method,
`Drop::drop`, and that function is by fiat not callable in user code.
So there is really no use case for using `Drop` in trait bounds.

**Known problems:** None.

**Example:**
```rust
fn foo<T: Drop>() {}
```

Fixes #3773
2019-02-19 09:46:29 +00:00
Michael Wright
a6864297a7 Format again 2019-02-19 06:39:22 +02:00
Michael Howell
2da7f084fe Fix formatting 2019-02-18 19:36:58 -07:00
phil
ef72b2cac0 Check {print,write}_with_newline for literal newline
Both regular strings and raw strings can contain literal newlines. This commit
extends the lint to also warn about terminating strings with these.

Behaviour handling for raw strings is also moved into `check_newlines` by
passing in the `is_raw` boolean from `check_tts` as
[suggested](https://github.com/rust-lang/rust-clippy/pull/3781#pullrequestreview-204663732)
2019-02-18 19:22:20 -05:00
Daniel Wagner-Hall
bcefd688c9 Restore tests
Also, fix existing test
2019-02-18 22:56:43 +00:00
Daniel Wagner-Hall
422c9a0fa2 wildcard_enum_match_arm gives suggestions
And is also more robust
2019-02-18 22:56:43 +00:00
phil
cf5d4a1b45 Add failing test for #3778 write_with_newline
Literal `\n` characters (not a newline) in a `r"raw"` string should not
fail the lint.

This affects both write_with_newline and print_with_newline, so it is added in
both places.

I also copied a missing test case from write_with_newline over to
print_with_newline and added a note that one of those tests is supposed to
fail.
2019-02-18 11:39:40 -05:00
Michael Howell
2df14c3701 Add a lint to warn on T: Drop bounds
**What it does:** Checks for generics with `std::ops::Drop` as bounds.

**Why is this bad?** `Drop` bounds do not really accomplish anything.
A type may have compiler-generated drop glue without implementing the
`Drop` trait itself. The `Drop` trait also only has one method,
`Drop::drop`, and that function is by fiat not callable in user code.
So there is really no use case for using `Drop` in trait bounds.

**Known problems:** None.

**Example:**
```rust
fn foo<T: Drop>() {}
```
2019-02-17 22:53:08 -07:00
Michael Wright
6e7a813ed2 Improve iter_cloned_collect suggestions
Fixes #3704
2019-02-18 07:30:50 +02:00
phil
2d28d9f02a Add failing test for #3778 write_with_newline
Literal `\n` characters (not a newline) in a `r"raw"` string should not
fail the lint.
2019-02-17 22:32:58 -05:00
flip1995
9148fc274a
Add test for ICE #3717 fix 2019-02-17 01:50:31 +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
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
Grzegorz
f7c0df9183 test formatting 2019-02-10 21:23:04 +01:00
bors
bd23cb89ec Auto merge of #3754 - phansch:uicleanup, r=oli-obk
UI test cleanup: Extract similar_names tests

cc #2038
2019-02-10 14:06:20 +00: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
Philipp Hansch
1eeda35118
rustfmt 2019-02-10 10:48:24 +01:00