Commit graph

4732 commits

Author SHA1 Message Date
xordi
83f1454ade Fix function and variable names 2021-08-31 09:06:14 +02:00
xordi
abbcea86ff Add new ui tests 2021-08-31 08:56:53 +02:00
bors
fd30241281 Auto merge of #7573 - Jarcho:option_if_let_else, r=giraffate
Fix `option_if_let_else`

fixes: #5822
fixes: #6737
fixes: #7567

The inference from #6137 still exists so I'm not sure if this should be moved from the nursery. Before doing that though I'd almost want to see this split into two lints. One suggesting `map_or` and the other suggesting `map_or_else`.

`map_or_else` tends to have longer expressions for both branches so it doesn't end up much shorter than a match expression in practice. It also seems most people find it harder to read. `map_or` at least has the terseness benefit of being on one line most of the time, especially when the `None` branch is just a literal or path expression.

changelog: `break` and `continue` statments local to the would-be closure are allowed in `option_if_let_else`
changelog: don't lint in const contexts  in `option_if_let_else`
changelog: don't lint when yield expressions are used  in `option_if_let_else`
changelog: don't lint when the captures made by the would-be closure conflict with the other branch  in `option_if_let_else`
changelog: don't lint when a field of a local is used when the type could be pontentially moved from  in `option_if_let_else`
changelog: in some cases, don't lint when scrutinee expression conflicts with the captures of the would-be closure  in `option_if_let_else`
2021-08-30 13:57:21 +00:00
Jason Newcomb
3e5dcba2ee
Small cleanup of option_if_let_else and additional tests. 2021-08-26 11:44:36 -04:00
bors
de80188c64 Auto merge of #7543 - DevinR528:disallowed-mod, r=Manishearth
Add module_style lint to style

changelog: Add new [`module_style`] style lint

This is a configurable (no mod file/mod file) lint that determines if `mod.rs` is used consistently or if `mod.rs` is never used (using the new mod layout).
2021-08-25 15:20:28 +00:00
bors
305177342f Auto merge of #7453 - F3real:assume_function_calls_have_side_effect, r=flip1995
Don't report function calls as unnecessary operation if used in array index

Attempts to fix: #7412

changelog: Don't report function calls used in indexing as unnecessary operation. [`unnecessary_operation`]
2021-08-25 08:31:20 +00:00
Devin Ragotzy
31738b1da3 Add module_style lint to restriction
Add tests for disallowed_mod in ui-cargo test section

Use correct algorithm to determine if mod.rs is missing

Move to two lints and remove config option

Switch lint names so they read "warn on ..."

Emit the same help info for self_named_mod_file warnings

Bail when both lints are Allow

Reword help message for both module_style lints
2021-08-24 15:53:58 -04:00
bors
87c6f32756 Auto merge of #7592 - lengyijun:redundant_allocation, r=camsteffen
redundant_allocation: fix 7487

Fixes #7487

changelog: [`redundant_allocation`] - allow `Box<Box<dyn T>>` which replaces wide pointers with thin pointers
2021-08-24 12:32:01 +00:00
lengyijun
641be558fc redundant_allocation: fix 7487 2021-08-24 13:03:48 +08:00
bors
22606e7358 Auto merge of #7539 - Labelray:master, r=camsteffen
Add new lint `negative_feature_names` and `redundant_feature_names`

Add new lint [`negative_feature_names`] to detect feature names with prefixes `no-` or `not-` and new lint [`redundant_feature_names`] to detect feature names with prefixes `use-`, `with-` or suffix `-support`
changelog: Add new lint [`negative_feature_names`] and [`redundant_feature_names`]
2021-08-23 13:56:18 +00:00
Labelray
0a021d5900 Add new lints negative_feature_names and redundant_feature_names 2021-08-23 21:05:44 +08:00
Jason Newcomb
8b3ca9a315
Fix option_if_let_else
* `break` and `continue` statments local to the would-be closure are allowed
* don't lint in const contexts
* don't lint when yield expressions are used
* don't lint when the captures made by the would-be closure conflict with the other branch
* don't lint when a field of a local is used when the type could be pontentially moved from
* in some cases, don't lint when scrutinee expression conflicts with the captures of the would-be closure
2021-08-16 16:12:00 -04:00
Jason Newcomb
a7f376fbd3
Add lint manual_split_once 2021-08-16 09:34:58 -04:00
dswij
711c5cb6d2 Add false positive test for manual_flatten
Add a scenario where `manual_flatten` is triggered when match expression will still be used after the match in `if let`.
2021-08-16 16:24:44 +08:00
Jason Newcomb
10c0460a47
update stderr messages 2021-08-14 19:52:59 -04:00
Jason Newcomb
9500974bdb
Fix tracking of which locals would need to be captured in a closure.
* Captures by sub closures are now considered
* Copy types are correctly borrowed by reference when their value is used
* Fields are no longer automatically borrowed by value
* Bindings in `match` and `let` patterns are now checked to determine how a local is captured
2021-08-14 19:49:57 -04:00
Jason Newcomb
251dd30d77
Improve manual_map
In some cases check if a borrow made in the scrutinee expression would prevent creating the closure used by `map`
2021-08-14 19:49:54 -04:00
Jason Newcomb
4838c78ba4
Improve manual_map and map_entry
Locals which can be partially moved created within the to-be-created closure shouldn't block the use of a closure
2021-08-14 19:49:45 -04:00
dswij
e9f56f949d Add false positive test for iterator method 2021-08-13 14:56:37 +08:00
xFrednet
c02dcd5405 Update type UI tests to use private items 2021-08-12 22:18:45 +02:00
xFrednet
09b7745f34 Updated lint message for rc_mutex 2021-08-12 13:53:23 +02:00
flip1995
d02016d686
Merge remote-tracking branch 'upstream/master' into rustup 2021-08-12 10:58:44 +02:00
bors
62f4187ed0 Auto merge of #7546 - mgeier:patch-1, r=giraffate
similar_names: allow "iter" and "item"

changelog: [`similar_names`] no longer complains about `iter` and `item` being too similar
2021-08-12 08:16:50 +00:00
bors
e62a6cad1e Auto merge of #7516 - lf-:unwrap-or-default, r=xFrednet
Add `unwrap_or_else_default` lint

---

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: Add a new [`unwrap_or_else_default`] style lint. This will catch `unwrap_or_else(Default::default)` on Result and Option and suggest `unwrap_or_default()` instead.
2021-08-12 08:02:44 +00:00
F3real
979ce29086 Correctly report inclusive range in no_effect lint 2021-08-12 01:05:41 +02:00
Matthias Geier
f7784ef534
fix line numbers 2021-08-11 20:42:01 +02:00
Matthias Geier
ee63ebe11b
rustfmt 2021-08-11 20:35:48 +02:00
Matthias Geier
573b897441
Add test for similar names "iter" and "item" 2021-08-11 20:32:26 +02:00
bors
b1b38604f2 Auto merge of #7541 - LeSeulArtichaut:for-never-loop, r=camsteffen
`never_loop`: suggest using an `if let` instead of a `for` loop

changelog: suggest using an `if let` statement instead of a `for` loop that [`never_loop`]s

Fixes #7537, r? `@camsteffen.`
2021-08-11 14:49:37 +00:00
LeSeulArtichaut
fc0af8e4d8 never_loop: suggest using an if let instead of a for loop 2021-08-11 16:35:33 +02:00
Esteban Kuber
652b6a771f update clippy 2021-08-11 14:21:33 +00:00
Jade
11ef04728c Add unwrap_or_else_default lint
This will catch `unwrap_or_else(Default::default)` on Result and Option
and suggest `unwrap_or_default()` instead.
2021-08-10 14:40:26 -07:00
bors
76c4a337d1 Auto merge of #7535 - LeSeulArtichaut:7518-self-ty-arg, r=xFrednet
Properly handle `Self` type for `trivially_copy_pass_by_ref`

changelog: properly handle `Self` type for [`trivially_copy_pass_by_ref`].

Fixes #7518
2021-08-10 10:25:26 +00:00
F3real
ede977cf31 Update suggestion in case of index for unnecessary_operation lint 2021-08-10 12:08:09 +02:00
bors
f998e89e43 Auto merge of #7478 - DevinR528:preemtive, r=llogiq
Fix nonstandard_macro_braces FP and docs of disallowed_types

changelog: Fix FP in [`nonstandard_macro_braces`] lint
2021-08-10 00:52:04 +00:00
bors
0084195dee Auto merge of #7506 - HKalbasi:add-xor-swap, r=camsteffen
Add xor case to `manual swap` lint

Continue of #7153
closes #6598

changelog: Add "xor swap" case to [`manual_swap`]
2021-08-09 13:34:42 +00:00
hamidreza kalbasi
6d36d1a835 merge XOR_SWAP with MANUAL_SWAP 2021-08-09 02:15:10 +04:30
bors
6cb30ad581 Auto merge of #7534 - LeSeulArtichaut:7517-closure-too-many-lines, r=flip1995
Don't emit `too_many_lines` for closures

changelog: don't emit the [`too_many_lines`] lint inside closures to avoir duplicated diagnostics.

Fixes #7517.
2021-08-07 13:05:53 +00:00
LeSeulArtichaut
ccb5d73dec Properly handle Self type for trivially_copy_pass_by_ref 2021-08-05 18:11:08 +02:00
valentine-mario
8a4ffb881d fixed bug that had to deal with mut and non mut suggestion 2021-08-05 16:15:44 +01:00
LeSeulArtichaut
4743ec1948 Don't emit too_many_lines for closures 2021-08-05 15:38:57 +02:00
bors
4e760b675c Auto merge of #7522 - dswij:map-flatten-result, r=llogiq
Cover `Result` on `map_flatten` lint

Closes #7496

changelog: `[map_flatten]` handles `Result` type
2021-08-02 07:27:09 +00:00
bors
b6c23297bf Auto merge of #7519 - Jarcho:rustfmt_fix, r=giraffate
Workaround rust-lang/rustfmt#4477 - relative paths in `path` attribute

See rust-lang/rustfmt#4477
changelog: None
2021-08-02 00:56:54 +00:00
Dharma Saputra Wijaya
69d439065e Handle Result on map_flatten lint
Adds a check on `.map(..).flatten()` on `Result` type that follows the
behaviour on `Option` type.
2021-08-01 17:47:54 +08:00
Jason Newcomb
205aa88921
Fix while_let_on_iterator
When the iterator is one field within a local correctly check for usages of the field
2021-07-31 09:32:54 -04:00
Jason Newcomb
fe75faa6ee
Fix while_let_on_iterator
Reborrow mutable references rather then take a reference to them.
2021-07-31 00:11:46 -04:00
Jason Newcomb
fc387b877a
Workaround rust-lang/rustfmt#4477 - relative paths in path attribute 2021-07-30 23:43:04 -04:00
bors
c9e45e47d5 Auto merge of #86754 - estebank:use-multispans-more, r=varkor
Use `multipart_suggestions` more

Built on top of #86532
2021-07-30 23:18:12 +00:00
Yuki Okushi
0af50b4d32 Rollup merge of #87385 - Aaron1011:final-enable-semi, r=petrochenkov
Make `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` warn by default

This PR makes the `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lint warn by default.

To avoid showing a large number of un-actionable warnings to users, we only enable the lint for macros defined in the same crate. This ensures that users will be able to fix the warning by simply removing a semicolon.

In the future, I'd like to enable this lint unconditionally, and eventually make it into a hard error in a future edition. This PR is a step towards that goal.
2021-07-31 04:09:20 +09:00
Esteban Küber
9a6ae783d4 Use multispan suggestions more often
* Use more accurate span for `async move` suggestion
* Use more accurate span for deref suggestion
* Use `multipart_suggestion` more often
2021-07-30 09:26:31 -07:00