Commit graph

16700 commits

Author SHA1 Message Date
John Kelly
478555d468 wip 2023-04-30 13:16:04 +01:00
bors
7bc3da975a Auto merge of #10647 - y21:while_pop_unwrap, r=llogiq
new lint: `manual_while_let_some`

This PR implements the lint I suggested [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/lint.20on.20while.20pop.20unwrap).
It looks for while loops like these:
```rs
let mut numbers = vec![0, 1, 2];
while !numbers.is_empty() {
  let number = numbers.pop().unwrap();
  // use `number`
}
```
and suggests replacing it with a while-let loop, like this:
```rs
let mut numbers = vec![0, 1, 2];
while let Some(number) = numbers.pop() {
  // use `number`
}
```
... which is more concise and idiomatic.

It only looks for `Vec::pop()` calls in the first statement of the loop body in an attempt to not trigger FPs (as pop might only be called conditionally).

changelog: new lint [`manual_while_let_some`]
2023-04-29 17:57:25 +00:00
y21
9613ea85c6 fix run-rustfix directive 2023-04-29 19:10:52 +02:00
y21
8d8178f931 rename lint to manual_while_let_some 2023-04-29 18:59:07 +02:00
y21
f10e39fd2b make PopStmt copy+clone 2023-04-29 18:59:07 +02:00
y21
ab9b7a5ad2 remove unnecessary reference 2023-04-29 18:59:07 +02:00
y21
1d08325293 move lint to loops, emit proper suggestion, more tests 2023-04-29 18:59:07 +02:00
y21
bcdcc34ba9 elide lifetimes, get rid of glob import 2023-04-29 18:59:06 +02:00
y21
bb58083ce5 new lint: while_pop_unwrap 2023-04-29 18:59:06 +02:00
bors
3594d55439 Auto merge of #10719 - blyxyas:fix-items_after_test_mod_imported_modules, r=Alexendoo
Fix `items_after_test_module`: Ignore imported modules

Fixes #10713. It does a little bit of dark magic, but intention is what really counts.
changelog:[`items_after_test_module`]: Ignore imported modules (`mod foo;`) with no body.
2023-04-28 18:42:58 +00:00
blyxyas
395b1f5bf3
Rename items + Delete imported_module.stderr 2023-04-28 20:40:47 +02:00
blyxyas
2b5820d58b
Change module import system 2023-04-28 20:23:05 +02:00
blyxyas
f37054b396
Remove useless span magic 2023-04-28 20:19:36 +02:00
bors
b7939f4d6c Auto merge of #10720 - SergenKaraoglan:personal, r=flip1995
run linkcheck in clippy ci

fixes #10711

changelog: Run [linkcheck.sh](https://github.com/rust-lang/rust/blob/master/src/tools/linkchecker/linkcheck.sh) from rustc repo in Remark.yml to check Clippy book.
2023-04-28 14:21:48 +00:00
Sergen Karaoglan
d1f55e6b53 run linkcheck in Remark CI
fix new lints link

install nightly rust-docs

run linkcheck without nightly toolchain

remove nightly toolchain, add rust-docs component

Test Remark

Update basics.md

Update basics.md

Update basics.md

update workflow

add rust docs toolchain

Update remark.yml

workflow test

manual test

update book path

add linkcheck book to CI

Update lint_passes.md
2023-04-28 15:11:48 +01:00
blyxyas
273c898aef
Fix #10713 and move the tests to a subdir 2023-04-27 16:43:51 +02:00
bors
990bbdc2be Auto merge of #10656 - Centri3:master, r=xFrednet
Add configuration for `semicolon_block` lints

Does exactly what it says on the tin, suggests moving a block's final semicolon inside if it's multiline and outside if it's singleline.

I don't really like how this is implemented so I'm not too sure if this is ready yet. Alas, it might be ok.

---

fixes #10654

changelog: Enhancement: [`semicolon_inside_block`]: Added `semicolon-inside-block-ignore-singleline` as a new config value.
[#10656](https://github.com/rust-lang/rust-clippy/pull/10656)
changelog: Enhancement: [`semicolon_outside_block`]: Added `semicolon-outside-block-ignore-multiline` as a new config value.
[#10656](https://github.com/rust-lang/rust-clippy/pull/10656)
<!-- changelog_checked -->
2023-04-25 20:12:00 +00:00
Centri3
8c8cf40707 Update lint_configuration.md 2023-04-25 14:44:56 -05:00
bors
a7335cbf90 Auto merge of #10712 - blyxyas:fix-fixflag_implies_all_targets, r=llogiq
Document that `cargo clippy --fix` implies `--all-targets`

In [`cargo fix`'s documentation](https://doc.rust-lang.org/cargo/commands/cargo-fix.html) they indicate that `fix` implies `--all-targets` if no target is supplied. As Clippy uses Cargo under the hood, this also applies to Clippy, but we didn't document that behaviour.

This PR changes that

Fixes #10690
changelog: Add to documentation that `--fix` implies `--all-targets`
2023-04-25 17:11:52 +00:00
bors
19465c9a36 Auto merge of #10715 - xFrednet:changelog-1-69, r=llogiq
Catching, stray, commas, (I'll, never, learn, to, use, them, correctly)  😅

Roses are red,
Violets are blue,
Fixing commas,
Is the completed todo.

(It's always impressive, that the poems are getting worse)

---

Follow-up from: https://github.com/rust-lang/rust-clippy/pull/10668

changelog: none
2023-04-25 16:39:57 +00:00
Centri3
e3ee10d428 use //@ for commands in tests 2023-04-25 11:23:02 -05:00
Centri3
aa6c27a74e change names to not be implicitly negative 2023-04-25 11:14:52 -05:00
xFrednet
637d10b292
Catching, stray, commas, (I'll, never, learn, to, use, them, correctly) 😅 2023-04-25 17:33:27 +02:00
bors
abd2c1e8e4 Auto merge of #10665 - Centri3:string_lit_as_bytes_changes, r=giraffate
Don't apply `string_lit_as_bytes` if in macro expansion

The following code will emit a warning on both w! and h!, despite there being nothing the user (or library author) could do about it:
```rust
#![warn(clippy::string_lit_as_bytes)]

use windows::w;
use windows::h;

fn main() {
    let _w = w!("example");
    let _h = h!("example");
}
```
This is because windows-rs will create a binding `const INPUT: &[u8] = $s.as_bytes()`, and changing this to b"$s" is, well, suboptimal. I don't know enough about Rust to know if this is something that can be detected though if it can be I'm happy with closing this in favor of implementing that.

I'm not sure whether this is how it should be done though, as this simply tells clippy to not invoke this even if it's applicable (this also affects the other string lints, but didn't cause any tests to fail).

changelog: [`string_lit_as_bytes`]: Don't lint if in external macro
2023-04-25 13:02:52 +00:00
Centri3
14a6fa4a34 use in_external_macro 2023-04-25 05:06:45 -05:00
Centri3
1ac30d3c86 make cargo test pass 2023-04-25 05:06:11 -05:00
Centri3
8efe9ff9fb run cargo dev fmt 2023-04-25 05:06:11 -05:00
Centri3
acfb2c45ba don't check if from macro invocation 2023-04-25 05:06:11 -05:00
blyxyas
4a76b6f04f
Add the warning to all documentation. 2023-04-25 02:05:32 +02:00
bors
c4f2c48d9b Auto merge of #10702 - blyxyas:fix-let_underscore_untyped_help_message, r=Manishearth
Improve the help message + add a help span

This would close #10410, because it applies the general consensus achieved in that issue (that replacing `let _ = ...` to `_ = ...` doesn't present any benefits).

I also added a little help message span.

changelog:[`let_underscore_untyped`]: Fix the help message confusion + add a help message span.
2023-04-24 20:28:34 +00:00
bors
30db6edf36 Auto merge of #10707 - y21:redudant_pattern_matching_rest_pat, r=Manishearth
check for `..` pattern in `redundant_pattern_matching`

The `redundant_pattern_matching` lint currently checks for `if let Some(_) = ...`, but not for `if let Some(..) = ...`.
This PR makes sure to also check for the `..` pattern in tuple structs.
It also found one such instance in clippy itself so that shows it's worth checking for this pattern as well 😅

changelog: [`redundant_pattern_matching`]: check for `..` pattern in tuple structs
2023-04-24 19:33:53 +00:00
bors
4b6fdb4dff Auto merge of #10683 - Centri3:allow-attributes, r=Alexendoo
Fix false positive in `allow_attributes`

This would emit a warning if used in a proc-macro with the feature `lint_reasons` enabled. This is now fixed.

changelog: [`allow_attributes`]: Don't lint if in external macro
2023-04-24 17:52:17 +00:00
Centri3
3045998bcc Update allow_attributes_false_positive.rs 2023-04-24 12:01:29 -05:00
bors
5161c4ce4d Auto merge of #10697 - lochetti:fix_9757, r=dswij
Ignore `shadow` warns in code from macro expansions

This PR fixes https://github.com/rust-lang/rust-clippy/issues/9757

I am in doubt if just looking for `pat.span.from_expansion()` would be sufficient instead of looking for both `pat.span.desugaring_kind().is_some()` or `pat.span.from_expansion()`. The tests (including the new one) passes if I leave the only `if pat.span.from_expansion()`. Any feedbacks?

Also, this is my first PR here, sorry for anything and thanks for the patience!

changelog: [`shadow_same`, `shadow_reuse`, `shadow_unrelated`]: avoiding warns in macro-generated code
2023-04-24 06:25:52 +00:00
bors
96f8471d81 Auto merge of #10649 - jsoref:spelling, r=Jarcho
Spelling

This PR corrects misspellings identified by the [check-spelling action](https://github.com/marketplace/actions/check-spelling).

The misspellings have been reported at https://github.com/jsoref/rust-clippy/actions/runs/4710771873#summary-12776860721

The action reports that the changes in this PR would make it happy: https://github.com/jsoref/rust-clippy/actions/runs/4710771874#summary-12776860722

changelog: none
2023-04-23 22:30:06 +00:00
y21
e8726b20b2 also check for rest pat in redundant_pattern_matching 2023-04-23 21:34:42 +02:00
bors
7a870aef1a Auto merge of #10432 - samueltardieu:issue-10430, r=Manishearth
New lint: detect `if` expressions with simple boolean assignments to the same target

Closes #10430

changelog: [`needless_bool_assign`] new lint to detect simple boolean assignment to the same target in `if` branches
2023-04-23 15:47:00 +00:00
Josh Soref
6f7801f810 Rewrite search_same description 2023-04-23 10:53:06 -04:00
Josh Soref
d2061faf9e Spelling
* applying
* binding
* complex
* constituent
* demonstrate
* desugaring
* exact
* expression
* for
* functionalities
* github
* implementation
* infers
* multiple conflicting traits
* mutable
* necessarily
* nightly
* nonexistent
* optional
* parameter
* reassignments
* resources
* substitution
* suggestion
* that
* that array is
* using the

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-23 10:52:27 -04:00
bors
797a7fed67 Auto merge of #10706 - Alexendoo:remove-old-generated-files-check, r=llogiq
Remove check for `lib.register_*` and `src/docs*` in `cargo dev update_lints`

The transition period has well passed

changelog: none
2023-04-23 14:39:07 +00:00
Alex Macleod
022baa5ce3 Remove check for lib.register_* and src/docs* in cargo dev update_lints
This reverts commit 22d435b266.
2023-04-23 14:25:19 +00:00
bors
e1f6305ecf Auto merge of #10704 - matthiaskrgr:splitest, r=llogiq
split test into 2

changelog: none
2023-04-23 13:44:57 +00:00
bors
496c11005c Auto merge of #10679 - y21:better-const-ctx-check, r=Jarcho
use `is_inside_const_context` for `in_constant` util fn

Fixes #10452.

This PR improves the `in_constant` util function to detect more cases of const contexts. Previously this function would not detect cases like expressions in array length position or expression in an inline const block `const { .. }`.

changelog: [`bool_to_int_with_if`]: recognize array length operand as being in a const context and don't suggest `usize::from` there
2023-04-23 13:33:51 +00:00
bors
316d83a4d8 Auto merge of #10670 - lukaslueg:issue10634, r=Jarcho
Don't suggest `suboptimal_flops` unavailable in nostd

Fixes #10634

changelog: Enhancement: [`suboptimal_flops`]: Do not suggest `{f32,f64}::abs()` or `{f32,f64}::mul_add()` in a `no_std`-environment.
2023-04-23 13:23:48 +00:00
Matthias Krüger
572eecd267 split test into 2 2023-04-23 15:11:31 +02:00
Samuel Tardieu
69da902f41 Detect if expressions with boolean assignments to the same target 2023-04-23 13:44:49 +02:00
bors
f16bfa478f Auto merge of #10703 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2023-04-23 11:07:14 +00:00
bors
a3ed905928 Auto merge of #10578 - blyxyas:items_after_test_module, r=dswij
Add `items_after_test_module` lint

Resolves task *3* of #10506, alongside *1* resolved at #10543 in an effort to help standarize a little bit more testing modules.

---

changelog:[`items_after_test_module`]: Added the lint.
2023-04-23 10:56:50 +00:00
blyxyas
acf50a7dc6
Improve the help message + add a help span 2023-04-23 12:52:45 +02:00
Philipp Krones
36bf3ef004
Fix dogfood test 2023-04-23 03:44:24 -07:00