Commit Graph

9219 Commits

Author SHA1 Message Date
Oli Scherer
e610ddfa5e box a bunch of large types 2023-04-04 13:58:50 +00:00
bors
5d149c5dac Auto merge of #10543 - blyxyas:tests_outside_test_module, r=flip1995
Add `tests_outside_test_module` lint

Adds `tests_outside_test_module` from #10506. This PR **doesn't** close the issue, just resolves task 1.

changelog: [`tests_outside_test_module`]: The lint has been added
2023-04-04 09:46:50 +00:00
Oli Scherer
ff7636db6a Split out ast::ItemKind::Const into its own struct 2023-04-04 09:44:50 +00:00
Oli Scherer
929696d754 rust-analyzer guided tuple field to named field 2023-04-04 09:44:50 +00:00
Oli Scherer
a6beddcc5a rust-analyzer guided enum variant structification 2023-04-04 09:44:45 +00:00
blyxyas
b2f9191820
Fix formatting and lint description 2023-04-04 11:42:32 +02:00
bors
73e412b6d4 Auto merge of #10592 - beetrees:parent-dir-bug-fix, r=giraffate
Fix bug with getting parent directories in `lookup_conf_file`

Currently `lookup_conf_file` doesn't canonicalize the configuration directory before using [`PathBuf::pop`](https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.pop) to get the parent directory. This isn't usually an issue when clippy is invoked via `cargo clippy` as `CARGO_MANIFEST_DIR` is already canonicalized. However, this currently causes `clippy-driver` to ignore any `clippy.toml` in any parent directories when  `CARGO_MANIFEST_DIR` and `CLIPPY_CONF_DIR` are not set.

changelog: Fix a bug that would cause parent directories not to be searched for `clippy.toml` when using `clippy-driver` directly.
2023-04-04 04:48:35 +00:00
feniljain
c12748fab3 fix(needless_return): do not trigger on ambiguous match arms return 2023-04-04 09:44:49 +05:30
bors
85d9f176b7 Auto merge of #10589 - blyxyas:fix-double_must_use, r=giraffate
Mini-fix `double_must_use` for async functions

From Rust 1.67 onwards, the `#[must_use]` attribute also applies to the `Future::Output` (rust-lang/rust#100633). So the lint `double_must_use` was linting all async functions. This PR changes the `double_must_use` lint so it ignores `async` functions.

---

Closes #10486
changelog: [`double_must_use`]: Fix false positive in async function
2023-04-04 00:09:11 +00:00
blyxyas
bd2a5b2322
Remove check for #[cfg(test)] 2023-04-03 18:42:00 +02:00
bhould287
3b22352d0d
Fix bug with getting parent directories in lookup_conf_file 2023-04-03 16:16:48 +01:00
blyxyas
a37eb4dfc9
Fix false negative on Result<(), ()> 2023-04-03 16:07:17 +02:00
bhould287
afdfbf8fde
Show multiple clippy.toml warnings with sess.warn instead of eprintln! 2023-04-03 15:03:05 +01:00
blyxyas
d602743558
only focus on double_must_use + Add Result<(), ()> test 2023-04-03 15:16:18 +02:00
blyxyas
e2742a0ea2
Fix double_must_use for async functions 2023-04-03 01:27:53 +02:00
bors
7fe83edc11 Auto merge of #10588 - blyxyas:fix-allow_nonminimal_bool, r=llogiq
Fix `nonminimal_bool` `#[allow]` attributes.

Closes #10435
changelog: [`nonminimal_bool`]: Fix false-positive where the lint ignore `#[allow]` attributes.

r? `@llogiq`
2023-04-02 22:12:46 +00:00
blyxyas
36047b0216
Fix nonminimal_bool #[allow] attributes. 2023-04-02 16:18:03 +02:00
Caio
05650b7215 [arithmetic_side_effects] Fix #10583 2023-04-02 07:50:25 -03:00
blyxyas
b2856a763e
Add tests_outside_test_module lint 2023-04-02 00:35:46 +02:00
bors
ac4838c554 Auto merge of #10534 - samueltardieu:lines-filter-map-ok, r=llogiq
Flag `bufreader.lines().filter_map(Result::ok)` as suspicious

This lint detects a problem that happened recently in https://github.com/uutils/coreutils and is described in https://github.com/rust-lang/rust/issues/64144.

changelog: [`lines_filter_map_ok`]: new lint
2023-04-01 12:41:08 +00:00
bors
6a6a262f7b Auto merge of #109010 - compiler-errors:rtn, r=eholk
Initial support for return type notation (RTN)

See: https://smallcultfollowing.com/babysteps/blog/2023/02/13/return-type-notation-send-bounds-part-2/

1. Only supports `T: Trait<method(): Send>` style bounds, not `<T as Trait>::method(): Send`. Checking validity and injecting an implicit binder for all of the late-bound method generics is harder to do for the latter.
    * I'd add this in a follow-up.
3. ~Doesn't support RTN in general type position, i.e. no `let x: <T as Trait>::method() = ...`~
    * I don't think we actually want this.
5. Doesn't add syntax for "eliding" the function args -- i.e. for now, we write `method(): Send` instead of `method(..): Send`.
    * May be a hazard if we try to add it in the future. I'll probably add it in a follow-up later, with a structured suggestion to change `method()` to `method(..)` once we add it.
7. ~I'm not in love with the feature gate name 😺~
    * I renamed it to `return_type_notation` ✔️

Follow-up PRs will probably add support for `where T::method(): Send` bounds. I'm not sure if we ever want to support return-type-notation in arbitrary type positions. I may also make the bounds require `..` in the args list later.

r? `@ghost`
2023-03-31 18:04:12 +00:00
bors
29987062d9 Auto merge of #10536 - mkrasnitski:suggestions, r=flip1995
Add suggestions to `extra_unused_type_parameters`

Change the `extra_unused_type_parameters` lint to provide machine applicable suggestions rather than just help messages. Exception to this are cases when any unused type parameters appear bounded in where clauses - for now I've deemed these cases unfixable and separated them out. Future work might be able to provide suggestions in these cases.

Also, added a test case for the `avoid_breaking_exported_api` config option.

r? `@flip1995`

changelog: [`extra_unused_type_parameters`]: Now provides fixable suggestions.
2023-03-31 16:16:36 +00:00
Samuel "Sam" Tardieu
6601d85c22 Flag bufreader.lines().filter_map(Result::ok) as suspicious 2023-03-31 14:43:30 +02:00
Yuri Astrakhan
41b367fa5f Gramar, and spelin kleanup
A few minor cleanups in various markdown files, mostly focusing on spelling and ignoring non-compilable codeblocks.
2023-03-30 15:31:14 -04:00
Alex Macleod
17f80456d1 Ignore file!() macro in print_literal, write_literal 2023-03-30 16:20:04 +00:00
bors
799732cbd8 Auto merge of #10414 - csmoe:large-future, r=xFrednet
add large future lint

Closes #5263

---

changelog: new lint: [`large_futures`]
[#10414](https://github.com/rust-lang/rust-clippy/pull/10414)
<!-- changelog_checked -->
2023-03-30 08:51:29 +00:00
bors
ef3867f394 Auto merge of #9102 - botahamec:unused-box, r=xFrednet
Added the `[unnecessary_box_returns]` lint

fixes #5

I'm not confident in the name of this lint. Let me know if you can think of something better

---

changelog: New lint: ``[`unnecessary_box_returns`]``
[#9102](https://github.com/rust-lang/rust-clippy/pull/9102)
<!-- changelog_checked -->
2023-03-30 08:22:16 +00:00
Elliot Bobrow
a2165533e1 fix single_component_path_imports FP 2023-03-29 18:19:29 -07:00
Trevor Gross
4cf5bdc60c Stabilize a portion of 'once_cell'
Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try'
2023-03-29 18:04:44 -04:00
csmoe
4f5a019d6e Update clippy_lints/src/large_futures.rs
Co-authored-by: Fridtjof Stoldt <xFrednet@gmail.com>
2023-03-29 08:47:32 +00:00
Alex Macleod
6589d79492 Replace remaining usage of FormatArgsExpn 2023-03-28 21:28:57 +00:00
bors
84e42fb363 Auto merge of #10484 - Alexendoo:format-args-ast-2, r=Manishearth
Migrate `format_args.rs` to `rustc_ast::FormatArgs`

changelog: none

Part of https://github.com/rust-lang/rust-clippy/issues/10233

Empty precision specifiers are no longer linted as the span for that isn't present in [`FormatOptions`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/format/struct.FormatOptions.html)

```rust
format!("{:.}", ...)
```

That could be fixed later with some hackery or a change upstream

r? `@flip1995`
2023-03-28 18:33:02 +00:00
bors
d9821e1d9d Auto merge of #10542 - Alexendoo:items-after-statements, r=giraffate
Fix allow attribute, items from macros in `items_after_statements`

Fixes #10540

changelog: [`items_after_statements`]: Fixes `#[allow(clippy::items_after_statements)]` when applied to an item, and ignores items after statements from different macro contexts
2023-03-28 13:21:14 +00:00
Alex Macleod
3259b48568 Migrate format_args.rs to rustc_ast::FormatArgs
No longer lints empty precisions `{:.}` as the spans aren't available
2023-03-28 12:22:22 +00:00
Michael Goulet
fc6262fa0c Add (..) syntax for RTN 2023-03-28 01:14:28 +00:00
Guillaume Gomez
538e8bdcc8 Rollup merge of #109354 - Swatinem:rm-closureid, r=compiler-errors
Remove the `NodeId` of `ast::ExprKind::Async`

This is a followup to https://github.com/rust-lang/rust/pull/104833#pullrequestreview-1314537416.

In my original attempt, I was using `LoweringContext::expr`, which was not correct as it creates a fresh `DefId`.
It now uses the correct `DefId` for the wrapping `Expr`, and also makes forwarding `#[track_caller]` attributes more explicit.
2023-03-27 18:56:19 +02:00
bors
70db22648b Auto merge of #10528 - bluthej:clear-with-drain, r=llogiq
Clear with drain

changelog: [`clear_with_drain`]: Add new lint

Fixes #9339
2023-03-27 11:41:48 +00:00
Micha White
76d13bb7fa
Don't lint functions with "box" in their name 2023-03-26 17:49:57 -04:00
Micha White
a143fb7a11
Avoid breaking exported API 2023-03-26 17:49:57 -04:00
Micha White
1b55c81db5
Lint on trait declarations, not implementations 2023-03-26 17:49:56 -04:00
Micha White
022f76d432
Added the new lint with some docs and tests 2023-03-26 17:49:46 -04:00
Michael Goulet
db4e4afce8 Don't elaborate non-obligations into obligations 2023-03-26 20:33:54 +00:00
bluthej
2493be2196 Improve is_range_full implementation
Make this function work with signed integer types by extracting the
underlying type and finding the min and max values.

Change the signature to make it more consistent:
- The range is now given as an `Expr` in order to extract the type
- The container's path is now passed, and only as an `Option` so that
  the function can be called in the general case without a container
2023-03-26 19:12:36 +02:00
bluthej
1d168b31c3
Merge branch 'rust-lang:master' into clear-with-drain 2023-03-26 19:11:38 +02:00
Alex Macleod
a6f56cbdba Move unnecessary_struct_initialization to nursery 2023-03-26 14:21:58 +00:00
bors
5ed64d4c61 Auto merge of #10496 - J-ZhengLi:issue_10366, r=Alexendoo
fix [`cast_possible_truncation`] offering wrong suggestion for casting float to integer

fixes: #10366

---

changelog: [`cast_possible_truncation`] Fix incorrect suggestions when casting from float types or to `_`
2023-03-25 13:11:46 +00:00
bors
f1b9105f87 Auto merge of #10454 - Alexendoo:transmutes-expressible-as-ptr-casts-parens, r=Jarcho
Wrap `transmutes_expressible_as_ptr_casts` suggestions in parentheses

changelog: [`transmutes_expressible_as_ptr_casts`]: Fix suggestion missing wrapping parentheses

Fixes #10449

r? `@Jarcho`

Is this the best way to go about this? `unused_parens` will catch the unnecessary ones but emitting them in the first place isn't ideal
2023-03-25 02:29:54 +00:00
J-ZhengLi
52c4dc65d9 fix [cast_possible_truncation] offering wrong suggestion when casting from float
suggest `try_into` when casting to wildcard type;
fix [`cast_possible_truncation`] suggesting useless parenthesis;

remove suggesting for float to float conversion in [`cast_possible_truncation`]

style nit
2023-03-25 09:26:43 +08:00
Alex Macleod
b13f99c7e7 Fix allow attribute, items from macros in items_after_statements 2023-03-24 15:33:14 +00:00
FixedThink
982c81ad28
docs fix: unknown field allowed-locales
changelog: fix: Replace the nonexistent `allowed-locales` in the `DISALLOWED_SCRIPT_IDENTS` docs with `allowed-scripts`.
2023-03-24 16:08:27 +01:00
Philipp Krones
8df896c076 Merge commit 'd5e2a7aca55ed49fc943b7a07a8eba05ab5a0079' into clippyup 2023-03-24 14:26:19 +01:00
Philipp Krones
62cba5d971
Merge remote-tracking branch 'upstream/master' into rustup 2023-03-24 13:36:09 +01:00
Michael Krasnitski
50d92d0b60 Add suggestions to extra_unused_type_parameters 2023-03-23 23:56:31 -04:00
bors
c72c914d21 Auto merge of #10489 - samueltardieu:issue-10476, r=giraffate
New lint: detect unnecessary struct building

Fixes #10476.

Running this lint on the top 500 crates produced one hit (in `rust-lang/rust-bindgen`) and [a PR has been submitted there](https://github.com/rust-lang/rust-bindgen/pull/2440).

changelog: [`unnecessary_struct_initialization`]: new lint
2023-03-24 00:12:02 +00:00
Samuel "Sam" Tardieu
d7d3dbf060 New lint: detect unnecessary struct building 2023-03-23 20:56:45 +01:00
Alex Macleod
ecc201253e Wrap transmutes_expressible_as_ptr_casts suggestions in parentheses 2023-03-23 18:58:10 +00:00
bors
be01b983c4 Auto merge of #10533 - Nilstrieb:cache, r=dswij
Significantly optimize `significant_drop_tightening`

The lint is very slow as it doesn't cache the deeply nested check for the attribute. If we cache it, we can reduce the time spent on checking `rustc_borrowck` from 28s to 9s, which is a nice improvement. In the profile, the time inside `has_sig_drop_attr` goes from 66% to 0.2%, which is a lot more reasonable.

<details>
<summary>Flame graphs</summary>

Before (all the tall `clippy` towers are `has_sig_drop_attr`):
![before](https://user-images.githubusercontent.com/48135649/227037243-bcd93bbe-a4ad-45c3-be25-2b021b12a5c0.svg)

After:
![after](https://user-images.githubusercontent.com/48135649/227040322-8d3f0448-18e3-4923-8187-c72df324a3fa.svg)
</details>

Fixes #10532

changelog: [`significant_drop_tightening`]: significantly optimized
2023-03-23 09:23:07 +00:00
Nilstrieb
966d5b0e34 Cache has_sig_drop_attr for significant_drop_tightening
The lint is very slow as it doesn't cache the deeply nested check for
the attribute. If we cache it, we can reduce the time spent on checking
`rustc_borrowck` from 28s to 9s, which is a nice improvement. In the
profile, the time inside `has_sig_drop_attr` goes from 66% to 0.2%,
which is a lot more reasonable.

See the PR for nice graphs.
2023-03-22 22:22:16 +01:00
bors
1d1e72308e Auto merge of #10527 - samueltardieu:issue-10523, r=dswij
Do not propose to simplify a not expression coming from a macro

Fixes #10523

changelog: FP [`nonminimal_bool`]: do not propose to change code coming from a macro
2023-03-22 15:46:08 +00:00
bluthej
d56c941792
Merge branch 'rust-lang:master' into clear-with-drain 2023-03-22 11:15:23 +01:00
bluthej
e8ec242a61 Finish tests - add rustfix 2023-03-22 11:01:57 +01:00
bluthej
c7e3e304d5 Add the lint logic 2023-03-22 11:01:57 +01:00
bluthej
484c82e041 Update lint declaration 2023-03-22 11:01:57 +01:00
bluthej
85d428101d Pull is_full_range method from iter_with_drain
Rename method to `is_range_full` because the type is actually
`RangeFull`.

Method moved to `clippy_utils` for reuse in `clear_with_drain`.
2023-03-22 11:01:51 +01:00
Vadim Petrochenkov
cae7b87711 rustc: Remove unused Session argument from some attribute functions 2023-03-22 13:55:55 +04:00
bors
583962150b Auto merge of #10490 - samueltardieu:issue-10482, r=xFrednet
Do not propose to remove `async move` if variables are captured by ref

Fixes #10482

changelog: FP [`redundant_async_block`] Do not propose to remove `async move` if variables are captured by ref
2023-03-22 08:19:39 +00:00
bors
6db2d5989f Auto merge of #109119 - lcnr:trait-system-cleanup, r=compiler-errors
a general type system cleanup

removes the helper functions `traits::fully_solve_X` as they add more complexity then they are worth. It's confusing which of these helpers should be used in which context.

changes the way we deal with overflow to always add depth in `evaluate_predicates_recursively`. It may make sense to actually fully transition to not have `recursion_depth` on obligations but that's probably a bit too much for this PR.

also removes some other small - and imo unnecessary - helpers.

r? types
2023-03-22 05:33:18 +00:00
Samuel "Sam" Tardieu
b138bb587b Do not propose to simplify a not expression coming from a macro 2023-03-22 01:12:52 +01:00
Samuel "Sam" Tardieu
349708655e Do not propose to remove async move if variables are captured by ref 2023-03-22 00:29:17 +01:00
bluthej
7f44530f54 Create clear_with_drain lint 2023-03-21 22:51:51 +01:00
Samuel "Sam" Tardieu
728ee6f8cd Really dogfood clippy
The dogfood success condition was inverted in `tests/dogfood.rs`:

```rust
  assert!(!failed_packages.is_empty(), …);
```

while instead the `failed_packages` collection must be empty:

```rust
  assert!(failed_packages.is_empty(), …);
```

And indeed, several clippy lint source files were not clean and had to be
fixed in the process.
2023-03-21 22:00:58 +01:00
Michael Goulet
6f62887968 Use local key in providers 2023-03-21 15:38:51 +00:00
lcnr
5810f1fe3c remove some trait solver helpers
they add more complexity then they are worth. It's confusing
which of these helpers should be used in which context.
2023-03-21 09:57:20 +01:00
csmoe
4fdae81c70 add large future lint 2023-03-20 22:51:01 +08:00
Arpad Borsos
1e17a443b3 Remove the NodeId of ast::ExprKind::Async 2023-03-19 19:01:31 +01:00
bors
e64c5961dc Auto merge of #10456 - samueltardieu:issue-10450, r=Manishearth
Issue function modifiers in the right order in manual_async_fn lint

Fixes #10450

changelog: [`manual_async_fn`] output function modifiers in correct order
2023-03-18 15:19:27 +00:00
bors
d3c8442d4d Auto merge of #10483 - samueltardieu:issue-10480, r=llogiq
New lint to detect `&std::path::MAIN_SEPARATOR.to_string()`

Fixes #10480

changelog: [`manual_main_separator_str`] new lint
2023-03-17 13:49:53 +00:00
bors
5c4040e9bb Auto merge of #10502 - blyxyas:fix-almost_swapped, r=giraffate
fix `almost_swapped`: Ignore external macros

Fixes #10421 ; Related to #10499 (Fixing points *1* and *3* from #10421)
changelog: [`almost_swapped`]: Add a check to ignore external macros
2023-03-17 00:03:45 +00:00
Samuel "Sam" Tardieu
ffabdab8cf New lint to detect &std::path::MAIN_SEPARATOR.to_string() 2023-03-16 21:42:04 +01:00
blyxyas
9546517a84
Add external macro test + Now it works 2023-03-16 20:22:39 +01:00
Samuel Tardieu
afe27ba1a2 Issue function modifiers in the right order in manual_async_fn lint 2023-03-16 18:59:14 +01:00
bors
5afa93bd8e Auto merge of #10481 - blyxyas:allow_attribute, r=xFrednet
Add `allow_attribute` lint

Fixes #10468

changelog: new lint: [`allow_attributes`]
[#10481](https://github.com/rust-lang/rust-clippy/pull/10481)
2023-03-16 10:18:19 +00:00
blyxyas
1cab0cbaf0
Fix formatting, remove commented code, etc... 2023-03-16 11:10:59 +01:00
blyxyas
4b9cb857f9
Rename lint 2023-03-15 23:18:25 +01:00
blyxyas
3eea49446b
Ignore external macros 2023-03-14 20:59:39 +01:00
clubby789
f2eddc5924 Remove box expressions from HIR 2023-03-14 17:18:26 +00:00
bors
c465bf7f67 Auto merge of #10499 - blyxyas:fix-almost_swapped, r=giraffate
Fix `almost_swapped` false positive (`let mut a = b; a = a`)

Fixes `2` in #10421
changelog: [`almost_swapped`]: Fix false positive when a variable is changed to itself. (`a = a`)
2023-03-14 13:30:21 +00:00
Simonas Kazlauskas
5924b46543 Fix documentation for derived_hash_with_manual_eq
The documentation retained "vice versa" from the previous incarnation of
the lint but the lint itself no longer lints against manual `Hash`
implementations with a derived `PartialEq`.

I also adjusted the documentation for `PartialOrd`-`Ord` lint as "vice
versa" seemed a little confusing to me there (as to what it was refering
to exactly.)
2023-03-14 12:48:06 +02:00
bors
491f63214a Auto merge of #104833 - Swatinem:async-identity-future, r=compiler-errors
Remove `identity_future` indirection

This was previously needed because the indirection used to hide some unexplained lifetime errors, which it turned out were related to the `min_choice` algorithm.

Removing the indirection also solves a couple of cycle errors, large moves and makes async blocks support the `#[track_caller]`annotation.

Fixes https://github.com/rust-lang/rust/issues/104826.
2023-03-14 10:12:58 +00:00
bors
ff843ac9ae Auto merge of #10350 - J-ZhengLi:issue_10272, r=xFrednet
enhance [`ifs_same_cond`] to warn same immutable method calls as well

fixes: #10272

---

changelog: Enhancement: [`ifs_same_cond`]: Now also detects immutable method calls.
[#10350](https://github.com/rust-lang/rust-clippy/pull/10350)
<!-- changelog_checked -->
2023-03-14 08:16:58 +00:00
blyxyas
6631480a7b
Fix false positive with a = a 2023-03-13 19:13:56 +01:00
Alex Macleod
555f56862e Fix semicolon insertion in match_single_binding 2023-03-13 14:17:35 +00:00
J-ZhengLi
f4ccb06d69 extract is_interior_mutable_type from [mut_key] to clippy_utils::ty;
fix configuration of [`ifs_same_cond`];

add some style improvement for [`ifs_same_cond`];
2023-03-13 20:17:30 +08:00
J-ZhengLi
f0ae2b71ca make [ifs_same_cond] use ignore_interior_mutablility configuration 2023-03-13 20:13:56 +08:00
J-ZhengLi
8a9492aa03 enhance [ifs_same_cond] to lint same immutable method calls as well 2023-03-13 20:13:56 +08:00
clubby789
15f24234c8 Remove box_syntax from AST and use in tools 2023-03-12 13:19:46 +00:00
blyxyas
d65c9a5700
Extend tests + improve description + general improvement 2023-03-11 21:30:34 +01:00
bors
f19db28361 Auto merge of #10434 - Jarcho:snip_context, r=dswij
Remove `snippet_with_macro_callsite`

`snippet_with_context` is used instead to support nested macro calls.

changelog: None
2023-03-11 12:45:20 +00:00
bors
e426ba4e06 Auto merge of #10420 - Jarcho:no_mangle_diag, r=dswij
Improve diagnostic of `no_mangle_with_rust_abi`

fixes #10409

Pending rust-lang/rustfmt#5701

This rewords the message to focus on the error being an implicit ABI, rather than the `Rust` ABI. Also downgrades the suggestion to `MaybeIncorrect` and changes the suggestion span to better highlight the change.

---

changelog: None
<!-- changelog_checked -->
2023-03-11 12:14:48 +00:00
blyxyas
2d572d4a9c
Replace list indexing for .get (fail-safe) 2023-03-11 13:11:27 +01:00