Commit Graph

9554 Commits

Author SHA1 Message Date
Samuel Tardieu
2b0e7bb4a7 Fix lifetimes elision suggestion in where clauses 2024-11-30 21:57:16 +01:00
Samuel Tardieu
9a692ec8cd Add more cases to the useless_conversion lint
The new cases are `x.map(f)` and `x.map_err(f)` when `f` is `Into::into`
or `From::from` with the same input and output types.
2024-11-30 21:57:16 +01:00
Dominik Stolz
a6a6936019 Remove hir::ArrayLen, introduce ConstArgKind::Infer
Remove Node::ArrayLenInfer
2024-11-30 21:00:31 +01:00
Jason Newcomb
650e0c8d3d Fix shadow_unrelated's behaviour with closures (#13677)
Fixes https://github.com/rust-lang/rust-clippy/issues/10780

We correctly no longer give a warning when a closure is passed to a
method, where one of the arguments to that method uses the variable
which would be shadowed by an argument to that closure.
Uses is defined loosely as any expression used in the calling expression
mentions the shadowee binding (except for the closure itself):

```rust
#![deny(clippy::shadow_unrelated)]
let x = Some(1);
let y = x.map(|x| x + 1);
```
will now succeed.

See https://github.com/linebender/xilem/pull/745 - without this change,
all of the `expect(shadow_unrelated)` in the repository are met; with
it, none of them are.

changelog: [`shadow_unrelated`]: Don't treat closures arguments as
unrelated when the calling function uses them
2024-11-30 17:08:08 +00:00
Natsume-Neko
120b84125e Modified the tests so that if we place wrong parentheses we will get a different result 2024-11-30 14:26:47 +08:00
y21
1329547367 add targetted help messages to zombie_processes diagnostic 2024-11-30 00:38:13 +00:00
Philipp Krones
d58b911e01 Merge commit 'ff4a26d442bead94a4c96fb1de967374bc4fbd8e' into clippy-subtree-update 2024-11-28 19:38:59 +01:00
Natsume-Neko
66e212b544 Extend precedence for bitmasking and shift
Changelog: extended [`precedence`] to lint for bitmasking and bit shifting without parentheses
2024-11-28 16:52:11 +08:00
Michael Howell
44feca7f3f doc_nested_refdefs: new lint for suspicious refdef syntax
This is more likely to be intended as an intra-doc link than it is
to be intended as a refdef. If a refdef is intended, it does not
need to be nested within a list item or quote.

```markdown
- [`LONG_INTRA_DOC_LINK`]: this
  looks like an intra-doc link,
  but is actually a refdef.
  The first line will seem to
  disappear when rendered as HTML.
```
2024-11-27 13:42:04 -07:00
Timo
67657da671 Handle repetition of associated constant constraint as well (#13723)
changelog: [`trait_duplication_in_bounds`]: trigger on duplicate const
associated constraint as well

~~The first commit is part of #13722 which must be merged first.~~
2024-11-27 20:23:54 +00:00
Philipp Krones
9b0597d78a Fix: Use multipart_suggestion for derivable_impls (#13717)
This should address #13099 for the `derivable_impls` test. As I've not
contributed to clippy before, I'd like to make sure i'm on the right
track before doing more :)

changelog: [`derivable_impls`]: Use multipart_suggestion to aggregate
feedback
2024-11-27 17:07:51 +00:00
Samuel Tardieu
2bf03f19e2 Handle repetition of associated constant constraint as well 2024-11-25 23:24:51 +01:00
Samuel Tardieu
9fd8e99d91 Prevent ICE in case of a bound constraint on generic argument 2024-11-23 21:25:34 +01:00
Guillaume Gomez
cfc6444f84 Limit literal_string_with_formatting_args to known variables if no formatting argument is passed 2024-11-22 14:58:59 +01:00
Guillaume Gomez
607a3f6c08 Rename literal_string_with_formatting_arg into literal_string_with_formatting_args 2024-11-22 14:57:20 +01:00
Guillaume Gomez
9ea769a479 Disable checks on {} 2024-11-22 14:57:20 +01:00
Guillaume Gomez
05705b6938 Update new failing tests 2024-11-22 14:57:20 +01:00
Scott Gerring
9f7fb41272 fix: multipart suggestions for derivable_impls 2024-11-22 14:17:45 +01:00
Alejandra González
8298da72e7 Add new lint doc_include_without_cfg (#13625)
It's becoming more and more common to see people including markdown
files in their code using `doc = include_str!("...")`, which is great.
However, often there is no condition on this include, which is not great
because it slows down compilation and might trigger recompilation if
these files are updated.

This lint aims at fixing this situation.

changelog: Add new lint `doc_include_without_cfg`
2024-11-21 21:48:57 +00:00
Guillaume Gomez
404e47aa84 Add new lint doc_include_without_cfg 2024-11-21 22:43:55 +01:00
Samuel Tardieu
425346a1bc Use a better message for unnecessary_map_or lint
Suggested by @smoelius.
2024-11-19 21:44:29 +01:00
Guillaume Gomez
922aabe348 Add regression test for literal_string_with_formatting_arg 2024-11-19 15:44:19 +01:00
Samuel Moelius
eaec0cab7e Fix 13578 (#13583)
changelog: don't consider lifetimes in bounded types unused (fix `extra_unused_lifetimes` FP #13578)
2024-11-18 20:20:19 -05:00
Manish Goregaokar
53994bda92 Remove extern vectorcall tests (#13702)
On arm64 I get

```
error[E0570]: `"vectorcall"` is not a supported ABI for the current target
```

We don't seem to be doing any ABI specific handling so it seems fine to
just remove this one since there are other tests

changelog: none
2024-11-18 19:00:14 +00:00
Catherine Flores
d3edd057b9 Handle Option::map_or(true, …) in unnecessary_map_or lint (#13653)
changelog: [`unnecessary_map_or`]: handle `Option::map_or(true, …)`
2024-11-18 17:33:42 +00:00
Alex Macleod
90de44ab26 Remove extern vectorcall tests 2024-11-18 16:31:10 +00:00
Timo
97b9e4af17 Do not trigger if_let_mutex starting from Edition 2024 (#13695)
Close #13679

changelog: [`if_let_mutex`]: disable lint from Edition 2024 since
[stabilized if_let_rescope
](https://github.com/rust-lang/rust/issues/131154)
2024-11-17 18:10:29 +00:00
Alexey Semenyuk
ef42a66afe Do not trigger if_let_mutex strating from Edition 2024 2024-11-17 22:49:17 +05:00
Catherine Flores
8698c31f88 Don't lint CStr literals, do lint float literals in redundant_guards (#13698)
Two changes to `redundant_guards`:

- Lint float literals. We used to do that before but that was changed in
#11305 because at the time there was a future compat warning and it was
planned to make pattern matching floats a hard error.

In rust-lang/rust#116284 it was decided to actually remove the lint and
only make matching `NAN` specifically a hard error. The `NAN` part isn't
relevant/important here because this PR only changes what literals are
warned and `f64::NAN` isn't a literal, but I've added a test anyway to
make sure we continue to not lint there.
- Don't lint CStr literals because that can't be a pattern right now
(fixes #13681)

changelog: none
2024-11-17 04:24:43 +00:00
y21
8859847373 redundant_guards: lint float literals, don't lint cstr literals 2024-11-17 04:14:27 +01:00
Samuel Tardieu
de03a05bc8 unnecessary_map_or: lint .map_or(true, …) as well 2024-11-16 00:12:41 +01:00
Samuel Tardieu
d1688b53f1 unnecessary_map_or: add non-comparaison tests 2024-11-15 23:56:19 +01:00
Samuel Moelius
b97ad4eccd Add const parameter REPLACEMENT_ALLOWED to DisallowedPath 2024-11-15 17:37:45 -05:00
Samuel Moelius
d0f3577720 Properly handle disallowed_types 2024-11-15 17:37:10 -05:00
Samuel Moelius
f159a3eb1d Support replacements in disallowed_methods 2024-11-15 17:37:08 -05:00
Samuel Moelius
10e29413bc Remove unncesssary compile-flags directive 2024-11-15 17:33:49 -05:00
Yuri Astrakhan
81dceed8ba Support user format-like macros
Add support for `#[clippy::format_args]` attribute that can be attached to any macro to indicate that it functions the same as the built-in format macros like `format!`, `println!` and `write!`
2024-11-15 15:26:48 -05:00
Alejandra González
627363e811 Reverse dependency between clippy_utils and clippy_config (#13691)
In preparation of #13556, I want to remove the dependency on
`clippy_config`, as I don't think that we want to publish that for
outside consumers. To do this the 2 dependecies on `clippy_config` had
to be removed:

1. The MSRV implementation was in `clippy_config`, but was required in
`qualify_min_const`. I think exposing the MSRV infrastructure and the
MSRVs we defined might also be helpful for `clippy_utils` users. I don't
see why it should not be able to live in `clippy_utils` from a technical
point of few.
2. The `create_disallowed_map` function that took in a
`clippy_utils::types::DisallowedPath` is moved to the `DisallowedPath`
implementation. This also fits there and is only useful for Clippy and
not in `clippy_utils` for external consumers.

`clippy_config` now depends in `clippy_utils`, so the dependecy just got
reversed. But having the `clippy_utils` crate as the base of the
dependency tree in Clippy makes sense.

changelog: none
2024-11-15 20:08:03 +00:00
Alex Macleod
83f7526cf0 Allow conditional Send futures in future_not_send (#13590)
Closes #6947

This changes the lint to allow futures which are not `Send` as a result
of a generic type parameter not having a `Send` bound and only lint
futures that are always `!Send` for any type, which I believe is the
more useful behavior (like the comments in the linked issue explain).

This is still only a heuristic (I'm not sure if there's a more general
way to do this), but it should cover the common cases I could think of
(including the code examples in the linked issue)

changelog: [`future_not_send`]: allow conditional `Send` futures
2024-11-15 19:23:58 +00:00
Philipp Krones
5c1811ab94 Rename all clippy_config::msrvs -> clippy_utils::msrvs 2024-11-15 19:38:09 +01:00
Philipp Krones
1ceaa90413 Merge commit '786fbd6d683933cd0e567fdcd25d449a69b4320c' into clippy-subtree-update 2024-11-14 19:35:26 +01:00
Philipp Krones
c166ee1fc8 Merge remote-tracking branch 'upstream/master' into rustup 2024-11-14 18:27:35 +01:00
blyxyas
febe549113 Fix needless_match FP on if-lets 2024-11-14 15:57:45 +01:00
Jacherr
89210d7c5a new lint unnecessary_map_or 2024-11-12 23:00:26 +00:00
Daniel McNab
d1cab0860a Fix shadow_unrelated's behaviour with closures
Fixes https://github.com/rust-lang/rust-clippy/issues/10780
2024-11-12 17:31:17 +00:00
bors
e2962cc079 Auto merge of #126597 - estebank:unicode-output, r=fmease
Add Unicode block-drawing compiler output support

Add nightly-only theming support to rustc output using Unicode box
drawing characters instead of ASCII-art to draw the terminal UI.

In order to enable, the flags `-Zunstable-options=yes --error-format=human-unicode` must be passed in.

After:

```
error: foo
  ╭▸ test.rs:3:3
  │
3 │       X0 Y0 Z0
  │   ┌───╿──│──┘
  │  ┌│───│──┘
  │ ┏││━━━┙
  │ ┃││
4 │ ┃││   X1 Y1 Z1
5 │ ┃││   X2 Y2 Z2
  │ ┃│└────╿──│──┘ `Z` label
  │ ┃└─────│──┤
  │ ┗━━━━━━┥  `Y` is a good letter too
  │        `X` is a good letter
  ╰╴
note: bar
  ╭▸ test.rs:4:3
  │
4 │ ┏   X1 Y1 Z1
5 │ ┃   X2 Y2 Z2
6 │ ┃   X3 Y3 Z3
  │ ┗━━━━━━━━━━┛
  ├ note: bar
  ╰ note: baz
note: qux
  ╭▸ test.rs:4:3
  │
4 │   X1 Y1 Z1
  ╰╴  ━━━━━━━━
```

Before:

```
error: foo
 --> test.rs:3:3
  |
3 |       X0 Y0 Z0
  |    ___^__-__-
  |   |___|__|
  |  ||___|
  | |||
4 | |||   X1 Y1 Z1
5 | |||   X2 Y2 Z2
  | |||____^__-__- `Z` label
  | ||_____|__|
  | |______|  `Y` is a good letter too
  |        `X` is a good letter
  |
note: bar
 --> test.rs:4:3
  |
4 | /   X1 Y1 Z1
5 | |   X2 Y2 Z2
6 | |   X3 Y3 Z3
  | |__________^
  = note: bar
  = note: baz
note: qux
 --> test.rs:4:3
  |
4 |   X1 Y1 Z1
  |   ^^^^^^^^
```

After:

![rustc output with unicode box drawing characters](https://github.com/rust-lang/rust/assets/1606434/d210b79a-6579-4407-9706-ba8edc6e9f25)

Before:
![current rustc output with ASCII art](https://github.com/rust-lang/rust/assets/1606434/5aecccf8-a6ee-4469-8b39-72fb0d979a9f)
2024-11-11 00:00:58 +00:00
Esteban Küber
da93d78049 Add Unicode block-drawing compiler output support
Add nightly-only theming support to rustc output using Unicode box
drawing characters instead of ASCII-art to draw the terminal UI:

After:

```
error: foo
  ╭▸ test.rs:3:3
  │
3 │       X0 Y0 Z0
  │   ┌───╿──│──┘
  │  ┌│───│──┘
  │ ┏││━━━┙
  │ ┃││
4 │ ┃││   X1 Y1 Z1
5 │ ┃││   X2 Y2 Z2
  │ ┃│└────╿──│──┘ `Z` label
  │ ┃└─────│──┤
  │ ┗━━━━━━┥  `Y` is a good letter too
  │        `X` is a good letter
  ╰╴
note: bar
  ╭▸ test.rs:4:3
  │
4 │ ┏   X1 Y1 Z1
5 │ ┃   X2 Y2 Z2
6 │ ┃   X3 Y3 Z3
  │ ┗━━━━━━━━━━┛
  ├ note: bar
  ╰ note: baz
note: qux
  ╭▸ test.rs:4:3
  │
4 │   X1 Y1 Z1
  ╰╴  ━━━━━━━━
```

Before:

```
error: foo
 --> test.rs:3:3
  |
3 |       X0 Y0 Z0
  |    ___^__-__-
  |   |___|__|
  |  ||___|
  | |||
4 | |||   X1 Y1 Z1
5 | |||   X2 Y2 Z2
  | |||____^__-__- `Z` label
  | ||_____|__|
  | |______|  `Y` is a good letter too
  |        `X` is a good letter
  |
note: bar
 --> test.rs:4:3
  |
4 | /   X1 Y1 Z1
5 | |   X2 Y2 Z2
6 | |   X3 Y3 Z3
  | |__________^
  = note: bar
  = note: baz
note: qux
 --> test.rs:4:3
  |
4 |   X1 Y1 Z1
  |   ^^^^^^^^
```
2024-11-10 23:57:18 +01:00
y21
1309e8f3f3 allow conditional Send futures in future_not_send 2024-11-10 19:58:11 +01:00
Timo
f58088b23e Add match-based manual try to clippy::question_mark (#13627)
Closes #10.

changelog: [`question_mark`]: Now lints for match-based manual try
2024-11-10 16:26:56 +00:00
Manish Goregaokar
4f0e46b74d Fix large_include_file lint being triggered all the time by doc comments (#13672)
Fixes #13670.

Bug was that I forgot to add the comparison with the included file
content length...

changelog: Fix `large_include_file` lint being triggered all the time by
doc comments
2024-11-09 16:01:12 +00:00