Commit Graph

1397 Commits

Author SHA1 Message Date
bors
65d88c7ba7 Auto merge of #4011 - phansch:add_test_for_derive_expansion, r=flip1995
Add test for derives for used_underscore_binding lint

This closes #852 as I can't reproduce the original issue anymore.

changelog: none
2019-04-20 18:55:48 +00:00
bors
54e80c7b34 Auto merge of #4007 - phansch:fix_allowing_toplevel_ref_arg, r=flip1995
Allow allowing of toplevel_ref_arg lint

I'm not sure why some lints need the `HirId` to be able to recognize the
lint level attributes, but this commit makes the lint level attributes
work for `toplevel_ref_arg`.

Fixes #2332

changelog: Allow allowing of `toplevel_ref_arg` lint
2019-04-20 18:22:53 +00:00
bors
fc1c2f5f1a Auto merge of #4005 - phansch:rustfix_match_as_ref, r=flip1995
Add run-rustfix for match_as_ref lint

* Extracts `match_as_ref` into separate file
* Adds `// run-rustfix` to `tests/ui/match_as_ref.rs`

cc #3630

changelog: none
2019-04-20 17:21:20 +00:00
bors
7a6d5c00d3 Auto merge of #4006 - phansch:fix_module_name_repetitions_fp, r=flip1995
Fix false positive in module_name_repetitions lint

This lint was triggering on modules inside expanded attrs, like
for example `#[cfg(test)]` and possibly more.

It was not reporting a location in #3892 because `span.lo()` and `span.hi()` both were 0.

Fixes #3892

changelog: Fix false positive in `module_name_repetitions` lint
2019-04-20 16:58:51 +00:00
Philipp Hansch
60a1759b5f
Add test for derives for used_underscore_binding lint
This closes #852 as I can't reproduce the original issue anymore.
2019-04-20 09:33:13 +02:00
Philipp Hansch
158aa39a7c
Allow allowing of toplevel_ref_arg lint
I'm not sure why some lints need the `HirId` to be able to recognize the
lint level attributes, but this commit makes the lint level attributes
work for `toplevel_ref_arg`.
2019-04-19 15:18:32 +02:00
Grzegorz
aa9cf07d56 redundant closure for functions restricted to FnDefs 2019-04-19 15:14:49 +02:00
Philipp Hansch
850c24edd3
Fix false positive in module_name_repetitions lint
This lint was triggering on modules inside expanded attrs, like
for example `#[cfg(test)]` and possibly more.
2019-04-19 12:53:03 +02:00
Philipp Hansch
9a6c82094f
Add run-rustfix for match_as_ref lint
* Extracts `match_as_ref` into separate file
* Adds `// run-rustfix` to `tests/ui/match_as_ref.rs`
2019-04-19 12:08:34 +02:00
bors
12e8075d91 Auto merge of #3989 - flip1995:assert_on_const, r=phansch
Don't trigger assertions_on_constants on debug_assert!(false)

Fixes #3948
Fixes #3765

changelog: Fix `debug_assert!` false positive on `assertions_on_constants` lint
2019-04-19 09:57:35 +00:00
bors
77fbdb6494 Auto merge of #3978 - phansch:rustfix_len_zero, r=flip1995
Add run-rustfix for len_zero lint

* Extracts len_without_is_empty into separate file
* Adds `// run-rustfix` to `tests/ui/len_zero.rs`

cc #3630
2019-04-18 21:18:23 +00:00
bors
c6e43b1ba7 Auto merge of #3954 - andrehjr:add-lint-path-buf-overwrite, r=flip1995
Add Lint PathBufPushOverwrite

Closes #3923

This is a very simple Lint that checks if push is being called with a Root Path. Because that can make it overwrite the previous path.

I used std::path::Path to check if it's root, in order to keep it working across windows/linux environments instead of checking for '/'. Is that alright?

On the `if_chain!` block, Is there a way to make it short while getting the value of the first argument? I got the example from other lints.

Note that this is first Lint, I hope I got everything covered  🚀
2019-04-18 11:29:43 +00:00
André Luis Leal Cardoso Junior
7e9cb5b84a Add lint PathBufPushOverwrite 2019-04-18 08:05:55 -03:00
bors
6feed2713c Auto merge of #3985 - phansch:move_some_cast_tests, r=flip1995
Move two cast_lossless tests to their correct files

First part of checking off the `tests/ui/cast.rs` checkbox in #3630.
2019-04-18 10:06:55 +00:00
flip1995
88359a136f
Update *.stderr file 2019-04-18 12:05:09 +02:00
flip1995
5b836e344c
Add test for debug_assert!(false) 2019-04-18 11:48:19 +02:00
bors
95e537b039 Auto merge of #3987 - phansch:rustfix_option_map_or_none, r=flip1995
Add run-rustfix for option_map_or_none lint

* Extracts `option_map_or_none` tests into separate file
 * Adds `// run-rustfix` to `tests/ui/option_map_or_none.rs`

cc #3630
2019-04-18 09:43:42 +00:00
Philipp Hansch
0f69aac3d9
Add run-rustfix for option_map_or_none lint 2019-04-18 08:12:59 +02:00
Philipp Hansch
8163a1a5f8
Move two cast_lossless tests to their correct files
First part of checking off the `tests/ui/cast.rs` checkbox in #3630.
2019-04-18 06:54:32 +02:00
Matthew Kraai
ef29db773e Add tests for declare_lint_pass and impl_lint_pass 2019-04-17 09:35:23 -07:00
bors
27d62cf603 Auto merge of #3966 - flip1995:internal_lints, r=oli-obk
Enable rustc internal lints

Closes #3965

I'm not 100% sure if enabling the `-Zunstable-options` flag in the `.cargo/config` file is the right place.
2019-04-17 04:46:19 +00:00
bors
ea25f044ec Auto merge of #3977 - phansch:add_rustfix_bool_comparison, r=flip1995
Add run-rustfix for bool_comparison lint

cc #3630
2019-04-17 02:35:02 +00:00
bors
1936368da1 Auto merge of #3976 - phansch:deref_addrof_rustfix, r=flip1995
Add run-rustfix for deref_addrof lint

* renames `tests/ui/reference.{rs,stderr}` to
  `tests/ui/deref_addrof.{rs,stderr}
* Moves small part of the testfile to a separate file as the lint
  triggered again on the fixed code (as intended)
* Adds `// run-rustfix` to `tests/ui/deref_addrof.rs`

cc #3630
2019-04-17 01:50:58 +00:00
Philipp Hansch
bae7d29dbe
Add run-rustfix for len_zero lint
* Extracts len_without_is_empty into separate file
* Adds `// run-rustfix` to `tests/ui/len_zero.rs`
2019-04-16 21:46:07 +02:00
Philipp Hansch
90ddf0da6c
Add run-rustfix for bool_comparison lint 2019-04-16 20:42:54 +02:00
Philipp Hansch
d1e84c615c
Add run-rustfix for deref_addrof lint
* renames `tests/ui/reference.{rs,stderr}` to
  `tests/ui/deref_addrof.{rs,stderr}
* Moves small part of the testfile to a separate file as the lint
  triggered again on the fixed code (as intended)
* Adds `// run-rustfix` to `tests/ui/deref_addrof.rs`
2019-04-16 20:32:54 +02:00
Manish Goregaokar
e9cde416ba Only suggest .copied() for Option right now 2019-04-15 15:44:09 -07:00
Manish Goregaokar
ad2c65bd1b Also suggest .copied() when .clone() is called on a Copy type 2019-04-15 14:39:41 -07:00
Manish Goregaokar
d2f7ae70ae Suggest .copied() instead of .cloned() in map_clone when dealing with references 2019-04-15 14:32:39 -07:00
flip1995
5361b842d1
Remove clippy::default_hash_types internal lint 2019-04-15 13:21:52 +02:00
Manish Goregaokar
1366b9516b Rust upgrade to rustc 1.35.0-nightly (00856722b 2019-04-13) 2019-04-13 18:57:16 -07:00
bors
d516925ec8 Auto merge of #3946 - rchaser53:issue-3920, r=flip1995
fix format does not parse escaped braces error

related: https://github.com/rust-lang/rust-clippy/issues/3920
2019-04-12 17:03:01 +00:00
rchaser53
db6ca9b8d3 fix format does not parse escaped braces error 2019-04-13 01:39:10 +09:00
Philipp Hansch
25e2affd31
UI test cleanup: Extract iter_nth tests 2019-04-11 08:23:43 +02:00
Philipp Hansch
fdc2255e81
UI test cleanup: Extract or_fun_call tests 2019-04-11 07:47:04 +02:00
bors
2278814c8e Auto merge of #3931 - phansch:3891, r=flip1995
Fix ICE in decimal_literal_representation lint

Handling the integer parsing properly instead of just unwrapping.

Note that the test is not catching the ICE because plain UI tests
[currently hide ICEs][compiletest_issue]. Once that issue is fixed, this
test would fail properly again.

Fixes #3891

[compiletest_issue]: https://github.com/laumann/compiletest-rs/issues/169
2019-04-10 20:57:15 +00:00
bors
3d469f436f Auto merge of #3933 - phansch:add_rustfix_eta, r=oli-obk
Add // run-rustfix for eta.rs test

cc #3071, #3630
2019-04-10 09:15:27 +00:00
Philipp Hansch
9e4e1302a6
Add // run-rustfix for eta.rs test
cc #3071, #3630
2019-04-10 08:16:07 +02:00
Philipp Hansch
2b0dc39f5b
Don't emit useless_attribute lint in external macros 2019-04-10 07:30:59 +02:00
bors
37f5c1ec73 Auto merge of #3925 - phansch:3741, r=flip1995
Fix ICE in suspicious_else_formatting

Fixes #3741
2019-04-09 07:13:08 +00:00
Philipp Hansch
0307ff020c
Fix ICE in decimal_literal_representation lint
Handling the integer parsing properly instead of just unwrapping.

Note that the test is not catching the ICE because plain UI tests
[currently hide ICEs][compiletest_issue]. Once that issue is fixed, this
test would fail properly again.

[compiletest_issue]: https://github.com/laumann/compiletest-rs/issues/169
2019-04-08 22:16:34 +02:00
Philipp Hansch
3ab8038450
Remove force-host and explain no-prefer-dynamic 2019-04-08 21:23:39 +02:00
Klemen Košir
560fd163d6
Escape a single quote in single_char_pattern hint 2019-04-08 21:55:50 +09:00
bors
4fdd113bed Auto merge of #3921 - euclio:single-char-names-multispan, r=flip1995
use a multispan for MANY_SINGLE_CHAR_NAMES
2019-04-08 08:42:13 +00:00
bors
e91ba8af85 Auto merge of #3848 - felix91gr:null_transmute, r=flip1995
Transmuting known null ptr to ref

Working on implementing #628
2019-04-08 07:20:25 +00:00
bors
42e1cf3763 Auto merge of #3901 - rail-rain:issue_1670, r=flip1995
Fix `explicit_counter_loop` suggestion

#1670

This code seems to me to work, but I have two question.
* Because range expression desugared in hir, `Sugg::hir` doesn't add parenthesis to range expression.  Which function is better to check range do you think, `check_for_loop_explicit_counter` or `hir_from_snippet`?
* Do you think we need to distinguish between range expression and struct expression that creates `std::ops::Range*`?
2019-04-08 06:28:15 +00:00
Philipp Hansch
60c1bb0546
Fix ICE in suspicious_else_formatting 2019-04-07 11:11:06 +02:00
Andy Russell
0d50d44ea6
use a multispan for MANY_SINGLE_CHAR_NAMES 2019-04-05 10:07:39 -04:00
Philipp Hansch
b545f1c3bb
Add missing // run-pass annotations to ICE tests
compiletest UI tests do not fail when encountering panics and ICEs
unless the `// run-pass` flag is used.

(This was forgotten in https://github.com/rust-lang/rust-clippy/pull/3743)
2019-04-05 07:22:36 +02:00
Félix Fischer
069957a8ad Add TransmutingNull Lint
* Late Lint pass, catches:
  * One liner: 0 -> null -> transmute
  * One liner: std:null() -> transmute
  * Const (which resolves to null) -> transmute
* UI Test case for Lint
* Updated test for issue 3849, because now the lint that code generated is in Clippy.
* Expanded `const.rs` miri-based Constant Folding code, to cover
  raw pointers
2019-04-02 11:39:43 -03:00
flip1995
41927796bf
Run rustfmt 2019-04-01 20:37:05 +02:00
Philipp Hansch
b253c564d5
Rustup to https://github.com/rust-lang/rust/pull/58805 2019-04-01 20:37:05 +02:00
flip1995
6f01ecfefd
Fix question_mark lint+test 2019-04-01 20:37:05 +02:00
rail
2b82c71b55 use span_lint_and_sugg in explicit_counter_loop 2019-03-28 08:51:57 +09:00
Oliver Scherer
d020565ed2 Hacky rustup 2019-03-26 10:55:03 +01:00
rail
9698e41994 Change explicit_counter_loop's message to add parentheses if necessary 2019-03-23 15:36:48 +09:00
rail
bd6c2df066 Change explicit_counter_loop's message to reflect original variable name 2019-03-23 15:30:17 +09:00
Philipp Hansch
0452704978
cargo fmt 2019-03-19 06:57:41 +01:00
Philipp Hansch
f1d0858a8f
Add rustfix tests for mistyped_literal_suffix lint
This moves all `mistyped_literal_suffix` tests to their own file and
enables rustfix tests for them.

cc #3603, #2038

Based on #3887
2019-03-19 06:55:42 +01:00
Philipp Hansch
4e51c980bc
Move some unreadable_literal ui tests to correct file
The moved tests were part of `tests/ui/literals.rs` before. Now they are
placed in `tests/ui/unreadable_literal.rs`, which now also runs
`rustfix` on these 4 extra let statements.
2019-03-19 06:55:42 +01:00
bors
54e20519d2 Auto merge of #3886 - phansch:rustfix_useless_asref, r=flip1995
Enable rustfix for `useless_asref` lint tests

cc #3630
2019-03-15 09:43:29 +00:00
Philipp Hansch
0019ca5e4f
Enable rustfix for useless_asref lint tests 2019-03-15 07:29:12 +01:00
bors
e7806413c6 Auto merge of #3883 - daxpedda:missing_docs_in_private_items, r=phansch
Add `doc(include = ...)` detection to `missing_docs_in_private_items`

The whole `missing documentation in crate` part doesn't have any tests. If I should add test cases tell me.
2019-03-15 06:18:28 +00:00
daxpedda
9061fd3199
Another test for missing crate documentation. 2019-03-14 19:38:41 +01:00
daxpedda
e1096e3310
Add a test for doc(include)
Tiny code improvement.
2019-03-14 19:33:06 +01:00
bors
bb41b16423 Auto merge of #3879 - phansch:rustfix_string_lit_as_bytes, r=flip1995
Run rustfix for string_lit_as_bytes tests

This moves the `string_lit_as_bytes` tests into a new file and enables
rustfix tests for them.

cc #3603, #2038
2019-03-14 17:29:19 +00:00
bors
9df38117d9 Auto merge of #3877 - rink1969:3842, r=flip1995
casting integer literal to float is unnecessary

fix issue https://github.com/rust-lang/rust-clippy/issues/3842
2019-03-14 16:32:15 +00:00
rink1969
d9dd008e44 casting integer literal to float is unnecessary 2019-03-14 15:53:08 +08:00
Philipp Hansch
5e4a7eb1fc
UI test cleanup: Extract manual_memcpy tests 2019-03-14 07:26:47 +01:00
Philipp Hansch
67aad6c180
Run rustfix for string_lit_as_bytes tests
This moves the `string_lit_as_bytes` tests into a new file and enables
rustfix tests for them.
2019-03-14 06:59:30 +01:00
bors
8fc0a738e3 Auto merge of #3869 - taiki-e:use_self, r=flip1995
Fix `use_self` false positive on nested functions

Related to https://github.com/rust-lang/rust-clippy/pull/3640

The current `use_self` warns the following code.

```rust
#![warn(clippy::use_self)]
struct Foo {}
impl Foo {
    fn bar() {
        fn baz() -> Foo { //^ warning: unnecessary structure name repetition
            Foo {} //^ warning: unnecessary structure name repetition
         }
    }
}
```
2019-03-12 12:09:56 +00:00
bors
3d31c2157a Auto merge of #3794 - mikerite:fix-3739, r=phansch
Fix `boxed_local` suggestion

Don't warn about an argument that is moved into a closure.

ExprUseVisitor doesn't walk into nested bodies so use a new
visitor that collects the variables that are moved into closures.

Fixes #3739
2019-03-12 07:43:14 +00:00
bors
75bfa29533 Auto merge of #3871 - taiki-e:needless_continue, r=phansch
Fix `needless_continue` false positive

If the `continue` has a label, check it matches the label of the loop.

Fixes https://github.com/rust-lang/rust-clippy/issues/2329
2019-03-12 07:04:44 +00:00
Michael Wright
6937d5581a Merge branch 'master' into fix-3739 2019-03-12 08:13:44 +02:00
Taiki Endo
1bc7da2fec Fix needless_continue false positive 2019-03-12 03:40:30 +09:00
Taiki Endo
187ce4c5ab Fix use_self false positive on nested functions 2019-03-11 23:24:49 +09:00
Taiki Endo
4896b259eb Filter out proc_macro and proc_macro_attribute 2019-03-11 20:45:57 +09:00
flip1995
44c46d2059
Run rustfmt 2019-03-10 22:12:26 +01:00
flip1995
3282955238
Update tests 2019-03-10 22:07:10 +01:00
Alexander Regueiro
a7c0800938 Reblessed test outputs. 2019-03-10 18:13:15 +00:00
Alexander Regueiro
d2b85323ad Addressed points raised in review. 2019-03-10 18:06:28 +00:00
Alexander Regueiro
d43966a176 Various cosmetic improvements. 2019-03-10 18:06:28 +00:00
Manish Goregaokar
038ec7f5d8 Move get_unwrap to restriction
fixes #3862
2019-03-09 13:48:06 -08:00
rchaser53
ae787d954e fix missing a semicolon 2019-03-07 23:26:47 +09:00
Michael Wright
7b948232ba Enable rustfix on unused_unit tests 2019-03-07 08:26:53 +02:00
Michael Wright
fbcf7eefb9 Add [rustfmt::skip] to unused_unit test 2019-03-07 08:13:59 +02:00
Michael Wright
131c8f6bf2 Add [rustfmt::skip] to doc_markdown tests 2019-03-07 08:03:15 +02:00
Félix Fischer
ddc718087f Renamed: Cyclomatic Complexity -> Cognitive Complexity
* Ran automatic naming update

* Formalized rename of `cyclomatic_complexity` to `cognitive_complexity`
** Added the rename to `lib.rs`
** Added rename test

* Added warning for deprecated key `cyclomatic_complexity_threshold` and tests for it

* Added deprecation status for Clippy's builtin attribute

* Updated tests for new builtin attribute renaming
2019-03-06 10:07:38 -03:00
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
Michael Wright
9d6ecc7485 Fix boxed_local suggestion
Don't warn about an argument that is moved into a closure.

ExprUseVisitor doesn't walk into nested bodies so use a new
visitor that collects the variables that are moved into closures.

Fixes #3739
2019-02-21 06:59:10 +02: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
Philipp Hansch
8abdfb6567
UI test cleanup: Rename copies.rs to match_same_arms.rs 2019-02-10 10:20:28 +01:00
Philipp Hansch
83a87fb7b6
UI test cleanup: Extract match_same_arms tests 2019-02-10 10:19:24 +01:00
Philipp Hansch
9dbabffe60
UI test cleanup: Extract similar_names tests 2019-02-10 09:48:31 +01: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
Philipp Hansch
a586f52a0f
Move run-pass tests to UI tests
This should give us more UI coverage for free.
It also removes the `run-pass` suite, so we now only have the `ui` suite.
2019-02-06 08:17:39 +01:00
flip1995
cb2d987ed4
Add tests for assertion_on_constants macro check 2019-02-05 19:37:54 +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
rhysd
4b736ff29b Merge branch 'master' into issue3721 2019-02-03 21:27:23 +09:00
rhysd
3100fecb99 use snippet for making a suggestion if possible 2019-02-03 18:28:42 +09: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
Unknown
21e2b13125 Fix test broken by removing comment. 2019-02-01 13:21:19 -05:00
Unknown
ae3bcb770e Updating to just warn for one test. 2019-02-01 13:21:19 -05:00
Unknown
057037a6b9 Adding back tests, but also reducing threshold by 1 2019-02-01 13:21:19 -05:00
Unknown
65f62d0497 Moving tests to ui-toml to make use of clippy.toml 2019-02-01 13:21:19 -05:00
Unknown
be514a4336 Updating number of lines for the failing test to be > 100.
Due to updating the configuration to be 101 instead of 51
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
02456208b4 Fix test broken by removing comment. 2019-02-01 13:21:19 -05:00
Unknown
50c82e0270 Updating to just warn for one test. 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
3a97b5fa20 Moving tests to ui-toml to make use of clippy.toml 2019-02-01 13:21:19 -05:00
Unknown
6b86c3b1e7 Updating number of lines for the failing test to be > 100.
Due to updating the configuration to be 101 instead of 51
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
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
Michael Wright
488cdebd26 Merge branch 'master' into fix-2728 2019-02-01 06:27:36 +02:00
rhysd
7ec5528e0c fix category and use suggestion 2019-02-01 09:31:26 +09:00
Philipp Hansch
ec261a28f0
Rustup: unused trim result 2019-01-31 08:27:04 +01:00
Michael Wright
3cf8c0b3b5 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-01-31 06:32:29 +02:00
rhysd
f894adce8c implement dbg_macro rule (fixes #3721) 2019-01-31 02:39:38 +09:00
Alex Hamilton
efaed8e0c0 wildcard_match_arm: lint only enum matches. 2019-01-29 15:33:04 -06:00
Alex Hamilton
c676578097 wildcard_match_arm: update ui test stderr 2019-01-29 15:33:04 -06:00
Alex Hamilton
c7ae44c0e2 wildcard_match_arm: format test. 2019-01-29 15:33:04 -06:00
Alex Hamilton
068924198b wildcard_match_arm: add simple ui test. 2019-01-29 15:33:04 -06:00
bors
6b1a2a9c3e Auto merge of #3648 - phansch:const_fn_lint, r=oli-obk
Add initial version of const_fn lint

This adds an initial version of a lint that can tell if a function could be `const`.

TODO:

- [x] Finish up the docs
- [x] Fix the ICE

cc #2440
2019-01-29 19:58:13 +00:00
Philipp Hansch
aed001b8d4
Update various docs
* `const_transmute` currently also seems to depend on the `const_fn`
  feature.
* Only `Sized` is currently allowed as a bound, not Copy.
2019-01-29 08:19:05 +01:00
Philipp Hansch
0c6bdda562
Use built-in entry_fn detection over self-built 2019-01-29 08:19:05 +01:00
Philipp Hansch
c0a02691d8
cargo fmt 2019-01-29 08:19:05 +01:00
Philipp Hansch
f9d65b6356
Reorganize conditionals: Run faster checks first 2019-01-29 08:19:05 +01:00
Philipp Hansch
c3980bf0bc
Add initial version of const_fn lint 2019-01-29 08:19:05 +01:00
Michael Wright
df04238d3a Fix unit_arg false positive
Ignore arguments with the question mark operator.

Closes #2945
2019-01-29 07:22:08 +02:00
bors
410d5ba6c3 Auto merge of #3700 - phansch:would_you_like_some_help_with_this_const_fn, r=oli-obk
Prevent incorrect cast_lossless suggestion in const_fn

`::from` is not a const fn, so applying the suggestion of
`cast_lossless` would fail to compile. The fix is to skip the lint if
the cast is found inside a const fn.

Fixes #3656
2019-01-28 14:30:18 +00:00
Oliver Scherer
8a417204f8 Remove tests for deprecated items 2019-01-28 10:17:04 +01:00
Oliver Scherer
dc8c7b1677 Atomics constants are now handled by the deprecation lint 2019-01-28 10:10:27 +01:00
Matthias Krüger
16c0a2fa6f update test stderr 2019-01-27 13:46:22 +01:00
Matthias Krüger
e9e0a7e3bd rustup https://github.com/rust-lang/rust/pull/57726 2019-01-27 01:42:34 +01:00
Philipp Hansch
8c416c3197
Prevent incorrect cast_lossless suggestion in const_fn
`::from` is not a const fn, so applying the suggestion of
`cast_lossless` would fail to compile. The fix is to skip the lint if
the cast is found inside a const fn.
2019-01-26 10:57:15 +01:00
Michael Wright
5284b95a06 Fix expect_fun_call lint suggestions
This commit corrects some bad suggestions produced by the
`expect_fun_call` lint and enables `rust-fix` checking on the tests.

Addresses #3630
2019-01-24 06:58:53 +02:00
A.A.Abroskin
c771f339d7 allow assertions_on_constants for collapsible_if and missing_test_files 2019-01-23 17:58:33 +03:00
A.A.Abroskin
f11d993c0f Merge branch 'master' into add-lints-aseert-checks
* master: (58 commits)
  Rustfmt all the things
  Don't make decisions on values that don't represent the decision
  Improving comments.
  Rustup
  Added rustfix to the test.
  Improve span shortening.
  Added "make_return" and "blockify" convenience methods in Sugg and used them in "needless_bool".
  Actually check for constants.
  Fixed potential mistakes with nesting. Added tests.
  formatting fix
  Update clippy_lints/src/needless_bool.rs
  formatting fix
  Fixing typo in CONTRIBUTING.md
  Fix breakage due to rust-lang/rust#57651
  needless bool lint suggestion is wrapped in brackets if it is an "else" clause of an "if-else" statement
  Fix automatic suggestion on `use_self`.
  Remove negative integer literal checks.
  Fix `implicit_return` false positives.
  Run rustfmt
  Fixed breakage due to rust-lang/rust#57489
  ...
2019-01-23 11:36:12 +03:00
bors
a40d8e4479 Auto merge of #3679 - daxpedda:use_self, r=phansch
Fix automatic suggestion on `use_self`.

In an example like this:
```rust
impl Example {
    fn fun_1() { }
    fn fun_2() {
        Example::fun_1();
    }
}
```
Clippy tries to replace `Example::fun_1` with `Self`, loosing `::fun_1` in the process, it should rather try to replace `Example` with `Self`.

**Question**
- There may be other paths that need the same treatment, but I'm not sure I understand them fully:
  - e648adf086/clippy_lints/src/use_self.rs (L94-L96)
  - e648adf086/clippy_lints/src/use_self.rs (L225-L229)
2019-01-22 19:18:39 +00:00
daxpedda
e6f2239bc3
Added rustfix to the test. 2019-01-22 15:16:54 +01:00
bors
9d5b148648 Auto merge of #3677 - daxpedda:integer_arithmetic, r=oli-obk
Remove negative integer literal checks.

Fixes #3678.
2019-01-21 15:07:22 +00:00
daxpedda
87d24e1fc9
Actually check for constants. 2019-01-21 13:59:49 +01:00
bors
e0bcec717a Auto merge of #3676 - daxpedda:implicit_return, r=oli-obk
Fix `implicit_return` false positives.

Fixes the following false positives:
- linting on `if let` without `else` in a `loop` even with a present `return`
- linting on `unreachable!()`
2019-01-21 12:25:45 +00:00
daxpedda
2e0977f3b4
Fixed potential mistakes with nesting. Added tests. 2019-01-21 13:06:32 +01:00
bors
54978a571c Auto merge of #3680 - g-bartoszek:needless-bool-else-if-brackets, r=oli-obk
needless bool lint suggestion is wrapped in brackets if it is an "els…

…e" clause of an "if-else" statement
2019-01-21 11:47:06 +00:00
Grzegorz Bartoszek
adce3ef966 needless bool lint suggestion is wrapped in brackets if it is an "else" clause of an "if-else" statement 2019-01-20 16:15:00 +01:00
daxpedda
13b5ea4223
Fix automatic suggestion on use_self. 2019-01-20 14:50:26 +01:00
daxpedda
0555ca1c2d
Remove negative integer literal checks. 2019-01-20 14:18:31 +01:00
daxpedda
2183cfcc13
Fix implicit_return false positives. 2019-01-20 13:45:22 +01:00
Michael Wright
f51f0178dd Fixed breakage due to rust-lang/rust#57489 2019-01-20 12:21:30 +02:00