Commit graph

6822 commits

Author SHA1 Message Date
bors
e0b25c5a64 Auto merge of #11998 - cocodery:fix/issue11762, r=llogiq
Check whether out of bound when access a known length array with a constant index

fixes [Issue#11762](https://github.com/rust-lang/rust-clippy/issues/11762)

Issue#11762 points that `Array references with known length are not flagged when indexed out of bounds`.

To fix this problem, it is needed to add check for `Expr::Index`. We expand this issue include reference and direct accessing a array.

When we access a array with a constant index `off`, and already know the length `size`, if `off >= size`, these code will throw an error, instead rustc's lint checking them or runtime panic happening.

changelog: [`out_of_bound_indexing`]: Add check for illegal accessing known length array with a constant index
2023-12-22 17:01:17 +00:00
cocodery
18eb406776 Add test for indexing_slicing_index and modify related test 2023-12-22 20:31:48 +08:00
J-ZhengLi
a556d00c0a stop [bool_comparison]'s suggestion from consuming parentheses 2023-12-21 18:20:25 +08:00
Quinn Sinclair
25b9ca3f64 New lints iter_filter_is_some and iter_filter_is_ok
Adds a pair of lints that check for cases of an iterator over `Result`
and `Option` followed by `filter` without being followed by `map` as
that is covered already by a different, specialized lint.

changelog: New Lint: [`iter_filter_is_some`]
changelog: New Lint: [`iter_filter_is_ok`]
2023-12-21 00:16:47 +02:00
Jules Bertholet
4ab8cdd5b9 Hide foreign #[doc(hidden)] paths in import suggestions 2023-12-20 00:19:45 -05:00
Guillaume Gomez
238c5f9f27 Add ui tests for UNNECESSARY_TO_OWNED on split 2023-12-18 16:55:42 +01:00
bors
dd857f8207 Auto merge of #11966 - StackOverflowExcept1on:issue-8159, r=Jarcho
Do not lint `assertions_on_constants` for `const _: () = assert!(expr)`

Fixes #8159

```rust
pub fn f() {
    // warning
    assert!(true);
    assert!(usize::BITS >= 32);

    // ok
    const _: () = assert!(usize::BITS >= 32);
}
```

changelog: Fix `const _: () = assert!(expr)` false positive on `assertions_on_constants` lint
2023-12-17 14:03:13 +00:00
Samuel Tardieu
4cea5a8f33 Do not suggest [T; n] instead of vec![T; n] if T is not Copy 2023-12-17 11:32:15 +01:00
bors
f9b5def2ae Auto merge of #11869 - PartiallyTyped:result-filter-map, r=Alexendoo
New Lint: `result_filter_map` / Mirror of `option_filter_map`

Added the `Result` mirror of `option_filter_map`.

changelog: New Lint: [`result_filter_map`]

I had to move around some code because the function def was too long 🙃.

I have also added some pattern checks on `option_filter_map`
2023-12-16 23:29:07 +00:00
bors
fff484d18e Auto merge of #11977 - y21:is_const_evaluatable_ice, r=Manishearth
don't visit nested bodies in `is_const_evaluatable`

Fixes #11939

This ICE happened in `if_let_some_else_none`, but the root problem is in one of the utils that it uses.
It is (was) possible for `is_const_evalutable` to visit nested bodies which would lead to it trying to get the type of one of the expressions with the wrong typeck table, which won't have the type stored.

Notably, for the expression `Bytes::from_static(&[0; 256 * 1024]);` in the linked issue, the array length is an anonymous const in which type checking happens on its own, so we can't use the typeck table of the enclosing function in there.

Visiting nested bodies is also not needed for checking whether an expression can be const, so I think it's safe to ignore just ignore them altogether.

changelog: Fix ICE when checking for constness in nested bodies
2023-12-16 22:54:50 +00:00
y21
b5169aea52 don't visit any nested bodies in is_const_evaluatable 2023-12-16 22:13:54 +01:00
bors
9907b90b1e Auto merge of #11938 - GuillaumeGomez:unconditional_recursion, r=llogiq
Add new `unconditional_recursion` lint

Currently, rustc `unconditional_recursion` doesn't detect cases like:

```rust
enum Foo {
    A,
    B,
}

impl PartialEq for Foo {
    fn eq(&self, other: &Self) -> bool {
        self == other
    }
}
```

This is because the lint is currently implemented only for one level, and in the above code, `self == other` will then call `impl PartialEq for &T`, escaping from the detection. The fix for it seems to be a bit tricky (I started investigating potential solution to add one extra level of recursion [here](https://github.com/rust-lang/rust/compare/master...GuillaumeGomez:rust:trait-impl-recursion?expand=1) but completely broken at the moment).

I expect that this situation will remain for a while. In the meantime, I think it's acceptable to check it directly into clippy for the time being as a lot of easy cases like this one can be easily checked (next I plan to extend it to cover other traits like `ToString`).

changelog: Add new `unconditional_recursion` lint
2023-12-16 18:21:01 +00:00
Guillaume Gomez
6b444f3092 Also check code generated by macros 2023-12-16 18:45:24 +01:00
y21
bc22407b79 add tests, lint on while let true and matches!(.., true) 2023-12-16 17:40:32 +01:00
Philipp Krones
3596d44988 Merge commit 'a859e5cc1ce100df22346a1005da30532d04de59' into clippyup 2023-12-16 14:12:50 +01:00
Philipp Krones
80ccd6392f
Merge remote-tracking branch 'upstream/master' into rustup 2023-12-16 13:59:56 +01:00
Quinn Sinclair
8892420aa7 New Lint: Result_filter_map
Added the `Result` mirror of `option_filter_map` to catch

```
   .into_iter().filter(Result::is_ok).map(Result::unwrap)
```

changelog: New Lint: [`result_filter_map`]
Co-authored-by: Alex Macleod <alex@macleod.io>
2023-12-16 00:43:52 +01:00
Samuel Tardieu
e52405a859 Do not consider async { (impl IntoFuture).await } as redundant 2023-12-15 22:58:22 +01:00
StackOverflowExcept1on
058b74fce4
Do not lint assertions_on_constants for const _: () = assert!(expr) 2023-12-15 22:52:38 +03:00
J-ZhengLi
eae2317977 improve [cast_sign_loss], to skip warning on mathmatical expression that is always positive 2023-12-14 09:27:01 +08:00
bors
29bdc8b2bc Auto merge of #11953 - Jarcho:issue_11952, r=Alexendoo
Fix binder handling in `unnecessary_to_owned`

fixes #11952

The use of `rebind` instead of `EarlyBinder::bind` isn't technically needed, but it is the semantically correct operation.

changelog: None
2023-12-13 18:57:50 +00:00
bors
1839b79e51 Auto merge of #11956 - intgr:doc_markdown-include-function-parenthesis, r=Alexendoo
[`doc_markdown`] Recognize words followed by empty parentheses `()` for quoting

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: [`doc_markdown`] Recognize words followed by empty parentheses for quoting, e.g. `func()`.

---

Developers often write function/method names with trailing `()`, but `doc_markdown` lint did not consider that.

Old clippy suggestion was not very good:

```patch
-/// There is no try (do() or do_not()).
+/// There is no try (do() or `do_not`()).
```

New behavior recognizes function names such as `do()` even they contain no `_`/`::`; and backticks are suggested outside of the `()`:

```patch
-/// There is no try (do() or do_not()).
+/// There is no try (`do()` or `do_not()`).
```
2023-12-13 17:53:59 +00:00
J-ZhengLi
60c059114c [default_numeric_fallback]: don't lint on return and macro calls with stated type 2023-12-13 11:09:08 +08:00
Marti Raudsepp
1f2ca8127c [doc_markdown] Recognize words followed by empty parenthesis () for quoting 2023-12-13 01:16:12 +02:00
bors
c19508b356 Auto merge of #11895 - ericwu2003:useless_vec-FP, r=blyxyas
Useless vec false positive

changelog: [`useless_vec`]: fix false positive in macros.

fixes #11861

We delay the emission of `useless_vec` lints to the check_crate_post stage, which allows us to effectively undo lints if we find that a `vec![]` expression is being used multiple times after macro expansion.
2023-12-12 22:57:24 +00:00
bors
2e96c74dce Auto merge of #11829 - J-ZhengLi:issue11438, r=matthiaskrgr
new lint to detect infinite loop

closes: #11438

changelog: add new lint to detect infinite loop

~*I'll change the lint name*~. Should I name it  `infinite_loop` or `infinite_loops` is fine? Ahhhh, English is hard...
2023-12-12 17:53:51 +00:00
Eric
884bec3d85 emit lints in check_crate_post for useless_vec
this fixes issue #11861 by adding an extra map to
keep track of which spans are ok to lint
2023-12-12 08:47:22 -08:00
Guillaume Gomez
2c867ce01e Add ui tests for unconditional_recursion lint 2023-12-12 15:37:51 +01:00
Guillaume Gomez
5accd517ee Add ui test for write_and_append lint 2023-12-12 14:56:35 +01:00
Jason Newcomb
27c5b21fb6 Fix binder handling in unnecessary_to_owned 2023-12-11 13:52:55 -05:00
bors
2a1645d009 Auto merge of #11878 - samueltardieu:uninhabited_reference, r=flip1995
uninhabited_reference: new lint

Close #11851

The lint is implemented on function parameters and return types, as this is the place where the risk of exchanging references to uninhabited types is the highest. Other constructs, such as in a local variable,
would require the use of `unsafe` and will clearly be done on purpose.

changelog: [`uninhabited_reference`]: new lint
2023-12-11 09:28:54 +00:00
Jason Newcomb
184845fb0c Fix is_from_proc_macro patterns 2023-12-10 15:36:31 -05:00
Samuel Tardieu
cdfa38a9d1 new lint: uninhabited_reference 2023-12-08 17:21:30 +01:00
bors
1c8cbe79ab Auto merge of #11907 - cocodery:issue11885, r=y21,xFrednet
Add a function to check whether binary oprands are nontrivial

fixes [#issue11885](https://github.com/rust-lang/rust-clippy/issues/11885)

It's hard to check whether operator is overrided through context of lint.
So, assume non-trivial structure like tuple, array or sturt, using a overrided binary operator in this lint, which might cause a side effict.
This is not detected before.
Althrough this might weaken the ability of this lint, it may more useful than before. Maybe this lint will cause an error, but now, it not. And assuming side effect of non-trivial structure with operator  is not a bad thing, right?

changelog: Fix: [`no_effect`] check if binary operands are nontrivial
2023-12-08 13:39:47 +00:00
cocodery
56d20c2b53 Fix nits and add test for unnecessary_operation 2023-12-08 21:33:28 +08:00
bors
2793e8d103 Auto merge of #11913 - KisaragiEffective:fix/ptr-as-ptr-with-null, r=llogiq
fix(ptr_as_ptr): handle `std::ptr::null{_mut}`

close rust-lang#11066
close rust-lang#11665
close rust-lang#11911

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: [`ptr_as_ptr`]: handle `std::ptr::null` and `std::ptr::null_mut`
2023-12-06 13:53:07 +00:00
Urgau
a2ea760b88 Drop clippy::vtable_address_comparisons 2023-12-06 09:03:48 +01:00
cocodery
ee2354badf Add check for unary-operator
Fix typo and add test for unary-opeator
2023-12-06 12:17:48 +08:00
bors
4a56563154 Auto merge of #11900 - Enselic:needless-borrow-drop, r=Manishearth
needless_borrows_for_generic_args: Handle when field operand impl Drop

Before this fix, the lint had a false positive, namely when a reference was taken to a field when the field operand implements a custom Drop. The compiler will refuse to partially move a type that implements Drop, because that would put the type in a weird state.

## False Positive Example (Fixed)

```rs
struct CustomDrop(String);

impl Drop for CustomDrop {
    fn drop(&mut self) {}
}

fn check_str<P: AsRef<str>>(_to: P) {}

fn test() {
    let owner = CustomDrop(String::default());
    check_str(&owner.0); // Don't lint. `owner` can't be partially moved because it impl Drop
}
```

changelog: [`needless_borrows_for_generic_args`]: Handle when field operand impl Drop
2023-12-05 19:10:09 +00:00
bors
8fc8aa98d6 Auto merge of #11904 - pgerber:regex, r=xFrednet
Update regex-syntax to support new word boundry assertions

From the regex v1.10.0 release notes [1]:

    This is a new minor release of regex that adds support for start
    and end word boundary assertions. [...]

    The new word boundary assertions are:

        • \< or \b{start}: a Unicode start-of-word boundary (\W|\A
          on the left, \w on the right).
        • \> or \b{end}: a Unicode end-of-word boundary (\w on the
          left, \W|\z on the right)).
        • \b{start-half}: half of a Unicode start-of-word boundary
          (\W|\A on the left).
        • \b{end-half}: half of a Unicode end-of-word boundary
          (\W|\z on the right).

[1]: https://github.com/rust-lang/regex/blob/master/CHANGELOG.md#1100-2023-10-09

changelog: [`regex`]: add support for start and end word boundary assertions ("\<", "\b{start}", etc.) introduced in regex v0.10
2023-12-05 18:34:58 +00:00
Philipp Krones
ebb0ff6932
Merge remote-tracking branch 'upstream/master' into rustup 2023-12-05 17:29:25 +01:00
cocodery
89774234be Rewrite logic of has_nontrivial_oprand.
Check whether operator is overrided with a `struct` operand.
The struct here refers to `struct`, `enum`, `union`.
Add and fix test for `no_effect` lint.
2023-12-04 15:57:27 +08:00
Kisaragi Marine
8eea8b1577
fix: handle std::ptr::null{_mut}
close rust-lang#11066
close rust-lang#11665
close rust-lang#11911
2023-12-03 10:38:46 +09:00
Peter Gerber
af1b58fa39
Update regex-syntax to support new word boundry assertions
From the regex v1.10.0 release notes [1]:

    This is a new minor release of regex that adds support for start
    and end word boundary assertions. [...]

    The new word boundary assertions are:

        • \< or \b{start}: a Unicode start-of-word boundary (\W|\A
          on the left, \w on the right).
        • \> or \b{end}: a Unicode end-of-word boundary (\w on the
          left, \W|\z on the right)).
        • \b{start-half}: half of a Unicode start-of-word boundary
          (\W|\A on the left).
        • \b{end-half}: half of a Unicode end-of-word boundary
          (\W|\z on the right).

[1]: https://github.com/rust-lang/regex/blob/master/CHANGELOG.md#1100-2023-10-09
2023-12-02 19:44:36 +00:00
bors
75bdbfcea5 Auto merge of #11853 - J-ZhengLi:issue11814, r=llogiq
expending lint [`blocks_in_if_conditions`] to check match expr as well

closes: #11814

changelog: rename lint `blocks_in_if_conditions` to [`blocks_in_conditions`] and expand it to check blocks in match scrutinees
2023-12-02 14:03:46 +00:00
bors
ee8376075d Auto merge of #11837 - y21:issue11835, r=dswij
[`missing_asserts_for_indexing`]: accept length equality checks

Fixes #11835

The lint now allows indexing with indices 0 and 1 when an `assert!(x.len() == 2);` is found.
(Also fixed a typo in the doc example)

changelog: [`missing_asserts_for_indexing`]: accept len equality checks as a valid assertion
2023-12-01 19:02:59 +00:00
bors
5ac76ac54f Auto merge of #11597 - y21:repeat_vec_with_capacity, r=dswij
new lint: `repeat_vec_with_capacity`

Closes #11537

[Lint description](https://github.com/y21/rust-clippy/blob/repeat_vec_with_capacity/clippy_lints/src/repeat_vec_with_capacity.rs#L14) should explain this PR :)

changelog: new lint: `repeat_vec_with_capacity`
2023-12-01 18:00:50 +00:00
Philipp Krones
c9a43b18f1 Merge commit 'f0cdee4a3f094416189261481eae374b76792af1' into clippy-subtree-sync 2023-12-01 18:21:58 +01:00
Philipp Krones
a9867e1847
Merge remote-tracking branch 'upstream/master' into rustup 2023-12-01 18:06:03 +01:00
y21
76eb781336 use iter::repeat_with in suggestion and add examples 2023-12-01 17:24:34 +01:00
y21
504941591f new lint: repeat_vec_with_capacity 2023-12-01 16:52:34 +01:00
bors
3a760909fa Auto merge of #117472 - jmillikin:stable-c-str-literals, r=Nilstrieb
Stabilize C string literals

RFC: https://rust-lang.github.io/rfcs/3348-c-str-literal.html

Tracking issue: https://github.com/rust-lang/rust/issues/105723

Documentation PR (reference manual): https://github.com/rust-lang/reference/pull/1423

# Stabilization report

Stabilizes C string and raw C string literals (`c"..."` and `cr#"..."#`), which are expressions of type [`&CStr`](https://doc.rust-lang.org/stable/core/ffi/struct.CStr.html). Both new literals require Rust edition 2021 or later.

```rust
const HELLO: &core::ffi::CStr = c"Hello, world!";
```

C strings may contain any byte other than `NUL` (`b'\x00'`), and their in-memory representation is guaranteed to end with `NUL`.

## Implementation

Originally implemented by PR https://github.com/rust-lang/rust/pull/108801, which was reverted due to unintentional changes to lexer behavior in Rust editions < 2021.

The current implementation landed in PR https://github.com/rust-lang/rust/pull/113476, which restricts C string literals to Rust edition >= 2021.

## Resolutions to open questions from the RFC

* Adding C character literals (`c'.'`) of type `c_char` is not part of this feature.
  * Support for `c"..."` literals does not prevent `c'.'` literals from being added in the future.
* C string literals should not be blocked on making `&CStr` a thin pointer.
  * It's possible to declare constant expressions of type `&'static CStr` in stable Rust (as of v1.59), so C string literals are not adding additional coupling on the internal representation of `CStr`.
* The unstable `concat_bytes!` macro should not accept `c"..."` literals.
  * C strings have two equally valid `&[u8]` representations (with or without terminal `NUL`), so allowing them to be used in `concat_bytes!` would be ambiguous.
* Adding a type to represent C strings containing valid UTF-8 is not part of this feature.
  * Support for a hypothetical `&Utf8CStr` may be explored in the future, should such a type be added to Rust.
2023-12-01 13:33:55 +00:00
Martin Nordholts
512f302fd2 needless_borrows_for_generic_args: Handle when field operand impl Drop
Before this fix, the lint had a false positive, namely when a reference
was taken to a field when the field operand implements a custom Drop.
The compiler will refuse to partially move a type that implements Drop,
because that would put the operand in a weird state. See added
regression test.
2023-12-01 09:14:56 +01:00
clubby789
2cda044f8c Allow allowing upper_case_acronyms on enum variants 2023-11-30 16:00:40 +00:00
bors
646b28f5f6 Auto merge of #11896 - samueltardieu:issue-11893, r=Alexendoo
`option_if_let_else`: do not trigger on expressions returning `()`

Fix #11893

Trigerring on expressions returning `()` uses the arguments of the `map_or_else()` rewrite only for their side effects. This does lead to code which is harder to read than the original.

changelog: [`option_if_let_else`]: do not trigger on unit expressions
2023-11-30 15:17:29 +00:00
bors
665fd5219a Auto merge of #11872 - llogiq:test-attr-in-doctest, r=xFrednet
add lint against unit tests in doctests

During RustLab, Alice Ryhl brought to my attention that the Andoid team stumbled over the fact that if one attempts to write a unit test within a doctest, it will be summarily ignored. So this lint should help people wondering why their tests won't run.

---

changelog: New lint: [`test_attr_in_doctest`]
[#11872](https://github.com/rust-lang/rust-clippy/pull/11872)
2023-11-30 10:24:16 +00:00
J-ZhengLi
40b558af76 rename [blocks_in_if_conditions] to [blocks_in_conditions];
add more test cases with `match`;
minor fixes in message output regarding review feedback
2023-11-30 15:41:54 +08:00
J-ZhengLi
fff7aa0e18 expending lint [blocks_in_if_conditions] to check match expr as well 2023-11-30 14:44:27 +08:00
Samuel Tardieu
e3c73f17ec option_if_let_else: do not trigger on expressions returning ()
Fix #11893

Trigerring on expressions returning `()` uses the arguments of the
`map_or_else()` rewrite only for their side effects. This does lead
to code which is harder to read than the original.
2023-11-29 19:38:02 +01:00
bors
8b0bf6423d Auto merge of #11818 - y21:more_redundant_guards, r=llogiq
[`redundant_guards`]: catch `is_empty`, `starts_with` and `ends_with` on slices and `str`s

Fixes #11807

Few things worth mentioning:
- Taking `snippet`s is now done at callsite, instead of passing a span and doing it in `emit_redundant_guards`. This is because we now need custom suggestion strings in certain places, like `""` for `str::is_empty`.
- This now uses `snippet` instead of `snippet_with_applicability`. I don't think this really makes any difference for `MaybeIncorrect`, though?
- This could also lint byte strings, as they're of type `&[u8; N]`, but that can be ugly so I decided to leave it out for now

changelog: [`redundant_guards`]: catch `str::is_empty`, `slice::is_empty`, `slice::starts_with` and `slice::ends_with`
2023-11-29 13:20:59 +00:00
Andre Bogus
0ba9bf9f9a add lint against unit tests in doctests 2023-11-28 21:29:08 +01:00
bors
57397a5190 Auto merge of #11363 - KisaragiEffective:fix_redundant_closure_call_on_closure_returns_async_block, r=llogiq
[`redundant_closure_call`]: avoid duplicated `async` keyword when triggering on closure that returns `async` block

close #11357

----

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: [`redundant_closure_call`]: avoid duplicated `async` keyword when triggering on closure that returns `async` block
2023-11-28 20:27:48 +00:00
J-ZhengLi
758d0e8661 change name to [infinite_loop];
& apply review suggestions;
2023-11-28 10:28:55 +08:00
bors
e6f33905e8 Auto merge of #11836 - lukaslueg:issue11831, r=Alexendoo
Don't suggest `a.mul_add(b, c)` if parameters are not float

clippy::suboptimal_flops used to not check if the second parameter to f32/f64.mul_add() was float. Since the method is only defined to take `Self` as parameters, the suggestion was wrong.

Fixes #11831

changelog: [`suboptimal_float`]: Don't suggest `a.mul_add(b, c)` if parameters are not f32/f64
2023-11-27 20:37:34 +00:00
bors
003e910760 Auto merge of #11817 - y21:ptr_arg_mut_ref, r=Alexendoo
[`ptr_arg`]: recognize methods that also exist on slices

Fixes #11816

Not a new lint, just a very small improvement to the existing `ptr_arg` lint which would have caught the linked issue.

The problem was that the lint checks if a `Vec`-specific method was called, that is, if the receiver is `Vec<_>`.
This is the case for `len` and `is_empty`, however these methods also exist on slices so we can still lint there.
This logic exists in a different lint, so we can just reuse that here.

Interestingly, there was even a comment up top that explained what it should have been doing, but the logic for it just wasn't there?

changelog: [`ptr_arg`]: recognize methods that also exist on slices

<sub>Also, this is my 100th PR to clippy 🎉 </sub>
2023-11-27 20:26:31 +00:00
bors
caa73941f8 Auto merge of #11879 - samueltardieu:issue-11876, r=Alexendoo
`manual_try_fold`: check that `fold` is really `Iterator::fold`

Fix #11876

changelog: [`manual_try_fold`]: suggest using `try_fold` only for `Iterator::fold` uses
2023-11-27 20:18:40 +00:00
Kisaragi Marine
33182495ac
don't add paren on occurrences that is in call args 2023-11-28 00:27:51 +09:00
Kisaragi Marine
40b6aa0e86
cargo uibless 2023-11-27 23:53:07 +09:00
Kisaragi Marine
1acd8068bd
remove double-paren on test case 2023-11-27 23:50:08 +09:00
Kisaragi Marine
1661e7ee76
re-implement fix for rust-lang#11357 2023-11-27 23:43:39 +09:00
Samuel Tardieu
0d09cb0a6b manual_try_fold: check that fold is really Iterator::fold 2023-11-26 22:46:13 +01:00
Samuel Tardieu
23d533264f Fix box_default behaviour with empty vec![] coming from macro arg 2023-11-26 18:40:50 +01:00
bors
3664d6328d Auto merge of #11864 - GuillaumeGomez:option_map_or_err_ok, r=flip1995
Create new lint `option_map_or_err_ok`

Fixes #10045.

For the following code:

```rust
let opt = Some(1);
opt.map_or(Err("error"), Ok);
```

It suggests to instead write:

```rust
let opt = Some(1);
opt.ok_or("error");
```

r? `@flip1995`

changelog: Create new lint `option_map_or_err_ok`
2023-11-25 11:35:46 +00:00
Nilstrieb
c2c73189c8 Bless clippy tests
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24 19:15:52 +01:00
bors
6cfbe57075 Auto merge of #11862 - christophbeberweil:7125-single-element-loop-over-range, r=llogiq
suggest alternatives to iterate an array of ranges

works towards #7125
changelog: [`single_element_loop`]: suggest better syntax when iterating over an array of a single range

`@thinkerdreamer` and myself worked on this issue during a workshop by `@llogiq` at the RustLab 2023 conference. It is our first contribution to clippy.

When iterating over an array of only one element, _which is a range_, our change suggests to replace the array with the contained range itself. Additionally, a hint is printed stating that the user probably intended to iterate over the range and not the array. If the single element in the array is not a range, the previous suggestion in the form of `let {pat_snip} = {prefix}{arg_snip};{block_str}`is used.

This change lints the array with the single range directly, so any prefixes or suffixes are covered as well.
2023-11-24 17:15:33 +00:00
Guillaume Gomez
3a3773fa30 Add test for option_map_or_err_ok lint 2023-11-24 18:14:34 +01:00
Christoph Beberweil
f9c6335a0f feat: 7125 code snippets are wrapped in backticks 2023-11-24 17:47:31 +01:00
Christoph Beberweil
bce869f0c0 fix: 7125 lint message should start with a small letter 2023-11-24 17:29:03 +01:00
bors
e075823e2c Auto merge of #11850 - Nilstrieb:tbd, r=dswij
[`deprecated_semver`]: Allow `#[deprecated(since = "TBD")]`

"TBD" is allowed by rustdoc, saying that it will be deprecated in a future version. rustc will also not actually warn on it.
I found this while checking the rust-lang/rust with clippy.

changelog: [`deprecated_semver`]: allow using `since = "TBD"`
2023-11-24 14:46:50 +00:00
bors
96eab0655f Auto merge of #11859 - y21:issue11856, r=blyxyas
[`missing_asserts_for_indexing`]: work with bodies instead of blocks separately

Fixes #11856

Before this change, this lint would check blocks independently of each other, which means that it misses `assert!()`s from parent blocks.
```rs
// check_block
assert!(x.len() > 1);

{
  // check_block
  // no assert here
  let _ = x[0] + x[1];
}
```

This PR changes it to work with bodies rather than individual blocks. That means that a function will be checked in one go and we can remember if an `assert!` occurred anywhere.

Eventually it would be nice to have a more control flow-aware analysis, possibly by rewriting it as a MIR lint, but that's more complicated and I wanted this fixed first.

changelog: [`missing_asserts_for_indexing`]: accept `assert!`s from parent blocks
2023-11-24 12:18:11 +00:00
Christoph Beberweil
2512341fe4 feat: 7125 shorten lint text 2023-11-24 10:38:45 +01:00
Christoph Beberweil
447edf92b4 suggest alternatives to iterate an array of ranges
Co-authored-by: ThinkerDreamer <74881094+ThinkerDreamer@users.noreply.github.com>
2023-11-23 23:07:36 +01:00
Guillaume Gomez
6c84b96886 Improve error messages format 2023-11-23 13:32:41 +01:00
Guillaume Gomez
5d330d08fb Add new test for result_map_or_into_option extension 2023-11-23 10:57:37 +01:00
y21
553857bb2b check on a per-body level instead of blocks independently 2023-11-23 09:31:49 +01:00
bors
c24784ed81 Auto merge of #11757 - matthri:iter-kv-map-msrv-fix, r=Alexendoo
Fix iter_kv_map false positive into_keys and into_values suggestion

fixes: #11752

changelog: [`iter_kv_map`]: fix false positive: Don't suggest `into_keys()` and `into_values()` if the MSRV is to low
2023-11-22 20:39:44 +00:00
bors
a72730e9a1 Auto merge of #11844 - GuillaumeGomez:manual_non_exhaustive-rm-underscore-check, r=flip1995
Remove underscore check for `manual_non_exhaustive` lint

Fixes https://github.com/rust-lang/rust-clippy/issues/10550.

As indicated in https://github.com/rust-lang/rust-clippy/pull/10559, the underscore check should be removed.

changelog: remove underscore check for `manual_non_exhaustive` lint

r? `@blyxyas`
2023-11-22 13:37:31 +00:00
Guillaume Gomez
91fc4b3001 Remove underscore check for manual_non_exhaustive lint 2023-11-22 13:42:13 +01:00
bors
b21c9d4d31 Auto merge of #11849 - GuillaumeGomez:add-more-transmute_ref_to_ref-tests, r=blyxyas
Add tests for issues #10285, #10286, #10289, #10287

Fixes #10285.
Fixes #10286.
Fixes #10289.
Fixes #10287.

This PR simply adds tests for the listed issues as they're already implemented so we can close them.

r? `@blyxyas`

changelog:none
2023-11-22 11:29:13 +00:00
Nilstrieb
43d8d51b6d Allow #[deprecated(since = "TBD")]
"TBD" is allowed by rustdoc, saying that it will be deprecated in a future version.
rustc will also not actually warn on it.
2023-11-21 22:03:00 +01:00
Guillaume Gomez
2fa87fb93d Add tests for issues #10285, #10286, #10289, #10287 2023-11-21 14:04:19 +01:00
y21
a74fa97fab [needless_return_with_question_mark]: dont lint in case of coercion 2023-11-21 12:02:12 +01:00
J-ZhengLi
3e9a6d142e stop warning never-returning calls
and add more test cases
2023-11-21 16:18:18 +08:00
bors
72c0d80f46 Auto merge of #11801 - y21:split_doc_pass, r=blyxyas
Split `doc.rs` up into a subdirectory

So, first, sorry for the bad diff. 😅

In #11798, `@flip1995`  suggested splitting `doc.rs` up, much like how we have the `methods/`, `matches/`, `types/` subdirectories.
I agree with this, the file is getting bigger as we add more and more doc lints that it makes sense to do this refactoring.

This is purely an internal change that moves things around a bit.
(**EDIT:** depending on the outcome of https://github.com/rust-lang/rust-clippy/pull/11801#issuecomment-1816715615 , this may change the lint group name from `doc_markdoc` to `doc`).

I tried to not change any of the actual logic of the lints and as such some things weren't as easy to move to a separate file. So we still have some `span_lint*` calls in the `doc/mod.rs` file, which I think is fine. This is also the case in `methods/mod.rs`.

Also worth mentioning that the lints missing_errors_doc, missing_panics_doc, missing_safety_doc and unnecessary_safety_doc have a lot of the same logic so it didn't make much sense for each of these to be in their own file. Instead I just put them all in `missing_headers.rs`

I also added a bit of documentation to the involved `check_{attrs,doc}` methods.

changelog: none
2023-11-20 17:22:05 +00:00
ofeeg
34d9e88a47
New lint clippy::join_absolute_paths
* `join_absolute_paths` Address PR review
* Move `clippy::join_absolute_paths` to `clippy::suspicious`
* `join_absolute_paths`: Address PR review

Co-Authored-By: ofeeg <mhanna0000@gmail.com>
2023-11-20 13:28:28 +01:00
y21
56cee3c587 move doc.rs to its own subdirectory 2023-11-20 12:08:07 +01:00
bors
41140e3cb8 Auto merge of #11840 - GuillaumeGomez:improve-maybe_misused_cfg, r=blyxyas
Improve maybe misused cfg

Follow-up of the improvements that were suggested to me in https://github.com/rust-lang/rust-clippy/pull/11821:

 * I unified the output to use the same terms.
 * I updated the code to prevent creating a new symbol.

r? `@blyxyas`

changelog: [`maybe_misued_cfg`]: Output and code improvements
2023-11-19 22:31:11 +00:00
Guillaume Gomez
dfbca7ffa8 Improve maybe_misused_cfg lint output
Small performance improvement when comparing symbols for `maybe_misused_cfg`
Improve suggestion for `maybe_misused_cfg` lint
2023-11-19 22:46:19 +01:00
bors
9c3a365fd2 Auto merge of #11781 - partiallytyped:11710, r=xFrednet
Verify Borrow<T> semantics for types that implement Hash, Borrow<str> and Borrow<[u8]>.

Fixes #11710

The essence of the issue is that types that implement Borrow<T> provide a facet or a representation of the underlying type. Under these semantics `hash(a) == hash(a.borrow())`.

This is a problem when a type implements `Borrow<str>`, `Borrow<[u8]>` and Hash, it is expected that the hash of all three types is identical. The problem is that the hash of [u8] is not the same as that of a String, even when the byte reference ([u8]) is derived from `.as_bytes()`

- [x] Followed [lint naming conventions][lint_naming]
- [x] Added passing UI tests (including committed `.stderr` file)
- [x] `cargo test` passes locally
- [x] Executed `cargo dev update_lints`
- [x] Added lint documentation
- [x] Run `cargo dev fmt`

---

 - [x] Explanation of the issue in the code
 - [x] Tests reproducing the issue
 - [x] Lint rule and emission

---

changelog: New lint: [`impl_hash_borrow_with_str_and_bytes`]
[#11781](https://github.com/rust-lang/rust-clippy/pull/11781)
2023-11-19 10:59:34 +00:00
Quinn Sinclair
3c1e0afa58 New Lint [impl_hash_with_borrow_str_and_bytes]
Implements a lint to prevent implementation of Hash, Borrow<str> and
Borrow<[u8]> as it breaks Borrow<T> "semantics". According to the book,
types that implement Borrow<A> and Borrow<B> must ensure equality of
borrow results under Eq,Ord and Hash.

> In particular Eq, Ord and Hash must be equivalent for borrowed and
owned values: x.borrow() == y.borrow() should give the same result as x == y.

In the same way, hash(x) == hash(x as Borrow<[u8]>) != hash(x as Borrow<str>).

changelog: newlint [`impl_hash_with_borrow_str_and_bytes`]
2023-11-19 11:33:01 +01:00
bors
dbd19f9b48 Auto merge of #11691 - sjwang05:lines-filter-map-ok-fix, r=Centri3
Lint `flatten()` under `lines_filter_map_ok`

Fixes #11686

changelog: [`lines_filter_map_ok`]: Also lint calls to `flatten()`
2023-11-19 01:50:24 +00:00
bors
9263f806d8 Auto merge of #11782 - Alexendoo:macro-use-imports-ordering, r=Centri3
Make `macro_use_imports` lint ordering more stable

changelog: none

Fixes [the `macro_use_imports` ordering dependence](https://github.com/rust-lang/rust/pull/117649#issuecomment-1797716088) on the hash of `Span`s
2023-11-19 01:39:06 +00:00
y21
4de845e375 [missing_asserts_for_indexing]: accept len equality checks 2023-11-18 14:59:24 +01:00
Lukas Lueg
a2e396badf Don't suggest a.mul_add(b, c) if parameters are not float
clippy::suboptimal_flops used to not check if the second parameter to f32/f64.mul_add() was float. Since the method is
only defined to take `Self` as paremters, the suggestion was wrong.

Fixes #11831
2023-11-18 13:50:18 +01:00
bors
e8e9510219 Auto merge of #11002 - y21:issue9422, r=Jarcho
teach `eager_or_lazy` about panicky arithmetic operations

Fixes #9422
Fixes #9814
Fixes #11793

It's a bit sad that we have to do this because arithmetic operations seemed to me like the prime example where a closure would not be necessary, but this has "side effects" (changes behavior when going from lazy to eager) as some of these panic on overflow/underflow if compiled with `-Coverflow-checks` (which is the default in debug mode).
Given the number of backlinks in the mentioned issues, this seems to be a FP that is worth fixing, probably.

changelog: [`unnecessary_lazy_evaluations`]: don't lint if closure has panicky arithmetic operations
2023-11-17 18:53:15 +00:00
bors
31e38fee23 Auto merge of #11821 - GuillaumeGomez:misspelled-cfg, r=blyxyas
Extend `maybe_misused_cfg` lint over `cfg(test)`

Fixes #11240.

One thought I had is that we could use the levenshtein distance (of 1) to ensure this is indeed `test` that was targeted. But maybe it's overkill, not sure.

changelog: [`maybe_misused_cfg`]: Extend lint over `cfg(test)`

r? `@blyxyas`
2023-11-17 11:49:20 +00:00
J-ZhengLi
2d9fc6dfc8 implement unoptimized code logic for [infinite_loops] 2023-11-17 18:10:50 +08:00
Nicholas Nethercote
aec4e8115b Move lint_store from GlobalCtxt to Session.
This was made possible by the removal of plugin support, which
simplified lint store creation.

This simplifies the places in rustc and rustdoc that call
`describe_lints`, which are early on. The lint store is now built before
those places, so they don't have to create their own lint store for
temporary use, they can just use the main one.
2023-11-17 10:39:18 +11:00
Philipp Krones
6246f0446a Merge commit 'edb720b199083f4107b858a8761648065bf38d86' into clippyup 2023-11-16 19:13:24 +01:00
Philipp Krones
6fab1485c3
Merge remote-tracking branch 'upstream/master' into rustup 2023-11-16 19:02:04 +01:00
Guillaume Gomez
a621d71b4e Add UI test for mispelled test 2023-11-16 18:07:26 +01:00
y21
7696c9d1d5 allow more div and rem operations that can be checked 2023-11-16 17:30:10 +01:00
y21
23ee33255c lint when relevant sides of binops are constants 2023-11-16 04:49:11 +01:00
y21
1b4e2ef3d7 fix empty needle corner case and add tests 2023-11-15 21:10:03 +01:00
y21
bb694615b8 [ptr_arg]: recognize methods that also exist on slices 2023-11-15 14:59:11 +01:00
bors
3ea5bcf5ee Auto merge of #11809 - hrxi:pr_if_same_then_else_style, r=Alexendoo
Change `if_same_then_else` to be a `style` lint

CC #3770

From https://github.com/rust-lang/rust-clippy/issues/3770#issuecomment-687565594 (`@flip1995):`

> Oh I thought I replied to this: I definitely see now that having this
> as a correctness lint might be the wrong categorization. What we might
> want to do is to just allow this lint, if there are comments in the
> arm bodies. But a good first step would be to downgrade this lint to
> style or complexity. I would vote for style since merging two arms is
> not always less complex.

changelog: [`if_same_then_else`]: Change to be a `style` lint
2023-11-15 12:11:14 +00:00
bors
7ad3373bb1 Auto merge of #11802 - dswij:issue-11765, r=xFrednet
`needless_return_with_question_mark` ignore let-else

Fixes #11765

This PR makes `needless_return_with_question_mark` to ignore expr inside let-else.

changelog: [`needless_return_with_question_mark`] ignore let-else
2023-11-15 10:15:47 +00:00
Jason Newcomb
cdc4c697b5 Make expr_use_ctxt always return Some unless the syntax context changes. 2023-11-14 23:23:35 -05:00
bors
783b914fae Auto merge of #11804 - y21:issue-11803, r=dswij
[`impl_trait_in_params`]: avoid ICE when function with `impl Trait` type has no parameters

Fixes #11803

If I'm reading the old code correctly, it was taking the span of the first parameter (without checking that it exists, which caused the ICE) and uses that to figure out where the generic parameter to insert should go (cc `@blyxyas` you wrote the lint, is that correct?).
This seemed equivalent to just `generics.span`, which doesn't require calculating the spans like that and simplifies it a fair bit

changelog: don't ICE when function has no parameters but generics have an `impl Trait` type
2023-11-15 04:03:44 +00:00
Jason Newcomb
b587871e27 Simplify get_enclosing_loop_or_multi_call_closure 2023-11-14 22:17:02 -05:00
hrxi
b3073c536b Change if_same_then_else to be a style lint
CC #3770

From https://github.com/rust-lang/rust-clippy/issues/3770#issuecomment-687565594 (@flip1995):

> Oh I thought I replied to this: I definitely see now that having this
> as a correctness lint might be the wrong categorization. What we might
> want to do is to just allow this lint, if there are comments in the
> arm bodies. But a good first step would be to downgrade this lint to
> style or complexity. I would vote for style since merging two arms is
> not always less complex.
2023-11-15 00:33:14 +01:00
bors
0c42e451d6 Auto merge of #11791 - Jacherr:iter_over_hash_type, r=Jarcho
Implement new lint `iter_over_hash_type`

Implements and fixes https://github.com/rust-lang/rust-clippy/issues/11788

This PR adds a new *restriction* lint `iter_over_hash_type` which prevents `Hash`-types (that is, `HashSet` and `HashMap`) from being used as the iterator in `for` loops.

The justification for this is because in `Hash`-based types, the ordering of items is not guaranteed and may vary between executions of the same program on the same hardware. In addition, it reduces readability due to the unclear iteration order.

The implementation of this lint also ensures the following:
- Calls to `HashMap::keys`, `HashMap::values`, and `HashSet::iter` are also denied when used in `for` loops,
- When this expression is used in procedural macros, it is not linted/denied.

changelog: add new `iter_over_hash_type` lint to prevent unordered iterations through hashed data structures
2023-11-14 15:55:00 +00:00
Yudai Fukushima
a9d42e6d6d fix: reduce [manual_memcpy] indexing when array length is same to loop range
Format

refactor: extract function to shrink function length

fix: remove cmp to calculate range

fix: replace if_chain with let chains
2023-11-14 22:05:44 +09:00
y21
3f6b29ad32 [impl_trait_in_params]: fix span calculation 2023-11-14 13:52:44 +01:00
dswij
48f38eb131 needless_return_with_question_mark ignore let-else 2023-11-14 16:30:52 +08:00
Jacherr
f8ea496495 add tests for type-aliased hash types 2023-11-13 16:52:59 +00:00
bors
07bc130074 Auto merge of #11760 - compiler-errors:escaping, r=Jarcho
Don't check for late-bound vars, check for escaping bound vars

Fixes an assertion that didn't make sense. Many valid and well-formed types *have* late-bound vars (e.g. `for<'a> fn(&'a ())`), they just must not have *escaping* late-bound vars in order to be normalized correctly.

Addresses rust-lang/rust-clippy#11230, cc `@jyn514` and `@matthiaskrgr`

changelog: don't check for late-bound vars, check for escaping bound vars. Addresses rust-lang/rust-clippy#11230
2023-11-12 22:15:43 +00:00
Michael Goulet
1539eb8c03 Don't check for late-bound vars, check for escaping bound vars 2023-11-12 12:15:30 -08:00
Michael Goulet
661e91be57 Add test 2023-11-12 12:14:41 -08:00
bors
6a15f3bd49 Auto merge of #11787 - Jarcho:divergence_check, r=dswij
Fixes to `manual_let_else`'s divergence check

A few changes to the divergence check in `manual_let_else` and moves it the implementation to `clippy_utils` since it's generally useful:
* Handle internal `break` and `continue` expressions.
    e.g. The first loop is divergent, but the second is not.
    ```rust
    {
        loop {
            break 'outer;
        };
    }
    {
        loop {
            break;
        };
    }
    ```
* Match rust's definition of divergence which is defined via the type system.
    e.g. The following is not considered divergent by rustc as the inner block has a result type of `()`:
    ```rust
    {
        'a: {
            panic!();
            break 'a;
        };
    }
    ```
* Handle when adding a single semicolon would make the expression divergent.
    e.g. The following would be a divergent if a semicolon were added after the `if` expression:
    ```rust
    { if panic!() { 0 } else { 1 } }
    ```

changelog: None
2023-11-12 15:44:13 +00:00
Matthias Richter
5f651da2de fix iter_kv_map dont suggest into_keys and into_values if msrv is to low 2023-11-12 15:43:08 +01:00
bors
886d5fbeb0 Auto merge of #11508 - Jarcho:issue_11474, r=blyxyas
Lint `needless_borrow` and `explicit_auto_deref` on most union field accesses

Changes both lints to follow rustc's rules around auto-deref through `ManuallyDrop` union fields rather than just bailing on union fields.

changelog: [`needless_borrow`] & [`explicit_auto_deref`]: Lint on most union field accesses
2023-11-12 11:24:01 +00:00
bors
8ee9a9c549 Auto merge of #11767 - matthri:unnecessary-fallible-conversions-ext-notes, r=blyxyas
Add type details to unnecessary_fallible_conversions note

fixes: #11753

changelog: [`unnecessary_fallible_conversions`]: add type details to lint note
2023-11-11 22:51:27 +00:00
Jacherr
941164807f implement more types to lint, fix wording 2023-11-11 21:26:50 +00:00
Jason Newcomb
1a01132417 Lint explicit_auto_deref on most union field accesses. 2023-11-11 15:54:58 -05:00
Matthias Richter
4dead776e1 add type details to unnecessary_fallible_conversions note 2023-11-11 21:01:36 +01:00
Jason Newcomb
a68cd88860 Lint needless_borrow on most union field accesses 2023-11-11 14:50:19 -05:00
bors
d487579efd Auto merge of #11792 - y21:issue11764, r=llogiq
[`map_identity`]: respect match ergonomics

Fixes #11764

Note: the original tests before this were slightly wrong themselves already and had to be changed. They were calling `map` on an iterator of `&(i32, i32)`s, so this PR would stop linting there, but they were meant to test something else unrelated to binding modes, so I just changed them to remove the references so that it iterates over owned values and they all bind by value. This way they continue to test what they checked for before: the identity function for tuple patterns.

changelog: [`map_identity`]: respect match ergonomics
2023-11-11 14:58:00 +00:00
y21
b2cf8f7a24 [map_identity]: respect match ergonomics 2023-11-11 13:48:26 +01:00
Jacherr
cb90674aed add iter_over_hash_type lint 2023-11-11 00:20:47 +00:00
bors
6be0f7414d Auto merge of #11780 - Jacherr:vec-allocator-nolint, r=xFrednet
Disable `vec_box` when using different allocators

Fixes #7114

This PR disables the `vec_box` lint when the `Box` and `Vec` use different allocators (but not when they use the same - custom - allocator).

For example - `Vec<Box<i32, DummyAllocator>>` will disable the lint, and `Vec<Box<i32, DummyAllocator>, DummyAllocator>` will not disable the lint.

In addition, the applicability of this lint has been changed to `Unspecified` due to the automatic fixes potentially breaking code such as the following:

```rs
fn foo() -> Vec<Box<i32>> { // -> Vec<i32>
  vec![Box::new(1)]
}
```

It should be noted that the `if_chain->let-chains` fix has also been applied to this lint, so the diff does contain many changes.

changelog: disable `vec_box` lint when using nonstandard allocators
2023-11-09 23:33:46 +00:00
Jacherr
eabc64f56c add additonal non-trigger testcase 2023-11-09 23:03:44 +00:00
Jason Newcomb
a44bb07900 Change divergence checking to match the compiler's type system based definition of divergence. 2023-11-09 17:57:06 -05:00
Alex Macleod
d8c0e6460b Make macro_use_imports lint ordering more stable 2023-11-09 13:34:00 +00:00
Jacherr
483b109e6e cargo dev fmt 2023-11-08 21:17:40 +00:00
Jacherr
b6d56c47f9 add no-rustfix since suggestions are invalid 2023-11-08 21:15:11 +00:00
Jacherr
67bb503f26 add support for std::alloc::Global, add more tests 2023-11-08 21:10:27 +00:00
Jacherr
79325604da update testcases, cleanup 2023-11-08 18:42:58 +00:00
PartiallyTyped
399fe32893 [arc_with_non_send_sync] Improve suggested resolution
Fixes: #11714
changelog: [`arc_with_non_send_sync`]: Suggest RC over unsafe impl

Co-authored-by: Alejandra González <blyxyas@gmail.com>
2023-11-08 19:38:59 +01:00
dswij
8c79f7840d read_zero_byte_vec refactor for better heuristics 2023-11-07 18:29:32 +08:00
Dinu Blanovschi
67cc4b0cad fix clippy author and failing test 2023-11-04 21:43:18 +01:00
Nadrieril
17c7d21650 Warn when lint level is set on a match arm 2023-11-04 14:44:00 +01:00
y21
294df80e2c [unused_enumerate_index]: don't ICE on empty tuples 2023-11-03 21:13:51 +01:00
sjwang05
39eded7b05
Lint flatten() under lines_filter_map_ok 2023-11-02 18:24:15 -07:00
y21
c9d2961100 teach eager_or_lazy that arithmetic ops can panic 2023-11-02 23:53:00 +01:00
bors
902c79c654 Auto merge of #11743 - Alexendoo:dbg-macro-stmt-span, r=xFrednet
Fix `dbg_macro` semi span calculation

`span_including_semi` was using a `BytePos` to index into a file's source which happened to work because the root file of the test started at `BytePos` 0, it didn't work for other files

changelog: none
2023-11-02 20:11:32 +00:00
Philipp Krones
77c1e3aaa1 Merge commit '09ac14c901abc43bd0d617ae4a44e8a4fed98d9c' into clippyup 2023-11-02 17:35:56 +01:00
Philipp Krones
62a82b361c
Format let-chains across the code base
In the updated nightly version, it seems that rustfmt now supports formatting
let-chains. Since we're using them a lot, it's a lot of reformatting.
2023-11-02 17:24:30 +01:00
Philipp Krones
95dc7be92f
Merge remote-tracking branch 'upstream/master' into rustup 2023-11-02 17:24:19 +01:00
Matthias Richter
3b759bce9d fix get_first false negative for VecDeque 2023-11-01 23:26:43 +01:00
Alex Macleod
57a464439e Fix dbg_macro semi span calculation 2023-11-01 16:25:15 +00:00
John Millikin
e3a1555648 Stabilize C string literals 2023-11-01 09:16:34 +09:00
Dinu Blanovschi
14b82909b0 Apply suggestions from code review
Co-authored-by: Alejandra González <blyxyas@gmail.com>
2023-10-31 18:21:34 +01:00
Dinu Blanovschi
0b90f72064 feat: unused_enumerate_index lint 2023-10-31 17:53:24 +01:00
bors
7d34406015 Auto merge of #11669 - y21:issue11577, r=Jarcho
new lint: `unnecessary_fallible_conversions`

Closes #11577

A new lint that looks for calls such as `i64::try_from(1i32)` and suggests `i64::from(1i32)`. See lint description (and linked issue) for more details for why.

There's a tiny bit of overlap with the `useless_conversion` lint, in that the other one warns `T::try_from(T)` (i.e., fallibly converting to the same type), so this lint ignores cases like `i32::try_from(1i32)` to avoid emitting two warnings for the same expression.

Also, funnily enough, with this one exception, this lint would warn on exactly every case in the `useless_conversion_try` ui test that `useless_conversion` didn't cover (but never two warnings at the same time), which is neat. I did add an `#![allow]` though since we don't want interleaved warnings from multiple lints in the same uitest.

changelog: new lint: `unnecessary_fallible_conversions`
2023-10-31 05:13:48 +00:00
bors
3da80dc752 Auto merge of #11498 - jonboh:issue11494_enumvariants_order_affects_lint, r=Centri3
fix enum_variant_names depending lint depending on order

changelog: [`enum_variant_names`]: fix single word variants preventing lint of later variant pre/postfixed with the enum name

fixes #11494

Single word variants prevented checking the `check_enum_start` and `check_enum_end` for being run on later variants
2023-10-31 01:33:25 +00:00
y21
69c3b9c252 new lint: unnecessary_fallible_conversions 2023-10-30 20:54:24 +01:00
Andre Bogus
e6c804c457 ignore lower-camel-case words in doc_markdown 2023-10-29 23:04:17 +01:00
jonboh
c51e2a0f75 fix enum_variant_names depending lint depending on order 2023-10-29 17:34:11 +01:00
bors
5852ca8443 Auto merge of #11724 - rust-lang:fix-11559, r=blyxyas
Fix missing parenthesis in suboptimal floating point help

This fixes #11559 by adding a branch in the `Neg` implementation for `Sugg` that adds parentheses to keep precedence in order, then using that in the suggestion. I also removed some needless `.to_string()`s while I was at it.

---

changelog: none
2023-10-28 18:46:28 +00:00
bors
f8409ef85f Auto merge of #11696 - y21:iter_without_into_iter_suggestion, r=xFrednet
[`iter_without_into_iter`]: fix papercuts in suggestion and restrict linting to exported types

See #11692 for more context.

tldr: the lint `iter_without_into_iter` has suggestions that don't compile, which imo isn't that problematic because it does have the appropriate `Applicability` that tells external tools that it shouldn't be auto-applied.
However there were some obvious "errors" in the suggestion that really should've been included in my initial PR adding the lint, which is fixed by this PR:
- `IntoIterator::into_iter` needs a `self` argument.
- `IntoIterator::Iter` associated type doesn't exist. This should've just been `Item`.

This still doesn't make it machine applicable, and the remaining things are imho quite non-trivial to implement, as I've explained in https://github.com/rust-lang/rust-clippy/issues/11692#issuecomment-1773886111.
I personally think it's fine to leave it there and let the user change the remaining errors when copy-pasting the suggestion (e.g. errors caused by lifetimes that were permitted in fn return-position but are not in associated types).
This is how many of our other lint suggestions already work.

Also, we now restrict linting to only exported types. This required moving basically all of the tests around since they were previously in the `main` function. Same for `into_iter_without_iter`. The git diff is a bit useless here...

changelog: [`iter_without_into_iter`]: fix papercuts in suggestion and restrict linting to exported types

(cc `@lopopolo,` figured I should mention you since you created the issue)
2023-10-28 14:50:51 +00:00
Andre Bogus
1ed1001440 Fix missing parenthesis in suboptimal floating point help 2023-10-27 16:28:10 +02:00
bors
2f0f4ddcf7 Auto merge of #11698 - a1phyr:waker_clone_and_wake, r=y21
Add `waker_clone_and_wake` lint to check needless `Waker` clones

Check for patterns of `waker.clone().wake()` and replace them with `waker.wake_by_ref()`.

An alternative name could be `waker_clone_then_wake`

changelog: [ `waker_clone_wake`]: new lint
2023-10-26 21:01:40 +00:00
bors
0da4dab720 Auto merge of #11584 - koka831:fix/11335, r=blyxyas
let_and_return: Wrap with parenthesis if necessary

- fixes https://github.com/rust-lang/rust-clippy/issues/11335

changelog: [`let_and_return`]: Wrap suggestion with parenthesis if necessary

r? `@Centri3`
2023-10-26 14:20:13 +00:00
bors
7ce6e0d853 Auto merge of #11670 - lengyijun:ignored_unit_pattern_ref, r=dswij
[`ignored_unit_patterns`]: check &(), &&(), ...

changelog: [`ignored_unit_patterns`]: check &(), &&(), ...
2023-10-25 18:02:33 +00:00
Benoît du Garreau
ebf6667b57 Apply suggestions 2023-10-25 15:15:29 +02:00
Oli Scherer
ffc741965e Work around the fact that check_mod_type_wf may spuriously return ErrorGuaranteed, even if that error is only emitted by check_modwitem_types 2023-10-25 12:04:54 +00:00
bors
cd6ec97f0d Auto merge of #116773 - dtolnay:validatestable, r=compiler-errors
Validate `feature` and `since` values inside `#[stable(…)]`

Previously the string passed to `#[unstable(feature = "...")]` would be validated as an identifier, but not `#[stable(feature = "...")]`. In the standard library there were `stable` attributes containing the empty string, and kebab-case string, neither of which should be allowed.

Pre-existing validation of `unstable`:

```rust
// src/lib.rs

#![allow(internal_features)]
#![feature(staged_api)]
#![unstable(feature = "kebab-case", issue = "none")]

#[unstable(feature = "kebab-case", issue = "none")]
pub struct Struct;
```

```console
error[E0546]: 'feature' is not an identifier
 --> src/lib.rs:5:1
  |
5 | #![unstable(feature = "kebab-case", issue = "none")]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

For an `unstable` attribute, the need for an identifier is obvious because the downstream code needs to write a `#![feature(...)]` attribute containing that identifier. `#![feature(kebab-case)]` is not valid syntax and `#![feature(kebab_case)]` would not work if that is not the name of the feature.

Having a valid identifier even in `stable` is less essential but still useful because it allows for informative diagnostic about the stabilization of a feature. Compare:

```rust
// src/lib.rs

#![allow(internal_features)]
#![feature(staged_api)]
#![stable(feature = "kebab-case", since = "1.0.0")]

#[stable(feature = "kebab-case", since = "1.0.0")]
pub struct Struct;
```

```rust
// src/main.rs

#![feature(kebab_case)]

use repro::Struct;

fn main() {}
```

```console
error[E0635]: unknown feature `kebab_case`
 --> src/main.rs:3:12
  |
3 | #![feature(kebab_case)]
  |            ^^^^^^^^^^
```

vs the situation if we correctly use `feature = "snake_case"` and `#![feature(snake_case)]`, as enforced by this PR:

```console
warning: the feature `snake_case` has been stable since 1.0.0 and no longer requires an attribute to enable
 --> src/main.rs:3:12
  |
3 | #![feature(snake_case)]
  |            ^^^^^^^^^^
  |
  = note: `#[warn(stable_features)]` on by default
```
2023-10-24 15:06:20 +00:00
Benoît du Garreau
f8790963d9 Add a lint to check needless Waker clones 2023-10-24 09:58:23 +02:00
bors
330d7fafb8 Auto merge of #116033 - bvanjoi:fix-116032, r=petrochenkov
report `unused_import` for empty reexports even it is pub

Fixes #116032

An easy fix. r? `@petrochenkov`

(Discovered this issue while reviewing #115993.)
2023-10-23 20:24:09 +00:00
Alex Macleod
4622203c9b Move configuration to new clippy_config crate 2023-10-23 20:05:10 +00:00
David Tolnay
7ade24e824 Fix stable feature names in tests 2023-10-23 13:03:11 -07:00
bors
9f5de6626b Auto merge of #11460 - J-ZhengLi:issue11429, r=Centri3
suggest passing function instead of calling it in closure for [`option_if_let_else`]

fixes: #11429

changelog: suggest passing function instead of calling it in closure for [`option_if_let_else`]
2023-10-23 14:37:13 +00:00
bors
350a6827a8 Auto merge of #116849 - oli-obk:error_shenanigans, r=cjgillot
Avoid a `track_errors` by bubbling up most errors from `check_well_formed`

I believe `track_errors` is mostly papering over issues that a sufficiently convoluted query graph can hit. I made this change, while the actual change I want to do is to stop bailing out early on errors, and instead use this new `ErrorGuaranteed` to invoke `check_well_formed` for individual items before doing all the `typeck` logic on them.

This works towards resolving https://github.com/rust-lang/rust/issues/97477 and various other ICEs, as well as allowing us to use parallel rustc more (which is currently rather limited/bottlenecked due to the very sequential nature in which we do `rustc_hir_analysis::check_crate`)

cc `@SparrowLii` `@Zoxc` for the new `try_par_for_each_in` function
2023-10-23 09:59:40 +00:00
bors
f942470ca7 Auto merge of #11028 - BenWiederhake:dev-ifnotelse_neqzero, r=llogiq
Skip if_not_else lint for '!= 0'-style checks

Currently, clippy makes unhelpful suggestions such as this:

```
warning: unnecessary `!=` operation
   --> src/vm.rs:598:36
    |
598 |                     *destination = if source & 0x8000 != 0 { 0xFFFF } else { 0 };
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: change to `==` and swap the blocks of the `if`/`else`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else
    = note: `-W clippy::if-not-else` implied by `-W clippy::pedantic`
```

Bit tests often take on the form `if foo & 0x1234 != 0 { … } else { … }`, and the `!= 0` part reads as "has any bits set". Therefore, this code already has the "correct" order, and shouldn't be changed.

This PR disables the lint for these cases, and in fact all cases where the condition is "foo is non-zero".

I did my homework:
- \[X] Followed [lint naming conventions][lint_naming] → Not applicable, this PR fixes an existing lint
- \[X] Added passing UI tests (including committed `.stderr` file) → Yes, `tests/ui/if_not_else_bittest.rs`
- \[X] `cargo test` passes locally
- \[X] Executed `cargo dev update_lints`
- \[X] Added lint documentation → Not applicable, this PR fixes an existing lint
- \[X] Run `cargo dev fmt`

changelog: Fix [`if_not_else`] false positive when something like `bitflags != 0` is used
2023-10-23 07:42:15 +00:00
y21
3c501e4e41 [iter_without_into_iter]: fix papercuts + only lint on pub types 2023-10-22 20:19:31 +02:00
bohan
87d0ace9ac use visibility to check unused imports and delete some stmts 2023-10-22 21:27:46 +08:00
y21
d6fc606259 [map_identity]: recognize tuples 2023-10-21 15:40:34 +02:00
Philipp Krones
8e7d1678c4 Merge commit '2b030eb03d9e5837440b1ee0b98c50b97c0c5889' into clippyup 2023-10-21 14:16:11 +02:00
Philipp Krones
5f031561ef
Merge remote-tracking branch 'upstream/master' into rustup 2023-10-21 13:41:46 +02:00
Oli Scherer
d9259fdedd s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
bors
e230f19e18 Auto merge of #11521 - y21:issue9122, r=llogiq
[`map_identity`]: allow closure with type annotations

Fixes #9122

`.map(|a: u32| a)` can help type inference, so we should probably allow this and not warn about "unnecessary map of the identity function"

changelog: [`map_identity`]: allow closure with type annotations
2023-10-20 13:28:30 +00:00
Oli Scherer
4fc503ee37 Avoid a track_errors by bubbling up most errors from check_well_formed 2023-10-20 08:46:27 +00:00
Esteban Küber
a07c032e96 Tweak wording of type errors involving type params
Fix #78206.
2023-10-18 23:53:18 +00:00
Guillaume Gomez
3e6db95e30 Add regression test for #11561 2023-10-18 21:17:32 +02:00
Guillaume Gomez
3b4b07c5f8 Add test for closure in non-async function for needless_pass_by_ref_mut lint 2023-10-18 21:17:31 +02:00
bors
fe21991520 Auto merge of #11496 - jonboh:prefix_postfix_struct, r=y21
add lint for struct field names

changelog: [`struct_field_names`]: lint structs with the same pre/postfix in all fields or with fields that are pre/postfixed with the name of the struct.

fixes #2555

I've followed general structure and naming from the code in [enum_variants](b788addfcc/clippy_lints/src/enum_variants.rs) lint, which implements the same logic for enum variants.
2023-10-18 18:47:27 +00:00
jonboh
8b02dac542 add lint for struct field names
side effect for `enum_variants`:
use .first() instead of .get(0) in enum_variants lint
move to_camel_case to str_util module
move module, enum and struct name repetitions check to a single file `item_name_repetitions`
rename enum_variants threshold config option
2023-10-18 19:20:08 +02:00
Guillaume Gomez
80a092c6df Add test for needless_pass_by_ref_mut to ensure that the lint is not emitted if variable is used in an unsafe block or function 2023-10-17 15:36:38 +02:00
bors
2640d5cc85 Auto merge of #11622 - GuillaumeGomez:needless_pass_by_ref_mut-regression-test-11610, r=blyxyas
Add regression test for #11610 about mutable usage of argument in async function for the `needless_pass_by_ref_mut` lint

Fixes https://github.com/rust-lang/rust-clippy/issues/11610.

This was already fixed. I simply added a regression test.

changelog: Add regression test for #11610 about mutable usage of argument in async function for the `needless_pass_by_ref_mut` lint
2023-10-17 12:20:03 +00:00
lengyijun
536114c857 [ignored_unit_patterns]: check &(), &&(), ... 2023-10-17 10:41:15 +08:00
bors
2cf708d04f Auto merge of #11646 - Nilstrieb:compiler-does-not-comply-with-the-lints!!, r=giraffate
Make `multiple_unsafe_ops_per_block` ignore await desugaring

The await desugaring contains two calls (`Poll::new_unchecked` and `get_context`) inside a single unsafe block. That violates the lint.

fixes #11312

changelog: [`multiple_unsafe_ops_per_block`]: fix false positives in `.await`
2023-10-17 00:35:50 +00:00
bors
9f27b1562c Auto merge of #11673 - y21:issue11672, r=Manishearth
[`unnecessary_lazy_eval`]: reduce applicability if closure has return type annotation

Fixes #11672

We already check if closure parameters don't have type annotations and reduce the applicability to `MaybeIncorrect` if they do, since those help type inference and removing them breaks code. We didn't do this for return type annotations however. This PR adds it. This doesn't change it to produce a fix that will compile, but it will prevent rustfix from auto-applying it.

(In general I'm not sure if we can suggest a fix that will compile. In this specific example, it might be possible to suggest `&[] as &[u8]`, but as-casts won't always work, e.g. `Default::default() as &[u8]` is a compile error, so just reducing applicability should be a safe fix in any case for now)

changelog: [`unnecessary_lazy_eval`]: reduce applicability to `MaybeIncorrect` if closure has return type annotation
2023-10-16 16:27:01 +00:00
bors
ef95be517c Auto merge of #11609 - y21:get_first_non_primitives, r=giraffate
[`get_first`]: lint on non-primitive slices

Fixes #11594

I left the issue open for a couple days before making the PR to see if anyone has something to say, but it looks like there aren't any objections to removing this check that prevented linting on non-primitive slices, so here's the PR now.
There's a couple of instances in clippy itself where we now emit the lint. The actual relevant change is in the first commit and fixing the `.get(0)` instances in clippy itself is in the 2nd commit.

changelog: [`get_first`]: lint on non-primitive slices
2023-10-15 23:53:22 +00:00
y21
bb6516ace0 [unnecessary_lazy_eval]: don't emit autofix suggestion if closure has return type 2023-10-16 00:47:13 +02:00
Nilstrieb
6ed04af81c Make multiple_unsafe_ops_per_block ignore await desugaring
The await desugaring contains two calls (`Poll::new_unchecked` and
`get_context`) inside a single unsafe block. That violates the lint.
2023-10-14 23:15:00 +02:00
Michael Goulet
1ffd09af29 Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
bors
c40359d97a Auto merge of #11664 - koka831:fix/11134, r=blyxyas
Fix/11134

Fix #11134

Hir of `qpath` will be `TypeRelative(Ty { kind: Path(LangItem...` when a closure contains macro (e.g. https://github.com/rust-lang/rust-clippy/issues/11651) and #11134, it causes panic.
This PR avoids panicking and emitting incomplete path string when `qpath` contains `LangItem`.

changelog: none
2023-10-13 10:18:49 +00:00
koka
9fc717dea3
add test for macro-in-loop 2023-10-13 17:12:41 +09:00
koka
eb6fb18a99
Avoid panic!, omit instead 2023-10-13 17:07:29 +09:00
Alona Enraght-Moony
b5488f9850 [manual_is_ascii_check]: Also check for is_ascii_hexdigt 2023-10-12 19:12:42 +00:00
y21
0b60531e42 [map_identity]: allow closure with type annotations 2023-10-09 21:39:28 +02:00
Michael Goulet
70b8d15a85 Extend impl's def_span to include where clauses 2023-10-09 11:47:02 +00:00
bors
bde04824cc Auto merge of #11550 - blyxyas:fix-impl_trait_in_params-for_assocfn, r=dswij
`impl_trait_in_params` now supports impls and traits

Before this PR, the lint `impl_trait_in_params`. This PR gives the lint support for functions in impls and traits. (Also, some pretty heavy refactor)

fixes #11548
changelog:[`impl_trait_in_params`] now supports `impl` blocks and functions in traits
2023-10-08 21:57:56 +00:00
blyxyas
775573768e
Fix tests, only lint for public tests 2023-10-08 23:49:32 +02:00
blyxyas
5ed338dff9
impl_trait_in_params now supports impls and traits 2023-10-08 23:49:32 +02:00
y21
1c6fa2989d [into_iter_without_iter]: look for iter method in deref chains 2023-10-07 16:33:06 +02:00
koka
68d2082d69
Fix ice 2023-10-07 01:28:06 +09:00
Philipp Krones
8ebed4cc1a Merge commit 'b105fb4c39bc1a010807a6c076193cef8d93c109' into clippyup 2023-10-06 17:35:45 +02:00
Philipp Krones
82c3064c47
Merge remote-tracking branch 'upstream/master' into rustup 2023-10-06 17:31:44 +02:00
bors
7217c0f3ac Auto merge of #11628 - koka831:fix/11625, r=blyxyas
Improve `redundant_locals` help message

Fixes #11625

AFAIK, `span_lint_and_help` points the beginning of spans when we pass multiple spans to the second argument, so This PR I also modified its help span and its message.

lint result of the given example in the issue will be:

```console
error: redundant redefinition of a binding `apple`
 --> src/main.rs:5:5
  |
5 |     let apple = apple;
  |     ^^^^^^^^^^^^^^^^^^
  |
help: `apple` is initially defined here
 --> src/main.rs:4:9
  |
4 |     let apple = 42;
  |         ^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_locals
```

I hope that this change might help reduce user confusion, but I'd appreciate alternative suggestions:)

changelog: [`redundant_locals`]: Now points at the rebinding of the variable
2023-10-06 15:06:00 +00:00
bors
279127ce2e Auto merge of #11611 - Alexendoo:items-after-test-module-check-crate, r=blyxyas
Fix `items_after_test_module` for non root modules, add applicable suggestion

Fixes #11050
Fixes #11153

changelog: [`items_after_test_module`]: Now suggests a machine-applicable suggestion.
changelog: [`items:after_test_module`]: Also lints for non root modules
2023-10-06 14:19:45 +00:00
koka
48d2770e52
Improve redundant_locals help message 2023-10-06 22:18:11 +09:00
Alex Macleod
dcc400191e Fix items_after_test_module for non root modules, add applicable suggestion 2023-10-06 12:46:04 +00:00
Guillaume Gomez
ddd1564e5d Add regression test for #11610 about mutable usage of argument in async function for the needless_pass_by_ref_mut lint 2023-10-06 11:18:34 +02:00
Michael Goulet
c5c6d703de Point to closure return instead of output if defaulted 2023-10-04 21:09:54 +00:00
Michael Goulet
56794fa5f1 Fix clippy 2023-10-04 21:09:54 +00:00
y21
31fd282732 [get_first]: lint on non-primitive types 2023-10-04 18:07:54 +02:00
bors
b437069f59 Auto merge of #11603 - koka831:fix/11599, r=y21
Fix: avoid changing drop order

Fixes https://github.com/rust-lang/rust-clippy/issues/11599

changelog: [`redundant_locals`] No longer lints which implements Drop trait to avoid reordering
2023-10-03 15:49:28 +00:00
koka
c7152679ef
Apply review suggestions from @y21 2023-10-04 00:13:53 +09:00
koka
1a56f90ee5
Fix: avoid changing drop order 2023-10-03 21:28:01 +09:00
koka
e465264d47
Avoid invoking ignored_unit_patterns in macro definition 2023-10-03 20:36:35 +09:00
Michael Goulet
2c525fd758 Point to full async fn for future 2023-10-03 02:25:32 +00:00
bors
81400e2db8 Auto merge of #11589 - koka831:fix/10198, r=giraffate
std_instead_of_core: avoid lint inside of proc-macro

- fixes https://github.com/rust-lang/rust-clippy/issues/10198

note: The lint for the reported `thiserror::Error` has been suppressed by [Don't lint unstable moves in std_instead_of_core](https://github.com/rust-lang/rust-clippy/pull/9545/files#diff-2cb8a24429cf9d9898de901450d640115503a10454d692dddc6a073a299fbb7eR29) because `thiserror::Error`  internally implements `std::error::Error for (derived struct)`.

changelog: [`std_intead_of_core`]: avoid linting inside proc-macro

I confirmed this change fixes the problem:
<details>
<summary>test result without the change</summary>

```console
error: used import from `std` instead of `core`
  --> tests/ui/std_instead_of_core.rs:65:14
   |
LL |     #[derive(ImplStructWithStdDisplay)]
   |              ^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the derive macro `ImplStructWithStdDisplay` (in Nightly builds, run with -Z macro-backtrace for more info)
```
</details>
2023-10-03 01:26:29 +00:00
bors
08c429f241 Auto merge of #11596 - blyxyas:fix-fp-needless_pass_by_ref_mut, r=Jarcho
Move `needless_pass_by_ref_mut`: `suspicious` -> `nursery`

[Related to [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/needless_pass_by_ref_mut.20isn't.20ready.20for.20stable)]

`needless_pass_by_ref_mut` has been released with some important bugs (notably having a lot of reported false positives and an ICE). So it may not be really ready for being in stable until these problems are solved. This PR changes the lint's category from `suspicious` to `nursery`, just that.
changelog: none
2023-10-02 18:40:32 +00:00
blyxyas
07e63291ec
Modify tests to account for the new allow-by-default needless_pass_by_ref_mut 2023-10-02 20:14:43 +02:00
Alex Macleod
258b9a8562 Don't escape unicode escape braces in print_literal 2023-10-01 21:43:09 +00:00
bors
3169423ce9 Auto merge of #115670 - Zoxc:outline-panic-macro-1, r=Mark-Simulacrum
Partially outline code inside the panic! macro

This outlines code inside the panic! macro in some cases. This is split out from https://github.com/rust-lang/rust/pull/115562 to exclude changes to rustc.
2023-10-01 05:56:47 +00:00
Victor Song
e683e3eeac Don't lint manual_non_exhaustive when enum explicitly marked as non_exhaustive
There are cases where users create a unit variant for the purposes
of tracking the number of variants for an nonexhaustive enum.
We should check if an enum is explicitly marked as nonexhaustive
before reporting `manual_non_exhaustive` in these cases. Fixes #11583
2023-09-30 22:57:54 -05:00
bors
0e43a04fab Auto merge of #11587 - y21:into_iter_without_iter, r=Jarcho
new lint: `into_iter_without_iter`

Closes #9736 (part 2)

This implements the other lint that my earlier PR missed: given an `IntoIterator for &Type` impl, check that there exists an inherent `fn iter(&self)` method.

changelog: new lint: `into_iter_without_iter`

r? `@Jarcho` since you reviewed #11527 I figured it makes sense for you to review this as well?
2023-09-30 18:43:37 +00:00
y21
8eb586d154 new lint: into_iter_without_iter 2023-09-30 19:38:16 +02:00
koka
d5cc97e32c
Add macro for test which use std internally 2023-10-01 00:47:57 +09:00
bors
b00236d7f0 Auto merge of #11580 - y21:issue11579, r=Jarcho
[`manual_let_else`]: only omit block if span is from same ctxt

Fixes #11579.

The lint already had logic for omitting a block in `else` if a block is already present, however this didn't handle the case where the block is from a different expansion/syntax context. E.g.
```rs
macro_rules! panic_in_block {
  () => { { panic!() } }
}

let _ = match Some(1) {
  Some(v) => v,
  _ => panic_in_block!()
};
```
It would see this in its expanded form as `_ => { panic!() }` and think it doesn't have to include a block in its suggestion because it is already there, however that's not true if it's from a different expansion like in this case.

changelog: [`manual_let_else`]: only omit block in suggestion if the block is from the same expansion
2023-09-29 18:49:57 +00:00
y21
2d2017942a [manual_let_else]: only omit block if span is from same ctxt 2023-09-29 16:54:50 +02:00
koka
f4a8b12ed5
Wrap with parenthesis if necessary 2023-09-29 23:17:49 +09:00
y21
330ebbb9f9 new lint: iter_without_into_iter 2023-09-28 22:22:36 +02:00
koka
b413bf6c4e
Fix index of the remaining positional arguments 2023-09-28 17:34:02 +09:00
bors
4494b6947f Auto merge of #11569 - Alexendoo:needless-raw-string-descr, r=llogiq
Describe the type of string in raw_strings lints

changelog: none
2023-09-26 21:16:33 +00:00
Alex Macleod
ec2f62677f Add manual_hash_one lint 2023-09-26 13:49:15 +00:00
Alex Macleod
6cdff10778 Describe the type of string in raw_strings lints 2023-09-26 11:49:44 +00:00