Commit Graph

1363 Commits

Author SHA1 Message Date
Philipp Krones
6fab1485c3
Merge remote-tracking branch 'upstream/master' into rustup 2023-11-16 19:02:04 +01:00
bors
7ad3373bb1 Auto merge of #11802 - dswij:issue-11765, r=xFrednet
`needless_return_with_question_mark` ignore let-else

Fixes #11765

This PR makes `needless_return_with_question_mark` to ignore expr inside let-else.

changelog: [`needless_return_with_question_mark`] ignore let-else
2023-11-15 10:15:47 +00:00
y21
19eec0b7cc disallow struct_span_lint 2023-11-15 03:20:04 +01:00
bors
0c42e451d6 Auto merge of #11791 - Jacherr:iter_over_hash_type, r=Jarcho
Implement new lint `iter_over_hash_type`

Implements and fixes https://github.com/rust-lang/rust-clippy/issues/11788

This PR adds a new *restriction* lint `iter_over_hash_type` which prevents `Hash`-types (that is, `HashSet` and `HashMap`) from being used as the iterator in `for` loops.

The justification for this is because in `Hash`-based types, the ordering of items is not guaranteed and may vary between executions of the same program on the same hardware. In addition, it reduces readability due to the unclear iteration order.

The implementation of this lint also ensures the following:
- Calls to `HashMap::keys`, `HashMap::values`, and `HashSet::iter` are also denied when used in `for` loops,
- When this expression is used in procedural macros, it is not linted/denied.

changelog: add new `iter_over_hash_type` lint to prevent unordered iterations through hashed data structures
2023-11-14 15:55:00 +00:00
dswij
48f38eb131 needless_return_with_question_mark ignore let-else 2023-11-14 16:30:52 +08:00
lcnr
9ab054d714 update type flags
- `HAS_RE_LATE_BOUND` -> `HAS_RE_BOUND`
- `HAS_TY_LATE_BOUND` -> `HAS_TY_BOUND`
- `HAS_CT_LATE_BOUND` -> `HAS_CT_BOUND`
- `HAS_LATE_BOUND` -> `HAS_BOUND_VARS`
- `fn has_late_bound_regions` -> `fn has_bound_regions`
- `fnhas_non_region_late_bound` -> `fn has_non_region_bound_vars`
- `fn has_late_bound_vars` -> `fn has_bound_vars`
2023-11-13 14:13:54 +00:00
lcnr
c4971f9f65 rename ReLateBound to ReBound
other changes:
- `Region::new_late_bound` -> `Region::new_bound`
- `Region::is_late_bound` -> `Region::is_bound`
2023-11-13 14:13:54 +00:00
bors
07bc130074 Auto merge of #11760 - compiler-errors:escaping, r=Jarcho
Don't check for late-bound vars, check for escaping bound vars

Fixes an assertion that didn't make sense. Many valid and well-formed types *have* late-bound vars (e.g. `for<'a> fn(&'a ())`), they just must not have *escaping* late-bound vars in order to be normalized correctly.

Addresses rust-lang/rust-clippy#11230, cc `@jyn514` and `@matthiaskrgr`

changelog: don't check for late-bound vars, check for escaping bound vars. Addresses rust-lang/rust-clippy#11230
2023-11-12 22:15:43 +00:00
Michael Goulet
1539eb8c03 Don't check for late-bound vars, check for escaping bound vars 2023-11-12 12:15:30 -08:00
bors
6a15f3bd49 Auto merge of #11787 - Jarcho:divergence_check, r=dswij
Fixes to `manual_let_else`'s divergence check

A few changes to the divergence check in `manual_let_else` and moves it the implementation to `clippy_utils` since it's generally useful:
* Handle internal `break` and `continue` expressions.
    e.g. The first loop is divergent, but the second is not.
    ```rust
    {
        loop {
            break 'outer;
        };
    }
    {
        loop {
            break;
        };
    }
    ```
* Match rust's definition of divergence which is defined via the type system.
    e.g. The following is not considered divergent by rustc as the inner block has a result type of `()`:
    ```rust
    {
        'a: {
            panic!();
            break 'a;
        };
    }
    ```
* Handle when adding a single semicolon would make the expression divergent.
    e.g. The following would be a divergent if a semicolon were added after the `if` expression:
    ```rust
    { if panic!() { 0 } else { 1 } }
    ```

changelog: None
2023-11-12 15:44:13 +00:00
bors
886d5fbeb0 Auto merge of #11508 - Jarcho:issue_11474, r=blyxyas
Lint `needless_borrow` and `explicit_auto_deref` on most union field accesses

Changes both lints to follow rustc's rules around auto-deref through `ManuallyDrop` union fields rather than just bailing on union fields.

changelog: [`needless_borrow`] & [`explicit_auto_deref`]: Lint on most union field accesses
2023-11-12 11:24:01 +00:00
Jacherr
941164807f implement more types to lint, fix wording 2023-11-11 21:26:50 +00:00
Jason Newcomb
1a01132417 Lint explicit_auto_deref on most union field accesses. 2023-11-11 15:54:58 -05:00
bors
d487579efd Auto merge of #11792 - y21:issue11764, r=llogiq
[`map_identity`]: respect match ergonomics

Fixes #11764

Note: the original tests before this were slightly wrong themselves already and had to be changed. They were calling `map` on an iterator of `&(i32, i32)`s, so this PR would stop linting there, but they were meant to test something else unrelated to binding modes, so I just changed them to remove the references so that it iterates over owned values and they all bind by value. This way they continue to test what they checked for before: the identity function for tuple patterns.

changelog: [`map_identity`]: respect match ergonomics
2023-11-11 14:58:00 +00:00
y21
b2cf8f7a24 [map_identity]: respect match ergonomics 2023-11-11 13:48:26 +01:00
Jacherr
cb90674aed add iter_over_hash_type lint 2023-11-11 00:20:47 +00:00
Alex Macleod
13b4bb12ad Clean up after if chain removal 2023-11-10 18:03:13 +00:00
Alex Macleod
9681b4afe0 Run if-to-let-chain clippy*/**/*.rs
https://github.com/Alexendoo/if-to-let-chain
2023-11-10 17:29:28 +00:00
Jason Newcomb
a44bb07900 Change divergence checking to match the compiler's type system based definition of divergence. 2023-11-09 17:57:06 -05:00
Jason Newcomb
16d58a2982 Lift expr_diverges to clippy_utils as is_never_expr 2023-11-09 17:45:59 -05:00
Jacherr
483b109e6e cargo dev fmt 2023-11-08 21:17:40 +00:00
Jacherr
67bb503f26 add support for std::alloc::Global, add more tests 2023-11-08 21:10:27 +00:00
bors
ba43632808 Auto merge of #11736 - gernot-ohner:issue-10267, r=flip1995
Make SpanlessEq more consistent

1) Remove wildcard as requested in https://github.com/rust-lang/rust-clippy/issues/10267.
2) Implement `hir_utils::eq_expr` for `ExprKind::Closure`, `ExprKind::ConstBlock`, `ExprKind::InlineAsm` and `ExprKind::Yield`.
3) Reorder branches of `hir_utils::eq_expr` to be in alphabetical order.

---
changelog: none
2023-11-08 09:58:56 +00:00
Gernot Ohner
171845d5a8 Reorder ExprKinds in hash_expr alphabetically 2023-11-06 11:51:07 -07:00
bors
2d9af160af Auto merge of #117507 - nnethercote:rustc_span, r=Nilstrieb
`rustc_span` cleanups

Just some things I found while looking over this crate.

r? `@oli-obk`
2023-11-03 14:57:40 +00:00
Philipp Krones
77c1e3aaa1 Merge commit '09ac14c901abc43bd0d617ae4a44e8a4fed98d9c' into clippyup 2023-11-02 17:35:56 +01:00
Philipp Krones
62a82b361c
Format let-chains across the code base
In the updated nightly version, it seems that rustfmt now supports formatting
let-chains. Since we're using them a lot, it's a lot of reformatting.
2023-11-02 17:24:30 +01:00
Philipp Krones
95dc7be92f
Merge remote-tracking branch 'upstream/master' into rustup 2023-11-02 17:24:19 +01:00
Nicholas Nethercote
e1ec2d5cc9 Minimize pub usage in source_map.rs.
Most notably, this commit changes the `pub use crate::*;` in that file
to `use crate::*;`. This requires a lot of `use` items in other crates
to be adjusted, because everything defined within `rustc_span::*` was
also available via `rustc_span::source_map::*`, which is bizarre.

The commit also removes `SourceMap::span_to_relative_line_string`, which
is unused.
2023-11-02 19:35:00 +11:00
Camille GILLOT
aae86ccc47 Rename hook. 2023-11-01 16:49:18 +00:00
Dinu Blanovschi
bb9cc6d47c refactor: extract common pat_is_wild to clippy_utils
This function was previously defined for the iter_kv_map,
for_kw_map, and unused_enumerate_index lints. This commit extracts
it into clippy_utils.
2023-11-01 14:19:23 +01:00
Gernot Ohner
6d840652dc Add branches in eq_expr 2023-10-30 18:04:36 -06:00
Gernot Ohner
67d379ba42 Reorder ExprKinds in eq_expr to alphabetical 2023-10-30 15:54:53 -06:00
Gernot Ohner
ed982afc8f Expliticly specify else branches in hir_utils::hash_expr 2023-10-30 15:16:23 -06:00
bors
325e9fd339 Auto merge of #11723 - Alexendoo:clippy-utils-internal, r=Jarcho
Remove internal feature from clippy_utils

It's only used to gate a few `const`s, removing the feature gate means it doesn't have to be recompiled when moving between a normal and `-F internal` build/test/etc

changelog: none
2023-10-30 17:11:53 +00:00
David Tolnay
2e907aa90c Rename Since -> StableSince in preparation for a DeprecatedSince 2023-10-29 21:39:57 -07:00
bors
f2a0776f77 Auto merge of #116447 - oli-obk:gen_fn, r=compiler-errors
Implement `gen` blocks in the 2024 edition

Coroutines tracking issue https://github.com/rust-lang/rust/issues/43122
`gen` block tracking issue https://github.com/rust-lang/rust/issues/117078

This PR implements `gen` blocks that implement `Iterator`. Most of the logic with `async` blocks is shared, and thus I renamed various types that were referring to `async` specifically.

An example usage of `gen` blocks is

```rust
fn foo() -> impl Iterator<Item = i32> {
    gen {
        yield 42;
        for i in 5..18 {
            if i.is_even() { continue }
            yield i * 2;
        }
    }
}
```

The limitations (to be resolved) of the implementation are listed in the tracking issue
2023-10-29 00:03:52 +00:00
Andre Bogus
1ed1001440 Fix missing parenthesis in suboptimal floating point help 2023-10-27 16:28:10 +02:00
Alex Macleod
f4b4e2ca1b Remove internal feature from clippy_utils 2023-10-27 13:13:26 +00:00
Oli Scherer
0c8caee7b9 Add gen blocks to ast and do some broken ast lowering 2023-10-27 13:05:48 +00:00
David Tolnay
d736992ac9 Parse rustc version at compile time 2023-10-26 18:55:05 -07:00
bors
2f0f4ddcf7 Auto merge of #11698 - a1phyr:waker_clone_and_wake, r=y21
Add `waker_clone_and_wake` lint to check needless `Waker` clones

Check for patterns of `waker.clone().wake()` and replace them with `waker.wake_by_ref()`.

An alternative name could be `waker_clone_then_wake`

changelog: [ `waker_clone_wake`]: new lint
2023-10-26 21:01:40 +00:00
David Tolnay
76d7af0df1 Expose a non-Symbol way to access current rustc version string 2023-10-24 18:11:20 -07:00
David Tolnay
f4f5b05cbb Handle structured stable attribute 'since' version in clippy 2023-10-24 18:00:26 -07:00
Benoît du Garreau
f8790963d9 Add a lint to check needless Waker clones 2023-10-24 09:58:23 +02:00
Gernot Ohner
a799249766 Add additional branches to hir_utils::eq_expr 2023-10-23 23:22:30 -06:00
Alex Macleod
4622203c9b Move configuration to new clippy_config crate 2023-10-23 20:05:10 +00:00
Alex Macleod
7347c1803f Set existing doc-tests to no_run 2023-10-23 15:28:26 +00:00
y21
d6fc606259 [map_identity]: recognize tuples 2023-10-21 15:40:34 +02:00
Philipp Krones
8e7d1678c4 Merge commit '2b030eb03d9e5837440b1ee0b98c50b97c0c5889' into clippyup 2023-10-21 14:16:11 +02:00