Commit graph

1451 commits

Author SHA1 Message Date
Oliver Schneider
90fcdafb79
Merge pull request #2608 from mrecachinas/feature/print-string-literal
Check for literals as println! args
2018-04-02 23:34:17 +02:00
Michael Recachinas
fa8161ba2e Revert adding env! to tests 2018-04-02 21:34:04 +01:00
Michael Recachinas
d504290839 Add edge case with env! arg to test and known problems 2018-04-02 21:14:29 +01:00
Michael Wright
0fbcb30303 Merge branch 'master' into dogfood_target_dir 2018-04-02 07:28:10 +02:00
Michael Recachinas
ddd75fbfec Add #![allow(print_literal)] to other test/ui/print_*.rs tests 2018-04-02 00:24:40 +01:00
Michael Recachinas
62220abfa6 Add implementation and tests for literal checking in print/println format args 2018-04-01 23:19:53 +01:00
Michael Wright
1ab96db791 Make dogfood test output to seperate directory
This commit makes `cargo clippy` output the build artifacts to a
separate directory if the `CLIPPY_DOGFOOD` env var is set. This should
prevent dogfood builds from interfering with regular builds.

This should help with issue #2595.
2018-04-01 09:44:30 +02:00
Philipp Hansch
db1ec44616
Handle nested block comments 2018-03-30 12:36:50 +02:00
Philipp Hansch
b7929cafe1
Fix false positive in empty_line_after_outer_attr
Before, when you had a block comment between an attribute and the
following item like this:

```rust
\#[crate_type = "lib"]
/*

*/
pub struct Rust;
```

It would cause a false positive on the lint, because there is an empty
line inside the block comment.

This makes sure that basic block comments are detected and removed from
the snippet that was created before.
2018-03-30 12:36:50 +02:00
Oliver Schneider
c1bbc173da
Address review comments 2018-03-29 13:41:53 +02:00
Oliver Schneider
eafb9fe8df
Update test suite 2018-03-28 23:49:32 +02:00
Oliver Schneider
d6344c47e3
Categorize all the lints! 2018-03-28 15:24:26 +02:00
Oliver Schneider
b6e2c47df0
Merge pull request #2572 from flip1995/immut_while
Fix check of immutable condition in closure
2018-03-27 07:07:27 +02:00
Michael Wright
546d2fec29 Fix enum_glob_use false positives
Closes #2397.

This checks the def of the `ItemUse` path instead of checking the
capitalization of the path segements. It was noted that this def would
sometimes be `Def::Mod` instead of `Def::Enum` but it seems correct now.
2018-03-27 06:34:11 +02:00
flip1995
7d29075132
Skip the mutation in while body case for closures 2018-03-27 02:13:06 +02:00
flip1995
d458f22d89
Fix check of immutable condition in closure 2018-03-27 01:21:25 +02:00
Oliver Schneider
b01b0083ba
Merge pull request #2576 from kimsnj/infinite_loop
while_immutable_condition: fix handling of self
2018-03-27 00:06:16 +02:00
Karim Snj
737247e50e while_immutable_condition: limit suggestion span to condition 2018-03-26 23:24:57 +02:00
Karim Snj
85bcaad412 while_immutable_condition: fix handling of self 2018-03-26 23:16:54 +02:00
Philipp Hansch
034c81b761
Fix false positive in empty_line_after_outer_attribute
`empty_line_after_outer_attribute` produced a false positive warning when
deriving `Copy` and/or `Clone` for an item.

It looks like the second point in [this comment][that_comment] is related,
as the attribute that causes the false positive has a path of
`rustc_copy_clone_marker`.

Fixes #2475

[that_comment]: https://github.com/rust-lang/rust/issues/35900#issuecomment-245978831
2018-03-26 21:57:42 +02:00
Oliver Schneider
1aaeb3f16b
Update needless_lifetimes_impl_trait.rs 2018-03-26 07:05:46 +02:00
Oliver Schneider
9fb63d5fc4
Merge pull request #2574 from mark-i-m/i128
i128 is stabilizing
2018-03-26 07:04:42 +02:00
Mark Mansi
e9f6a7c72f whitespace 2018-03-25 21:26:10 -05:00
Mark Mansi
e2d7ef9972 attempt fix stderr 2018-03-25 21:17:38 -05:00
Mark Mansi
f25d4fd253 make it pass for now 2018-03-25 21:04:05 -05:00
Mark Mansi
748ad9fb4b i128 is stable 2018-03-25 20:34:44 -05:00
Michael Wright
2b68f00722 Add tests to ensure that issue #2420 is resolved
The issue was probably fixed by ff32d5f7. Closes #2420.
2018-03-23 20:26:52 +02:00
Oliver Schneider
2d01f42dde
Merge pull request #2539 from Baelyk/master
Add suggestion to useless_format
2018-03-20 08:22:04 +01:00
Baelyk
48027105dc Add suggestion to useless_format
Resolves #2505

Suggests that you use `"foo".to_string()` instead of `format!("foo")`.
2018-03-19 09:27:15 -05:00
flip1995
ad459184a3 Don't lint comparison operators in arithmetic impls 2018-03-17 22:02:34 +01:00
Mateusz Mikuła
23bfa396a0 Format code
Signed-off-by: Mateusz Mikuła <mati865@gmail.com>
2018-03-16 10:54:49 +01:00
Oliver Schneider
8749927973
Rustup 2018-03-16 09:44:20 +01:00
Mateusz Mikuła
3662ee76ab Merge branch 'miri' 2018-03-15 10:49:13 +01:00
Mateusz Mikuła
ca785afc31 Update tests
Signed-off-by: Mateusz Mikuła <mati865@gmail.com>
2018-03-15 10:25:57 +01:00
Oliver Schneider
21f387d278
Update dependencies 2018-03-13 16:54:13 +01:00
Oliver Schneider
f7b2578aea
Update to rustc master 2018-03-13 11:38:21 +01:00
Hidehito Yabuuchi
ed769a3bc4 Ignore all macros in redundant_field_names 2018-03-11 13:57:28 +09:00
Karim Snj
ae5354e6ef lint: while immutable condition: do not lint constants 2018-03-07 18:25:09 +01:00
Oliver Schneider
4cf02c7e1a
Merge pull request #2483 from kimsnj/infinite_loop
immutable while condition
2018-03-07 08:09:48 +01:00
Karim Snj
814827113e lint: immutable condition: add internally mutable test 2018-03-06 18:27:11 +01:00
Oliver Schneider
7d5ecd5ad5
Merge pull request #2511 from flip1995/sus_impl
UnNeg and UnNot count as additional operations now
2018-03-06 14:35:54 +01:00
Niklas Fiekas
d55890a2b1 Increase unreadable_literal digits (fixes #1958) 2018-03-06 14:24:01 +01:00
flip1995
ed4535641b
UnNeg and UnNot count as additional operations now 2018-03-06 13:58:03 +01:00
Oliver Schneider
05f92b84c9
Merge pull request #2507 from ordovicia/redundant_field_names_range
Don't lint range syntax with var name `start` and/or `end`
2018-03-05 09:41:00 +01:00
Oliver Schneider
40ebff8c7a
Merge pull request #2493 from bootandy/fix_cow
Lint passing Cow by reference
2018-03-05 09:35:11 +01:00
Hidehito Yabuuchi
cdb60c6547 Make redundant_field_name not care range expressions
Hand-written `Range` struct family are treated normally.
2018-03-05 17:30:07 +09:00
Oliver Schneider
598acba7d5
Merge pull request #2497 from waywardmonkeys/single-char-pattern
Fix single_char_pattern for \n, \t, etc.
2018-03-05 08:43:17 +01:00
Oliver Schneider
6662aa41f9
Merge branch 'master' into fix_cow 2018-03-05 08:42:19 +01:00
Oliver Schneider
f071d1994f
Merge pull request #2504 from flip1995/lit_float_repr
Fix unreadable_literal lint for scientific float notation
2018-03-05 08:38:32 +01:00
Oliver Schneider
5b48b03375
Typo 2018-03-05 08:33:37 +01:00
Hidehito Yabuuchi
7b59557dcd Don't lint range syntax with var name start and end 2018-03-05 14:31:37 +09:00
HMPerson1
3045f432c7
Fix #2496 2018-03-04 22:56:03 -05:00
flip1995
86ce897084
Fix unreadable_literal lint for scientific float notation 2018-03-04 16:28:34 +01:00
bootandy
e3c13da830 Change recomendation to: &[type] from Cow<type> 2018-03-03 12:25:20 -05:00
Alex Butler
fc5b377cec Fix #2494 add suggestion for unreadable_literal
Add `rustc --explain E0308` line to relevant tests
2018-03-03 12:25:20 -05:00
Bruce Mitchener
769a1d9b6c Fix single_char_pattern for \n, \t, etc.
Single characters that are escaped weren't being searched / replaced
correctly in the hint string, so it was saying to replace, say,
`"\n"` with `"\n"` rather than `'\n'`.
2018-03-02 22:00:01 +07:00
Karim Snj
7d35fab304 lint: while loop: detect if no var from the condition is mutated 2018-03-02 00:01:08 +01:00
Karim Snj
37eca59438 lint: while immutable condition: refactor to use hir::Visitor 2018-03-01 22:00:43 +01:00
Alex Butler
42000c6cf9
Fix #2494 add suggestion for unreadable_literal
Add `rustc --explain E0308` line to relevant tests
2018-03-01 15:26:39 +00:00
bootandy
9a002e52e5 Lint passing Cow by reference
Add lint for reference to Cow to the same place in the code where
lint for reference to String lives.

https://github.com/rust-lang-nursery/rust-clippy/issues/2405
2018-02-28 10:24:10 -05:00
Karim Snj
5c1be4a4ba lint: immutable only vars in while condition 2018-02-25 18:25:31 +01:00
Guillem Nieto
8494f57c82 Fix author lint
The author lint was generating invalid code as shown on issue:
https://github.com/rust-lang-nursery/rust-clippy/issues/2442

I've changed the generated code to properly track cast
expressions.

Unfortunatelly, I've had to rewrite the `visit_decl` method, to
avoid that last if of the chain will be added. After looking at the code,
this last line was being added because of the `let x: char` part, but not
because of the `0x45df as char` expression.

It seems that let statements should not generate code on the author
lint, but I'm not sure that this is true or if I'm breaking
something on other code generation parts.

Finally, I've added a test for the author lint, but I'm not sure that
this needs to be added to the testsuite.
2018-02-24 02:19:47 +01:00
Oliver Schneider
575c3c4b54
Merge pull request #2471 from bootandy/fix_span2
Fix: point to correct problem part of code, update test
2018-02-23 08:31:57 +01:00
Oliver Schneider
5e6342d4ae
Merge pull request #2473 from phansch/handle_multiline_attributes
Lint multiline attributes properly
2018-02-21 21:44:04 +01:00
Philipp Hansch
d3d3d7d7be
Lint multiline attributes properly
This makes it so that the `empty_line_after_outer_attribute` lint only
checks for newlines between the end of the attribute and the beginning
of the following item.

We need to check for the empty line count being bigger than 2 because
now the snippet of valid code contains only `\n` and splitting it
produces `["", ""]`
Invalid code will contain more than 2 empty strings.
2018-02-21 21:29:05 +01:00
bootandy
a7c97256dc Stop unwanted newlines being applied on unwrap_or 2018-02-21 11:29:08 -05:00
bootandy
f3d1a0cec2 Add newlines in unwrap_or ui test 2018-02-20 12:37:30 -05:00
bootandy
941e062fd4 Fix: point to correct problem part of code
Fix span so it no longer contains the whole train-wreck of code and only
points to the problem function (for the unwrap_or lint).

https://github.com/rust-lang-nursery/rust-clippy/issues/2422

Update ui test methods - it had several cases where the error message
span is now shorter
2018-02-19 12:14:53 -05:00
Philipp Krones
c43e053f3f
Merge branch 'master' into suspicious_impl 2018-02-19 13:04:14 +01:00
flip1995
aa20277a17 Lint for suspicious implementations of arithmetic std::ops traits 2018-02-13 15:40:17 +01:00
TomasKralCZ
42120141bd Suggestion fixed, simplified lint logic. 2018-02-12 11:26:00 +01:00
TomasKralCZ
85642ddd23 Implement redundant field names lint #2244 2018-02-10 22:52:31 +01:00
Oliver Schneider
6feb0dd982
Fixes #2426 (if_same_then_else false positive) 2018-02-09 15:31:55 +01:00
Oliver Schneider
ff32d5f734
Fix #2427 2018-02-09 15:25:12 +01:00
Jonathan Goodman
44780aca5d make the copies.rs test actually test the correct lints 2018-02-08 13:26:50 -06:00
Oliver Schneider
6f48e37d22
Merge pull request #2444 from phansch/fix_incorrect_useless_attribute_suggestion
Partly fix incorrect useless_attribute suggestion
2018-02-07 09:07:46 +01:00
Philipp Hansch
81f5969704
Partly fix incorrect useless_attribute suggestion
This fixes an incorrect suggestion from the `useless_attribute` lint
when using `cfg_attr`.

Additionally, it will not show a suggestion anymore, if the attribute
begins on a previous line, because it is much harder to construct the
span of multi-line `cfg_attr` attributes as they don't appear in the AST.

To fix it completely, one would have to parse upwards into the file,
and find the beginning of the `cfg_attr` attribute.
2018-02-06 22:35:11 +01:00
Jonathan Goodman
73f2ba5ded don't suggest eliding 'static on associated consts 2018-02-06 12:22:34 -06:00
flip1995
63a7daf78c Make decimal_literal_representation a restriction lint 2018-02-06 13:05:20 +01:00
Guillem Nieto
bcf2e41421 Fix ICE comparing ExprRange
`eq_expr` on hir::utils was throwing an ICE due to an invalid
LateContext being used. Due to this missusage, it was generating an ICE
with the code on the following issue:
https://github.com/rust-lang-nursery/rust-clippy/issues/2423
2018-02-06 01:06:32 +01:00
Oliver Schneider
30a37efaac
Merge pull request #2433 from kimsnj/matches_sugg
Fix suggestions for ref matches
2018-02-05 08:21:21 +01:00
Oliver Schneider
7fddc6116e
Merge pull request #2415 from HMPerson1/fix-2356
Fix `ImplItem`s being ignored
2018-02-05 08:19:11 +01:00
Oliver Schneider
bef22006b4
Merge pull request #2419 from phansch/fix_doc_comment_false_positive
Fix false positive in empty_line_after_outer_attr
2018-02-05 08:17:29 +01:00
Karim Snj
21f606bd68 Removing extra newline 2018-02-04 13:55:37 +01:00
Karim Snj
9575dac491 Fix suggestions for ref matches 2018-02-04 13:41:54 +01:00
HMPerson1
10d2feddba
Fix const_static_lifetime 2018-02-02 02:03:21 -05:00
HMPerson1
ff83b3ecb9
Fix non_expressive_names 2018-02-02 01:54:07 -05:00
HMPerson1
3a4ea45821
Fix get_enclosing_block 2018-02-02 01:53:48 -05:00
Oliver Schneider
d5bac82837
Give travis a guaranteed existing directory for ui test output 2018-02-01 14:35:56 +01:00
Philipp Hansch
a64724fac4
Fix false positive in empty_line_after_outer_attr
Doc comments are syntactic sugar for #[doc] attributes, so this lint was
catching them, too.

This commit makes it so that doc comments are ignored in this lint.

I think, for normal attributes it makes sense to warn about following empty
lines, for doc comments, less. This way the user has some freedom over
the formatting.
2018-02-01 07:43:03 +01:00
Guillem Nieto
05ed421930 Update UI tests 2018-01-31 00:10:35 +01:00
Guillem Nieto
74ae9b15b5 Add question mark operator 2018-01-31 00:10:35 +01:00
flip1995
bd421cb5a5 Additionally suggest the semantic equal variant 2018-01-30 17:45:35 +01:00
flip1995
b7cb0752ff Improved suggestion on misrefactored_assign_op lint. Fixes #1239 2018-01-30 14:58:38 +01:00
Oliver Schneider
39d1d6081f
Merge pull request #2340 from phansch/newline_after_attributes
Warn on empty lines after outer attributes
2018-01-30 13:09:23 +01:00
Seiichi Uchida
a3c2323767 Add double comparions lint 2018-01-30 10:35:35 +09:00
Tim Nielens
0778ac81c8 #1121: already fixed, adding a test 2018-01-29 16:52:22 +01:00
Philipp Hansch
aade0d563e
Make lint work on all members of ast::Item_ 2018-01-29 10:03:52 +01:00
Philipp Hansch
83909398d2
Add test case for comments between item and attr 2018-01-29 10:03:52 +01:00
Philipp Hansch
80827c1f74
Warn on empty lines after outer attributes 2018-01-29 10:03:52 +01:00
Manish Goregaokar
4b9a0b8644 Update spans 2018-01-29 09:48:11 +05:30
Manish Goregaokar
bca80a83a5 mut_mut_macro is missing plugin(clippy) 2018-01-29 09:48:06 +05:30
Devon Hollowood
0413b3f6cf Add misaligned_transmute lint 2018-01-25 00:48:36 -08:00
Oliver Schneider
ea042657e5
Enable more patterns in the author lint 2018-01-24 13:04:06 +01:00
flip1995
31892e205e let invalid_regex point to the right place for raw strings 2018-01-23 16:52:14 +01:00
Oliver Schneider
8e7f76db9a
Merge pull request #2362 from flip1995/master
Lint for numeric literals that have a better representation
2018-01-23 15:54:35 +01:00
flip1995
600147926b Apply requested changes 2018-01-23 15:29:31 +01:00
flip1995
d7677fb2b6 Adapt to updated ui tests 2018-01-23 12:52:20 +01:00
flip1995
23f90afa1b Add configurable threshold, default: 4096 2018-01-23 12:34:40 +01:00
Phil Ellison
2132e5c58c Fix unnecessary_fold bug 2018-01-22 05:34:42 +00:00
Oliver Schneider
e6428873cb
Merge pull request #2350 from theotherphil/fold_any
Lint for using hand-writing a fold with the same behaviour as any
2018-01-19 13:31:00 +01:00
Oliver Schneider
71abd81d22 Update error count 2018-01-19 13:18:44 +01:00
Oliver Schneider
920fc17485 Don't run dogfood on windows or in the rustc test suite 2018-01-19 13:14:43 +01:00
Oliver Schneider
70302595a4
Merge branch 'master' of github.com:Manishearth/rust-clippy into fold_any 2018-01-19 12:10:24 +01:00
Oliver Schneider
9a2c50f3d6
Merge pull request #2364 from flip1995/precedence
Add macro check to precedence lint
2018-01-19 12:07:00 +01:00
Oliver Schneider
3c6064130b
Merge pull request #2367 from etaoins/inline-fn-without-body-lint
Lint for trait methods without bodies
2018-01-19 09:14:46 +01:00
Oliver Schneider
26c415ab2d
Merge pull request #2381 from HMPerson1/remove_is_unit_expr
Replace `is_unit_expr`
2018-01-19 09:14:04 +01:00
Michael Wright
79c6c60f51 Added further tests 2018-01-19 08:10:09 +02:00
Michael Wright
fca248957b Merge branch 'master' into option_option_pr 2018-01-19 07:56:46 +02:00
HMPerson1
8081f6fd6e
Replace is_unit_expr 2018-01-18 17:04:26 -05:00
Oliver Schneider
10c96e50c3
Don't run dogfood tests in the rustc test suite 2018-01-18 22:02:58 +01:00
Oliver Schneider
8217e33718
Only suggest implementing Copy if it can actually be done 2018-01-18 14:27:47 +01:00
Ryan Cumming
7467b83377 Suggest removing inline attributes
This adds a `suggest_remove_item` helper that will remove an item and
all trailing whitespace. This should handle both attributes on the same
line as the function and on a separate line; the function takes the
position of the original attribute.
2018-01-18 20:02:42 +11:00
Ryan Cumming
5f3c340bfb Lint for trait methods without bodies
As discussed in rust-lang/rust#47475 the #[inline] attribute is
currently allowed on trait methods without bodies (i.e. without a
default implementation). This is misleading as it could be interpreted
as affecting the implementations of the trait method. Add a lint for any
use of #[inline] on a trait method without a body.

Fixes rust-lang/rust#47475
2018-01-18 20:01:24 +11:00
Manish Goregaokar
552e950080 needless_pass_by_value: Whitelist RangeArgument (fixes #2357) 2018-01-18 14:30:53 +05:30
Manish Goregaokar
2a30c8a194 needless_pass_by_value: Add suggestion for implementing Copy (fixes #2222) 2018-01-18 14:30:47 +05:30
Manish Goregaokar
cf1fbaa36a needless_pass_by_value: Ignore for extern funcs (fixes #1844) 2018-01-18 14:30:32 +05:30
Michael Wright
d13af87d8a Fixed tests 2018-01-18 07:48:03 +02:00
Michael Wright
ec60baa864 Merge branch 'master' into option_option_pr 2018-01-18 07:21:48 +02:00
Phil Ellison
b73efad600 Add some reviewer comments 2018-01-17 21:06:16 +00:00
Phil Ellison
29a2dd4cb8 Fix bug. Don't expect lint when acc is on rhs 2018-01-17 20:11:40 +00:00
Phil Ellison
1cac693bc7 Lint on folds implementing .all, .sum and .product 2018-01-17 19:12:44 +00:00
Oliver Schneider
4f21b5b112
Update changed ui tests 2018-01-17 14:44:40 +01:00
Oliver Schneider
a2fdfc05d7
Merge pull request #2298 from goodmanjonathan/else_if_without_else
add new lint else_if_without_else
2018-01-17 09:35:58 +01:00
Michael Wright
e7567f2eac Made requested changes 2018-01-17 07:24:33 +02:00
Michael Wright
21fde9a9d1 Merge branch 'master' into option_option_pr 2018-01-17 06:52:00 +02:00
Phil Ellison
a64d19cc0e Fix error span to play nicely with rustfix 2018-01-16 21:20:55 +00:00
Manish Goregaokar
37f62a54f8 Show wider and more accurate suggestion for const_static_lifetime
fixes #2365
2018-01-16 20:46:44 +05:30
flip1995
877321ba32 Add macro check to precedence lint 2018-01-16 15:52:16 +01:00
flip1995
647da97622 Lint for numeric literals that have a better representation in another format 2018-01-16 14:01:07 +01:00
Oliver Schneider
61e2b7a4d6
Merge pull request #2355 from alusch/clone_on_ref_ptr_restriction
Fix #2048: Move `clone_on_ref_ptr` to the restriction lints
2018-01-16 10:40:12 +01:00
Oliver Schneider
28c3d0321a Update changed test output from rustc 2018-01-16 08:52:14 +01:00
Jonathan Goodman
40c6f431da add new lint else_if_without_else 2018-01-14 22:53:00 -06:00
Adam Lusch
f343cd22f6 Adds the missing turbofish 2018-01-14 20:19:55 -08:00
Adam Lusch
30de2e7106 Update UI test expected output 2018-01-14 20:10:36 -08:00
Adam Lusch
1615813960 Moves clone_on_ref_ptr to be a restriction lint
Also updates the suggestion to include the full type (e.g. `Arc<Foo>::clone(&rc)`)
and adds a case using trait objects to the UI tests.
2018-01-14 19:58:09 -08:00
Phil Ellison
ad164939ed Check that we're calling Iterator::fold 2018-01-14 20:04:34 +00:00
Phil Ellison
70a5535ffa Address some review comments 2018-01-14 18:18:09 +00:00
Oliver Schneider
2f62d803ab
Merge pull request #2349 from rust-lang-nursery/no-main-doc
Don't warn about missing docs for main()
2018-01-14 13:16:54 +01:00
Phil Ellison
1feb9fd550 Tidy using if_chain and snippet function. Actually check that the initial fold value is false. Remove some unwraps 2018-01-14 09:30:08 +00:00