Commit graph

3948 commits

Author SHA1 Message Date
bors
908815ce98 Auto merge of #8001 - Jarcho:unprefixed_strlen, r=giraffate
Improve `strlen_on_c_string`

fixes: #7436

changelog: lint `strlen_on_c_string` when used without a fully-qualified path
changelog: suggest removing the surrounding unsafe block for `strlen_on_c_string` when possible
2021-11-29 01:03:48 +00:00
bors
4e84dd121f Auto merge of #8006 - togami2864:generalize-copied, r=camsteffen
apply iter_cloned_collect to collect() using copied()

fix: #6703

changelog: apply `iter_cloned_collect` to `collect()` using`copied()`
2021-11-28 20:59:20 +00:00
togami2864
f51bbc7db9 apply iter_cloned_collect to copied() 2021-11-28 23:59:31 +09:00
bors
3720735f9a Auto merge of #7995 - Alexendoo:needless_late_init, r=giraffate
Add `needless_late_init` lint

examples:

```rust
let a;
a = 1;
// to
let a = 1;
```
```rust
let b;
match 3 {
    0 => b = "zero",
    1 => b = "one",
    _ => b = "many",
}
// to
let b = match 3 {
    0 => "zero",
    1 => "one",
    _ => "many",
};
```
```rust
let c;
if true {
    c = 1;
} else {
    c = -1;
}
// to
let c = if true {
    1
} else {
    -1
};
```

changelog: Add [`needless_late_init`]
2021-11-27 14:24:02 +00:00
Alex Macleod
d346ec94fe Add async/const fn tests for needless-late-init
+nits
2021-11-26 14:27:53 +00:00
togami2864
e8ef6ca5e3 fix stderr 2021-11-26 18:49:14 +09:00
togami2864
140ba610e4 add test suit 2021-11-26 18:34:07 +09:00
Dharma Saputra Wijaya
c0bad8bcab Add more descriptive help info for needless_question_mark 2021-11-25 14:01:14 +08:00
Jason Newcomb
a135347f5d Run rustfix for strlen_on_c_strings tests 2021-11-24 20:16:27 -05:00
Alex Macleod
3957244120 Add needless_late_init lint 2021-11-23 15:08:49 +00:00
flip1995
5740230ec7
Merge remote-tracking branch 'upstream/master' into rustup 2021-11-23 11:22:34 +01:00
dswij
ec3d1c8ca3 Fix FP on if_then_some_else_none when there is early return 2021-11-23 10:11:30 +08:00
bors
57a8804ef9 Auto merge of #8007 - birkenfeld:octal_escapes, r=xFrednet
Add new lint `octal_escapes`

This checks for sequences in strings that would be octal character
escapes in C, but are not supported in Rust.  It suggests either
to use the `\x00` escape, or an equivalent hex escape if the octal
was intended.

Fixes #7981

---

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

changelog: Add new lint [`octal_escapes`], which checks for literals like `"\033[0m"`.
2021-11-22 20:29:53 +00:00
Georg Brandl
0bc25d04c6 octal_escapes: emit only one lint for all cases found each literal 2021-11-22 21:00:19 +01:00
Georg Brandl
850e7f533e octal_escapes: updates from review, fix byte string prefix 2021-11-22 18:02:17 +01:00
bors
5fbfdfa319 Auto merge of #8009 - xFrednet:8004-suboptimal-flops-in-const, r=giraffate
Allow `suboptimal_flops` in const functions

This PR allows `clippy::suboptimal_flops` in constant functions. The check also effects the `clippy::imprecise_flops` lint logic. However, this doesn't have any effects as all functions checked for are not const and can therefore not be found in such functions.

---

changelog: [`suboptimal_flops`]: No longer triggers in constant functions

Closes: rust-lang/rust-clippy#8004
2021-11-22 00:01:49 +00:00
bors
de2208a351 Auto merge of #7997 - surechen:Fixes_7915, r=giraffate
Fixes shadow_same's false positive for #7915

Fix shadow_same's false positive for async function's params(Fixes #7915):

Example Code:
```rust
#![deny(clippy::shadow_same)]

pub async fn foo(_a: i32) {
}
```
Output:
```
error: `_a` is shadowed by itself in `_a
```

Hir:
```rust
pub async fn foo(_a: i32)
 ->
     /*impl Trait*/ #[lang = "from_generator"](move |mut _task_context|
                                                   {
                                                       let _a = _a;
                                                       { let _t = { }; _t }
                                                   })
```

Skip checking async function's params.

changelog: Fix shadow_same's false positive for async function's params
2021-11-21 23:48:24 +00:00
Cameron Steffen
e58ffb88e6 Fix Clippy with changed for loop desugar 2021-11-21 08:16:09 -06:00
surechen
846c0bef07 Fixes #7915
Fix shadow_same's positive false for async function's params:

Example Code:
```rust
#![deny(clippy::shadow_same)]

pub async fn foo(_a: i32) {
}
```
Output:
```
error: `_a` is shadowed by itself in `_a
```

Hir:
```rust
pub async fn foo(_a: i32)
 ->
     /*impl Trait*/ #[lang = "from_generator"](move |mut _task_context|
                                                   {
                                                       let _a = _a;
                                                       { let _t = { }; _t }
                                                   })
```

Skip checking async function's params.

changelog: Fix shadow_same's positive false for async function's params
2021-11-21 14:28:44 +08:00
Georg Brandl
0c4055c283 Avoid inline hints with double backticks for doc-markdown 2021-11-20 18:13:24 +01:00
xFrednet
1c8085d705
Allow suboptimal_flops in const functions 2021-11-20 15:39:29 +01:00
Georg Brandl
982124acfa Add new lint octal_escapes
This checks for sequences in strings that would be octal character
escapes in C, but are not supported in Rust.  It suggests either
to use the `\x00` escape, or an equivalent hex escape if the octal
was intended.
2021-11-20 11:57:25 +01:00
togami2864
ec7364f227 add test suit 2021-11-20 18:49:30 +09:00
Jason Newcomb
0d1f1cec44 Remove surrounding unsafe block in strlen_on_c_strings when possible 2021-11-19 21:14:51 -05:00
Jason Newcomb
c443f8fb95 Fix strlen_on_c_strings when not used with a full path 2021-11-19 20:02:49 -05:00
bors
38bd2514ad Auto merge of #7984 - phansch:disallowed-type-rename, r=xFrednet
Pluralize `disallowed_type` lint

This was brought up in [Zulip] and is also mentioned in the lint naming
conventions. Since this is still a nursery lint, I think there shouldn't
be any problem in renaming it.

[Zulip]: rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/disallow_type.20vs.20disallowed-types

changelog: Rename nursery lint [`disallowed_type`] to [`disallowed_types`].
2021-11-19 13:39:08 +00:00
togami2864
cd81bb9dc3 fix stderr 2021-11-19 16:17:17 +09:00
togami2864
abb7155387 add test case for result_map_or_into_option 2021-11-19 16:12:46 +09:00
bors
2776076efa Auto merge of #7977 - Jarcho:multi_needless_borrow, r=xFrednet
Improve `needless_borrow` lint

fixes: #5327
fixes: #1726
fixes: #1212

This is merging `needless_borrow` into the `dereference` pass in preparation for `explicit_auto_deref`. `explicit_auto_deref` needs to implement most of what `needless_borrow` implements in order to work.

There is a minor regression here where `let x: &str = &x.deref()` will trigger `needless_borrow` without triggering `explicit_deref_methods`. Removing the redundant borrow will cause `explicit_deref_methods` to trigger. This will be fixed when `explicit_auto_deref` is implemented.

changelog: Lint `needless_borrow` when a borrow is auto-derefed more than once
changelog: Lint `needless_borrow` in the trailing expression of a block for a match arm
2021-11-18 23:35:03 +00:00
flip1995
9b38fb7b71
Also pluralize disallowed_method(s) lint
To stay consistent with the sister lint disallowed_type, also rename the
disallowed_method lint to disallowed_methods.
2021-11-18 17:37:06 +01:00
Philipp Hansch
b7f18916fa
Pluralize disallowed_type lint
This was brought up in [Zulip] and is also mentioned in the lint naming
conventions. Since this is still a nursery lint, I think there shouldn't
be any problem in renaming it.

[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/disallow_type.20vs.20disallowed-types
2021-11-18 17:37:02 +01:00
flip1995
731dfde267
Merge remote-tracking branch 'upstream/master' into rustup 2021-11-18 12:22:00 +01:00
bors
bb58dc84c1 Auto merge of #7968 - Jarcho:manual_map_unsafe, r=xFrednet
Fix `manual_map` with unsafe functions

fixes: #7820
changelog: Fix `manual_map` suggestion when used with unsafe functions and unsafe blocks
2021-11-17 16:20:04 +00:00
bors
6ac42fe6fa Auto merge of #7971 - togami2864:fix/option-map-or-none, r=llogiq
fix suggestion in option_map_or_none

fix: #7960
changelog: change suggestion in the lint rule `option_map_or_none`
2021-11-17 16:01:55 +00:00
togami2864
8e317f5283 fix suggestion message 2021-11-18 00:43:49 +09:00
Jason Newcomb
5f861ee1ae Addition manual_map test for unsafe blocks 2021-11-17 10:39:53 -05:00
bors
d550e5f5e6 Auto merge of #7988 - giraffate:fix_ice_on_undocumented_unsafe_blocks, r=flip1995
Fix ICE on `undocumented_unsafe_blocks`

fix https://github.com/rust-lang/rust-clippy/issues/7979

changelog: Fix ICE on `undocumented_unsafe_blocks`
2021-11-17 15:24:07 +00:00
togami2864
e34927ecf6 add multi-line test case 2021-11-18 00:13:55 +09:00
bors
94ca94fa5f Auto merge of #7898 - F3real:unit_struct, r=camsteffen
Don't show no_effect warning on unit structs implementing fn_once

Fixes #7792

changelog: Don't show [`no_effect`] or [`unecessary_operation`] warning for unit struct implementing FnOnce
2021-11-17 14:09:51 +00:00
Takayuki Nakata
3f3d7c2005 Fix ICE on undocumented_unsafe_blocks 2021-11-17 22:35:01 +09:00
bors
46687f1313 Auto merge of #7896 - surechen:fix_manual_split_once, r=camsteffen
Fix for #7889 and add new lint needless_splitn

fixes: #7889
1. Fix the problem of manual_split_once changing the original behavior.
2. Add a new lint needless_splitn.

changelog: Fix the problem of manual_split_once changing the original behavior and add a new lint needless_splitn.
2021-11-17 01:46:58 +00:00
surechen
c051656c83 fixes: #7889
1. Fix the problem of manual_split_once changing the original behavior.
2. Add a new lint needless_splitn.

changelog: Fix the problem of manual_split_once changing the original behavior and add a new lint needless_splitn.
2021-11-17 08:38:45 +08:00
F3real
e9bf5ec659 Don't show no_effect warning on unit structs implementing fn* traits 2021-11-17 00:50:07 +01:00
bors
83ad51108b Auto merge of #7982 - Blckbrry-Pi:master, r=llogiq
Fix `needless_collect`'s tendency to suggest code requiring multiple mutable borrows of the same value.

Fixes error specified in #7975.

changelog: [`needless_collect`] no longer suggests removal of `collect` when removal would create code requiring mutably borrowing a value multiple times.
2021-11-16 23:01:02 +00:00
Skyler Calaman
5b3c00f012 Successfully generalize prevention of suggestions causing multiple mutable borrows.
Also add some more tests to check that it's working.
2021-11-16 09:18:49 -05:00
Jason Newcomb
2938ffd0d9 Improve heuristics for determining whether eager of lazy evaluation is preferred 2021-11-15 20:54:13 -05:00
Jason Newcomb
8ded385ddc Improve needless_borrow lint.
* Lint when a borrow is auto dereferenced more than once
* Lint when the expression is used as the expression of a block for a match arm

Moves `needless_borrow` and `ref_binding_to_reference` to `dereference`
lint pass in preperation for `explicit_auto_deref` lint.
2021-11-15 13:17:59 -05:00
togami2864
300282c09a fix fmt 2021-11-16 02:53:35 +09:00
togami2864
02e0726149 fix a bug that the closure arguments are not displayed 2021-11-16 02:29:02 +09:00
togami2864
bbffe825ed add reduce_unit_expression 2021-11-16 02:06:31 +09:00