Commit Graph

1788 Commits

Author SHA1 Message Date
bors 040129b774 Auto merge of #13629 - samueltardieu:push-nwukowumrvsn, r=flip1995
Return iterator must not capture lifetimes in Rust 2024

In Rust 2024, by default lifetimes will be captured which does not reflect the reality since we return an iterator of `DefId` which do not capture the input parameters.

changelog: none
2024-11-03 15:50:48 +00:00
bors e8b78e2f66 Auto merge of #13630 - samueltardieu:push-qrnxuykslnsl, r=y21
Use match ergonomics compatible with editions 2021 and 2024

This PR contains the minimal changes needed to make Clippy match ergonomics work with both Rust 2021 and Rust 2024.

changelog: none
2024-11-01 20:23:33 +00:00
bors c782988378 Auto merge of #13615 - GnomedDev:document-constevalctx-point, r=Alexendoo
Explain why clippy's HIR const eval exists

When I initially found this, I was wondering why clippy wasn't just using miri, but after some discussion with some rustc folks let's document why.

changelog: none
2024-11-01 13:39:21 +00:00
GnomedDev 012e30622c
Explain why clippy's HIR const eval exists 2024-11-01 11:06:54 +00:00
Samuel Tardieu 540e116a38 Return iterator must not capture lifetimes in Rust 2024
In Rust 2024, by default lifetimes will be captured which does not
reflect the reality since we return an iterator of `DefId` which do
not capture the input parameters.
2024-10-30 11:22:17 +01:00
Samuel Tardieu 0c1ef98454 Use match ergonomics compatible with editions 2021 and 2024 2024-10-30 11:22:17 +01:00
Ruairidh Williamson 59ecf4d073
Fix is_from_proc_macro attr 2024-10-25 15:25:17 +01:00
y21 38cf3f3234 add debug assertions for overlapping spans and empty replacements 2024-10-19 19:23:56 +02:00
Philipp Krones 4d5eaa0344
Bump Clippy version -> 0.1.84 2024-10-18 13:25:50 +02:00
Philipp Krones 224d1e323a
Merge remote-tracking branch 'upstream/master' into rustup 2024-10-18 13:25:37 +02:00
bors c512a221c2 Auto merge of #131481 - nnethercote:rm-GenKillSet, r=cjgillot
Remove `GenKillAnalysis`

There are two kinds of dataflow analysis in the compiler: `Analysis`, which is the basic kind, and `GenKillAnalysis`, which is a more specialized kind for gen/kill analyses that is intended as an optimization. However, it turns out that `GenKillAnalysis` is actually a  pessimization! It's faster (and much simpler) to do all the gen/kill analyses via `Analysis`. This lets us remove `GenKillAnalysis`, and `GenKillSet`, and a few other things, and also merge `AnalysisDomain` into `Analysis`. The PR removes 500 lines of code and improves performance.

r? `@tmiasko`
2024-10-16 09:45:05 +00:00
bors c16ba359b5 Auto merge of #131723 - matthiaskrgr:rollup-krcslig, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #122670 (Fix bug where `option_env!` would return `None` when env var is present but not valid Unicode)
 - #131095 (Use environment variables instead of command line arguments for merged doctests)
 - #131339 (Expand set_ptr_value / with_metadata_of docs)
 - #131652 (Move polarity into `PolyTraitRef` rather than storing it on the side)
 - #131675 (Update lint message for ABI not supported)
 - #131681 (Fix up-to-date checking for run-make tests)
 - #131702 (Suppress import errors for traits that couldve applied for method lookup error)
 - #131703 (Resolved python deprecation warning in publish_toolstate.py)
 - #131710 (Remove `'apostrophes'` from `rustc_parse_format`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-10-15 11:50:31 +00:00
Matthias Krüger 66359a7c87 Rollup merge of #130635 - eholk:pin-reborrow-sugar, r=compiler-errors
Add `&pin (mut|const) T` type position sugar

This adds parser support for `&pin mut T` and `&pin const T` references. These are desugared to `Pin<&mut T>` and `Pin<&T>` in the AST lowering phases.

This PR currently includes #130526 since that one is in the commit queue. Only the most recent commits (bd450027eb4a94b814a7dd9c0fa29102e6361149 and following) are new.

Tracking:

- #130494

r? `@compiler-errors`
2024-10-15 05:12:34 +02:00
Michael Goulet 5aa3e115f6 Move trait bound modifiers into ast::PolyTraitRef 2024-10-14 09:20:38 -04:00
Nicholas Nethercote 5a8943649a Remove `ResultsCursor::contains`.
It's hardly worth it, and it needs to be removed so that
`GenKillAnalysis` can be removed.
2024-10-14 16:35:28 +11:00
bors 236751d093 Auto merge of #13540 - GnomedDev:create-dir-single-arg, r=y21
Check MethodCall/Call arg count earlier or at all

This gets rid of a bunch of possible panic spots, as well as bailing out earlier for optimisation reasons.

I started doing this because I saw that a significant amount of time was being spent in the `create_dir` restriction lint when running clippy with `perf`, but this also helps with robustness.

changelog: none
2024-10-13 13:34:48 +00:00
GnomedDev ef1db3f502 Check MethodCall/Call arg count earlier or at all 2024-10-13 11:24:47 +01:00
bors 8125cd5c2a Auto merge of #13359 - blyxyas:declare_clippy_macro, r=Alexendoo
Turn declare_clippy_lint into a declarative macro

Ease of development, and hopefully compile times (the dependencies are still there because of ui-test). The procedural macro was doing just some very basic processing (like assigning a lint level to each category), so it didn't have a reason to stay IMO

changelog: None
2024-10-11 14:10:01 +00:00
bors 806a9dfddd Auto merge of #13464 - y21:issue13458, r=flip1995
Don't warn on proc macro generated code in `needless_return`

Fixes #13458
Fixes #13457
Fixes #13467
Fixes #13479
Fixes #13481
Fixes #13526
Fixes #13486

The fix is unfortunately a little more convoluted than just simply adding a `is_from_proc_macro`. That check *does*  fix the issue, however it also introduces a bunch of false negatives in the tests, specifically when the returned expression is in a different syntax context, e.g. `return format!(..)`.

The proc macro check builds up a start and end pattern based on the HIR nodes and compares it to a snippet of the span, however that would currently fail for `return format!(..)` because we would have the patterns `("return", <something inside of the format macro>)`, which doesn't compare equal. So we now return an empty string pattern for when it's in a different syntax context.

"Hide whitespace" helps a bit for reviewing the proc macro detection change

changelog: none
2024-10-10 11:34:13 +02:00
bors 8e60f143d8 Auto merge of #13464 - y21:issue13458, r=flip1995
Don't warn on proc macro generated code in `needless_return`

Fixes #13458
Fixes #13457
Fixes #13467
Fixes #13479
Fixes #13481
Fixes #13526
Fixes #13486

The fix is unfortunately a little more convoluted than just simply adding a `is_from_proc_macro`. That check *does*  fix the issue, however it also introduces a bunch of false negatives in the tests, specifically when the returned expression is in a different syntax context, e.g. `return format!(..)`.

The proc macro check builds up a start and end pattern based on the HIR nodes and compares it to a snippet of the span, however that would currently fail for `return format!(..)` because we would have the patterns `("return", <something inside of the format macro>)`, which doesn't compare equal. So we now return an empty string pattern for when it's in a different syntax context.

"Hide whitespace" helps a bit for reviewing the proc macro detection change

changelog: none
2024-10-10 09:17:20 +00:00
Eric Holk c038c3030b Add sugar for &pin (const|mut) types 2024-10-07 11:15:04 -07:00
bors b013e69692 Auto merge of #13496 - y21:issue10619, r=Alexendoo
Show interior mutability chain in `mutable_key_type`

Fixes #10619

Just ran into this myself and I definitely agree it's not very nice to have to manually go through all the types involved to figure out why this happens and to evaluate if this is really a problem (knowing if the field of a struct is something that a hash impl relies on), so this changes the lint to emit notes for each step involved.

changelog: none
2024-10-07 15:32:34 +00:00
Nicholas Nethercote 121d3ab89e Avoid another `&Lrc<..>` in a return value. 2024-10-07 13:59:50 +11:00
bors a1beaa1992 Auto merge of #129244 - cjgillot:opaque-hir, r=compiler-errors
Make opaque types regular HIR nodes

Having opaque types as HIR owner introduces all sorts of complications. This PR proposes to make them regular HIR nodes instead.

I haven't gone through all the test changes yet, so there may be a few surprises.

Many thanks to `@camelid` for the first draft.
Fixes https://github.com/rust-lang/rust/issues/129023

Fixes #129099
Fixes #125843
Fixes #119716
Fixes #121422
2024-10-05 06:19:35 +00:00
Noah Lev 1a29a78335 rm `ItemKind::OpaqueTy`
This introduce an additional collection of opaques on HIR, as they can no
longer be listed using the free item list.
2024-10-04 23:28:22 +00:00
Jubilee 47b681d276 Rollup merge of #130518 - scottmcm:stabilize-controlflow-extra, r=dtolnay
Stabilize the `map`/`value` methods on `ControlFlow`

And fix the stability attribute on the `pub use` in `core::ops`.

libs-api in https://github.com/rust-lang/rust/issues/75744#issuecomment-2231214910 seemed reasonably happy with naming for these, so let's try for an FCP.

Summary:
```rust
impl<B, C> ControlFlow<B, C> {
    pub fn break_value(self) -> Option<B>;
    pub fn map_break<T>(self, f: impl FnOnce(B) -> T) -> ControlFlow<T, C>;
    pub fn continue_value(self) -> Option<C>;
    pub fn map_continue<T>(self, f: impl FnOnce(C) -> T) -> ControlFlow<B, T>;
}
```

Resolves #75744

``@rustbot`` label +needs-fcp +t-libs-api -t-libs

---

Aside, in case it keeps someone else from going down the same dead end: I looked at the `{break,continue}_value` methods and tried to make them `const` as part of this, but that's disallowed because of not having `const Drop`, so put it back to not even unstably-const.
2024-10-04 14:11:34 -07:00
y21 19d1358b31 print cause chain in `mutable_key_type` 2024-10-03 21:27:05 +00:00
bors a01975b152 Auto merge of #13493 - y21:trait_duplication_in_bounds_fix, r=Manishearth
Compare trait references in `trait_duplication_in_bounds` correctly

Fixes #13476
Fixes #11067
Fixes #9915
Fixes #9626

Currently, the `trait_duplication_in_bounds` lints has a helper type for a trait reference that can be used for comparison and hashing, represented as `{trait: Res, generic_args: Vec<Res>}`. However, there are a lot of issues with this. For one, a `Res` can't represent e.g. references, slices, or lots of other types, as well as const generics and associated type equality. In those cases, the lint simply ignores them and has no way of checking if they're actually the same.

So, instead of using `Res` for this, use `SpanlessEq` and `SpanlessHash` for comparisons with the trait path for checking if there are duplicates.

However, using `SpanlessEq` as is alone lead to a false negative in the test. `std::clone::Clone` + `foo::Clone` wasn't recognized as a duplicate, because it has different segments. So this also adds a new "mode" to SpanlessEq which compares by final resolution. (I've been wondering if this can't just be the default but it's quite a large scale change as it affects a lot of lints and I haven't yet looked at all uses of it to see if there are lints that really do care about having exactly the same path segments).

Maybe an alternative would be to turn the hir types/consts into middle types/consts and compare them instead but I'm not sure there's really a good way to do that

changelog: none
2024-10-03 21:16:22 +00:00
Matthias Krüger 743623d4f7 Rollup merge of #131183 - compiler-errors:opaque-ty-origin, r=estebank
Refactoring to `OpaqueTyOrigin`

Pulled out of a larger PR that uses these changes to do cross-crate encoding of opaque origin, so we can use them for edition 2024 migrations. These changes should be self-explanatory on their own, tho 😄
2024-10-03 21:52:46 +02:00
y21 d6be597fbc Use SpanlessEq for in `trait_bounds` lints 2024-10-03 15:49:37 +00:00
Philipp Krones 277c4e4baf Merge commit 'aa0d551351a9c15d8a95fdb3e2946b505893dda8' into clippy-subtree-update 2024-10-03 16:32:51 +02:00
Philipp Krones d300cdfcda
Merge remote-tracking branch 'upstream/master' into rustup 2024-10-03 14:47:50 +02:00
Michael Goulet ce22fd34d9 Remove redundant in_trait from hir::TyKind::OpaqueDef 2024-10-02 21:59:55 -04:00
Ralf Jung 4891dd4627 make InterpResult a dedicated type to avoid accidentally discarding the error 2024-10-01 21:45:35 +02:00
bors db1bda3df1 Auto merge of #13286 - smoelius:elidable-impl-lifetimes, r=Alexendoo
Extend `needless_lifetimes` to suggest eliding `impl` lifetimes

Example:
```
error: the following explicit lifetimes could be elided: 'a
  --> tests/ui/needless_lifetimes.rs:332:10
   |
LL |     impl<'a> Foo for Baz<'a> {}
   |          ^^              ^^
   |
help: elide the lifetimes
   |
LL -     impl<'a> Foo for Baz<'a> {}
LL +     impl Foo for Baz<'_> {}
```
The main change is in how `impl` lifetime uses are tracked. Previously, a hashmap was created, and lifetimes were removed from the hashmap as their uses were discovered. However, the uses are needed to generate elision suggestions. So, now, uses are added to the hashmap as they are discovered.

The PR is currently organized as six commits, which I think are self-explanatory:
- Extend `needless_lifetimes` to suggest eliding `impl` lifetimes
- Reorder functions _[not strictly necessary, but IMHO, the code is better structured as a result]_
- Fix lifetime tests
- Fix non-lifetime tests
- Fix `clippy_lints` and `clippy_utils`
- Fix typo in `needless_lifetimes` test

r? `@Alexendoo` (I think you are `needless_lifetimes`' primary author? Sorry if I have this wrong.)

---

changelog: Extend `needless_lifetimes` to suggest eliding `impl` lifetimes
2024-10-01 00:41:21 +00:00
y21 55834a362c deal with differing syntax contexts for subexpressions in check_proc_macro 2024-09-29 15:58:44 +02:00
Yuri Astrakhan f7d5d9d892 Convert `&Option<T>` to `Option<&T>` 2024-09-28 19:51:02 -04:00
Scott McMurray d232d094b8 Remove the `control_flow_enum` feature from clippy 2024-09-25 19:00:19 -07:00
Samuel Moelius 66f1f544af Fix `clippy_lints` and `clippy_utils` 2024-09-25 13:52:12 -04:00
bors 52b31180b2 Auto merge of #130778 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update

r? `@Manishearth`

Really delayed sync (2 1/2 weeks), because of a `debug_assertion` we hit, and I didn't have the time to investigate earlier.

It would be nice to merge this PR with some priority, as it includes a lot of formatting changes due to the rustfmt bump.

Include Cargo.lock update due to Clippy version bump and ui_test bump in Clippy.
2024-09-25 11:40:41 +00:00
Trevor Gross e691743119 Rollup merge of #130764 - compiler-errors:inherent, r=estebank
Separate collection of crate-local inherent impls from error tracking

#119895 changed the return type of the `crate_inherent_impls` query from `CrateInherentImpls` to `Result<CrateInherentImpls, ErrorGuaranteed>` to avoid needing to use the non-parallel-friendly `track_errors()` to track if an error was reporting from within the query... This was mostly fine until #121113, which stopped halting compilation when we hit an `Err(ErrorGuaranteed)` in the `crate_inherent_impls` query.

Thus we proceed onwards to typeck, and since a return type of `Result<CrateInherentImpls, ErrorGuaranteed>` means that the query can *either* return one of "the list inherent impls" or "error has been reported", later on when we want to assemble method or associated item candidates for inherent impls, we were just treating any `Err(ErrorGuaranteed)` return value as if Rust had no inherent impls defined anywhere at all! This leads to basically every inherent method call failing with an error, lol, which was reported in #127798.

This PR changes the `crate_inherent_impls` query to return `(CrateInherentImpls, Result<(), ErrorGuaranteed>)`, i.e. returning the inherent impls collected *and* whether an error was reported in the query itself. It firewalls the latter part of that query into a new `crate_inherent_impls_validity_check` just for the `ensure()` call.

This fixes #127798.
2024-09-24 19:47:50 -04:00
Lukas Markeffsky 08a8e68d2e be even more precise about "cast" vs "coercion" 2024-09-24 23:12:02 +02:00
Lukas Markeffsky d802a7a3c7 unify dyn* coercions with other pointer coercions 2024-09-24 22:17:55 +02:00
Michael Goulet f8969853eb Fix tools 2024-09-24 10:12:05 -04:00
blyxyas 4997ee7afc Turn declare_clippy_lint into a declarative macro 2024-09-24 15:47:36 +02:00
Philipp Krones b61fcbee76 Merge commit '7901289135257ca0fbed3a5522526f95b0f5edba' into clippy-subtree-update 2024-09-24 11:58:04 +02:00
GnomedDev d099ceddad
Split def_path_res into two parts 2024-09-23 08:58:32 +01:00
Philipp Krones 3ab1da8bab
Formatting 2024-09-22 20:52:15 +02:00
Philipp Krones d140e26cc0
Merge remote-tracking branch 'upstream/master' into rustup 2024-09-22 20:51:17 +02:00
Ben Kimock 249210e8d8 Fix clippy 2024-09-21 01:07:00 -04:00