Commit graph

5118 commits

Author SHA1 Message Date
flip1995
0e5aee1fc1
items_after_statements: don't lint when they a separated by trailing semicolons 2020-11-28 17:18:15 +01:00
flip1995
c1b991588f
Fix weird dogfood error 2020-11-28 17:03:20 +01:00
bors
7a73a25622 Auto merge of #6086 - Ryan1729:add-suspicious_chained_operators-lint, r=llogiq
Add suspicious_operation_groupings lint

This is my (<del> currently WIP </del>) attempt to close #6039.

changelog: Added `suspicious_operation_groupings` lint.
2020-11-28 08:17:25 +00:00
bors
a644930b25 Auto merge of #6360 - mlegner:mod_one, r=llogiq
Trigger modulo_one lint also on -1.

Fixes #6321.

changelog: trigger `modulo_one` lint also on `-1`
2020-11-28 07:07:25 +00:00
Ryan1729
af1cc5c911 add suspicious_operation_groupings lint
run `cargo dev new_lint --category correctness --name suspicious_chained_operators --pass early`

add (currently failing) tests for suspicious_chained_operators
add some tests to answer a question that came up during implementation

write usage code for functions we'll need to find or create

Complete left-right tracking TODO

get it compiling with several `todo!` invocations.

refactor to a set of incomplete functions that don't expect to be able to edit a `Span`

create placeholder for `suggestion_with_swapped_ident` function and correct some comments

add `inside_larger_boolean_expression` test

fill out `get_ident` and `suggestion_with_swapped_ident`

Implementi the `IdentIter`

start on implementing the `IdentIter`
handle the `ExprKind::Path` case in `IdentIter`

on second thought, make the iterator type dynamic so we don't need an explicit type for each one we will need

handle `ExprKind::MacCall` in `IdentIter`

Try handling `box x` expressions

restructure `IdentIter`

set `self.done` when returning `None`

Handle `ExprKind::Array`

reduce duplication with a macro that we expect to use several more times

handle ExprKind::Call

add `new_p` convenience method

handle `MethodCall`

handle `Tup` and `Binary`

handle `Unary`

simplify by not returning an additional `Expr` from the `IdentIter`

add cross product test against false positives

rename suspicious_chained_operators to suspicious_operation_groupings within files

For the record, the exact commands run were:
find . -type f -name "*.md" -exec sed -i 's/suspicious_chained_operators/suspicious_operation_groupings/g' {} +

find . -type f -name "*.rs" -exec sed -i 's/suspicious_chained_operators/suspicious_operation_groupings/g' {} +

find . -type f -name "*.rs" -exec sed -i 's/SUSPICIOUS_CHAINED_OPERATORS/SUSPICIOUS_OPERATION_GROUPINGS/g' {} +

find . -type f -name "*.rs" -exec sed -i 's/SuspiciousChainedOperators/SuspiciousOperationGroupings/g' {} +

Also:
rename file to match module name

rename test file to match lint name

start implementing `IdentDifference` creation

add `IdentIter` utility

use `ident_iter::IdentIter`

fix bug in `suggestion_with_swapped_ident`

add `inside_if_statements` test

implement `Add` `todo`s

register `SuspiciousOperationGroupings` lint pass

fill in `chained_binops`, and fill in a stopgap version of `ident_difference_expr`, but then notice that the lint does not seem to ever be run in the tests

run `cargo dev update_lints` and not that the `suspicious_operation_groupings` lint still does not seem to be run

fix base index incrementing bug

fix paired_identifiers bug, and remove ident from `Single`

change help prefix and note our first successful lint messages!

add odd_number_of_pairs test

get the `non_boolean_operators` test passing, with two copies of the error message

extract `is_useless_with_eq_exprs` so we can know when `eq_op` will already handle something

add `not_caught_by_eq_op` tests since `s1.b * s1.b` was (reasonably) not caught by `eq_op`

cover the case where the change should be made on either side of the expression with `not_caught_by_eq_op` tests

produce the expected suggestion on the `not_caught_by_eq_op_middle_change_left` test

confirm that the previous tests still pass and update references

fix early continue bug and get `not_caught_by_eq_op_middle_change_right` passing

note that `not_caught_by_eq_op_start` already passes

fix bugs based on misunderstanding of what `Iterator::skip` does, and note that `not_caught_by_eq_op_end` now passes

add several parens tests and make some of them pass

handle parens inside `chained_binops_helper` and note that this makes several tests pass

get `inside_larger_boolean_expression_with_unsorted_ops` test passing by extracting out `check_same_op_binops` function

also run `cargo dev fmt`

note that `inside_function_call` already passes

add another `if_statement` test

remove the matching op requirement, making `inside_larger_boolean_expression_with_unsorted_ops` pass

prevent non-change suggestions from being emitted

get the `Nested` tests passing, and remove apparently false note about eq_op

add a test to justify comment in `ident_difference_expr_with_base_location` but find that the failure mode seems different than expected

complete `todo` making `do_not_give_bad_suggestions_for_this_unusual_expr` pass and add some more tests that already pass

add test to `eq_op`

note that `inside_fn_with_similar_expression` already passes

fix `inside_an_if_statement` and note that it already passes

attempt to implement if statement extraction and notice that we don't seem to handle unary ops correctly

add `maximum_unary_minus_right_tree` test and make it pass

add two tests and note one of them passes

filter out unary operations in several places, and find that the issue seems to be that we don't currently recognize the error in `multiple_comparison_types_and_unary_minus` even so.

remove filtering that was causing bad suggestions

remove tests that were deemed too much for now

run `cargo dev fmt`

correct eq_op post-merge

fill out the description and delete debugging code

run `cargo dev update_lints`

update eq_op references

add parens to work around rustfmt issue #3666 and run rustfmt

https://github.com/rust-lang/rustfmt/issues/3666#issuecomment-714612257

update references after formatting

fix dogfood issues

fix multi-cursor edit

fix missed dogfood error

fix more dogfood pedantic issues, including function length

even more nesting

insert hidden definition of Vec3 so docs compile

add spaces to second struct def

reword test description comment

Co-authored-by: llogiq <bogusandre@gmail.com>

add local `use BinOpKind::*;`

Apply suggestions from code review

Co-authored-by: llogiq <bogusandre@gmail.com>

switch `SUSPICIOUS_OPERATION_GROUPINGS` to a style lint

run `cargo dev update_lints`

put both usages of `op_types` in the same closure to satisfy `borrowck`

fix compile error
2020-11-27 17:50:16 -07:00
Eduardo Broto
18d37a5d25 Merge remote-tracking branch 'upstream/master' into rustup 2020-11-27 17:15:10 +01:00
Markus Legner
b822632073
Factor out check_binary from function check_expr. 2020-11-27 08:55:04 +01:00
Markus Legner
e42a18f02a
Run cargo dev fmt. 2020-11-27 08:55:04 +01:00
Markus Legner
82a7068007
Trigger modulo_one lint also on -1. 2020-11-27 08:54:35 +01:00
Takayuki Nakata
e91d15f42d cargo dev fmt 2020-11-27 10:32:44 +09:00
Takayuki Nakata
0924d6286a Merge remote-tracking branch 'upstream/master' into sync-from-rust 2020-11-27 10:25:07 +09:00
Camille GILLOT
d95f11bcd6 Remove ForeignMod struct. 2020-11-26 21:32:27 +01:00
pro-grammer1
cb6a654b75 Added known problem to comparison_chain docs 2020-11-26 20:07:50 +00:00
bors
403816fbc9 Auto merge of #6362 - nico-abram:unnecessary_cast_dot_float_literal, r=ebroto
Fix rust-lang/rust#79255 - Incorrect try suggestion for float cast

changelog: Fix rust-lang/rust#79255 - Incorrect try suggestion for float literal cast ending in dot
2020-11-26 08:41:16 +00:00
unknown
3b53de6b36 Fix rust-lang/rust#79255 - Incorrect try suggestion for unnecessary float literal cast ending in dot 2020-11-25 19:38:55 -03:00
PunitLodha
2345ef5b1f added lints str_to_string and string_to_string 2020-11-25 20:59:29 +05:30
flip1995
93f922a858
Add note where the first definition of msrv attr is 2020-11-25 12:23:28 +01:00
flip1995
b2e2c0806e
Improve extract_msrv_attr! situation 2020-11-25 12:22:58 +01:00
Suyash458
aaa4325045
add support for minimum supported rust version.
add configuration option for minimum supported rust version
add msrv attribute to some lints listed in #6097
add tests
2020-11-25 12:22:47 +01:00
Christiaan Dirkx
dc075b4266 Change redundant_pattern_matching to also lint std::net::IpAddr
Suggest using utility methods `is_ipv4` and `is_ipv6`.
2020-11-25 02:01:05 +01:00
Arlie Davis
f6827839c0 Move lev_distance to rustc_ast, make non-generic
rustc_ast currently has a few dependencies on rustc_lexer. Ideally, an AST
would not have any dependency its lexer, for minimizing unnecessarily
design-time dependencies. Breaking this dependency would also have practical
benefits, since modifying rustc_lexer would not trigger a rebuild of rustc_ast.

This commit does not remove the rustc_ast --> rustc_lexer dependency,
but it does remove one of the sources of this dependency, which is the
code that handles fuzzy matching between symbol names for making suggestions
in diagnostics. Since that code depends only on Symbol, it is easy to move
it to rustc_span. It might even be best to move it to a separate crate,
since other tools such as Cargo use the same algorithm, and have simply
contain a duplicate of the code.

This changes the signature of find_best_match_for_name so that it is no
longer generic over its input. I checked the optimized binaries, and this
function was duplicated at nearly every call site, because most call sites
used short-lived iterator chains, generic over Map and such. But there's
no good reason for a function like this to be generic, since all it does
is immediately convert the generic input (the Iterator impl) to a concrete
Vec<Symbol>. This has all of the costs of generics (duplicated method bodies)
with no benefit.

Changing find_best_match_for_name to be non-generic removed about 10KB of
code from the optimized binary. I know it's a drop in the bucket, but we have
to start reducing binary size, and beginning to tame over-use of generics
is part of that.
2020-11-24 16:12:23 -08:00
bors
f897d27d8b Auto merge of #6339 - CDirkx:redundant-pattern-match-poll, r=ebroto
Change `redundant_pattern_matching` to also lint `std::task::Poll`

`reduntant_pattern_matching` currently lints pattern matching on `Option` and `Result` where the `is_variant` utility methods could be used instead: `is_some`, `is_none`, `is_ok`, `is_err`. This PR extends this behaviour to `std::task::Poll`, suggesting the methods `is_pending` and `is_ready`.

Motivation: The current description of `redundant_pattern_matching` mentions

> It's more concise and clear to just use the proper utility function

which in my mind applies to `Poll` as well.

changelog: Enhance [`redundant_pattern_matching`] to also lint on `std::task::Poll`
2020-11-24 23:19:43 +00:00
flip1995
c6a577ea11
Merge remote-tracking branch 'upstream/master' into rustup 2020-11-24 17:05:01 +01:00
bors
53ce1dd719 Auto merge of #79228 - flip1995:clippyup, r=oli-obk
Update Clippy

Biweekly Clippy update

r? `@Manishearth`
2020-11-24 06:56:02 +00:00
bors
295fe28057 Auto merge of #6313 - giraffate:fix_fp_needless_collect, r=ebroto
Fix FP in indirect `needless_collect` when used multiple times

Fix https://github.com/rust-lang/rust-clippy/issues/5991
Fix https://github.com/rust-lang/rust-clippy/issues/6297

changelog: Fix FP in indirect `needless_collect` when used multiple times
2020-11-23 22:26:45 +00:00
Eduardo Broto
209ab1885c Merge remote-tracking branch 'upstream/master' into rustup 2020-11-23 23:02:12 +01:00
bors
e5fddb6747 Auto merge of #78439 - lzutao:rm-clouldabi, r=Mark-Simulacrum
Drop support for all cloudabi targets

`cloudabi` is a tier-3 target, and [it is no longer being maintained upstream][no].

This PR drops supports for cloudabi targets. Those targets are:
* aarch64-unknown-cloudabi
* armv7-unknown-cloudabi
* i686-unknown-cloudabi
* x86_64-unknown-cloudabi

Since this drops supports for a target, I'd like somebody to tag `relnotes` label to this PR.

Some other issues:
* The tidy exception for `cloudabi` crate is still remained because
  * `parking_lot v0.9.0` and `parking_lot v0.10.2` depends on `cloudabi v0.0.3`.
  * `parking_lot v0.11.0` depends on `cloudabi v0.1.0`.

[no]: https://github.com/NuxiNL/cloudabi#note-this-project-is-unmaintained
2020-11-23 19:01:19 +00:00
flip1995
284c359c61 Fix ICE in utils::implements_trait
This only happend when debug_assertions were enabled in rustc
2020-11-23 13:52:27 +01:00
flip1995
d3d2018ead Merge commit '3e7c6dec244539970b593824334876f8b6ed0b18' into clippyup 2020-11-23 13:51:04 +01:00
Cameron Steffen
a39a93faeb Disable unnecessary_cast for cfg-dependant types 2020-11-22 19:35:04 -06:00
Cameron Steffen
a8c47440b4 Use article_and_description for missing docs 2020-11-22 17:24:56 -06:00
Lzu Tao
4b698f2069 Drop support for cloudabi targets 2020-11-22 17:11:41 -05:00
Carol (Nichols || Goulding)
445466e567
Apply suggestions from code review to change "that" to "which"
Co-authored-by: oliver <16816606+o752d@users.noreply.github.com>
2020-11-22 10:17:34 -05:00
Carol (Nichols || Goulding)
034244f108
Small grammar, punctuation, and code style improvements to docs 2020-11-22 10:17:34 -05:00
oliver
9b910e19ce
a typo
typo
2020-11-22 04:44:47 +00:00
Jonas Schievink
1464dcedfb Thread Constness through selection 2020-11-22 02:13:53 +01:00
Daniel Smith
8b21241fd5 Revert "Convert the await holding lints to correctness"
This reverts commit d8c6bce440.
2020-11-20 11:44:26 -05:00
bors
8325d48d2d Auto merge of #6351 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2020-11-20 09:07:56 +00:00
flip1995
5ee0a400fc
Fix dogfood errors 2020-11-20 10:06:26 +01:00
flip1995
dd4e471b3f
Properly deprecate panic_params lint 2020-11-20 09:37:47 +01:00
Mara Bos
113c1476c9 Clippy: Match on assert!() expansions without an inner block. 2020-11-19 19:47:25 +01:00
Mara Bos
78faaef8de Remove the clippy::panic-params lint.
Rustc itself now warns for all cases that triggered this lint.
2020-11-19 18:34:40 +01:00
Mara Bos
577ebc8cd6 Rollup merge of #79145 - camelid:clippy-fix-panics, r=flip1995
Fix handling of panic calls

This should make Clippy more resilient and will unblock #78343.

This PR is made against rust-lang/rust to avoid the need for a subtree
sync at ``@flip1995's`` suggestion in rust-lang/rust-clippy#6310.

r? ``@flip1995``
cc ``@m-ou-se``
2020-11-18 15:46:36 +01:00
Takayuki Nakata
0502ac2a87 Improve doc about map_clone 2020-11-18 08:33:25 +09:00
Christiaan Dirkx
5a83968877 Change redundant_pattern_matching to also lint std::task::Poll
Suggest using utility methods `is_pending` and `is_ready`.
2020-11-17 23:40:31 +01:00
bors
44d944586c Auto merge of #6070 - matsujika:unnecessary_wrap, r=flip1995
Add new lint `unnecessary_wrap`

Fixes #5969

changelog: New lint [`unnecessary_wraps`]
2020-11-17 20:28:32 +00:00
Camelid
4e4c4fb8aa Fix handling of panic calls
This should make Clippy more resilient and will unblock #78343.

This PR is made against rust-lang/rust to avoid the need for a subtree
sync at @flip1995's suggestion in rust-lang/rust-clippy#6310.
2020-11-17 12:16:15 -08:00
bors
5464cbed2f Auto merge of #6337 - ThibsG:FixIce6332, r=Manishearth
Remove `expect()` calls to avoid ICEs in `deref_addrof` lint

Fixes: #6332

changelog: none
2020-11-17 17:55:46 +00:00
bors
a8cafc6196 Auto merge of #6338 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2020-11-17 17:10:04 +00:00
flip1995
bf2d31d053
Run cargo dev fmt 2020-11-17 18:08:12 +01:00
Hirochika Matsumoto
c7445d7f2c Pluralize lint name 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
4e5c02e898 Ignore trait implementations 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
bf46f78ca7 Fix clippy error 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
532d205218 Skip functions in PartialOrd 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
9d96311d73 Remove wildcard use 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
e998d61fe6 Downgrade applicability to MaybeIncorrect 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
c7692cf749 Skip function with no exprs contained 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
c5447eb3c1 Make lint skip macros 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
12474c62ff Add support for methods 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
2f85aa736e Make lint skip closures 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
8392bc7946 Run cargo dev fmt 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
1bdac87128 Improve lint message 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
eec7f5c111 Update clippy_lints/src/unnecessary_wrap.rs
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
df0d565e59 Move find_all_ret_expressions into utils 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
cdb72df6f9 Split lint suggestion into two 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
a433d4690e Run rustfmt 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
c775856727 Call diag.multipart_suggestion instead 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
3ed8902623 Fix typo
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
ebdd4e2c72 Refactor code according to reivews 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
0335b8d6a7 Fix lint example 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
750c118b34 Add suggestion on type signatures 2020-11-18 01:28:37 +09:00
Hirochika Matsumoto
a7ac441760 Add new lint to detect unnecessarily wrapped value 2020-11-18 01:28:37 +09:00
bors
a467c514a3 Auto merge of #78779 - LeSeulArtichaut:ty-visitor-return, r=oli-obk
Introduce `TypeVisitor::BreakTy`

Implements MCP rust-lang/compiler-team#383.
r? `@ghost`
cc `@lcnr` `@oli-obk`

~~Blocked on FCP in rust-lang/compiler-team#383.~~
2020-11-17 12:24:34 +00:00
ThibsG
5b8f2b6c93 Remove expect() calls to avoid ICEs in deref_addrof lint 2020-11-16 23:30:11 +01:00
Bastian Kauschke
3567ea546f clippy: fold by value 2020-11-16 22:42:09 +01:00
bors
ad4f82997a Auto merge of #6119 - rsulli55:find_is_some_on_strs, r=flip1995
Add a case to `lint_search_is_some` to handle searching strings

Fixes: #6010

This adds a lint which recommends using `contains()` instead of `find()` followed by `is_some()` on strings as suggested in #6010.

This was added as an additional case to
5af88e3c2d/clippy_lints/src/methods/mod.rs (L3037)

I would really appreciate any comments/suggestions for my code!

changelog: Added case to `lint_search_is_some` to handle searching strings
2020-11-16 08:45:10 +00:00
bors
df3bb5881d Auto merge of #6336 - giraffate:sync-from-rust, r=flip1995
Rustup

changelog: none
2020-11-16 08:23:27 +00:00
LeSeulArtichaut
1b55cc79cc Set the default BreakTy to ! 2020-11-14 21:46:39 +01:00
LeSeulArtichaut
cbb6b1c338 Introduce TypeVisitor::BreakTy 2020-11-14 20:25:27 +01:00
Fabian Zaiser
864e554b9a Add underscore expressions for destructuring assignments
Co-authored-by: varkor <github@varkor.com>
2020-11-14 13:53:12 +00:00
bors
408b615d34 Auto merge of #6320 - giraffate:fix_suggestion_in_manual_range_contains_using_float, r=llogiq
Fix suggestion in `manual_range_contains` when using float

Fix #6315

changelog: Fix suggestion in `manual_range_contains` when using float
2020-11-14 08:06:00 +00:00
bors
cf7b4b0fe6 Auto merge of #6329 - giraffate:sync-from-rust, r=matthiaskrgr
Rustup

changelog: none
2020-11-13 10:49:21 +00:00
Takayuki Nakata
c6b74df680 Fix dogfood test 2020-11-13 14:47:23 +09:00
Mara Bos
3a648ffc02 Rollup merge of #78836 - fanzier:struct-and-slice-destructuring, r=petrochenkov
Implement destructuring assignment for structs and slices

This is the second step towards implementing destructuring assignment (RFC: rust-lang/rfcs#2909, tracking issue: #71126). This PR is the second part of #71156, which was split up to allow for easier review.

Note that the first PR (#78748) is not merged yet, so it is included as the first commit in this one. I thought this would allow the review to start earlier because I have some time this weekend to respond to reviews. If ``@petrochenkov`` prefers to wait until the first PR is merged, I totally understand, of course.

This PR implements destructuring assignment for (tuple) structs and slices. In order to do this, the following *parser change* was necessary: struct expressions are not required to have a base expression, i.e. `Struct { a: 1, .. }` becomes legal (in order to act like a struct pattern).

Unfortunately, this PR slightly regresses the diagnostics implemented in #77283. However, it is only a missing help message in `src/test/ui/issues/issue-77218.rs`. Other instances of this diagnostic are not affected. Since I don't exactly understand how this help message works and how to fix it yet, I was hoping it's OK to regress this temporarily and fix it in a follow-up PR.

Thanks to ``@varkor`` who helped with the implementation, particularly around the struct rest changes.

r? ``@petrochenkov``
2020-11-12 19:46:09 +01:00
Takayuki Nakata
8f89108533 Fix FP in indirect needless_collect when used multiple times 2020-11-12 23:29:16 +09:00
bors
bd13a35856 Auto merge of #6325 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2020-11-12 07:40:33 +00:00
bors
92ece84873 Auto merge of #78782 - petrochenkov:nodoctok, r=Aaron1011
Do not collect tokens for doc comments

Doc comment is a single token and AST has all the information to re-create it precisely.
Doc comments are also responsible for majority of calls to `collect_tokens` (with `num_calls == 1` and `num_calls == 0`, cc https://github.com/rust-lang/rust/pull/78736).

(I also moved token collection into `fn parse_attribute` to deduplicate code a bit.)

r? `@Aaron1011`
2020-11-12 00:33:55 +00:00
Takayuki Nakata
5f64867e1d Fix suggestion in manual_range_contains when using float 2020-11-11 22:44:48 +09:00
Fabian Zaiser
5f310d9b83 Implement destructuring assignment for structs and slices
Co-authored-by: varkor <github@varkor.com>
2020-11-11 12:10:52 +00:00
Ikko Ashimine
f92f8d095d Fix typo in comment
occurences -> occurrences
2020-11-11 20:23:08 +09:00
rsulli55
56d252c53d Update clippy_lints/src/methods/mod.rs
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-11-10 23:18:48 -07:00
Ryan Sullivant
fd303132a2 Cleaned up message and suggestion for lint_search_is_some 2020-11-10 23:18:48 -07:00
Ryan Sullivant
ee1b959054 Added period back to lint search_is_some and ran
`update-all-references.sh`
2020-11-10 23:18:47 -07:00
rsulli55
fb74b4802e Remove borrow
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-11-10 23:18:47 -07:00
rsulli55
e9612f3eca Remove to_string on msg
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-11-10 23:18:47 -07:00
Ryan Sullivant
a1cf2d334d Added a lint as suggested in 6010 which recommends using contains()
instead of `find()` follows by `is_some()` on strings

Update clippy_lints/src/find_is_some_on_strs.rs
Co-authored-by: Takayuki Nakata <f.seasons017@gmail.com>

Update clippy_lints/src/methods/mod.rs
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-11-10 23:18:47 -07:00
bors
c4fc076e11 Auto merge of #6269 - camsteffen:map-clone-deref, r=ebroto
Fix map_clone with deref and clone

changelog: Fix map_clone false positive with deref coercion

Fixes #6239
2020-11-11 00:48:33 +00:00
Cameron Steffen
769094410a Fix map_clone with deref and clone 2020-11-10 18:37:17 -06:00
Eduardo Broto
effcb52bbf Run cargo dev fmt 2020-11-10 22:33:02 +01:00
Eduardo Broto
3ea6f77446 Merge remote-tracking branch 'upstream/master' into rustup 2020-11-10 22:32:24 +01:00
bors
dd826b4626 Auto merge of #6305 - smoelius:master, r=flip1995
Add `let_underscore_drop`

This line generalizes `let_underscore_lock` (#5101) to warn about any initializer expression that implements `Drop`.

So, for example, the following would generate a warning:
```rust
struct Droppable;
impl Drop for Droppable {
    fn drop(&mut self) {}
}
let _ = Droppable;
```

I tried to preserve the original `let_underscore_lock` functionality in the sense that the warning generated for
```rust
let _ = mutex.lock();
```
should be unchanged.

*Please keep the line below*
changelog: Add lint [`let_underscore_drop`]
2020-11-09 19:13:26 +00:00
Dylan DPC
6294300b8e Rollup merge of #78710 - petrochenkov:macvisit, r=davidtwco
rustc_ast: Do not panic by default when visiting macro calls

Panicking by default made sense when we didn't have HIR or MIR and everything worked on AST, but now all AST visitors run early and majority of them have to deal with macro calls, often by ignoring them.

The second commit renames `visit_mac` to `visit_mac_call`, the corresponding structures were renamed earlier in https://github.com/rust-lang/rust/pull/69589.
2020-11-09 19:06:55 +01:00
bors
d212c382c3 Auto merge of #6278 - ThibsG:DerefAddrOf, r=llogiq
Fix bad suggestions for `deref_addrof` and `try_err` lints

Fix bad suggestions when in macro expansion for `deref_addrof` and `try_err` lints.

Fixes: #6234
Fixes: #6242
Fixes: #6237

changelog: none

r? `@llogiq`
2020-11-09 05:25:04 +00:00
Vadim Petrochenkov
8845f10e94 Do not collect tokens for doc comments 2020-11-09 01:47:11 +03:00
Samuel E. Moelius III
40d7af50ed Update lints 2020-11-08 17:33:54 -05:00
Samuel E. Moelius
8211b597ba
Update clippy_lints/src/let_underscore.rs
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-11-08 17:25:50 -05:00
Samuel E. Moelius
9751cba2c6
Update clippy_lints/src/let_underscore.rs
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-11-08 17:25:23 -05:00
Samuel E. Moelius
aa6bf1f90d
Update clippy_lints/src/let_underscore.rs
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-11-08 17:24:55 -05:00
Cameron Steffen
9cab08465b Fix or_fun_call for index operator 2020-11-08 14:49:42 -06:00
Cameron Steffen
b0994064b0 Make KNOW_TYPES static 2020-11-08 14:34:06 -06:00
bors
7079de9b35 Auto merge of #6293 - Urcra:lint-example-fix, r=flip1995
Fix example used in cargo_common_metadata

The previous example used in `cargo_common_metadata`  included an authors field, even though the comment says it doesn't. And thus doesn't actually demonstrate an example of how the lint fails.

This removes that authors field from the _bad_ example and suggest to fix the _bad_ example by adding the authors field

changelog: Fix example used in `cargo_common_metadata`
2020-11-08 14:24:58 +00:00
bors
b1faa7f002 Auto merge of #6271 - camsteffen:vec-box-import, r=flip1995
Fix vec_box scope error

changelog: Fix vec_box suggestion with wrong type scope

Fixes #6236
2020-11-08 12:02:30 +00:00
Samuel E. Moelius III
f1f780c942 Add let_underscore_drop 2020-11-08 07:00:35 -05:00
Joseph Richey
3579b7de24
Update clippy_lints/src/loops.rs
Fix NITs

Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-11-08 12:38:10 +01:00
Joe Richey
c6a91df838
Enable empty_loop lint for no_std crates
We skip the lint if the `loop {}` is in the `#[panic_handler]` as the
main recommendation we give is to panic, which obviously isn't
possible in a panic handler.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-11-08 12:38:10 +01:00
bors
96d5f45ade Auto merge of #6301 - alex-700:fix-map-clone, r=matthiaskrgr
do not trigger map_clone in the case of &mut

fixes #6299
changelog: do not trigger map_clone in the case of &mut
2020-11-08 01:28:27 +00:00
bors
c015622568 Auto merge of #6304 - matthiaskrgr:crash_6302, r=llogiq
FROM_ITER_INSTEAD_OF_COLLECT: avoid unwrapping unconditionally

Fixes #6302

changelog: fix unwrap of None when checking libcore with clippy
2020-11-07 18:10:35 +00:00
bors
5effc99812 Auto merge of #6298 - JohnTitor:fix-example, r=llogiq
Fix `await_holding_refcell_ref` examples for clarify

- Remove redundant `()`
- Fix variable name

changelog: none
2020-11-07 17:48:46 +00:00
bors
92ba07582e Auto merge of #6134 - patrickelectric:as_utf8, r=llogiq
Check when `from_utf8` is called from sliced byte array from string

---

*Please keep the line below*
changelog: Fix #5487: Add linter to check when `from_utf8` is called from sliced byte array from string.
2020-11-07 17:06:27 +00:00
bors
694cec12be Auto merge of #6110 - rail-rain:care_enums_non_copy_const, r=llogiq
"Respect" enums in `interior_mutable_const`

fixes #3962
fixes #3825

Hello,

It might not be a good idea to submit another relatively large PR while I have an opened PR; but, I've finished this anyway. This may be able to wait for months.

Note: the code uses the MIR interpreter, which the author of #3962 thought unlikely to be a solution. This might be over-engineering; but, I think it's important to be able to work with the 'http' crate (#3825). (And, I don't want to write a MIR visitor)

---

changelog: fix a false positive in two `interior_mutable_const` lints where a constant with enums gets linted
even if it uses a clearly unfrozen variant
2020-11-07 15:51:13 +00:00
bors
4bbef42c48 Auto merge of #6272 - camsteffen:unnecesary-lazy-eval-type, r=llogiq
Fix unnecessary_lazy_eval suggestion applicability

changelog: Fix unnecessary_lazy_eval suggestion applicability when breaking type inference

Fixes #6240
2020-11-07 10:01:46 +00:00
Matthias Krüger
5253595b3b FROM_ITER_INSTEAD_OF_COLLECT: avoid unwrapping unconditionally
Fixes #6302
2020-11-06 19:34:34 +01:00
Takayuki Nakata
b7892c6a26 Refactor to make getting position just before RArrow a common function 2020-11-06 22:54:38 +09:00
Aleksei Latyshev
5f57608604
do not trigger map_clone in the case of &mut 2020-11-06 14:38:46 +03:00
Takayuki Nakata
1624b00bde Fix suggestion to add unneeded space in manual_async 2020-11-06 08:40:43 +09:00
Yuki Okushi
1e4ce0fcaa Fix await_holding_refcell_ref examples for clarify 2020-11-06 04:02:41 +09:00
ThibsG
83e75f9207 Fix incorrect suggestion for try_err lint when Err arg is itself a macro 2020-11-05 18:00:34 +01:00
flip1995
34244190d4 Merge commit 'b20d4c155d2fe3a8391f86dcf9a8c49e17188703' into clippyup 2020-11-05 14:29:48 +01:00
bors
b20d4c155d Auto merge of #6296 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2020-11-05 13:14:26 +00:00
ThibsG
f83762b79c Skip rustfmt as it is wanted for this test 2020-11-05 09:14:20 +01:00
Patrick José Pereira
bc27d1492d Add string_from_utf8_as_bytes linter
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2020-11-04 21:17:46 -03:00
bors
0c1531a5c4 Auto merge of #78662 - sexxi-goose:add_expr_id_to_delegate, r=nikomatsakis
Provide diagnostic suggestion in ExprUseVisitor Delegate

The [Delegate trait](981346fc07/compiler/rustc_typeck/src/expr_use_visitor.rs (L28-L38)) currently use `PlaceWithHirId` which is composed of Hir `Place` and the
corresponding expression id.

Even though this is an accurate way of expressing how a Place is used,
it can cause confusion during diagnostics.

Eg:

```
let arr : [String; 5];

let [a, ...]     =   arr;
 ^^^ E1 ^^^      =  ^^E2^^
 ```

 Here `arr` is moved because of the binding created E1. However, when we
 point to E1 in diagnostics with the message `arr` was moved, it can be
 confusing.  Rather we would like to report E2 to the user.

 Closes: https://github.com/rust-lang/project-rfc-2229/issues/20

r? `@ghost`
2020-11-04 22:45:15 +00:00
bors
0d2f1aef02 Auto merge of #6247 - giraffate:fix_suggestion_to_add_space_in_unused_unit, r=ebroto
Fix suggestion to add unneeded space in `unused_unit`

Fix https://github.com/rust-lang/rust-clippy/issues/6230

changelog: Fix suggestion to add unneeded space in `unused_unit`
2020-11-04 22:42:10 +00:00
Urcra
a4acb3164a Fix example for cargo common data 2020-11-04 23:39:52 +01:00
bors
5b52474ae6 Auto merge of #5911 - hegza:issue-568, r=ebroto
Add lint for 'field_reassign_with_default` #568

changelog: Add lint for field_reassign_with_default that checks if mutable object + field modification is used to edit a binding initialized with Default::default() instead of struct constructor.

Fixes #568

Notes:
- Checks for reassignment of one or more fields of a binding initialized with Default::default().
- Implemented using EarlyLintPass, might be future proofed better with LateLintPass.
- Does not trigger if Default::default() is used via another type implementing Default.
- This is a re-open of [PR#4761](https://github.com/rust-lang/rust-clippy/pull/4761), but I couldn't figure out how to re-open that one so here's a new one with the requested changes :S
2020-11-04 22:21:44 +00:00
Eduardo Broto
f5166e81b1 Run cargo dev fmt 2020-11-04 22:41:15 +01:00
Eduardo Broto
834ad5c516 Merge remote-tracking branch 'upstream/master' into rustup 2020-11-04 22:37:11 +01:00
oli
83edb2f4e4 s/Scalar::Raw/Scalar::Int 2020-11-04 10:11:31 +00:00
Oliver Scherer
6fdbde5f46 Split the "raw integer bytes" part out of Scalar 2020-11-04 09:58:59 +00:00
bors
c2cf40cdcd Auto merge of #6284 - camsteffen:rustc-sym, r=flip1995
Use const sym where possible

I ran a regex search and replace to use const `sym` values where possible. This should give some performance boost by avoiding string interning at runtime.

Con: It is not as consistent as always using `sym!`.

I also changed an internal lint to suggest using `sym::{}`, making an assumption that this will always work for diagnostic items.

changelog: none
2020-11-04 09:22:54 +00:00
Vadim Petrochenkov
c2a769f84c rustc_ast: visit_mac -> visit_mac_call 2020-11-03 23:39:51 +03:00
Vadim Petrochenkov
89fa373059 rustc_ast: Do not panic by default when visiting macro calls 2020-11-03 20:38:20 +03:00
bors
225ce5ff58 Auto merge of #6233 - montrivo:manual_ok_or, r=flip1995
add manual_ok_or lint

Implements partially #5923

changelog: add lint manual_ok_or
2020-11-03 16:42:59 +00:00
bors
2fe87a89c9 Auto merge of #6165 - dvermd:ref_option_ref, r=flip1995
Add lint 'ref_option_ref' #1377

This lint checks for usage of `&Option<&T>` which can be simplified as `Option<&T>` as suggested in #1377.

This WIP PR is here to get feedback on the lint as there's more cases to be handled:
* statics/consts,
* associated types,
* type alias,
* function/method parameter/return,
* ADT definitions (struct/tuple struct fields, enum variants)

changelog: Add 'ref_option_ref' lint
2020-11-03 16:21:51 +00:00
bors
a2bf404d34 Auto merge of #6101 - pitiK3U:from_iter_instead_of_collect, r=flip1995
Add lint: from_iter_instead_of_collect

Fixes #5679

This implements lint for `::from_iter()` from #5679 not the general issue (`std::ops::Add::add`, etc.).
This lint checks if expression is function call with `from_iter` name and if it's implementation of the `std::iter::FromIterator` trait.

changelog: Introduce  from_iter_instead_of_collect lint
2020-11-03 15:59:16 +00:00
Piti the little Light
ddf23d649a
Fix: Use .collect() instead of ::fromIterator() 2020-11-03 16:44:24 +01:00
Piti the little Light
52d1ea3c9a
Fix: Don't show lint for types that doesn't implement Iterator 2020-11-03 16:44:24 +01:00
Piti the little Light
f359fb872b
Improve error message 2020-11-03 16:44:24 +01:00
Piti the little Light
abdb7aeb55
Remove backticks 2020-11-03 16:44:24 +01:00
Piti the little Light
854f2cef06
Run cargo dev fmt 2020-11-03 16:44:24 +01:00