Commit Graph

8330 Commits

Author SHA1 Message Date
bors
332b5b3d8b Auto merge of #9566 - smoelius:diagnostic-item-path, r=dswij
Expand internal lint `unnecessary_def_path`

This PR does essentially two things:
* Separates the internal lints into modules by pass. (`internal_lints.rs` was over 1400 lines, which is a little unruly IMHO.)
* ~Adds a new~ Expands the `unnecessary_def_path` internal lint to flag hardcoded paths to diagnostic and language items.

My understanding is that the latter is currently done by reviewers. Automating this process should make things easier for both reviewers and contributors.

I could make the first bullet a separate PR, or remove it entirely, if desired.

changelog: Add internal lint `diagnostic_item_path`
2022-10-16 05:56:19 +00:00
bors
eba5ff9d05 Auto merge of #9636 - kraktus:numeric-fallback, r=dswij
[`default_numeric_fallback`] do not lint on constants

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

changelog:[`default_numeric_fallback`] do not lint on constants
2022-10-16 05:32:19 +00:00
Andre Bogus
f8ae2f5807 fix box-default linting no_std non-boxes 2022-10-15 23:19:43 +02:00
kraktus
d38175f271 explicit_ty_bound code golf 2022-10-15 14:57:08 +02:00
Samuel Moelius
5dc54c6066 Format affected files 2022-10-15 07:03:29 -04:00
Samuel Moelius
2e5e3560e9 Fix adjacent code 2022-10-15 07:03:29 -04:00
Samuel Moelius
8611a0bb5c Expand unnecessary_def_path lint 2022-10-15 07:03:29 -04:00
Samuel Moelius
c84ac4cee9 Move some things around 2022-10-15 07:03:29 -04:00
Samuel Moelius
dfd3525cff Separate internal lints by pass 2022-10-15 07:01:44 -04:00
bors
50f192f86a Auto merge of #9649 - Alexendoo:from-over-into-suggestion, r=llogiq
Add a suggestion and a note about orphan rules for `from_over_into`

Adds a machine applicable suggestion to convert the `Into` impl into a `From` one to `from_over_into`

Also adds a note explaining that `impl From<Local> for Foreign` is fine if the `Into` type is foreign

Closes #7444
Addresses half of #9638

changelog: [`from_over_into`] Add a suggestion and a note about orphan rules
2022-10-15 08:37:11 +00:00
Alex Macleod
4b8df8dc92 Add a suggestion and a note about orphan rules for from_over_into 2022-10-14 22:50:23 +00:00
Jason Newcomb
344b7bca86 Don't lint ptr_arg when used as an incompatible trait object 2022-10-14 13:21:59 -04:00
bors
fe3200c038 Auto merge of #9584 - royrustdev:implicit_saturating_sub, r=llogiq
add tests in `implicit_saturating_sub` lint

This adds more tests to the `implicit_saturating_sub` lint to rule out certain false positives that have appeared in the past.

Now with those false positives out of the equation, we can move the lint to `style`.

---

changelog: promote [`implicit-saturating-sub`] to the `style` category
2022-10-13 12:04:23 +00:00
bors
58ef56e39b Auto merge of #9600 - nyurik:inline-fmt-style, r=llogiq
Change uninlined_format_args into a style lint

As [previously discussed](https://github.com/rust-lang/rust-clippy/pull/9233#issuecomment-1256361205), the `uninlined_format_args` should probably be a part of the default style because `println!("{}", foo)` is not as concise or easy to understand as `println!("{foo}")`

changelog: [`uninlined_format_args`]: change to be the default `style`
2022-10-13 11:51:20 +00:00
bors
42bdfa23d3 Auto merge of #9590 - nyurik:fix-parens, r=Alexendoo
Fix to_string_in_format_args in parens

Fix suggestions like

```
print!("error: something failed at {}", (Location::caller().to_string()));
```

where the parenthesis enclose some portion of the value.

Fixes #9540

changelog: [`to_string_in_format_args`]: fix incorrect fix when value is enclosed in parenthesis
2022-10-12 22:53:48 +00:00
Yuri Astrakhan
7717904043 Fix to_string_in_format_args in parens
Fix suggestions like

```
print!("error: something failed at {}", (Location::caller().to_string()));
```

where the parenthesis enclose some portion of the value.
2022-10-12 18:47:49 -04:00
kraktus
36b2685977 refactor default_numeric_fallback
We only need to store if the literal binding has an explicit type bound or not
2022-10-12 23:04:08 +02:00
kraktus
e51e9308d5 default_numeric_fallback do not lint on constants 2022-10-12 22:34:32 +02:00
bors
b8a9a507bf Auto merge of #9617 - llogiq:cast-nan-to-int, r=Alexendoo
add `cast-nan-to-int` lint

This fixes #371.

r? `@Alexendoo`

---

changelog: add [`cast-nan-to-int`] lint
2022-10-12 11:48:30 +00:00
Andre Bogus
e4c80f2bba add cast-nan-to-int lint 2022-10-12 13:29:27 +02:00
royrustdev
31006b4227 update Applicability of rc_buffer from MachineApplicable to
`Unspecified`
2022-10-12 16:41:48 +05:30
royrustdev
ac6d2ba11e add tests in implicit_saturating_sub lint 2022-10-12 09:28:17 +05:30
Yuri Astrakhan
74ba7e1b99 Handle panic! inline_format-arg before ed2021 2022-10-11 21:27:41 -04:00
bors
854015c33c Auto merge of #9629 - est31:let_else, r=Jarcho
Replace manual let else patterns with let else

Clears the codebase from places where the lint added by #8437 is firing, by adopting let else.

changelog: none
2022-10-11 14:26:04 +00:00
bors
8e87d39f99 Auto merge of #9572 - Nilstrieb:as-ptr-cast-mut, r=dswij
Add `as_ptr_cast_mut` lint

This lint detects calls to a `&self`-taking `as_ptr` method, where the result is then immediately cast to a `*mut T`. Code like this is probably invalid, as that pointer will not have write permissions, and `*mut T` is usually used to write through.

Examples of broken code with this pattern:
https://miri.saethlin.dev/ub?crate=lol_alloc&version=0.1.3
https://miri.saethlin.dev/ub?crate=sophon-wasm&version=0.19.0
https://miri.saethlin.dev/ub?crate=polars-core&version=0.24.2
https://miri.saethlin.dev/ub?crate=ach-cell&version=0.1.17

changelog: Add [`as_ptr_cast_mut`]
2022-10-11 08:08:17 +00:00
est31
f48d13f8d1 Replace manual let else patterns with let else 2022-10-11 00:12:16 +02:00
bors
272bbfb857 Auto merge of #9386 - smoelius:further-enhance-needless-borrow, r=Jarcho
Further enhance `needless_borrow`, mildly refactor `redundant_clone`

This PR does the following:
* Moves some code from `redundant_clone` into a new `clippy_utils` module called `mir`, and wraps that code in a function called `dropped_without_further_use`.
* Relaxes the "is copyable" condition condition from #9136 by also suggesting to remove borrows from values dropped without further use. The changes involve the just mentioned function.
* Separates `redundant_clone` into modules.

Strictly speaking, the last bullet is independent of the others. `redundant_clone` is somewhat hairy, IMO. Separating it into modules makes it slightly less so, by helping to delineate what depends upon what.

I've tried to break everything up into digestible commits.

r? `@Jarcho`

(`@Jarcho` I hope you don't mind.)

changelog: continuation of #9136
2022-10-08 21:24:54 +00:00
bors
292e313259 Auto merge of #9451 - kraktus:manual_filter2, r=dswij
Add `manual_filter` lint for `Option`

Share much of its implementation with `manual_map` and should greatly benefit from its previous feedback.
I'm sure it's possible to even more refactor both and would gladly take input on that as well as any clippy idiomatic usage, since this is my first lint addition.

I've added the lint to the complexity section for now, I don't know if every new lint needs to go in nursery first.

The matching could be expanded to more than `Some(<value>)` to lint on arbitrary struct matching inside the `Some` but I've left it like it was for `manual_map` for now. `needless_match::pat_same_as_expr` provides a more generic match example.

close https://github.com/rust-lang/rust-clippy/issues/8822

changelog: Add lint [`manual_filter`] for `Option`
2022-10-08 15:58:51 +00:00
bors
2c8e473ffe Auto merge of #9585 - rust-lang:extend-box-default, r=Alexendoo
extend `box-default` lint, add suggestion

This extends the recently added `box-default` lint to also cover `Box::new(vec![])`, `Box::new(String::from(""))` and `Box::new(Vec::from([]))`. Also the lint now suggests a suitable replacement. I did not find a simple way to check whether the type is fully determined by the outside, so I at least checked for some variations to remove the turbofish in those cases.

---

changelog: none
2022-10-07 14:49:54 +00:00
Samuel Moelius
9cc8da222b Fix adjacent code 2022-10-07 05:07:44 -04:00
Samuel Moelius
037f698147 needless_borrow uses used_exactly_once 2022-10-07 05:07:44 -04:00
bors
65ae6666c8 Auto merge of #9595 - Alexendoo:author-let-chains, r=Jarcho
Replace if_chain with let chains in `clippy::author` output

Should help nudge new contributors towards let chains

changelog: none
2022-10-07 02:52:47 +00:00
Evan Typanski
39164acf6e Fix flipped variable that made it through 2022-10-06 15:36:28 -04:00
Evan Typanski
23b16998c3 Add curlies to scrutinees with side effects 2022-10-06 15:14:55 -04:00
Yuri Astrakhan
493684888f Change uninlined_format_args into a style lint 2022-10-06 12:12:55 -04:00
bors
8f1ebdd18b Auto merge of #9593 - Andy-Python-Programmer:master, r=llogiq
lint::unsafe_removed_from_name: fix false positive result when allowed

changelog: [`unsafe_removed_from_name`] Fix allowing on imports produces a false positive on `useless_attribute`.

Fixes: #9197

Signed-off-by: Andy-Python-Programmer <andypythonappdeveloper@gmail.com>
2022-10-06 14:39:26 +00:00
Andre Bogus
d3c041a086 extend box-default lint, add suggestion 2022-10-06 16:00:45 +02:00
Yuri Astrakhan
cfd6c8d19d Add a temporary workaround for multiline formart arg inlining
per suggestion in
https://github.com/rust-lang/rust/pull/102729#discussion_r988990080

workaround for an internal crash when handling multi-line format
argument inlining.
2022-10-06 09:24:57 -04:00
Yuri Astrakhan
c251f8d8dd lint: fix a few comments 2022-10-06 08:54:07 -04:00
Philipp Krones
e2808afd60
Merge remote-tracking branch 'upstream/master' into rustup 2022-10-06 09:19:29 +02:00
Alex Macleod
9e70a0ff12 Replace if_chain with let chains in clippy::author output 2022-10-05 17:21:32 +00:00
bors
887ba0c5a4 Auto merge of #9586 - Alexendoo:format-args-commas, r=Manishearth
FormatArgsExpn: Find comma spans and ignore weird proc macro spans

Fixes the following cases:

A missing `, 1` from the `expect_fun_call` suggestion:

```rust
Some(()).expect(&format!("{x} {}", 1));
```
```
warning: use of `expect` followed by a function call
 --> t.rs:7:14
  |
7 |     Some(()).expect(&format!("{x} {}", 1));
  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{x} {}"))`
```

The suggestion removing from the comma in the comment rather than the one after the format string:

```rust
println!(
    "{}",
    // a comment, with a comma in it
    x
);
```
```
warning: variables can be used directly in the `format!` string
  --> t.rs:9:5
   |
9  | /     println!(
10 | |         "{}",
11 | |         // a comment, with a comma in it
12 | |         x
13 | |     );
   | |_____^
   |
help: change this to
   |
10 ~         "{x}",
11 ~         // a comment
   |
```

It also no longer accepts expansions where a format string or argument has a "weird" proc macro span, that is one where the literal/expression it outputs has the span of one of its inputs. Kind of like a `format_args` specific `clippy_utils::is_from_proc_macro`, e.g. `format!(indoc! {" ... "})`

changelog: [`expect_fun_call`]: Fix suggestion for `format!` using captured variables
changelog: [`print_literal`], [`write_literal`], [`uninlined_format_args`]: Fix suggestion when following a comment including a comma
2022-10-05 16:27:03 +00:00
Alex Macleod
9226066bcb FormatArgsExpn: Find comma spans and ignore weird proc macro spans 2022-10-05 16:10:52 +00:00
Alex Macleod
86c86c3742 Add disallowed_macros lint 2022-10-05 13:44:06 +00:00
Andy-Python-Programmer
14f9f2b69d
lint::unsafe_removed_from_name: fix false positive result when allowed
* Allowing `unsafe_removed_from_name` on imports produces a false
positive on `useless_attribute`.

Fixes: #9197

Signed-off-by: Andy-Python-Programmer <andypythonappdeveloper@gmail.com>
2022-10-05 18:59:01 +11:00
Oli Scherer
da16cc1da9 It's not about types or consts, but the lack of regions 2022-10-04 14:10:44 +00:00
Caio
a44914fcd3 Dogfood 2022-10-03 20:10:00 -03:00
Caio
2a6a98f95b [arithmetic-side-effects] Do not ignore literal references 2022-10-03 19:49:03 -03:00
bors
e8c1b5478c Auto merge of #9559 - c410-f3r:arith, r=Alexendoo
Fix #9544

Fix #9544

r? `@Alexendoo`

changelog: [`arithmetic_side_effects`]: Fix false negative for `CustomType / usize`, `CustomType * float` and similar
2022-10-03 21:54:08 +00:00
Caio
99363fef65 Address comments 2022-10-03 18:36:12 -03:00