Commit graph

9322 commits

Author SHA1 Message Date
Samuel "Sam" Tardieu
c5d4b04dd5 needless_bool: do not simplify code if it loses comments 2023-05-10 21:19:24 +02:00
bors
1407c7627e Auto merge of #10751 - blyxyas:explain_with_config, r=xFrednet
Add configuration options to `--explain`

This PR rearranges some modules, taking `metadata_collector` out of `internal_lints` and making public just the necessary functions for `explain()` to use.

The output looks something like this:
```sh
$ cargo run --bin cargo-clippy --manifest-path ../rust-clippy/Cargo.toml -- --explain cognitive_complexity
### What it does
Checks for methods with high cognitive complexity.

### Why is this bad?
Methods of high cognitive complexity tend to be hard to
both read and maintain. Also LLVM will tend to optimize small methods better.

### Known problems
Sometimes it's hard to find a way to reduce the
complexity.

### Example
You'll see it when you get the warning.

========================================
Configuration for clippy::cognitive_complexity:
- cognitive-complexity-threshold: The maximum cognitive complexity a function can have (default: 25)
```

Fixes #9990
r? `@xFrednet`

---

changelog: Docs: `cargo clippy --explain LINT` now shows possible configuration options for the explained lint
[#10751](https://github.com/rust-lang/rust-clippy/pull/10751)
<!-- changelog_checked -->
2023-05-09 18:41:30 +00:00
blyxyas
3e8fea612d
Fix config formatting, less indenting, more spacing 2023-05-09 20:35:03 +02:00
bors
77e4d7a839 Auto merge of #10727 - john-h-k:lint/dup-auto-traits, r=Manishearth
Extend `trait_duplication_in_bounds` to cover trait objects

This PR extends `trait_duplication_in_bounds` to cover trait objects.

Currently,
```rs
fn foo(_a: &(dyn Any + Send + Send)) {}
```

generates no warnings. With this PR, it will complain about a duplicate trait and can remove it

Moved from rust-lang/rust#110991

changelog: [`trait_duplication_in_bounds`]: warn on duplicate trait object constraints
2023-05-09 13:46:18 +00:00
John Kelly
b169bdb732 Comments 2023-05-09 10:06:38 +01:00
bors
d696f3b652 Auto merge of #10584 - blyxyas:fix-wildcard_imports_testsrs, r=flip1995
fix: `wildcard_imports` ignore `test.rs` files

Adds a check to see if the building crate is a test one, if so, ignore it

---

Closes #10580
changelog:[`wildcard_imports`]: Add a check to ignore files named `test.rs` and `tests.rs`
2023-05-08 16:46:23 +00:00
blyxyas
4c3e2ff2a4
Fix header 2023-05-08 18:38:41 +02:00
bors
90ce1a2e7c Auto merge of #10761 - lochetti:fix_9871, r=Manishearth
Ignore `borrow_deref_ref` warnings in code from procedural macros.

Don't linting `borrow_deref_ref` if code was generated by procedural macro.

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

changelog: [`borrow_deref_ref`] avoiding warnings in macro-generated code
2023-05-08 16:29:02 +00:00
blyxyas
ba0e7e88cb
Now the lint ignores any crates with --cfg test 2023-05-08 18:24:59 +02:00
blyxyas
5acc2993e7
Really mini minor irrelevant change for formatting 2023-05-08 18:24:59 +02:00
blyxyas
54912410c7
Wildcard_imports ignore test.rs files 2023-05-08 18:24:58 +02:00
bors
e66488a669 Auto merge of #10757 - cakebaker:add_missing_word, r=Jarcho
Add missing word "are"

changelog: none
2023-05-08 15:43:18 +00:00
NotAPenguin
56e8e1a27d new lint: clippy::ref_patterns 2023-05-08 13:20:33 +02:00
Renato Lochetti
394b4c1906
Ignore borrow_deref_ref warnings in code from procedural macros. 2023-05-07 12:35:17 +01:00
John Kelly
5c8a00923b Comments 2023-05-07 10:10:44 +01:00
Daniel Hofstetter
f4b8cb1b28
Add missing word "are" 2023-05-06 16:21:45 +02:00
blyxyas
2a4571d959
Minimizing changes 2023-05-06 08:38:47 +02:00
Alex Macleod
68eb864c91 Ignore expressions from macros in default_constructed_unit_structs 2023-05-05 18:35:54 +00:00
Philipp Krones
88c7632659
Merge remote-tracking branch 'upstream/master' into rustup 2023-05-05 17:29:35 +02:00
bors
8518391e72 Auto merge of #110806 - WaffleLapkin:unmkI, r=lcnr
Replace `tcx.mk_trait_ref` with `TraitRef::new`

First step in implementing https://github.com/rust-lang/compiler-team/issues/616
r? `@lcnr`
2023-05-04 05:54:09 +00:00
bors
f9c1d155b4 Auto merge of #10716 - Icxolu:unitstruct_default_construction, r=Manishearth
Fixes #10609: 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.

changelog: [`default_constructed_unit_structs`]: detects construction of unit structs using `default`

fixes #10609
2023-05-03 21:43:02 +00:00
Icxolu
48ae5a071b fix lint docs 2023-05-03 21:43:10 +02:00
Icxolu
8701009860 add more test cases 2023-05-03 20:55:14 +02:00
Icxolu
4e04903631 rename to plural form 2023-05-03 19:25:25 +02:00
bors
9353170dfb Auto merge of #10730 - blyxyas:no_std_mul_add, r=Jarcho
`imprecise_flops`: Globally ignore `#[no_std]` crates

Really small fix.
Fixes #10728
changelog: [`imprecise_flops`]: Fix false positives with `#[no_std]`
2023-05-03 01:47:52 +00:00
Nicholas Nethercote
431cce1540 Restrict From<S> for {D,Subd}iagnosticMessage.
Currently a `{D,Subd}iagnosticMessage` can be created from any type that
impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static,
str>`, which are reasonable. It also includes `&String`, which is pretty
weird, and results in many places making unnecessary allocations for
patterns like this:
```
self.fatal(&format!(...))
```
This creates a string with `format!`, takes a reference, passes the
reference to `fatal`, which does an `into()`, which clones the
reference, doing a second allocation. Two allocations for a single
string, bleh.

This commit changes the `From` impls so that you can only create a
`{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static,
str>`. This requires changing all the places that currently create one
from a `&String`. Most of these are of the `&format!(...)` form
described above; each one removes an unnecessary static `&`, plus an
allocation when executed. There are also a few places where the existing
use of `&String` was more reasonable; these now just use `clone()` at
the call site.

As well as making the code nicer and more efficient, this is a step
towards possibly using `Cow<'static, str>` in
`{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing
the `From<&'a str>` impls to `From<&'static str>`, which is doable, but
I'm not yet sure if it's worthwhile.
2023-05-03 08:44:39 +10:00
blyxyas
0dd2501e0d
Don't ignore check_radians 2023-05-02 20:47:18 +02:00
John Kelly
122793b494 Update trait_bounds.rs 2023-05-02 18:21:23 +01:00
John Kelly
cbd0135bd2 Update trait_bounds.rs 2023-05-02 18:15:02 +01:00
Dylan DPC
eac589b4e4 Rollup merge of #110955 - fee1-dead-contrib:sus-operation, r=compiler-errors
uplift `clippy::clone_double_ref` as `suspicious_double_ref_op`

Split from #109842.

r? ``@compiler-errors``
2023-05-02 11:44:52 +05:30
bors
824f2e701c Auto merge of #10724 - lukaslueg:largeerrdocs, r=giraffate
Clarify docs for `RESULT_LARGE_ERR`

Adds a paragraph to address https://github.com/rust-lang/rust-clippy/issues/10211#issuecomment-1521548238

changelog: [`result_large_err`]: Update the document
2023-05-02 00:41:36 +00:00
Icxolu
220a9db642 fixed span and corrected test output 2023-05-01 20:12:34 +02:00
blyxyas
5749054241
globally ignore #[no_std] crates 2023-05-01 12:39:20 +02:00
John Kelly
b9788fef29 Working 2023-04-30 14:34:46 +01:00
John Kelly
8db21e9a9c WIP 2023-04-30 14:14:47 +01:00
John Kelly
0fb3f3b256 WIP 2023-04-30 14:10:26 +01:00
John Kelly
1eff408ca4 WIP 2023-04-30 13:45:45 +01:00
John Kelly
478555d468 wip 2023-04-30 13:16:04 +01:00
Icxolu
032bc11fd4
fix diagnostic message style
Co-authored-by: Ruby Lazuli <general@patchmixolydic.com>
2023-04-29 21:11:34 +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
Lukas Lueg
2ed254e29f Clarify docs for RESULT_LARGE_ERR 2023-04-29 14:18:31 +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
f37054b396
Remove useless span magic 2023-04-28 20:19:36 +02:00
Deadbeef
81a614145f uplift clippy::clone_double_ref as suspicious_double_ref_op 2023-04-28 17:24:48 +00:00
Michael Goulet
83504fa763 Make clippy happy 2023-04-27 17:18:12 +00:00