Commit graph

16687 commits

Author SHA1 Message Date
Icxolu
220a9db642 fixed span and corrected test output 2023-05-01 20:12:34 +02:00
Icxolu
032bc11fd4
fix diagnostic message style
Co-authored-by: Ruby Lazuli <general@patchmixolydic.com>
2023-04-29 21:11:34 +02:00
Icxolu
9428138562 adds lint to detect construction of unit struct using default
Using `default` to construct a unit struct increases code complexity and
adds a function call. This can be avoided by simply removing the call to
`default` and simply construct by name.
2023-04-26 21:12:59 +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
Philipp Krones
d5a2c2ba71
Bump nightly version -> 2023-04-23 2023-04-23 03:39:29 -07:00
Philipp Krones
0add5bb0f1
Bump Clippy version -> 0.1.71 2023-04-23 03:39:19 -07:00
Philipp Krones
583c97e9bb
Merge remote-tracking branch 'upstream/master' into rustup 2023-04-23 03:39:03 -07:00
bors
419552227f Auto merge of #10701 - blyxyas:fix-fp-let_underscore_untyped, r=llogiq
Bugfix: Ignore `impl Trait`(s) @ `let_underscore_untyped`

Fixes #10411

changelog:[`let_underscore_untyped`]: Ignore `impl Trait`(s) that caused false positives.
2023-04-23 10:13:41 +00:00
blyxyas
bdd05456b1
Ignore impl Trait(s) 2023-04-23 12:09:36 +02:00
bors
9a337784c6 Auto merge of #10688 - klensy:no-semver, r=flip1995
clippy: drop unused semver crate

Drop unused `semver` crate dependency.

changelog: none
2023-04-23 10:00:44 +00:00
bors
6328371d24 Auto merge of #10681 - J-ZhengLi:issue10529, r=flip1995
make [`len_zero`] lint not spanning over parenthesis

sorry it should be a quick fix but I was caught up by other stuffs last couple weeks 🤦‍♂️

---

fixes: #10529

changelog: make [`len_zero`] lint not spanning over parenthesis
2023-04-23 09:50:16 +00:00
bors
982423473a Auto merge of #10696 - Alexendoo:allow-enum-variant-names, r=flip1995
Fix `#[allow(clippy::enum_variant_names)]` directly on variants

changelog: [`enum_variant_names`]: Fix `#[allow]` attributes applied directly to the enum variant

Fixes #10695
2023-04-23 09:39:10 +00:00
Renato Lochetti
628605e07a
Ignore shadow warns in code from macro expansions 2023-04-22 20:28:08 +01:00
blyxyas
1ac8dc51bc
Compact emmited lint 2023-04-22 21:12:55 +02:00
blyxyas
0354cee137
Add lint items_after_test_module 2023-04-22 21:12:45 +02:00
Alex Macleod
397f36a78c Fix #[allow(clippy::enum_variant_names)] directly on variants 2023-04-22 14:53:15 +00:00
bors
f30fc0a5e2 Auto merge of #104844 - cjgillot:mention-eval-place, r=jackh726,RalfJung
Evaluate place expression in `PlaceMention`

https://github.com/rust-lang/rust/pull/102256 introduces a `PlaceMention(place)` MIR statement which keep trace of `let _ = place` statements from surface rust, but without semantics.

This PR proposes to change the behaviour of `let _ =` patterns with respect to the borrow-checker to verify that the bound place is live.

Specifically, consider this code:
```rust
let _ = {
    let a = 5;
    &a
};
```

This passes borrowck without error on stable. Meanwhile, replacing `_` by `_: _` or `_p` errors with "error[E0597]: `a` does not live long enough", [see playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c448d25a7c205dc95a0967fe96bccce8).

This PR *does not* change how `_` patterns behave with respect to initializedness: it remains ok to bind a moved-from place to `_`.

The relevant test is `tests/ui/borrowck/let_underscore_temporary.rs`. Crater check found no regression.

For consistency, this PR changes miri to evaluate the place found in `PlaceMention`, and report eventual dangling pointers found within it.

r? `@RalfJung`
2023-04-22 09:54:21 +00:00