Commit Graph

1483 Commits

Author SHA1 Message Date
Philipp Krones
1534e08250
Merge remote-tracking branch 'upstream/master' into rustup 2024-01-25 18:39:39 +01:00
Nicholas Nethercote
6b359b7e1b Rename TyCtxt::struct_span_lint_hir as TyCtxt::node_span_lint. 2024-01-23 08:09:01 +11:00
Nicholas Nethercote
cf355c6e9d Rename LintContext::struct_span_lint as LintContext::span_lint. 2024-01-23 07:59:45 +11:00
bors
a8017ae131 Auto merge of #12153 - GuillaumeGomez:non-exhaustive, r=llogiq
Don't emit `derive_partial_eq_without_eq` lint if the type has the `non_exhaustive` attribute

Part of https://github.com/rust-lang/rust-clippy/issues/9063.

If a type has a field/variant with the `#[non_exhaustive]` attribute or the type itself has it, then do no emit the `derive_partial_eq_without_eq` lint.

changelog: Don't emit `derive_partial_eq_without_eq` lint if the type has the `non_exhaustive` attribute
2024-01-22 18:20:12 +00:00
bors
93955e094a Auto merge of #120080 - cuviper:128-align-packed, r=nikic
Pack u128 in the compiler to mitigate new alignment

This is based on #116672, adding a new `#[repr(packed(8))]` wrapper on `u128` to avoid changing any of the compiler's size assertions. This is needed in two places:

* `SwitchTargets`, otherwise its `SmallVec<[u128; 1]>` gets padded up to 32 bytes.
* `LitKind::Int`, so that entire `enum` can stay 24 bytes.
  * This change definitely has far-reaching effects though, since it's public.
2024-01-22 13:08:19 +00:00
Guillaume Gomez
8b0931a2ba Rollup merge of #120000 - smoelius:fix-clippy, r=fee1-dead
Ensure `callee_id`s are body owners

This PR makes the `callee_id` argument of Clippy's `implements_trait_with_env` optional, and when it is passed, ensures it is a body owner.

#118661 added the `callee_id` parameter to alleviate an ICE. Specifically, the `callee_id` is used to determine an "effect arg" in certain situations.

Frankly, I [do not completely understand](https://github.com/rust-lang/rust/pull/118661#discussion_r1449013176) what an "effect arg" is. But the code that determines it seems to require that `callee_id` is a body owner:
- 1ead4761e9/src/tools/clippy/clippy_utils/src/ty.rs (L286-L288)
- 1ead4761e9/compiler/rustc_middle/src/ty/util.rs (L834)
- 1ead4761e9/compiler/rustc_middle/src/hir/map/mod.rs (L372)

In the current head, some def ids passed as `callee_id`s are not body owners. This PR fixes that.

cc ``@rust-lang/clippy``

r? ``@fee1-dead``
2024-01-20 20:06:34 +01:00
Guillaume Gomez
fd6e752f4e Move has_non_exhaustive_attr function into clippy_utils 2024-01-20 17:08:53 +01:00
Josh Stone
eb42f3e703 Pack the u128 in LitKind::Int 2024-01-19 20:10:39 -08:00
Matthias Krüger
21d719d90c Rollup merge of #119869 - oli-obk:track_errors2, r=matthewjasper
replace `track_errors` usages with bubbling up `ErrorGuaranteed`

more of the same as https://github.com/rust-lang/rust/pull/117449 (removing `track_errors`)
2024-01-18 20:56:20 +01:00
Samuel Moelius
6a331e37fb Apply suggestions from code review
Co-authored-by: fee1-dead <ent3rm4n@gmail.com>
2024-01-18 10:32:57 -05:00
Oli Scherer
4488653ec6 Fix clippy 2024-01-17 10:02:32 +00:00
Lieselotte
33e1e6f783 Add PatKind::Err 2024-01-17 03:14:16 +01:00
Martin Nordholts
6a74a0e17b compiler: Lower fn call arg spans down to MIR
To enable improved accuracy of diagnostics in upcoming commits.
2024-01-15 19:07:11 +01:00
Samuel Moelius
ad2a2ba94d Ensure callee_ids are body owners 2024-01-15 12:26:45 -05:00
y21
f09cd88199
fix false positive in suspicious_open_options, make paths work 2024-01-15 17:15:09 +00:00
atwam
6fb471d646
More helpful text, small style changes. 2024-01-15 17:15:08 +00:00
bors
a9fa2f5ed1 Auto merge of #12074 - ARandomDev99:12044-include-comments-while-checking-duplicate-code, r=Jarcho
Make `HirEqInterExpr::eq_block` take comments into account while checking if two blocks are equal

This PR:
- now makes `HirEqInterExpr::eq_block` take comments into account. Identical code with varying comments will no longer be considered equal.
- makes necessary adjustments to UI tests.

Closes #12044

**Lintcheck Changes**
- `match_same_arms` 53 => 52
- `if_same_then_else` 3 => 0

changelog: [`if_same_then_else`]: Blocks with different comments will no longer trigger this lint.
changelog: [`match_same_arms`]: Arms with different comments will no longer trigger this lint.
```
2024-01-15 04:06:52 +00:00
Bryanskiy
09d024117e Delegation implementation: step 1 2024-01-12 14:11:16 +03:00
Philipp Krones
aa220c7ee7 Merge commit '26ac6aab023393c94edf42f38f6ad31196009643' 2024-01-11 17:27:03 +01:00
Philipp Krones
2c0cea7cbc
Merge remote-tracking branch 'upstream/master' into rustup 2024-01-11 17:19:53 +01:00
Nicholas Nethercote
beeaee9785 Rename consuming chaining methods on DiagnosticBuilder.
In #119606 I added them and used a `_mv` suffix, but that wasn't great.

A `with_` prefix has three different existing uses.
- Constructors, e.g. `Vec::with_capacity`.
- Wrappers that provide an environment to execute some code, e.g.
  `with_session_globals`.
- Consuming chaining methods, e.g. `Span::with_{lo,hi,ctxt}`.

The third case is exactly what we want, so this commit changes
`DiagnosticBuilder::foo_mv` to `DiagnosticBuilder::with_foo`.

Thanks to @compiler-errors for the suggestion.
2024-01-10 07:40:00 +11:00
Nicholas Nethercote
122520d80c Make DiagnosticBuilder::emit consuming.
This works for most of its call sites. This is nice, because `emit` very
much makes sense as a consuming operation -- indeed,
`DiagnosticBuilderState` exists to ensure no diagnostic is emitted
twice, but it uses runtime checks.

For the small number of call sites where a consuming emit doesn't work,
the commit adds `DiagnosticBuilder::emit_without_consuming`. (This will
be removed in subsequent commits.)

Likewise, `emit_unless` becomes consuming. And `delay_as_bug` becomes
consuming, while `delay_as_bug_without_consuming` is added (which will
also be removed in subsequent commits.)

All this requires significant changes to `DiagnosticBuilder`'s chaining
methods. Currently `DiagnosticBuilder` method chaining uses a
non-consuming `&mut self -> &mut Self` style, which allows chaining to
be used when the chain ends in `emit()`, like so:
```
    struct_err(msg).span(span).emit();
```
But it doesn't work when producing a `DiagnosticBuilder` value,
requiring this:
```
    let mut err = self.struct_err(msg);
    err.span(span);
    err
```
This style of chaining won't work with consuming `emit` though. For
that, we need to use to a `self -> Self` style. That also would allow
`DiagnosticBuilder` production to be chained, e.g.:
```
    self.struct_err(msg).span(span)
```
However, removing the `&mut self -> &mut Self` style would require that
individual modifications of a `DiagnosticBuilder` go from this:
```
    err.span(span);
```
to this:
```
    err = err.span(span);
```
There are *many* such places. I have a high tolerance for tedious
refactorings, but even I gave up after a long time trying to convert
them all.

Instead, this commit has it both ways: the existing `&mut self -> Self`
chaining methods are kept, and new `self -> Self` chaining methods are
added, all of which have a `_mv` suffix (short for "move"). Changes to
the existing `forward!` macro lets this happen with very little
additional boilerplate code. I chose to add the suffix to the new
chaining methods rather than the existing ones, because the number of
changes required is much smaller that way.

This doubled chainging is a bit clumsy, but I think it is worthwhile
because it allows a *lot* of good things to subsequently happen. In this
commit, there are many `mut` qualifiers removed in places where
diagnostics are emitted without being modified. In subsequent commits:
- chaining can be used more, making the code more concise;
- more use of chaining also permits the removal of redundant diagnostic
  APIs like `struct_err_with_code`, which can be replaced easily with
  `struct_err` + `code_mv`;
- `emit_without_diagnostic` can be removed, which simplifies a lot of
  machinery, removing the need for `DiagnosticBuilderState`.
2024-01-08 15:24:49 +11:00
bors
17b2418208 Auto merge of #12104 - GuillaumeGomez:map-clone, r=llogiq
Extend `map_clone` lint to also work on non-explicit closures

I found it weird that this case was not handled by the current line so I added it. The only thing is that I don't see an obvious way to infer the current type to determine if it's copyable or not, so for now I always suggest `cloned` and I added a FIXME.

r? `@llogiq`

changelog: Extend `map_clone` lint to also work on non-explicit closures
2024-01-06 16:54:20 +00:00
Guillaume Gomez
af35d37749 Fix new dogfood issue 2024-01-06 17:22:21 +01:00
Matthew Jasper
f73e37d00c Update clippy for hir::Guard removal 2024-01-05 10:56:59 +00:00
y21
890c0702e4 don't change eagerness for struct literal syntax with significant drop 2024-01-05 11:45:59 +01:00
Yuxiang Qiu
88541d6637
fix some typos 2024-01-02 19:21:51 -05:00
Aneesh Kadiyala
543d56938e Make HirEqInterExpr::eq_block take comments into account
This commit:
- now makes `HirEqInterExpr::eq_block` take comments into account. Identical code with varying comments will no longer be considered equal.
- makes necessary adjustments to UI tests.
2024-01-02 11:30:20 +05:30
Philipp Krones
15b1edb209 Merge commit 'ac4c2094a6030530661bee3876e0228ddfeb6b8b' into clippy-subtree-sync 2023-12-28 19:33:07 +01:00
Philipp Krones
2a4c7d2b0f
Bump Clippy version -> 0.1.77 2023-12-28 19:21:01 +01:00
Philipp Krones
9ff84af787
Merge remote-tracking branch 'upstream/master' into rustup 2023-12-28 19:20:18 +01:00
Nicholas Nethercote
620a1e4c2f Remove Session methods that duplicate DiagCtxt methods.
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier
access.
2023-12-24 08:05:28 +11:00
bors
4ad06d1adf Auto merge of #118847 - eholk:for-await, r=compiler-errors
Add support for `for await` loops

This adds support for `for await` loops. This includes parsing, desugaring in AST->HIR lowering, and adding some support functions to the library.

Given a loop like:
```rust
for await i in iter {
    ...
}
```
this is desugared to something like:
```rust
let mut iter = iter.into_async_iter();
while let Some(i) = loop {
    match core::pin::Pin::new(&mut iter).poll_next(cx) {
        Poll::Ready(i) => break i,
        Poll::Pending => yield,
    }
} {
    ...
}
```

This PR also adds a basic `IntoAsyncIterator` trait. This is partly for symmetry with the way `Iterator` and `IntoIterator` work. The other reason is that for async iterators it's helpful to have a place apart from the data structure being iterated over to store state. `IntoAsyncIterator` gives us a good place to do this.

I've gated this feature behind `async_for_loop` and opened #118898 as the feature tracking issue.

r? `@compiler-errors`
2023-12-22 14:17:10 +00:00
Alona Enraght-Moony
062845421b Give VariantData::Struct named fields, to clairfy recovered. 2023-12-20 00:07:34 +00:00
Eric Holk
212ea0359c Plumb awaitness of for loops 2023-12-19 12:26:20 -08:00
bors
fff484d18e Auto merge of #11977 - y21:is_const_evaluatable_ice, r=Manishearth
don't visit nested bodies in `is_const_evaluatable`

Fixes #11939

This ICE happened in `if_let_some_else_none`, but the root problem is in one of the utils that it uses.
It is (was) possible for `is_const_evalutable` to visit nested bodies which would lead to it trying to get the type of one of the expressions with the wrong typeck table, which won't have the type stored.

Notably, for the expression `Bytes::from_static(&[0; 256 * 1024]);` in the linked issue, the array length is an anonymous const in which type checking happens on its own, so we can't use the typeck table of the enclosing function in there.

Visiting nested bodies is also not needed for checking whether an expression can be const, so I think it's safe to ignore just ignore them altogether.

changelog: Fix ICE when checking for constness in nested bodies
2023-12-16 22:54:50 +00:00
y21
b5169aea52 don't visit any nested bodies in is_const_evaluatable 2023-12-16 22:13:54 +01:00
y21
bc22407b79 add tests, lint on while let true and matches!(.., true) 2023-12-16 17:40:32 +01:00
y21
850d77ed55 [redundant_pattern_matching]: catch if let true 2023-12-16 16:37:58 +01:00
Philipp Krones
3596d44988 Merge commit 'a859e5cc1ce100df22346a1005da30532d04de59' into clippyup 2023-12-16 14:12:50 +01:00
Philipp Krones
80ccd6392f
Merge remote-tracking branch 'upstream/master' into rustup 2023-12-16 13:59:56 +01:00
Michael Goulet
677ccca13b Don't pass lint back out of lint decorator 2023-12-15 16:05:36 +00:00
zetanumbers
fe37cc1d97 Move some methods from tcx.hir() to tcx
Renamings:
- find -> opt_hir_node
- get -> hir_node
- find_by_def_id -> opt_hir_node_by_def_id
- get_by_def_id -> hir_node_by_def_id

Fix rebase changes using removed methods

Use `tcx.hir_node_by_def_id()` whenever possible in compiler

Fix clippy errors

Fix compiler

Apply suggestions from code review

Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>

Add FIXME for `tcx.hir()` returned type about its removal

Simplify with with `tcx.hir_node_by_def_id`
2023-12-12 06:40:29 -08:00
Jason Newcomb
184845fb0c Fix is_from_proc_macro patterns 2023-12-10 15:36:31 -05:00
Deadbeef
782520088f fix clippy 2023-12-10 13:10:46 +00:00
bors
0252580e72 Auto merge of #118420 - compiler-errors:async-gen, r=eholk
Introduce support for `async gen` blocks

I'm delighted to demonstrate that `async gen` block are not very difficult to support. They're simply coroutines that yield `Poll<Option<T>>` and return `()`.

**This PR is WIP and in draft mode for now** -- I'm mostly putting it up to show folks that it's possible. This PR needs a lang-team experiment associated with it or possible an RFC, since I don't think it falls under the jurisdiction of the `gen` RFC that was recently authored by oli (https://github.com/rust-lang/rfcs/pull/3513, https://github.com/rust-lang/rust/issues/117078).

### Technical note on the pre-generator-transform yield type:

The reason that the underlying coroutines yield `Poll<Option<T>>` and not `Poll<T>` (which would make more sense, IMO, for the pre-transformed coroutine), is because the `TransformVisitor` that is used to turn coroutines into built-in state machine functions would have to destructure and reconstruct the latter into the former, which requires at least inserting a new basic block (for a `switchInt` terminator, to match on the `Poll` discriminant).

This does mean that the desugaring (at the `rustc_ast_lowering` level) of `async gen` blocks is a bit more involved. However, since we already need to intercept both `.await` and `yield` operators, I don't consider it much of a technical burden.

r? `@ghost`
2023-12-08 19:13:57 +00:00
Michael Goulet
62f7337df8 Make some matches exhaustive to avoid bugs, fix tools 2023-12-08 17:23:26 +00:00
Michael Goulet
1512d37af5 coro_kind -> coroutine_kind 2023-12-08 17:23:25 +00:00
bors
f39d18b7a0 Auto merge of #118527 - Nadrieril:never_patterns_parse, r=compiler-errors
never_patterns: Parse match arms with no body

Never patterns are meant to signal unreachable cases, and thus don't take bodies:
```rust
let ptr: *const Option<!> = ...;
match *ptr {
    None => { foo(); }
    Some(!),
}
```
This PR makes rustc accept the above, and enforces that an arm has a body xor is a never pattern. This affects parsing of match arms even with the feature off, so this is delicate. (Plus this is my first non-trivial change to the parser).

~~The last commit is optional; it introduces a bit of churn to allow the new suggestions to be machine-applicable. There may be a better solution? I'm not sure.~~ EDIT: I removed that commit

r? `@compiler-errors`
2023-12-08 17:08:52 +00:00
Eric Holk
45be5dd8e6 Option<CoroutineKind> 2023-12-04 13:03:37 -08:00
Eric Holk
b4e3b859f1 Merge Async and Gen into CoroutineKind 2023-12-04 12:48:01 -08:00
Nadrieril
7ffe1ff55f Parse a pattern with no arm 2023-12-03 12:25:46 +01:00
Philipp Krones
c9a43b18f1 Merge commit 'f0cdee4a3f094416189261481eae374b76792af1' into clippy-subtree-sync 2023-12-01 18:21:58 +01:00
Philipp Krones
a9867e1847
Merge remote-tracking branch 'upstream/master' into rustup 2023-12-01 18:06:03 +01:00
Matthias Krüger
071f8f610d Rollup merge of #118157 - Nadrieril:never_pat-feature-gate, r=compiler-errors
Add `never_patterns` feature gate

This PR adds the feature gate and most basic parsing for the experimental `never_patterns` feature. See the tracking issue (https://github.com/rust-lang/rust/issues/118155) for details on the experiment.

`@scottmcm` has agreed to be my lang-team liaison for this experiment.
2023-11-29 12:34:47 +01:00
Nadrieril
02e50f03bf Add never_patterns feature gate 2023-11-29 03:58:29 +01:00
Nicholas Nethercote
684c4bfef1 Rework ast::BinOpKind::to_string and ast::UnOp::to_string.
- Rename them both `as_str`, which is the typical name for a function
  that returns a `&str`. (`to_string` is appropriate for functions
  returning `String` or maybe `Cow<'a, str>`.)
- Change `UnOp::as_str` from an associated function (weird!) to a
  method.
- Avoid needless `self` dereferences.
2023-11-28 09:42:07 +11:00
Vadim Petrochenkov
bf86fe130c rustc: hir().local_def_id_to_hir_id() -> tcx.local_def_id_to_hir_id() cleanup 2023-11-26 12:41:21 +03:00
Michael Goulet
fffee10632 Appease the clippy 2023-11-25 18:02:11 +00:00
Nicholas Nethercote
fa7cd2548c Update itertools to 0.11.
Because the API for `with_position` improved in 0.11 and I want to use
it.
2023-11-22 08:13:21 +11:00
bors
e8e9510219 Auto merge of #11002 - y21:issue9422, r=Jarcho
teach `eager_or_lazy` about panicky arithmetic operations

Fixes #9422
Fixes #9814
Fixes #11793

It's a bit sad that we have to do this because arithmetic operations seemed to me like the prime example where a closure would not be necessary, but this has "side effects" (changes behavior when going from lazy to eager) as some of these panic on overflow/underflow if compiled with `-Coverflow-checks` (which is the default in debug mode).
Given the number of backlinks in the mentioned issues, this seems to be a FP that is worth fixing, probably.

changelog: [`unnecessary_lazy_evaluations`]: don't lint if closure has panicky arithmetic operations
2023-11-17 18:53:15 +00:00
lcnr
8c6c542443 rename bound region instantiation
- `erase_late_bound_regions` -> `instantiate_bound_regions_with_erased`
- `replace_late_bound_regions_X` -> `instantiate_bound_regions_X`
2023-11-17 09:29:48 +00:00
y21
aca4086d7f simplify matching on binop result 2023-11-16 23:05:17 +01:00
Philipp Krones
6246f0446a Merge commit 'edb720b199083f4107b858a8761648065bf38d86' into clippyup 2023-11-16 19:13:24 +01:00
Philipp Krones
6f952fbe53
Bump Clippy version -> 0.1.76 2023-11-16 19:02:33 +01:00
Philipp Krones
6fab1485c3
Merge remote-tracking branch 'upstream/master' into rustup 2023-11-16 19:02:04 +01:00
y21
7696c9d1d5 allow more div and rem operations that can be checked 2023-11-16 17:30:10 +01:00
y21
23ee33255c lint when relevant sides of binops are constants 2023-11-16 04:49:11 +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
Jason Newcomb
cdc4c697b5 Make expr_use_ctxt always return Some unless the syntax context changes. 2023-11-14 23:23:35 -05:00
Jason Newcomb
b587871e27 Simplify get_enclosing_loop_or_multi_call_closure 2023-11-14 22:17:02 -05: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
y21
c9d2961100 teach eager_or_lazy that arithmetic ops can panic 2023-11-02 23:53:00 +01: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