Commit Graph

15527 Commits

Author SHA1 Message Date
Samuel Moelius
ef5f60285f Move line_span to source.rs 2022-11-19 05:53:49 -05:00
bors
f60186f35d Auto merge of #9800 - Alexendoo:def_path_res_multiple, r=dswij
Return multiple resolutions from `def_path_res`

Changes `def_path_res` to return all the resolutions matching the path rather than the first one (with a namespace hint that covered some cases).  This would fix any issues that come up with multiple versions of the same crate being present as they all have the same crate name

It also adds resolution of `impl _ {}` items for local items, and removes struct field resolution as it didn't seem to be used anywhere

I tested it on a local crate and it worked for the multiple crate issue, but I couldn't come up with a test that worked well with `// aux-build`, maybe `// aux-crate` after https://github.com/rust-lang/rust/pull/103266 could work but I'm not sure on that either

changelog: [`disallowed_methods`], [`disallowed_types`], [`disallowed_macros`]: fix path resolution with multiple versions of the same crate
changelog: [`disallowed_methods`]: Resolve methods in `impl`s in the current crate
2022-11-19 09:05:50 +00:00
bors
e144c7d1ae Auto merge of #9871 - koka831:fix/9864, r=xFrednet
Allow manual swap in const fn

Fix https://github.com/rust-lang/rust-clippy/issues/9864

changelog: Fix [`manual_swap`]: No longer lints in constant code
2022-11-18 16:04:18 +00:00
koka
3c86cade4e
Note about const fn
Since `std::mem::swap` is not stable as a const fn, the suggestion
would not be applicable in that cases
2022-11-19 00:28:02 +09:00
bors
d019fd9780 Auto merge of #9855 - Alexendoo:needless-borrowed-ref-extra, r=xFrednet
Extend `needless_borrowed_reference` to structs and tuples, ignore _

changelog: [`needless_borrowed_reference`]: Lint struct and tuple patterns, and patterns containing `_`

Now lints patterns like

```rust
&(ref a, ref b)
&Tuple(ref a, ref b)
&Struct { ref a, ref b }

&(ref a, _)
```
2022-11-18 14:26:50 +00:00
koka
928a158716
Allow manual swap in const fn 2022-11-18 21:51:43 +09:00
bors
01f40ce3bc Auto merge of #9863 - smoelius:expect-unwrap-used-typo, r=flip1995
Fix typo in `expect_used` and `unwrap_used` warning messages

"\`an Option\`" -> "an \`Option\`" and "\`a Result\`" -> "a \`Result\`".

changelog: fix typo in `expect_used` and `unwrap_used` warning messages
2022-11-18 11:49:47 +00:00
bors
dfe37f13cf Auto merge of #9850 - pheki:fix-7499-missing-ref, r=dswij
Preserve `ref` on `infallible_destructuring_match` suggestion

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

changelog: [`infallible_destructuring_match`]: Preserve `ref` on suggestion
2022-11-18 09:43:51 +00:00
bors
1c9c34de17 Auto merge of #9858 - DesmondWillowbrook:never_loop, r=dswij
`never_loop`: don't emit AlwaysBreaks if it targets a block

ref: https://github.com/rust-lang/rust-clippy/pull/9837#issuecomment-1312788194

The previous fix (#9837) was too simple and ignored all break commands inside a labelled block, regardless of whether their destination was a labelled block or a loop. This fix tracks all the labelled blocks in scope to ensure that only breaks targeting loops are considered.

changelog: [`never_loop`]: prevent false negatives from `breaks` nested in labelled blocks
2022-11-18 09:31:20 +00:00
Samuel Moelius
00ae5e15a8 Fix typo in expect_used and unwrap_used warning messages 2022-11-17 15:02:48 +00:00
bors
dac600e32f Auto merge of #9859 - koka831:no-run-side-effect, r=Manishearth
Avoid generating files via doctest

When we run `cargo test` in `clippy_lints` directory, it will generate [`foo.txt`](https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/foo.txt) in the directory.
In order to avoid that, this PR adds `no_run` to rustdoc which contains `File::create`.

changelog: none
2022-11-16 17:32:31 +00:00
koka
3f015a3630
Avoid generating files via doctest
When we run `cargo test` in `clippy_lints` directory, it will generate
`foo.txt` in the directory.
In order to avoid that, add `no_run` to rustdoc which contains
`File::create`.
2022-11-17 00:02:22 +09:00
Kartavya Vashishtha
bc3cd344a1
fix clippy suggestions 2022-11-16 13:15:22 +05:30
Kartavya Vashishtha
036a0108ac
update tests 2022-11-16 11:39:09 +05:30
Kartavya Vashishtha
9f3b6e9acd
don't emit AlwaysBreaks if it targets a block
Introduced an ignored_ids parameter.
Takes O(n^2) time in the worst case.

Can be changed to collect block ids in first phase,
and then filter with binary search in second.
2022-11-16 11:01:07 +05:30
Alex Macleod
f75fc85783 Extend needless_borrowed_reference to structs and tuples, ignore _ 2022-11-15 18:24:18 +00:00
bors
38e059028f Auto merge of #9849 - koka831:fix/9748, r=Manishearth
Allow return types for closures with lifetime binder

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

changelog: Fix [`unused_unit`] Allow return types for closures with lifetime binder
2022-11-15 09:13:54 +00:00
bors
5b0d727bad Auto merge of #9570 - nfejzic:lint-unchecked-duration-subtraction, r=llogiq
feat: lint unchecked subtraction of a 'Duration' from an 'Instant'

Hello all, I tried to tackle the open issue #9371 and this is what I came up with.

I have a difficulty currently - some tests are failing:

```
failures:
    [ui] ui/manual_instant_elapsed.rs
```

The `manual_instant_elapsed` is failing because of `Instant::now() - duration` test, this now gets also picked by `unchecked_duration_subtraction` lint.
What is the correct way to proceed in this case? Simply update the `.stderr` file for `manual_instant_elapsed` lint?

changelog: [`unchecked_duration_subtraction`]: Add lint for unchecked subtraction of a `Duration` from an `Instant`.

fixes #9371
2022-11-15 06:09:10 +00:00
Aphek
93ac0f58bf Keep ref on infallible_destructuring_match suggestion 2022-11-15 01:57:56 -03:00
koka
7c4611c7e1
Allow return types for closures with lifetime binder 2022-11-15 12:58:17 +09:00
Nadir Fejzic
0dd6ce0b19 docs: import Instant and Duration in doctests 2022-11-14 22:37:25 +01:00
Nadir Fejzic
72ab91d806 fix: add extract_msrv_attr call to instan_subtraction lint pass 2022-11-14 22:25:56 +01:00
Nadir Fejzic
912dc919af docs: update unchecked duration subtraction lint doc 2022-11-14 22:08:11 +01:00
Nadir Fejzic
3f89ab0618 chore: update lint version of MANUAL_INSTAN_ELAPSED to 1.65 2022-11-14 22:00:09 +01:00
bors
3c7f74de0b Auto merge of #9848 - lukas-code:vec-box, r=Jarcho
Fix `vec-box-size-threshold` off-by-one error

The docs for `vec-box-size-threshold` say "The size of the boxed type in bytes, where boxing in a `Vec` is allowed", but previously a boxed type of exactly that size wasn't allowed in `Vec`.

changelog: [`vec_box`]: Fix off-by-one error for `vec-box-size-threshold` configuration.
2022-11-14 15:54:45 +00:00
Lukas Markeffsky
b8357ffd1f fix vec-box-size-threshold off-by-one error 2022-11-14 16:06:21 +01:00
bors
a5995279fb Auto merge of #9837 - DesmondWillowbrook:never_loop, r=dswij
fix never_loop false positive

fixes #9831

changelog: [`never_loop`]: fixed false positive on unconditional break in internal labeled block
2022-11-13 15:44:14 +00:00
bors
493b78885a Auto merge of #9829 - hrxi:pr_or_fun_call, r=llogiq
Make it clear that `or_fun_call` can be a false-positive

Also move it to nursery so that the false-positives can be dealt with.

CC #8574

changelog: [`or_fun_call`]: Mention false-positives, move to nursery.
2022-11-13 14:29:42 +00:00
bors
6ba3a00b94 Auto merge of #9822 - Veykril:unnecessary-safety-doc, r=Jarcho
Add `unnecessary_safety_doc` lint

changelog: [`unnecessary_safety_doc`]: Add `unnecessary_safety_doc` lint

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

This lint does not trigger for private functions, just like `missing_safety_docs`. Reason for that was implementation simplicity and because I figured asking first would make more sense, so if it should trigger for private functions as well let me know and I'll fix that up as well.
2022-11-13 14:18:04 +00:00
bors
a8151409a0 Auto merge of #9698 - kraktus:xc_bool, r=xFrednet
[`fn_params_excessive_bools`] Make it possible to allow the lint at the method level

changelog: FP: [`fn_params_excessive_bools`]: `#[allow]` now works on methods

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

Tested without committing but `#[allow]`ing now works. Also rewrote the lint to be a late lint while at it :)
r? `@xFrednet`
2022-11-13 09:57:36 +00:00
hrxi
243661b739 Make it clear that or_fun_call can be a false-positive
Also move it to nursery so that the false-positives can be dealt with.

CC #8574
2022-11-12 22:26:09 +01:00
bors
9f283c97e1 Auto merge of #9835 - koka831:fix/9035, r=Alexendoo
Avoid linting unsized mutable reference

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

changelog: [`mut_mut`] avoid suggesting to reborrow unsized mutable reference
2022-11-12 21:07:18 +00:00
bors
bb326e761b Auto merge of #9836 - koka831:patch-9300, r=Alexendoo
Fix is_async_fn to check FnKind::Method

This is a follow-up PR of https://github.com/rust-lang/rust-clippy/pull/9828 to support also async methods.

changelog: [`cognitive_complexity`] support async method

r? `@Alexendoo`
2022-11-12 20:54:39 +00:00
Kartavya Vashishtha
989986144c
fix never_loop false positive
on unconditional break to internal labeled block

ref #9831
2022-11-12 20:36:30 +05:30
koka
34c4520eae
Fix is_async_fn to check FnKind::Method 2022-11-12 22:36:20 +09:00
bors
755fe4dc24 Auto merge of #9834 - koka831:refac/manual-is-ascii-check, r=xFrednet
refac: remove unnecessary mutability

refactor `manual_is_ascii_check` lint.

* remove unnecessary mutability
* fix typo

changelog: none

r? `@xFrednet`
2022-11-12 11:44:22 +00:00
koka
93edc127a0
Avoid lint to unsized mutable reference 2022-11-12 20:31:25 +09:00
koka
39398e163a
fix: use HasPlaceholders
* remove unnecessary mutability
* fix typo
2022-11-12 20:29:24 +09:00
bors
cad0d3d6da Auto merge of #9662 - ebobrow:result-large-err, r=dswij
`result_large_err` show largest variants in err msg

fixes #9538

changelog: Sugg: [`result_large_err`]: Now show largest enum variants in error message
2022-11-11 06:58:59 +00:00
bors
3c0ad8a0e0 Auto merge of #9830 - hrxi:pr_bool_to_int_with_if, r=Manishearth
Make `bool_to_int_with_if` a pedantic lint

In all the cases I've observed, it did not make the code clearer. Using bools as integer is frowned upon in some languages, in others it's simply not possible.

You can find comments on the original pull request #8131 that agree with this point of view.

changelog: [`bool_to_int_with_if`]: Change the categorization to pedantic
2022-11-10 19:37:05 +00:00
hrxi
3790aa3d5d Make bool_to_int_with_if a pedantic lint
In all the cases I've observed, it did not make the code clearer. Using
bools as integer is frowned upon in some languages, in others it's
simply not possible.

You can find comments on the original pull request #8131 that agree with
this point of view.
2022-11-10 19:42:20 +01:00
bors
4f1698db60 Auto merge of #9828 - koka831:fix/9300, r=Alexendoo
fix: cognitive_complexity for async fn

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

changelog: [`cognitive_complexity`] support async fn
2022-11-10 17:40:46 +00:00
koka
2bc04bdac2
fix: cognitive_complexity for async fn 2022-11-11 00:14:18 +09:00
Nadir Fejzic
36eac0cb4a fix: update lints 2022-11-10 15:55:45 +01:00
Nadir Fejzic
862ac29192 fix: remove (redundant) semicolon in lint suggestion 2022-11-10 15:47:12 +01:00
Nadir Fejzic
62ab4fb9c2 fix: add rust-fix annotation to unckd. duration subtr. lint test 2022-11-10 15:47:12 +01:00
Nadir Fejzic
852d802451 style: inline variables in format! 2022-11-10 15:47:12 +01:00
Nadir Fejzic
4bd6d0beb0 test: update tests for manual_instant_elapsed lint 2022-11-10 15:47:12 +01:00
Nadir Fejzic
80e3553f29 refactor: improve code re-use in InstantSubtraction lint pass 2022-11-10 15:47:12 +01:00
Nadir Fejzic
a566eb3765 docs: update docs for unchecked duration subtr. lint 2022-11-10 15:47:12 +01:00