Commit Graph

19837 Commits

Author SHA1 Message Date
bors
722de3b546 Auto merge of #12842 - J-ZhengLi:issue12801, r=y21
add parentheses to [`let_and_return`]'s suggestion

closes: #12801

---

changelog: suggest adding parentheses when linting [`let_and_return`] and [`needless_return`]
2024-05-27 08:04:36 +00:00
J-ZhengLi
03306b6ab6 suggest adding parentheses when linting [let_and_return] and [needless_return] 2024-05-27 11:49:10 +08:00
bors
5aae5f6ae6 Auto merge of #12740 - lrh2000:sig-drop, r=blyxyas
`significant_drop_in_scrutinee`: Trigger lint only if lifetime allows early significant drop

I want to argue that the following code snippet should not trigger `significant_drop_in_scrutinee` (https://github.com/rust-lang/rust-clippy/issues/8987). The iterator holds a reference to the locked data, so it is expected that the mutex guard must be alive until the entire loop is finished.
```rust
use std::sync::Mutex;

fn main() {
    let mutex_vec = Mutex::new(vec![1, 2, 3]);
    for number in mutex_vec.lock().unwrap().iter() {
        dbg!(number);
    }
}
```

However, the lint should be triggered when we clone the vector. In this case, the iterator does not hold any reference to the locked data.
```diff
-     for number in mutex_vec.lock().unwrap().iter() {
+     for number in mutex_vec.lock().unwrap().clone().iter() {
```

Unfortunately, it seems that regions on the types of local variables are mostly erased (`ReErased`) in the late lint pass. So it is hard to tell if the final expression has a lifetime relevant to the value with a significant drop.

In this PR, I try to make a best-effort guess based on the function signatures. To avoid false positives, no lint is issued if the result is uncertain. I'm not sure if this is acceptable or not, so any comments are welcome.

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

changelog: [`significant_drop_in_scrutinee`]: Trigger lint only if lifetime allows early significant drop.

r? `@flip1995`
2024-05-25 13:11:21 +00:00
bors
5d10538fb4 Auto merge of #12809 - GuillaumeGomez:missing-backticks-fix, r=y21
Correctly handle closing parens in `missing_backticks` doc lint

Fixes #12795.

changelog: Correctly handle closing parens in `doc_markdown` lint
2024-05-25 12:03:07 +00:00
bors
674c641ecf Auto merge of #12836 - hamirmahal:feat/quick-fix-for-bare-urls, r=y21
feat: `Quick Fix` for `bare URLs`

closes #12835.

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

changelog: [`clippy::doc_markdown`]: `Quick Fix` for `bare URLs`
2024-05-24 21:51:45 +00:00
Hamir Mahal
17cc0a3a7d
feat: auto-fix for bare URLs in doc comments 2024-05-24 14:30:42 -07:00
bors
f16317e9cc Auto merge of #12841 - B14CK313:fix-expect-derive, r=y21
fulfill expectations in `check_partial_eq_without_eq`

This is a followup to #12804, fixing a similar issue for `derive_partial_eq_without_eq` by using `span_lint_hir_and_then` instead of `span_lint_and_sugg`.

Additionally tests for both `#[allow(clippy::derive_partial_eq_without_eq)]` and `#[expect(clippy::derive_partial_eq_without_eq)]` are added.

changelog:[`derive_partial_eq_without_eq`]: fulfill expectations
2024-05-24 14:10:53 +00:00
bors
67b7b6a607 Auto merge of #12838 - kpreid:restriction-doc, r=llogiq
For restriction lints, replace “Why is this bad?” with “Why restrict this?”

The `restriction` group contains many lints which are not about necessarily “bad” things, but style choices — perhaps even style choices which contradict conventional Rust style — or are otherwise very situational. This results in silly wording like “Why is this bad? It isn't, but ...”, which I’ve seen confuse and distress a newcomer at least once.

To improve this situation, this PR replaces the “Why is this bad?” section heading with “Why restrict this?”, for most, but not all, restriction lints. I left alone the ones whose placement in the restriction group is more incidental.

In order to make this make sense, I had to remove the “It isn't, but” texts from the contents of the sections. Sometimes further changes were needed, or there were obvious fixes to make, and I went ahead and made those changes without attempting to split them into another commit, even though many of them are not strictly necessary for the “Why restrict this?” project; it seemed to me that it was more valuable to grab the low-hanging fruit than to be careful about it.

changelog: rephrased the documentation of `restriction` lints for clarity about their nature
2024-05-24 12:58:25 +00:00
Jakob Schwarz
7f30b20b28
fulfill expectations in check_partial_eq_without_eq
changelog: fulfill expectations in [derive_partial_eq_without_eq]
2024-05-24 08:44:41 +02:00
Kevin Reid
0f5338cd90 For restriction lints, replace “Why is this bad?” with “Why restrict this?”
The `restriction` group contains many lints which are not about
necessarily “bad” things, but style choices — perhaps even style choices
which contradict conventional Rust style — or are otherwise very
situational. This results in silly wording like “Why is this bad?
It isn't, but ...”, which I’ve seen confuse a newcomer at least once.

To improve this situation, this commit replaces the “Why is this bad?”
section heading with “Why restrict this?”, for most, but not all,
restriction lints. I left alone the ones whose placement in the
restriction group is more incidental.

In order to make this make sense, I had to remove the “It isn't, but”
texts from the contents of the sections. Sometimes further changes
were needed, or there were obvious fixes to make, and I went ahead
and made those changes without attempting to split them into another
commit, even though many of them are not strictly necessary for the
“Why restrict this?” project.
2024-05-23 15:51:33 -07:00
bors
76856ffb57 Auto merge of #12833 - kpreid:empty-enum-doc, r=Manishearth
Rephrase and expand `empty_enum` documentation.

* Remove incorrect claim that “wrappers around it are the conventional way to define an uninhabited type”.
* Discuss why one would use `!`, a newtype struct, or keep the enum.
* Add links to relevant documentation.

Before writing this change, I asked the community via [IRLO](https://internals.rust-lang.org/t/idiomatic-definition-of-uninhabited-never-newtypes/20877) and [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Never.20type.20wrappers.20.2F.20defining.20uninhabited.20newtypes) for feedback. The broad consensus seemed to me to be that in a world where both `never_type` and `min_exhaustive_patterns` are stable and therefore available for general use, we _might_ want to `!` or newtypes of it — but it's certainly not “conventional” _yet._ Therefore, I've removed “conventional” and added a discussion of the pros and cons of different choices.

changelog: [`empty_enum`]: expanded documentation
2024-05-23 16:19:15 +00:00
Kevin Reid
cfa150b0dd Rephrase and expand empty_enum documentation.
* Remove incorrect claim that “wrappers around it are the conventional
  way to define an uninhabited type”.
* Discuss why one would use `!`, a newtype struct, or keep the enum.
* Add links to relevant documentation.
2024-05-22 18:03:18 -07:00
Ruihan Li
6641f9f6e1 Track lifetime on values with significant drop 2024-05-23 00:37:02 +08:00
bors
05c4053628 Auto merge of #12398 - WeiTheShinobi:bug-lint-numbered_fields, r=Manishearth
bug fix: lint numbered_fields message error

fixes #12367

changelog: [`numbered_fields`]: fix macro expand message error.
2024-05-22 15:50:46 +00:00
WeiTheShinobi
038f6179d7 bug fix: lint numbered_fields message error 2024-05-22 15:26:32 +08:00
bors
ea535c97d5 Auto merge of #12804 - B14CK313:master, r=y21
fulfill expectations in `check_unsafe_derive_deserialize`

The utility function `clippy_utils::fulfill_or_allowed` is not used because using it would require to move the check for allowed after the check iterating over all inherent impls of the type, doing possibly unnecessary work.
Instead, `is_lint_allowed` is called as before, but additionally, once certain that the lint should be emitted, `span_lint_hir_and_then` is called instead of `span_lint_and_help` to also fulfill expectations.

Note: as this is my first contribution, please feel free to nitpick or request changes. I am happy to adjust the implementation.

fixes: #12802

changelog: fulfill expectations in [`unsafe_derive_deserialize`]
2024-05-21 19:05:36 +00:00
Guillaume Gomez
4f98cc6d55 Correctly handle closing parens in missing_backticks doc lint 2024-05-21 14:55:30 +02:00
bors
2efebd2f0c Auto merge of #12765 - yusufraji:while-float, r=llogiq
Add new lint `while_float`

This PR adds a nursery lint that checks for while loops comparing floating point values.

changelog:
```
changelog: [`while_float`]: Checks for while loops comparing floating point values.
```

Fixes #758
2024-05-21 11:36:31 +00:00
bors
0b1bf37722 Auto merge of #12818 - notriddle:master, r=y21
doc_lazy_continuation: do not warn on End events

```
changelog: none
```

This avoids event spans that would otherwise cause crashes, since an
End's span covers the range of the tag (which will be earlier than the
line break within the tag).
2024-05-18 23:46:57 +00:00
Michael Howell
b5cf8b8277 doc_lazy_continuation: do not warn on End events
This avoids event spans that would otherwise cause crashes, since an
End's span covers the range of the tag (which will be earlier than the
line break within the tag).
2024-05-18 16:19:41 -07:00
bors
680256f3ce Auto merge of #12813 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: None
2024-05-16 21:28:33 +00:00
Philipp Krones
9f6280b1e7
Bump nightly version -> 2024-05-16 2024-05-16 14:21:11 -07:00
Philipp Krones
c200dad300
Merge remote-tracking branch 'upstream/master' into rustup 2024-05-16 14:20:56 -07:00
bors
5459429f92 Auto merge of #12803 - wutchzone:panic-in-tests, r=y21
Add configuration option for ignoring `panic!()` in tests

```
changelog: [`panic`]: Now can be disabled in tests with the `allow-panic-in-tests` option
```

I often find myself using `panic!(…)` in tests a lot, where I often do something like:

```rust
match enam {
  Enam::A => …,
  Enam::B => …,
  _ => panic!("This should not happen at all."),
}
```
I think this patch should go nicely with already existing `allow-unwrap-in-tests` and `allow-expect-in-tests`.
2024-05-16 21:13:34 +00:00
bors
6c8ff3f894 Auto merge of #12812 - Alexendoo:driver-integration, r=flip1995
Manually set library paths in .github/driver.sh

Fixes https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Windows.20CI.20failing

Rustup 1.27.1 no longer adds `[SYSROOT]/bin` to `PATH` by default - https://github.com/rust-lang/rustup/issues/3825. This is fine for the packaged binaries since windows loads `dll`s from the folder the executable is in, but our built one is in a different folder

There's an environment variable to get the old behaviour back, but as it's deprecated and not much code I think returning to setting it manually is fine

changelog: none
2024-05-16 20:54:33 +00:00
Alex Macleod
821dc871af Manually set library paths in .github/driver.sh 2024-05-16 21:11:58 +01:00
Jakob Schwarz
1b6c91628e
add test for #[expect]ing unsafe_derive_deserialize
Adding `#![feature(lint_reasons)]` to the top of the file
also changed the line numbers in the expected error output.
2024-05-16 19:54:43 +02:00
Jakob Schwarz
fc2f7035c6
fulfill expectations in check_unsafe_derive_deserialize
The utility function `clippy_utils::fulfill_or_allowed` is not used because
using it would require to move the check for allowed after the check
iterating over all inherent impls of the type, doing possibly
unnecessary work.
Instead, `is_lint_allowed` is called as before, but additionally, once
certain that the lint should be emitted, `span_lint_hir_and_then` is called
instead of `span_lint_and_help` to also fulfill expectations.

fixes: #12802

changelog: fulfill expectations in `check_unsafe_derive_deserialize`
2024-05-16 19:54:42 +02:00
Daniel Sedlak
c342a61564 Add configuration option for ignoring panic!() in tests 2024-05-16 05:45:56 +00:00
bors
caad063933 Auto merge of #12713 - J-ZhengLi:issue8864, r=y21
make sure the msrv for `const_raw_ptr_deref` is met when linting [`missing_const_for_fn`]

fixes: #8864

---

changelog: make sure the msrv for `const_ptr_deref` is met when linting [`missing_const_for_fn`]
2024-05-15 21:29:34 +00:00
bors
e669d97494 Auto merge of #12706 - pacak:less-aggressive-needless-borrows, r=dswij
less aggressive needless_borrows_for_generic_args

Current implementation looks for significant drops, that can change the behavior, but that's not enough - value might not have a `Drop` itself but one of its children might have it.

A good example is passing a reference to `PathBuf` to `std::fs::File::open`. There's no benefits to pass `PathBuf` by value, but since `clippy` can't see `Drop` on `Vec` several layers down it complains forcing pass by value and making it impossible to use the same name later.

New implementation only looks at copy values or values created in place     so existing variable will never be moved but things that take a string reference created and value is created inplace `&"".to_owned()` will make it to suggest to use `"".to_owned()` still.

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

changelog: [`needless_borrows_for_generic_args`]: avoid moving variables
2024-05-15 15:51:27 +00:00
bors
a9b5c8ca81 Auto merge of #12790 - c410-f3r:blah, r=dswij
Fix #12760

Fix #12760

```
changelog: [missing_panics_doc]: Ignore panics in compile time
```
2024-05-15 15:40:36 +00:00
bors
a7f326574c Auto merge of #12779 - de-vri-es:move-assigng-clones-to-pedantic, r=y21
`assigning_clones`: move to `pedantic` so it is allow by default

In a nutshell, the `assigning_clones` lint suggests to make your code less readable for a small performance gain. See #12778 for more motivation.

fixes #12778

changelog: [`assigning_clones`]: move to the `pedantic` group
2024-05-15 14:50:29 +00:00
J-ZhengLi
1b7fc5f5aa add some msrv checks in is_min_const_fn 2024-05-15 16:38:57 +08:00
bors
c58b6e66fd Auto merge of #12798 - Alexendoo:no-effect-path-statements, r=y21
Don't lint path statements in no_effect

The rustc lint `path_statements` covers this case

Fixes #11547

changelog: none
2024-05-14 17:44:51 +00:00
Alex Macleod
9d790d6407 Don't lint path statements in no_effect 2024-05-14 17:22:56 +00:00
bors
a86378086b Auto merge of #12794 - J-ZhengLi:issue9251, r=blyxyas
improve [`match_same_arms`] messages, enable rustfix test

closes: #9251

don't worry about the commit size, most of them are generated

---

changelog: improve [`match_same_arms`] lint messages
2024-05-14 08:42:23 +00:00
J-ZhengLi
dc5b99b3b6 improve [match_same_arms] messages, enable rustfix test 2024-05-14 00:10:45 +02:00
Michael Goulet
2701a4175f Apply nits 2024-05-13 16:55:58 -04:00
Michael Goulet
760fbdf64e split out AliasTy -> AliasTerm 2024-05-13 11:59:42 -04:00
bors
d6991abc5a Auto merge of #12764 - lrh2000:ignore-place, r=blyxyas
`significant_drop_in_scrutinee`: Fix false positives due to false drops of place expressions

Place expressions do not really create temporaries, so they will not create significant drops. For example, the following code snippet is quite good (#8963):
```rust
fn main() {
    let x = std::sync::Mutex::new(vec![1, 2, 3]);
    let x_guard = x.lock().unwrap();
    match x_guard[0] {
        1 => println!("1!"),
        x => println!("{x}"),
    }
    drop(x_guard); // Some "usage"
}
```

Also, the previous logic thinks that references like `&MutexGuard<_>`/`Ref<'_, MutexGuard<'_, _>>` have significant drops, which is simply not true, so it is fixed together in this PR.

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

changelog: [`significant_drop_in_scrutinee`]: Fix false positives due to false drops of place expressions.

r? `@blyxyas`
2024-05-13 13:19:48 +00:00
Caio
12ec009f5a Fix #12760 2024-05-12 21:59:45 -03:00
Michael Goulet
e65cefcf6f Propagate errors rather than using return_if_err 2024-05-12 12:50:18 -04:00
bors
a4a1a7365d Auto merge of #12107 - y21:expr_metavars_in_unsafe, r=xFrednet
new lint: `macro_metavars_in_unsafe`

This implements a lint that I've been meaning to write for a while: a macro with an `expr` metavariable that is then expanded in an unsafe context. It's bad because it lets the user write unsafe code without an unsafe block.

Note: this has gone through some major rewrites, so any comment before https://github.com/rust-lang/rust-clippy/pull/12107#issuecomment-2029503545 is outdated and was based on an older version that has since been completely rewritten.

changelog: new lint: [`macro_metavars_in_unsafe`]
2024-05-12 16:32:41 +00:00
Michael Goulet
db193c1c9d Make LateCtxt be a type info delegate for EUV for clippy 2024-05-12 12:11:25 -04:00
Michael Goulet
dfc9c9132b Inline MemCategorization into ExprUseVisitor 2024-05-12 11:52:13 -04:00
y21
9747c80644 new lint: macro_metavars_in_unsafe 2024-05-12 17:03:30 +02:00
bors
7cfb9a0d6f Auto merge of #11540 - J-ZhengLi:issue11443, r=xFrednet
add new lint that disallow renaming parameters in trait functions

fixes: #11443
fixes: #486

changelog: add new lint [`renamed_function_params`]

Note that the lint name is not final, because I have a bad reputation in naming things, and I don't trust myself.
2024-05-12 14:21:22 +00:00
J-ZhengLi
46659acdbd add configuration to allow skipping on some certain traits & collect metadata 2024-05-12 22:13:17 +08:00
bors
9b446c7ff8 Auto merge of #12787 - J-ZhengLi:issue127311, r=blyxyas
make [`from_str_radix_10`] skip constant context

fixes: #12731

---

changelog: make [`from_str_radix_10`] skip constant context
2024-05-12 14:03:55 +00:00