Commit graph

21417 commits

Author SHA1 Message Date
lapla-cogito
d5059d8c1d
remove unnecessary notations 2024-12-10 00:00:51 +09:00
Ralf Jung
a9594c1635 fix ICE on type error in promoted 2024-12-09 15:17:26 +01:00
bors
dc713014aa Auto merge of #134052 - matthiaskrgr:rollup-puxwqrk, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #133567 (A bunch of cleanups)
 - #133789 (Add doc alias 'then_with' for `then` method on `bool`)
 - #133880 (Expand home_dir docs)
 - #134036 (crash tests: use individual mir opts instead of mir-opt-level where easily possible)
 - #134045 (Fix some triagebot mentions paths)
 - #134046 (Remove ignored tests for hangs w/ new solver)
 - #134050 (Miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-09 03:24:24 +00:00
Samuel Tardieu
f51f72b400 Detect shadowing in pattern field 2024-12-08 22:45:01 +01:00
Samuel Tardieu
69411e0e76 Better help message for comparison_chain lint 2024-12-08 20:34:00 +01:00
Matthias Krüger
24ccb158b8 Rollup merge of #133424 - Nadrieril:guard-patterns-parsing, r=fee1-dead
Parse guard patterns

This implements the parsing of [RFC3637 Guard Patterns](https://rust-lang.github.io/rfcs/3637-guard-patterns.html) (see also [tracking issue](https://github.com/rust-lang/rust/issues/129967)). This PR is extracted from https://github.com/rust-lang/rust/pull/129996 with minor modifications.

cc `@max-niederman`
2024-12-08 17:18:50 +01:00
llogiq
c4aeb32f1d
chore: use multipart_suggestions for manual_async_fn (#13788)
This addresses #13099 for the manual_async_fn test.

changelog: [manual_async_fn]: Updated manual_async_fn to use
multipart_suggestions where appropriate
2024-12-08 16:00:54 +00:00
llogiq
ec37eb6039
Move top-level files to mod.rs when applicable (#13732)
There are two modules in `clippy_utils` that are currently in the form
of:

```
src/
  | ast_utils/
  | ty/
  |
  | ast_utils.rs
  | ty.rs
```

This PR moves the top-level modules to become `mod.rs`, within their
respective folders.

```
src/
  | ast_utils/
  |   | mod.rs
  |
  | ty/
  |   | mod.rs
```

This reduces clutter in the `src` folder, and makes it easier to find
related files in certain editors.[^0] This also appears to be the
standard used in other crates in this repository, though I looked very
briefly.

I do realize that this is a style / opinionated change, so I'll close it
if it receives much push-back. :)

[^0]: I use VSCode, which groups all folders together and all files
separately. This means that `ty.rs` is quite "far" away from the `ty/`
folder, which makes it move difficult to navigate between the two.

```
changelog: none
```

- \[x] `cargo test` passes locally
- \[x] Run `cargo dev fmt`
2024-12-08 10:43:15 +00:00
Catherine Flores
d1e1aff8c8
Update known problems for default_numeric_fallback (#13794)
The existing known problem is not actually true, and the many false
positives and false negatives should be mentioned.

Allowing the lint on a single statement:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=328de43690af13ed126f7c00c15cd695

changelog: [`default_numeric_fallback`]: update known problems docs
2024-12-08 07:12:15 +00:00
Jack Wrenn
cfee37d358 Make Copy unsafe to implement for ADTs with unsafe fields
As a rule, the application of `unsafe` to a declaration requires that use-sites
of that declaration also require `unsafe`. For example, a field declared
`unsafe` may only be read in the lexical context of an `unsafe` block.

For nearly all safe traits, the safety obligations of fields are explicitly
discharged when they are mentioned in method definitions. For example,
idiomatically implementing `Clone` (a safe trait) for a type with unsafe fields
will require `unsafe` to clone those fields.

Prior to this commit, `Copy` violated this rule. The trait is marked safe, and
although it has no explicit methods, its implementation permits reads of `Self`.

This commit resolves this by making `Copy` conditionally safe to implement. It
remains safe to implement for ADTs without unsafe fields, but unsafe to
implement for ADTs with unsafe fields.

Tracking: #132922
2024-12-07 20:50:00 +00:00
nora
0a99eec958
Update known problems for default_numeric_fallback
The existing known problem is not actually true, and the many false positives and false negatives should be mentioned.
2024-12-07 13:35:05 +01:00
Jason Newcomb
7f866c7cc6
New lint for as *const _ and as *mut _ pointer casts (#13251)
changelog: New lint for as *const _ and as *mut _ pointer casts

EDIT: lets go with the simpler version
2024-12-06 20:50:33 +00:00
Jason Newcomb
5198941bb7
chore: use multipart_suggestions for str_splitn (#13789)
This addresses #13099 for the manual_split_once test, using the
str_splitn lint.

changelog: [str_splitn]: Updated str_splitn to use multipart_suggestions
where appropriate
2024-12-06 19:44:38 +00:00
Soveu
149671192d new lint for as *const _ and as *mut _ casting 2024-12-06 20:44:03 +01:00
bjorn3
63e4979399 Remove all threading through of ErrorGuaranteed from the driver
It was inconsistently done (sometimes even within a single function) and
most of the rest of the compiler uses fatal errors instead, which need
to be caught using catch_with_exit_code anyway. Using fatal errors
instead of ErrorGuaranteed everywhere in the driver simplifies things a
bit.
2024-12-06 18:42:31 +00:00
Scott Gerring
dcc4025405 chore: use multipart_suggestions for str_splitn 2024-12-06 16:04:21 +01:00
Scott Gerring
c963e22f05 chore: use multipart_suggestions for manual_async_fn 2024-12-06 15:40:50 +01:00
Alejandra González
f83a227d39
Fix various typos (#13785)
I ran [Typos](https://github.com/crate-ci/typos) on the project and
fixed all of the easy spelling mistakes! I made sure to avoid UI tests,
since those changes are more challenging to review due to the changes in
`.stderr` files.

```
changelog: Fixed several typos.
```

- \[x] `cargo test` passes locally
- \[x] Run `cargo dev fmt`
2024-12-05 21:56:21 +00:00
BD103
4907940a55 fix: various typos 2024-12-05 11:11:15 -05:00
Jason Newcomb
a5e46a6b08
update borrow_as_ptr to suggest &raw syntax (#13689)
This PR updates the `borrow_as_ptr` lint to no longer suggest `addr_of!`
and `addr_of_mut!` and instead use the preferred `&raw const` and `&raw
mut` syntax.

Not sure about two things:
1. Do I need to set or update a MSRV for the lint anywhere?
2. There is a `borrow_as_ptr_no_std` test as well as a `borrow_as_ptr`
test. They used to be more relevant as the lint needed to select `std`
or `core`, but that is gone now, so maybe the `borrow_as_ptr_no_std`
should be deleted?

changelog: update `borrow_as_ptr` to suggest `&raw` syntax
2024-12-05 10:18:19 +00:00
cyrgani
9925f999f6 update borrow_as_ptr to suggest &raw when the MSRV allows it 2024-12-05 09:48:55 +01:00
cyrgani
c8b10ac671 fix the order of emitting ref_as_ptr and borrow_as_ptr 2024-12-05 09:46:57 +01:00
León Orell Valerian Liehr
7cc19d7d1f Rollup merge of #118833 - Urgau:lint_function_pointer_comparisons, r=cjgillot
Add lint against function pointer comparisons

This is kind of a follow-up to https://github.com/rust-lang/rust/pull/117758 where we added a lint against wide pointer comparisons for being ambiguous and unreliable; well function pointer comparisons are also unreliable. We should IMO follow a similar logic and warn people about it.

-----

## `unpredictable_function_pointer_comparisons`

*warn-by-default*

The `unpredictable_function_pointer_comparisons` lint checks comparison of function pointer as the operands.

### Example

```rust
fn foo() {}
let a = foo as fn();

let _ = a == foo;
```

### Explanation

Function pointers comparisons do not produce meaningful result since they are never guaranteed to be unique and could vary between different code generation units. Furthermore different function could have the same address after being merged together.

----

This PR also uplift the very similar `clippy::fn_address_comparisons` lint, which only linted on if one of the operand was an `ty::FnDef` while this PR lints proposes to lint on all `ty::FnPtr` and `ty::FnDef`.

```@rustbot``` labels +I-lang-nominated

~~Edit: Blocked on https://github.com/rust-lang/libs-team/issues/323 being accepted and it's follow-up pr~~
2024-12-05 07:29:53 +01:00
Jason Newcomb
2550530266
Extend precedence for bitmasking and shift (#13743)
Now we can lint for the expressions like `_&_>>_`, `_<<_^_`, etc. And
will suggest to add parentheses like `_&(_>>_)` and `(_<<_)^_`.
I get implementation suggestions from
[https://github.com/rust-lang/rust-clippy/pull/8735#pullrequestreview-954273477](https://github.com/rust-lang/rust-clippy/pull/8735#pullrequestreview-954273477).
changelog: extended [`precedence`] to lint for bit masking and bit
shifting without parentheses
fixes #6632
2024-12-03 15:58:06 +00:00
Jason Newcomb
19426bfdfb
doc_lazy_continuation: Correctly count indent with backslashes (#13742)
changelog: [`doc_lazy_continuation`]: correctly count indent with
backslashes

Fixes #13705
2024-12-03 15:53:46 +00:00
Scott Gerring
e493664e15 index_refutable_slice: use multipart suggestions 2024-12-03 15:29:41 +01:00
Scott Gerring
ec243887d3 let_unit_value: Use multipart suggestions 2024-12-03 15:15:21 +01:00
Michael Howell
d3a7fb140c doc_lazy_continuation: Correctly count indent with backslashes
changelog: [`doc_lazy_continuation`]: correctly count indent with backslashes
2024-12-02 19:05:36 -07:00
Guillaume Gomez
f850d15b99 Rollup merge of #133746 - oli-obk:push-xwyrylxmrtvq, r=jieyouxu
Change `AttrArgs::Eq` to a struct variant

Cleanups for simplifying https://github.com/rust-lang/rust/pull/131808

Basically changes `AttrArgs::Eq` to a struct variant and then avoids several matches on `AttrArgsEq` in favor of methods on it. This will make future refactorings simpler, as they can either keep methods or switch to field accesses without having to restructure code
2024-12-02 23:08:58 +01:00
Alejandra González
646d72a01d
Correct report_elidable_impl_lifetimes comment following #13752 (#13771)
Tiny change to make `report_elidable_impl_lifetimes`'s doc comment
consistent with #13752. (cc: @samueltardieu)

---

changelog: none
2024-12-02 20:04:47 +00:00
Samuel Moelius
4a342df09b Correct report_elidable_impl_lifetimes comment following #13752 2024-12-02 14:26:31 -05:00
Jason Newcomb
66b15ad853
doc_nested_refdefs: new lint for suspicious list syntax (#13707)
https://github.com/rust-lang/rust/issues/133150

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.

```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.
```

> - [`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.

changelog: [`doc_nested_refdefs`]: add suspicious lint for link def at
start of list items and block quotes
2024-12-02 18:51:02 +00:00
Manish Goregaokar
df46e4cf13
add targeted help messages to zombie_processes diagnostic (#13760)
Fixes #13748

Diagnostic for that issue with this change:
```
warning: spawned process is not `wait()`ed on in all code paths
   --> x.rs:167:19
    |
167 |     let mut cmd = cmd.unwrap();
    |                   ^^^^^^^^^^^^
    |
note: no `wait()` call exists on the code path to this early return
   --> x.rs:178:47
    |
178 |             std::io::ErrorKind::BrokenPipe => return Some(0),
    |                                               ^^^^^^^^^^^^^^
note: `wait()` call exists, but it is unreachable due to the early return
   --> x.rs:185:10
    |
185 |     Some(cmd.wait().unwrap().code().unwrap()) // <-- wait()!
    |          ^^^
    = help: consider calling `.wait()` in all code paths
    = note: not doing so might leave behind zombie processes
    = note: see https://doc.rust-lang.org/stable/std/process/struct.Child.html#warning
```
Instead of saying "wait() is **never** called", it now says it's not
called by all code paths and points out the early return in particular.

changelog: none
2024-12-02 18:42:42 +00:00
Manish Goregaokar
74dd50c653
Fix lifetimes elision suggestion in where clauses (#13752)
Fix #13749

changelog: [`needless_lifetimes`]: do not suggest using `'_` in `where`
clauses
2024-12-02 18:42:13 +00:00
Urgau
c8d800e288 Drop uplifted clippy::fn_address_comparisons 2024-12-02 18:43:37 +01:00
Guillaume Gomez
a0a948ddaa Rollup merge of #133751 - lcnr:no-trait-solving-on-type, r=compiler-errors
remove `Ty::is_copy_modulo_regions`

Using these functions is likely incorrect if an `InferCtxt` is available, I moved this function to `TyCtxt` (and added it to `LateContext`) and added a note to the documentation that one should prefer `Infer::type_is_copy_modulo_regions` instead.

I didn't yet move `is_sized` and `is_freeze`, though I think we should move these as well.

r? `@compiler-errors` cc #132279
2024-12-02 17:36:11 +01:00
Guillaume Gomez
e66bd976c6 Rollup merge of #133603 - dtolnay:precedence, r=lcnr
Eliminate magic numbers from expression precedence

Context: see https://github.com/rust-lang/rust/pull/133140.

This PR continues on backporting Syn's expression precedence design into rustc. Rustc's design used mysterious integer quantities represented variously as `i8` or `usize` (e.g. `PREC_CLOSURE = -40i8`), a special significance around `0` that is never named, and an extra `PREC_FORCE_PAREN` precedence level that does not correspond to any expression. Syn's design uses a C-like enum with variants that clearly correspond to specific sets of expression kinds.

This PR is a refactoring that has no intended behavior change on its own, but it unblocks other precedence work that rustc's precedence design was poorly suited to accommodate.

- Asymmetrical precedence, so that a pretty-printer can tell `(return 1) + 1` needs parens but `1 + return 1` does not.

- Squashing the `Closure` and `Jump` cases into a single precedence level.

- Numerous remaining false positives and false negatives in rustc pretty-printer's parenthesization of macro metavariables, for example in `$e < rhs` where $e is `lhs as Thing<T>`.

FYI `@fmease` &mdash; you don't need to review if rustbot picks someone else, but you mentioned being interested in the followup PRs.
2024-12-02 17:36:03 +01:00
Alejandra González
2ddfc92ea2
Add more cases to the useless_conversion lint (#13756)
The new cases are the application of `Into::into` or `From::from`
through the following functions with no effect:
- `Option::map()`
- `Result::map()` and `Result::map_err()`
- `ControlFlow::map_break()` and `ControlFlow::map_err()`
- `Iterator::map()`

changelog: [`useless_conversion`]: detect useless calls to `Into::into`
and `From::from` application through `map*` methods
2024-12-02 15:41:25 +00:00
Jason Newcomb
0a07dc5d8c
typing_env_env_for_derived_eq -> typing_env_for_derived_eq (#13769)
I'm assuming the duplicated `env` was a typo. Apologies if I've made a
mistake. (cc: @lcnr)

---

changelog: none
2024-12-02 15:30:30 +00:00
Samuel Tardieu
ab5d55c996 Add more receivers to useless_conversion
- `ControlFlow::map_break()`
- `ControlFlow::map_continue()`
- `Iterator::map()`
2024-12-02 16:26:51 +01:00
lcnr
b330d9637a remove Ty::is_copy_modulo_regions 2024-12-02 13:57:56 +01:00
Oli Scherer
5082adf9b5 Change AttrArgs::Eq into a struct variant 2024-12-02 10:28:58 +00:00
Jacob Pratt
5e799b25b7 Rollup merge of #133589 - voidc:remove-array-len, r=boxyuwu
Remove `hir::ArrayLen`

This refactoring removes `hir::ArrayLen`, replacing it with `hir::ConstArg`. To represent inferred array lengths (previously `hir::ArrayLen::Infer`), a new variant `ConstArgKind::Infer` is added.

r? `@BoxyUwU`
2024-12-01 22:10:23 -05:00
Catherine Flores
278e316d67
Fix needless_match FP on if-lets (#13646)
Closes #13574

Make sure that `needless_match` doesn't simplify:

```
if let Some(_) = a() {
// ..
} else let Some(_) = b() {
// ..
}
```

to:

```
a()
```

changelog: [`needless_match`]: Fix false-positive on if lets
2024-12-02 02:51:48 +00:00
Samuel Moelius
92badb3d19 typing_env_env_for_derived_eq -> typing_env_for_derived_eq 2024-12-01 11:07:56 -05:00
Timo
0a1ba2ca07
Mention string_slice in indexing_slicing documentation (#13763)
Close #13703

changelog: none
2024-12-01 15:34:22 +00:00
Fridtjof Stoldt
1f966e98db
Add new literal_string_with_formatting_args lint (#13410)
Fixes #10195.

changelog: Added new [`literal_string_with_formatting_args`] `pedantic`
lint
[#13410](https://github.com/rust-lang/rust-clippy/pull/13410)
2024-12-01 11:46:18 +00:00
David Tolnay
c52fe8bc2a Eliminate magic numbers from expression precedence 2024-11-30 17:53:40 -08:00
Samuel Tardieu
092bfefa49 Do not mark attributes with unknown namespace as useless 2024-11-30 22:54:24 +01:00
Samuel Tardieu
736d1145d7 Extract lint namespace and lint name from the meta item
Lints with more than two segments are unrecognized, instead of having
the middle segments truncated.
2024-11-30 22:54:24 +01:00