Commit graph

6231 commits

Author SHA1 Message Date
Alex Macleod
124caeb9a2 Fix edition revision ui tests 2022-10-13 11:40:13 +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
bors
45dd9f31f3 Auto merge of #9627 - Jarcho:ice-9625, r=xFrednet
Use the correct type when comparing nested constants.

fixes #9625

changelog: `manual_range_contains`: fix ICE when the values are behind a reference
2022-10-12 18:49:34 +00: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
Yuri Astrakhan
74ba7e1b99 Handle panic! inline_format-arg before ed2021 2022-10-11 21:27:41 -04: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
Jason Newcomb
0cc749296f Use the correct type when comparing nested constants. 2022-10-10 15:33:49 -04:00
bors
cf72565a12 Auto merge of #9610 - Jarcho:fix-9608, r=Alexendoo
Don't suggest moving tuple structs with a significant drop to late evaluation

fixes #9608

changelog: Don't suggest moving tuple structs with a significant drop to late evaluation
2022-10-10 12:29:15 +00: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
Jason Newcomb
39a7d000b6 Don't suggest moving tuple structs with a significant drop to late evaluation. 2022-10-08 11:23:05 -04: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
23b16998c3 Add curlies to scrutinees with side effects 2022-10-06 15:14: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
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
bors
425e1ea73d Auto merge of #9587 - c410-f3r:arith, r=Alexendoo
[arithmetic-side-effects] Do not ignore literal references

To my utter surprise, `rustc` does does not warn stuff like `let n: u8 = &255 + &1` or `let n: u8 = 255 + &1`.

changelog: [arithmetic-side-effects] Do not ignore literal references
2022-10-04 11:05:24 +00:00
bors
2f90b2acbd Auto merge of #9547 - nyurik:capt, r=flip1995
fallout: fix tests to allow uninlined_format_args

In order to switch `clippy::uninlined_format_args` from pedantic to style, all existing tests must not raise a warning. I did not want to change the actual tests, so this is a relatively minor change that:

* add `#![allow(clippy::uninlined_format_args)]` where needed
* normalizes all allow/deny/warn attributes
   * all allow attributes are grouped together
   * sorted alphabetically
   * the `clippy::*` attributes are listed separate from the other ones.
   * deny and warn attributes are listed before the allowed ones

See also https://github.com/rust-lang/rust-clippy/pull/9233, https://github.com/rust-lang/rust-clippy/pull/9525, https://github.com/rust-lang/rust-clippy/pull/9527

cc: `@llogiq` `@Alexendoo`

changelog: none
2022-10-04 07:20:24 +00: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
bors
5825ae7bd4 Auto merge of #9581 - ebobrow:mul-add-negative, r=Manishearth
`suboptimal_flops` lint for multiply and subtract

fixes #9526

changelog: [`suboptimal_flops`] lint for multiply and subtract
2022-10-03 17:12:10 +00:00
royrustdev
f1c831ad17 add implicit_saturating_add lint 2022-10-03 16:46:38 +05:30
Elliot Bobrow
15431b36bb
Merge branch 'master' into mul-add-negative 2022-10-02 21:27:57 -07:00
Elliot Bobrow
7747032b77 suboptimal_flops lint for multiply and subtract 2022-10-02 21:00:51 -07:00
TennyZhuang
bf18768219 let upper_case_acronyms check the enum name
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2022-10-03 10:11:57 +08:00
bors
bef93d3b14 Auto merge of #7962 - Jarcho:fix_match_type_on_diagnostic_items, r=llogiq
Fix and improve `match_type_on_diagnostic_item`

This extracts the fix for the lint out of #7647. There's still a couple of other functions to check, but at least this will get lint working again.

The two added util functions (`is_diagnostic_item` and `is_lang_item`) are needed to handle `DefId` for unit and tuple struct/variant constructors. The `rustc_diagnostic_item` and `lang` attributes are attached to the struct/variant `DefId`, but most of the time they are used through their constructors which have a different `DefId`. The two utility functions will check if the `DefId` is for a constructor and switch to the associated struct/variant `DefId`.

There does seem to be a bug on rustc's side where constructor `DefId`s from external crates seem to be returning `DefKind::Variant` instead of `DefKind::Ctor()`. There's a workaround put in right.

changelog: None
2022-10-02 19:46:46 +00:00
Yuri Astrakhan
eb3970285b fallout: fix tests to allow uninlined_format_args
In order to switch `clippy::uninlined_format_args` from pedantic to
style, all existing tests must not raise a warning. I did not want to
change the actual tests, so this is a relatively minor change that:

* add `#![allow(clippy::uninlined_format_args)]` where needed
* normalizes all allow/deny/warn attributes
   * all allow attributes are grouped together
   * sorted alphabetically
   * the `clippy::*` attributes are listed separate from the other ones.
   * deny and warn attributes are listed before the allowed ones

changelog: none
2022-10-02 15:13:22 -04:00
bors
0341198ba1 Auto merge of #9574 - Alexendoo:unused-fixed, r=Jarcho
Remove unused `.fixed` files, only run asm_syntax doctests on x86

Two small changes, removes some unused `.fixed` and makes `clippy_lints` doctests pass on non x86 arches

changelog: none
2022-10-02 19:06:58 +00:00
Jason Newcomb
162aa19793 Fix and improve internal lint checking for match_type usages
* Check for `const`s and `static`s from external crates
* Check for `LangItem`s
* Handle inherent functions which have the same name as a field
* Also check the following functions:
    * `match_trait_method`
    * `match_def_path`
    * `is_expr_path_def_path`
    * `is_qpath_def_path`
* Handle checking for a constructor to a diagnostic item or `LangItem`
2022-10-02 15:02:55 -04:00
bors
f8ba19287d Auto merge of #9576 - TennyZhuang:unnecessary_cast_for_non_literal_expr, r=llogiq
let unnecessary_cast work for trivial non_literal expressions

Signed-off-by: TennyZhuang <zty0826@gmail.com>

---

changelog: [`unnecessary_cast`]: fix for trivial non_literal expressions

Fixes #9562
2022-10-02 15:26:45 +00:00
bors
11a6d19c59 Auto merge of #9479 - kraktus:manual_assert2, r=llogiq
[`manual_assert`]: Preserve comments in the suggestion

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

changelog: [`manual_assert`]: Preserve comments in the suggestion
2022-10-02 15:13:32 +00:00
TennyZhuang
f2043989ca ignore the lint on some test files
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2022-10-02 23:02:13 +08:00
TennyZhuang
081f73954b let unnecessary_cast work for trivial non_literal expressions
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2022-10-02 23:02:11 +08:00
bors
ac12011315 Auto merge of #9577 - kraktus:unnecessary_cast, r=llogiq
[`unnecessary_cast`] add parenthesis when negative number uses a method

fix #9563

The issue was probably introduced by 90fe3bea52

changelog: [`unnecessary_cast`] add parenthesis when negative number uses a method

r? llogiq
2022-10-02 14:18:41 +00:00
kraktus
3ab02aa359 fix tests 2022-10-02 15:25:50 +02:00
kraktus
a35734c172 revert manual_assert suggestion refactor
Because `Sugg` helper does not simplify multiple negations
2022-10-02 15:03:48 +02:00
kraktus
2c04c1a188 [manual_assert]: Preserve comments in the suggestion 2022-10-02 15:03:48 +02:00
kraktus
90b446fd38 [unnecessary_cast] add parenthesis when negative number uses a method 2022-10-02 14:35:38 +02:00