Commit graph

4440 commits

Author SHA1 Message Date
Cameron Steffen
dcf4e07458 Finish MSRV for cloned_instead_of_copied 2021-04-26 11:09:24 -05:00
bors
74f55996fe Auto merge of #7120 - cherryblossom000:7106, r=Manishearth
`single_component_path_imports`: ignore `pub(crate) use some_macro;`

Fixes #7106

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

changelog: Ignore exporting a macro within a crate using `pub(crate) use some_macro;` for [`single_component_path_imports`]
2021-04-22 14:36:21 +00:00
bors
0ab7acc890 Auto merge of #7100 - ABouttefeux:unused_io_amount, r=camsteffen
Unused io amount detects `.read().ok()?`

fixes #7096
changelog: unused_io_amount now detect expertion like `.read().ok()?`,  `.read().or_else(|err| ...)?` and similar expressions.
2021-04-22 13:57:06 +00:00
Aliénore Bouttefeux
5625d58f9f add detection unused_io_amount of "or", "or_else" and "ok" 2021-04-22 15:52:42 +02:00
cherryblossom
b48699e4cf
single_component_path_imports: ignore pub(crate) use some_macro; (fixes #7106) 2021-04-22 19:34:36 +10:00
flip1995
44c8057f4d
Merge remote-tracking branch 'upstream/master' into rustup 2021-04-22 11:24:26 +02:00
bors
79b9eb5371 Auto merge of #7072 - ebobrow:imports-ending-with-self, r=camsteffen
add unnecessary_self_imports lint

fixes #6552

changelog: add `unnecessary_self_imports` lint
2021-04-21 14:47:49 +00:00
Elliot Bobrow
224881b94d add unnecessary_self_imports lint 2021-04-21 07:17:42 -07:00
bors
bbc22e2ef3 Auto merge of #7083 - GuillaumeGomez:bool-assert-eq, r=camsteffen
Add lint to check for boolean comparison in assert macro calls

This PR adds a lint to check if an assert macro is using a boolean as "comparison value". For example:

```rust
assert_eq!("a".is_empty(), false);
```

Could be rewritten as:

```rust
assert!(!"a".is_empty());
```

PS: The dev guidelines are amazing. Thanks a lot for writing them!

changelog: Add `bool_assert_comparison` lint
2021-04-21 13:58:53 +00:00
bors
926286acfe Auto merge of #7109 - ctennis:ct/asm_syntax_aarch64, r=flip1995
Ignore aarch64 for this test as it's x86 assembly only.  Fixes #7091

fixes #7091 - asm_syntax lint test will not compile on aarch64

changelog: none
2021-04-21 08:49:15 +00:00
bors
ec38ea1ac1 Auto merge of #7097 - yawara:fix/7069, r=llogiq
Fixed inconsistent_struct_constructor triggers in macro-generated code

fixes #7069

changelog: `inconsistent_struct_constructor`: Fix FP in macro expansion.
2021-04-20 08:26:21 +00:00
Yawara ISHIDA
6eae905808 Add a test for FP in macro expansion 2021-04-20 13:34:30 +09:00
bors
b7c12f3aab Auto merge of #7092 - basavesh:fix#7066, r=giraffate
useless use of format! should return function directly

fixes #7066

changelog: [`useless_format`] wraps the content in the braces when it's needed.

r? `@giraffate`
2021-04-19 23:06:21 +00:00
Guillaume Gomez
e2e104b993 Add lint to check for boolean comparison in assert macro calls 2021-04-19 22:15:51 +02:00
lcnr
419bf6bbd8 fix suggestion for unsized function parameters 2021-04-19 20:06:19 +02:00
Caleb Tennis
42d070286e Ignore aarch64 for this test as it's x86 assembly only. Fixes #7091 2021-04-19 11:39:42 -04:00
Basavesh Shivakumar
c6b381c59b useless use of format! should return function directly 2021-04-19 17:20:21 +02:00
bors
fe5cefceba Auto merge of #7101 - camsteffen:flat-map-option, r=giraffate
Add flat_map_option lint

changelog: Add flat_map_option lint

Closes #2241
2021-04-19 13:34:23 +00:00
Andre Bogus
243dc46250 un-double return on try_err 2021-04-18 23:49:54 +02:00
bors
392d54963f Auto merge of #78880 - CDirkx:not_supported, r=joshtriplett
Add `Unsupported` to `std::io::ErrorKind`

I noticed a significant portion of the uses of `ErrorKind::Other` in std is for unsupported operations.
The notion that a specific operation is not available on a target (and will thus never succeed) seems semantically distinct enough from just "an unspecified error occurred", which is why I am proposing to add the variant `Unsupported` to `std::io::ErrorKind`.

**Implementation**:

The following variant will be added to `std::io::ErrorKind`:

```rust
/// This operation is unsupported on this platform.
Unsupported
```
`std::io::ErrorKind::Unsupported` is an error returned when a given operation is not supported on a platform, and will thus never succeed; there is no way for the software to recover. It will be used instead of `Other` where appropriate, e.g. on wasm for file and network operations.

`decode_error_kind` will be updated  to decode operating system errors to `Unsupported`:
- Unix and VxWorks: `libc::ENOSYS`
- Windows: `c::ERROR_CALL_NOT_IMPLEMENTED`
- WASI: `wasi::ERRNO_NOSYS`

**Stability**:
This changes the kind of error returned by some functions on some platforms, which I think is not covered by the stability guarantees of the std? User code could depend on this behavior, expecting `ErrorKind::Other`, however the docs already mention:

> Errors that are `Other` now may move to a different or a new `ErrorKind` variant in the future. It is not recommended to match an error against `Other` and to expect any additional characteristics, e.g., a specific `Error::raw_os_error` return value.

The most recent variant added to `ErrorKind` was `UnexpectedEof` in `1.6.0` (almost 5 years ago), but `ErrorKind` is marked as `#[non_exhaustive]` and the docs warn about exhaustively matching on it, so adding a new variant per se should not be a breaking change.

The variant `Unsupported` itself could be marked as `#[unstable]`, however, because this PR also immediately uses this new variant and changes the errors returned by functions I'm inclined to agree with the others in this thread that the variant should be insta-stabilized.
2021-04-18 20:03:54 +00:00
Christiaan Dirkx
024a49aed1 Fix clippy test using ErrorKind 2021-04-18 09:29:24 +02:00
bors
8c37e19da4 Auto merge of #84064 - hyd-dev:unknown-lints, r=petrochenkov
Do not ignore path segments in the middle in `#[allow]`/`#[warn]`/`#[deny]`/`#[forbid]` attributes

Fixes #83477.
2021-04-18 02:12:13 +00:00
hyd-dev
913780397a Do not ignore path segments in the middle in #[allow]/#[warn]/#[deny]/#[forbid] attributes 2021-04-17 18:11:07 +08:00
bors
e441b33ba0 Auto merge of #7099 - ABouttefeux:master, r=llogiq
add type in help message of from_over_into

fixes #7088
changelog: add type in help message of from_over_into
2021-04-16 21:22:24 +00:00
Cameron Steffen
5af078ac1b Add flat_map_option lint 2021-04-16 15:23:49 -05:00
bors
831c15737c Auto merge of #7087 - Jarcho:allman_style_else, r=camsteffen
Allow allman style braces in `suspicious_else_formatting`

fixes: #3864

Indentation checks could be added as well, but the lint already doesn't check for it.

changelog: Allow allman style braces in `suspicious_else_formatting`
2021-04-16 20:16:52 +00:00
Jason Newcomb
559deddb3b
Allow allman style braces in suspicious_else_formatting 2021-04-16 15:24:46 -04:00
bors
eaf0f3df15 Auto merge of #7075 - xFrednet:7054-fp-branches-sharing-code, r=camsteffen,flip1995
Fixing FPs for the `branches_sharing_code` lint

Fixes #7053
Fixes #7054
And an additional CSS adjustment to support dark mode for every inline code. It currently only works in paragraphs, which was an oversight on my part 😅. [Current Example](https://rust-lang.github.io/rust-clippy/master/index.html#blacklisted_name)

This also includes ~50 lines of doc comments and is therefor not as big as the changes would indicate. 🐧

---

changelog: none

All of these bugs were introduced in this dev version and are therefor not worth a change log entry.

r? `@phansch`
cc: `@camsteffen` since you have a pretty good overview of the `SpanlessEq` implementation 🙃
2021-04-16 18:33:45 +00:00
Aliénore Bouttefeux
ccd0f0b4af added missing line in test ouput 2021-04-16 20:13:25 +02:00
Aliénore Bouttefeux
2d050f4b2f add type in help of from over Into 2021-04-16 19:38:01 +02:00
bors
28dbcd85c8 Auto merge of #7098 - camsteffen:cloned-copied, r=Manishearth
Add `cloned_instead_of_copied` lint

Don't go cloning all willy-nilly.

Featuring a new `get_iterator_item_ty` util!

changelog: Add cloned_instead_of_copied lint

Closes #3870
2021-04-16 17:32:13 +00:00
bors
7f2068cc2b Auto merge of #6568 - Jarcho:redundant_pattern_matching, r=flip1995
Fix: redundant_pattern_matching drop order

Fixes #5746

A note about the change in drop order is added when the scrutinee (or any temporary in the expression) isn't known to be safe to drop in any order (i.e. doesn't implement the `Drop` trait, or contain such a type). There is a whitelist for some `std` types, but it's incomplete. Currently just `Vec<_>`, `Box<_>`, `Rc<_>` and `Arc<_>`, but only if the contained type is also safe to drop in any order.

Another lint for when the drop order changes could be added as allowed by default, but the drop order requirement is pretty subtle in this case. I think the note added to the lint should be enough to make someone think before applying the change.

changelog: Added a note to `redundant_pattern_matching` when the change in drop order might matter
2021-04-16 16:45:59 +00:00
Cameron Steffen
0462666c70 Add cloned_instead_of_copied lint 2021-04-16 11:39:31 -05:00
bors
1e0a3ff55c Auto merge of #6937 - Jarcho:map_entry_suggestion, r=giraffate
Improve `map_entry` suggestion

fixes: #5176
fixes: #4674
fixes: #4664
fixes: #1450

Still need to handle the value returned by `insert` correctly.

changelog: Improve `map_entry` suggestion. Will now suggest `or_insert`, `insert_with` or `match _.entry(_)` as appopriate.
changelog: Fix `map_entry` false positives where the entry api can't be used. e.g. when the map is used for multiple things.
2021-04-16 13:23:23 +00:00
bors
ddc2598230 Auto merge of #7093 - Jarcho:single_match_fp, r=llogiq
Fix `single_match`

fixes: #7038
changelog: Don't suggest an equality check for types which don't implement `PartialEq` in `single_match`
2021-04-16 06:44:26 +00:00
Charles Lew
696562d22d Remove #[main] attribute. 2021-04-16 13:04:02 +08:00
bors
faa97568a0 Auto merge of #7085 - Jarcho:manual_map_autoderef, r=giraffate
Don't allow adjustments for `manual_map`

fixes: #7077

The other option here would be to add the return type to the closure. It would be fine for simple types, but longer types can be rather unwieldy. Could also implement the adjustment manually.

changelog: Don't lint `manual_map` when type adjustments are added. e.g. autoderef
2021-04-16 03:05:52 +00:00
Jason Newcomb
9a55c0c176
Fix single_match
Check for `PartialEq` in addition to `StructuralPartialEq` before suggesting `==`
2021-04-15 22:09:20 -04:00
Jason Newcomb
b6581636bd
Improve redundant_pattern_matching
Add a note when the drop order change may result in different behaviour.
2021-04-15 20:37:15 -04:00
Jason Newcomb
f6c5d8d599
Remove all usages of match_path, match_qpath and match_path_ast except the author lint.
Add note to fix `MATCH_TYPE_ON_DIAG_ITEM`
Add false negative test for `uninit_assumed_init`
2021-04-15 19:27:25 -04:00
Jason Newcomb
779d98f6cc
Don't allow adjustments for manual_map 2021-04-15 10:37:42 -04:00
Jason Newcomb
bcf3488007
Minor cleanup of map_entry and a few additional tests. 2021-04-15 08:25:24 -04:00
Jason Newcomb
3323ff7145
map_entry improvements
Suggest using `or_insert_with` when possible
2021-04-15 08:22:40 -04:00
Jason Newcomb
b63a5b56d6
map_entry improvements
Lint `if _.[!]contains_key(&_) { .. } else { .. }` so long as one of the branches contains an insertion.
2021-04-15 08:19:59 -04:00
Jason Newcomb
ce5e927713
Improve map_entry lint
Fix false positives where the map is used before inserting into the map.
Fix false positives where two insertions happen.
Suggest using `if let Entry::Vacant(e) = _.entry(_)` when `or_insert` might be a semantic change
2021-04-15 08:19:40 -04:00
xFrednet
2992b19c82 Added inferred local type comparion to SpanlessEq 2021-04-14 20:06:26 +02:00
xFrednet
cbde4f2c67 parent_node_is_if_expr now also recognizes if let as parent if 2021-04-14 20:06:26 +02:00
bors
24921df7bd Auto merge of #7039 - phansch:melt-ice, r=flip1995
tabs_in_doc_comments: Fix ICE due to char indexing

This is a quick-fix for an ICE in `tabs_in_doc_comments`. The problem
was that we we're indexing into possibly multi-byte characters, such as '位'.

More specifically `get_chunks_of_tabs` was returning indices into
multi-byte characters. Those were passed on to a `Span` creation that
then caused the ICE.

This fix makes sure that we don't return indices that point inside a
multi-byte character. *However*, we are still iterating over unicode
codepoints, not grapheme clusters. So a seemingly single character like y̆ ,
which actually consists of two codepoints, will probably still cause
incorrect spans in the output. But I don't think we handle those cases
anywhere in Clippy currently?

Fixes #5835

changelog: Fix ICE in `tabs_in_doc_comments`
2021-04-14 04:53:24 +00:00
rail
26a1989041 Fix a FP in missing_const_for_fn
where a function that calls a standard library function whose constness
is unstable is considered as being able to be a const function
2021-04-14 09:23:44 +12:00
bors
2a96bc434b Auto merge of #7067 - TaKO8Ki:fix-false-negative-on-needless-return, r=llogiq
Fix a false negative on `needless return`

closes #7042

changelog: fix a false negative on `needless return`
2021-04-12 18:00:38 +00:00