Commit Graph

1353 Commits

Author SHA1 Message Date
y21
bba155ea9d move changed logic to into its own util function 2023-10-09 21:57:44 +02:00
y21
0b60531e42 [map_identity]: allow closure with type annotations 2023-10-09 21:39:28 +02:00
Philipp Krones
8ebed4cc1a Merge commit 'b105fb4c39bc1a010807a6c076193cef8d93c109' into clippyup 2023-10-06 17:35:45 +02:00
Philipp Krones
b8677e54d4
Bump Clippy version -> 0.1.75 2023-10-06 17:32:44 +02:00
Philipp Krones
82c3064c47
Merge remote-tracking branch 'upstream/master' into rustup 2023-10-06 17:31:44 +02:00
Alex Macleod
dcc400191e Fix items_after_test_module for non root modules, add applicable suggestion 2023-10-06 12:46:04 +00:00
Jason Newcomb
9de3e6c928 Add more diagnostic items for clippy 2023-10-05 18:21:47 -04:00
y21
e6f29f1900 dogfood 2023-10-04 18:08:30 +02:00
bors
f107a50b23 Auto merge of #115025 - ouz-a:ouz_testing, r=lcnr
Make subtyping explicit in MIR

This adds new mir-opt that pushes new `ProjectionElem` called `ProjectionElem::Subtype(T)` to `Rvalue` of a subtyped assignment so we can unsoundness issues like https://github.com/rust-lang/rust/issues/107205

Addresses https://github.com/rust-lang/rust/issues/112651

r? `@lcnr`
2023-10-03 10:02:52 +00:00
ouz-a
ea4b38820b subtyping_projections 2023-10-02 23:37:49 +03:00
bors
3169423ce9 Auto merge of #115670 - Zoxc:outline-panic-macro-1, r=Mark-Simulacrum
Partially outline code inside the panic! macro

This outlines code inside the panic! macro in some cases. This is split out from https://github.com/rust-lang/rust/pull/115562 to exclude changes to rustc.
2023-10-01 05:56:47 +00:00
Maybe Waffle
a4d11d936e Reverse postorder instead of using reversed postorder 2023-09-28 23:50:56 +00:00
bors
91997a4df4 Auto merge of #11565 - RalfJung:mir_to_const, r=Jarcho
mir_to_const improvements

This simplifies some code and also fixes the float array handling to properly take into account the `offset`, and to work with little-endian targets.

Fixes https://github.com/rust-lang/rust-clippy/issues/11488
changelog: none
2023-09-28 17:59:05 +00:00
bors
3b75db7aa6 Auto merge of #116163 - compiler-errors:lazyness, r=oli-obk
Don't store lazyness in `DefKind::TyAlias`

1. Don't store lazyness of a type alias in its `DefKind`, but instead via a query.
2. This allows us to treat type aliases as lazy if `#[feature(lazy_type_alias)]` *OR* if the alias contains a TAIT, rather than having checks for both in separate parts of the codebase.

r? `@oli-obk` cc `@fmease`
2023-09-27 01:48:53 +00:00
Alex Macleod
ec2f62677f Add manual_hash_one lint 2023-09-26 13:49:15 +00:00
Michael Goulet
55074827b5 Don't store lazyness in DefKind 2023-09-26 02:53:59 +00:00
Ralf Jung
0f198579d0 mir_to_const: fix handling of float arrays 2023-09-25 17:02:07 +02:00
Ralf Jung
ce45221163 simply some valtree-to-const conversion 2023-09-25 16:23:47 +02:00
Ralf Jung
84d6894f26 it's not Miri but MIR constants 2023-09-25 16:19:02 +02:00
Philipp Krones
772296c50e Merge commit '7671c283a50b5d1168841f3014b14000f01dd204' into clippyup 2023-09-25 11:28:58 +02:00
Philipp Krones
903add0c11
Fix dogfood fallout 2023-09-25 10:31:51 +02:00
Philipp Krones
81fe8dc084
Merge remote-tracking branch 'upstream/master' into rustup 2023-09-25 10:26:11 +02:00
Oli Scherer
5ee167e00d Add a way to decouple the implementation and the declaration of a TyCtxt method. 2023-09-22 09:23:15 +00:00
bors
84917c83a8 Auto merge of #114776 - fee1-dead-contrib:enable-effects-in-libcore, r=oli-obk
Enable effects for libcore

~~r? `@oli-obk~~`

forgot you are on vacation, oops
2023-09-22 07:00:52 +00:00
Deadbeef
74573fbab9 fix clippy errors (ignore effects in certainty) 2023-09-22 00:05:52 +00:00
Michael Goulet
823bcb478b Record asyncness span in HIR 2023-09-21 19:18:14 +00:00
Ralf Jung
2ea6ac5673 rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const 2023-09-21 08:12:30 +02:00
Ralf Jung
b30cefc775 move ConstValue into mir
this way we have mir::ConstValue and ty::ValTree as reasonably parallel
2023-09-19 11:11:02 +02:00
Alex Macleod
32d3387c80 used_underscore_bindings: respect lint levels on the binding definition 2023-09-17 20:40:51 +00:00
Jason Newcomb
fed036a57c Fix cycle detection in needless_borrow 2023-09-15 19:13:34 -04:00
bors
9756a13580 Auto merge of #115677 - matthewjasper:let-expr-recovery, r=b-naber
Improve invalid let expression handling

- Move all of the checks for valid let expression positions to parsing.
- Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location.
- Suppress some later errors and MIR construction for invalid let expressions.
- Fix a (drop) scope issue that was also responsible for #104172.

Fixes #104172
Fixes #104868
2023-09-14 19:56:55 +00:00
Alex Macleod
c29de92d85 Return a value from find_format_args instead of using a callback 2023-09-14 15:53:32 +00:00
Ralf Jung
477a9b88bf fix clippy (and MIR printing) handling of ConstValue::Indirect slices 2023-09-14 11:56:55 +02:00
Ralf Jung
b2d5d68c58 cleanup op_to_const a bit; rename ConstValue::ByRef → Indirect 2023-09-14 07:27:30 +02:00
Ralf Jung
2aaaeb4e81 use AllocId instead of Allocation in ConstValue::ByRef 2023-09-14 07:26:24 +02:00
Philipp Krones
471469d30f Merge commit '98363cbf6a7c3f8b571a7d92a3c645bb4376e4a6' into clippyup 2023-09-12 18:44:06 +02:00
Matthew Jasper
ab08a3d7b2 Update tools and fulldeps tests 2023-09-11 15:51:19 +00:00
Alex Macleod
cc8c0e0099 Ignore span's parents in collect_ast_format_args/find_format_args 2023-09-08 12:40:21 +00:00
John Kåre Alsaker
b5941a2fd5 Partially outline code inside the panic! macro 2023-09-08 14:05:57 +02:00
Philipp Krones
d2b08432db
Merge remote-tracking branch 'upstream/master' into rustup 2023-09-07 21:43:06 +02:00
John Kåre Alsaker
0f74faf158 Use Freeze for SourceFile.lines 2023-09-07 13:05:05 +02:00
Camille GILLOT
c3170771f3 Use relative positions inside a SourceFile. 2023-09-03 12:56:10 +00:00
cui fliter
b0eaa84cfb fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-09-02 07:30:01 +08:00
bors
3da21b089f Auto merge of #11396 - y21:issue11345, r=Jarcho
new lint: `iter_out_of_bounds`

Closes #11345

The original idea in the linked issue seemed to be just about arrays afaict, but I extended this to catch some other iterator sources such as `iter::once` or `iter::empty`.

I'm not entirely sure if this name makes a lot of sense now that it's not just about arrays anymore (specifically, not sure if you can call `.take(1)` on an `iter::Empty` to be "out of bounds"?).

changelog: [`iter_out_of_bounds`]: new lint
2023-08-30 19:51:32 +00:00
bors
af02b43015 Auto merge of #115183 - flip1995:clippyup, r=Manishearth,oli-obk
Update Clippy

r? `@oli-obk` Assigning you, because something broke with ui_test:

```
tests/ui/crashes/ice-7272.rs FAILED:
command: "<unknown>"

A bug in `ui_test` occurred: called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }

full stderr:

```

(and that 103 times)

Thought I would ping you, before starting to investigate. Maybe you know what's going on.
2023-08-29 17:03:26 +00:00
bors
b97eaab558 Auto merge of #11387 - y21:issue11371, r=blyxyas
[`unnecessary_unwrap`]: lint on `.as_ref().unwrap()`

Closes #11371

This turned out to be a little more code than I originally thought, because the lint also makes sure to not lint if the user tries to mutate the option:
```rs
if option.is_some() {
  option = None;
  option.unwrap(); // don't lint here
}
```
... which means that even if we taught this lint to recognize `.as_mut()`, it would *still* not lint because that would count as a mutation. So we need to allow `.as_mut()` calls but reject other kinds of mutations.
Unfortunately it doesn't look like this is possible with `is_potentially_mutated` (seeing what kind of mutation happened).
This replaces it with a custom little visitor that does basically what it did before, but also allows `.as_mut()`.

changelog: [`unnecessary_unwrap`]: lint on `.as_ref().unwrap()`
2023-08-28 20:29:42 +00:00
bors
4118738998 Auto merge of #11401 - y21:issue11394, r=xFrednet
[`if_then_some_else_none`]: look into local initializers for early returns

Fixes #11394

As the PR title says, problem was that it only looked for early returns in semi statements. Local variables don't count as such, so it didn't count `let _v = x?;` (or even just `let _ = return;`) as a possible early return and didn't realize that it can't lint then.

Imo the `stmts_contains_early_return` function that was used before is redundant. `contains_return` could already do that if we just made the parameter a bit more generic, just like `for_each_expr`, which can already accept `&[Stmt]`

changelog: [`if_then_some_else_none`]: look into local initializers for early returns
2023-08-28 08:48:35 +00:00
bors
19eaafb920 Auto merge of #11338 - y21:issue11337, r=Centri3
allow trait alias DefIds in `implements_trait_with_env_from_iter`

Fixes #11337

changelog: none
2023-08-24 22:28:29 +00:00
y21
dba7763128 [if_then_some_else_none]: look into local initializers 2023-08-24 23:44:17 +02:00
Philipp Krones
cc61aeea54 Merge commit '080b587854a73f2a8cbaecff1884860a78e2ff37' into clippyup 2023-08-24 21:32:12 +02:00
Philipp Krones
da06825124
Bump Clippy version -> 0.1.74 2023-08-24 21:06:31 +02:00
Philipp Krones
e1ec41b217
Fix dogfood issues 2023-08-24 21:06:18 +02:00
Philipp Krones
ef4d64f1bd
Merge remote-tracking branch 'upstream/master' into rustup 2023-08-24 21:04:57 +02:00
y21
86b6644379 new lint: iter_out_of_bounds 2023-08-24 20:21:55 +02:00
Ralf Jung
70f6321cf9 when terminating during unwinding, show the reason why 2023-08-24 13:28:26 +02:00
y21
42c6492ebc [unnecessary_unwrap]: lint on .as_ref().unwrap() 2023-08-23 21:02:01 +02:00
Esteban Küber
32eecd4b88 Fix clippy lint for identical if/else contraining ? expressions
Follow up to #114819.
2023-08-23 00:58:09 +00:00
Ralf Jung
50f7f8e0f8 give some unwind-related terminators a more clear name 2023-08-20 15:52:38 +02:00
Matthias Krüger
39219a6dd8 Rollup merge of #114819 - estebank:issue-78124, r=compiler-errors
Point at return type when it influences non-first `match` arm

When encountering code like

```rust
fn foo() -> i32 {
    match 0 {
        1 => return 0,
        2 => "",
        _ => 1,
    }
}
```

Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`.

Fix #78124.
2023-08-15 20:34:25 +02:00
Guillaume Gomez
9e33b69644 Rollup merge of #114772 - fee1-dead-contrib:typed-did, r=b-naber
Add `{Local}ModDefId` to more strongly type DefIds`

Based on #110862 by `@Nilstrieb`
2023-08-15 14:29:45 +02:00
Esteban Küber
89fdc3e383 Move scrutinee HirId into MatchSource::TryDesugar 2023-08-14 21:43:56 +00:00
y21
f746e19169 allow trait alias DefIds in implements_trait_with_env_from_iter 2023-08-14 19:10:33 +02:00
Nilstrieb
7c87e5c20d Use {Local}ModDefId in many queries 2023-08-14 07:22:48 +00:00
Deadbeef
b8b3e078f9 Remove constness from ImplSource::Param 2023-08-14 02:17:30 +00:00
unvalley
d5dbee4aa0 feat: update manual_retain to lint binary_heap_retain
refactor: rename variable

chore: reorder

test: update naming for msrv
2023-08-13 17:09:39 +09:00
Philipp Krones
f730a2655a Merge commit '1e8fdf492808a25d78a97e1242b835ace9924e4d' into clippyup 2023-08-11 14:05:13 +02:00
Philipp Krones
3927677234
Dogfood and bless tests 2023-08-11 10:53:18 +02:00
Catherine Flores
1ec0501bca Revert "New lint [filter_map_bool_then]"
This reverts commits 978b1daf99 and 3235d9d612.
2023-08-10 17:28:01 -05:00
Philipp Krones
17b9c42572
Merge remote-tracking branch 'upstream/master' into rustup 2023-08-10 21:15:24 +02:00
Matthias Krüger
5f8600939e Rollup merge of #114566 - fmease:type-alias-laziness-is-crate-specific, r=oli-obk
Store the laziness of type aliases in their `DefKind`

Previously, we would treat paths referring to type aliases as *lazy* type aliases if the current crate had lazy type aliases enabled independently of whether the crate which the alias was defined in had the feature enabled or not.

With this PR, the laziness of a type alias depends on the crate it is defined in. This generally makes more sense to me especially if / once lazy type aliases become the default in a new edition and we need to think about *edition interoperability*:

Consider the hypothetical case where the dependency crate has an older edition (and thus eager type aliases), it exports a type alias with bounds & a where-clause (which are void but technically valid), the dependent crate has the latest edition (and thus lazy type aliases) and it uses that type alias. Arguably, the bounds should *not* be checked since at any time, the dependency crate should be allowed to change the bounds at will with a *non*-major version bump & without negatively affecting downstream crates.

As for the reverse case (dependency: lazy type aliases, dependent: eager type aliases), I guess it rules out anything from slight confusion to mild annoyance from upstream crate authors that would be caused by the compiler ignoring the bounds of their type aliases in downstream crates with older editions.

---

This fixes #114468 since before, my assumption that the type alias associated with a given weak projection was lazy (and therefore had its variances computed) did not necessarily hold in cross-crate scenarios (which [I kinda had a hunch about](https://github.com/rust-lang/rust/pull/114253#discussion_r1278608099)) as outlined above. Now it does hold.

`@rustbot` label F-lazy_type_alias
r? `@oli-obk`
2023-08-08 03:30:56 +02:00
León Orell Valerian Liehr
3ff6fd2ac7 Store the laziness of type aliases in the DefKind 2023-08-07 15:54:31 +02:00
Morten Lohne
ab1281f54a fix: Make ConstEvalLateContext::new() public, to match the 'constant_context()' function that it replaced 2023-08-05 21:28:08 +02:00
Matthias Krüger
878a87d5b7 Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31
Improve spans for indexing expressions

fixes #114388

Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR.

r? compiler-errors
2023-08-04 21:31:57 +02:00
Nilstrieb
ed0dfed24f Improve spans for indexing expressions
Indexing is similar to method calls in having an arbitrary
left-hand-side and then something on the right, which is the main part
of the expression. Method calls already have a span for that right part,
but indexing does not. This means that long method chains that use
indexing have really bad spans, especially when the indexing panics and
that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an
extra span which is then put into the `fn_span` field in THIR.
2023-08-04 13:17:39 +02:00
Matthias Krüger
1589759334 Rollup merge of #114022 - oli-obk:tait_ice_alias_field_projection, r=cjgillot
Perform OpaqueCast field projection on HIR, too.

fixes #105819

This is necessary for closure captures in 2021 edition, as they capture individual fields, not the full mentioned variables. So it may try to capture a field of an opaque (because the hidden type is known to be something with a field).

See https://github.com/rust-lang/rust/pull/99806 for when and why we added OpaqueCast to MIR.
2023-08-04 09:18:58 +02:00
Catherine Flores
71c54137ea Extract never-like into clippy_utils 2023-08-02 14:00:26 -05:00
Deadbeef
b07de24a58 Remove constness from TraitPredicate 2023-08-02 15:38:00 +00:00
Philipp Krones
b0e64a9c09 Merge commit '5436dba826191964ac1d0dab534b7eb6d4c878f6' into clippyup 2023-07-31 23:53:53 +02:00
Jason Newcomb
caf601434b Resolve type aliases in type_certainty 2023-07-30 03:26:32 -04:00
Jason Newcomb
4d80a2ed2e Rework redundant_closure
* Better track when a early-bound region appears when a late-bound region is required
* Don't lint when the closure gives explicit types.
2023-07-30 01:19:29 -04:00
Jason Newcomb
71cc39e1f2 Add debug assertions to implements_trait
Improve debug assertions for `make_projection`
2023-07-30 00:38:04 -04:00
Philipp Krones
3d60241841
Merge remote-tracking branch 'upstream/master' into rustup 2023-07-28 23:44:28 +02:00
León Orell Valerian Liehr
4c9d68e9b8 Make Clippy understand generic const items 2023-07-28 22:21:41 +02:00
Deadbeef
39fb315396 bless clippy 2023-07-27 17:56:25 +00:00
Deadbeef
be0b4d5a9b Remove constness from ParamEnv 2023-07-27 15:50:42 +00:00
Catherine
978b1daf99 New lint [filter_map_bool_then] 2023-07-25 17:42:36 -05:00
bors
2153c0fcc8 Auto merge of #11226 - GuillaumeGomez:needless-ref-mut-cfg, r=llogiq
Needless ref mut cfg

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

cc `@Centri3`

changelog: Emit note if function is behind a cfg for `NEEDLESS_PASS_BY_REF_MUT` lint.
2023-07-25 19:00:59 +00:00
bors
70c5798993 Auto merge of #11198 - y21:issue10938, r=Centri3
[`slow_vector_initialization`]: catch `Vec::new()` followed by `.resize(len, 0)`

Closes #10938

changelog: [`slow_vector_initialization`]: catch `Vec::new()` followed by `.resize(len, 0)`
2023-07-25 17:23:01 +00:00
y21
c0484b74f7 simplify looking for Vec::with_capacity exprs 2023-07-25 18:56:57 +02:00
Guillaume Gomez
1c9772c773 Move inherits_cfg function into clippy_utils 2023-07-25 18:43:58 +02:00
Michael Goulet
f20a174c4f Make everything builtin! 2023-07-25 16:08:58 +00:00
Oli Scherer
d94d85f3d8 Perform OpaqueCast field projection on HIR, too.
This is necessary for closure captures in 2021 edition, as they capture individual fields, not the full mentioned variables. So it may try to capture a field of an opaque (because the hidden type is known to be something with a field).
2023-07-24 15:19:26 +00:00
bors
58775046a9 Auto merge of #11214 - y21:issue11213, r=Jarcho
check that the types are equal in `SpanlessEq::eq_expr`

Fixes #11213

changelog: [`if_same_then_else`]: don't lint for integer literals of different types
2023-07-23 20:00:31 +00:00
bors
a4e64ff375 Auto merge of #11166 - Jarcho:expr_use, r=Centri3
Refactor some of  `dereference.rs` to util functions

I've seen a few lints that need to be able to tell if changing the type of an expression would be a vaild suggestion. This extracts part of how that's done from `explicit_auto_deref`.

changelog: None
2023-07-23 18:27:48 +00:00
y21
e975d05cde check that the types are equal in SpanlessEq::eq_expr 2023-07-23 15:51:11 +02:00
Jason Newcomb
55dd8a9717 Refactor dereference.rs
Extract getting an expression's use context and the context's defined
type as util functions.
2023-07-23 01:21:12 -04:00
Catherine
9cf1509b25 New lint absolute_paths 2023-07-21 17:26:58 -05:00
bors
ee8a429792 Auto merge of #11188 - Centri3:#11178, r=blyxyas
Allow `Self::cmp(self, other)` as a correct impl

Fixes #11178

Also no longer checks if the method name is *just* cmp, but the path. That was an oversight on my part ^^

r? `@xFrednet`
(and `@blyxyas` too!)

changelog: [`incorrect_partial_ord_impl_on_ord_type`]: Now allows non-method calls to `cmp` like `Self::cmp(self, other)`
2023-07-20 22:37:02 +00:00
Catherine
a4c367d0e9 Allow Self::cmp(self, other) as a correct impl 2023-07-20 16:17:24 -05:00
Thibaut Vandervelden
f743fec6b0 fix: false positive for option_env! in ifs
Clippy had a false positive for with `ifs_same_cond` when two
if-let expressions have an `option_env!` macro. The fix is similar to the
`env!` macro fix.

The following example had a clippy error:

```rust
if let Some(env1) = option_env!("ENV1") {
    // ...
} else if let Some(env2) = option_env!("ENV2") {
    // ...
}
```

See https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=01b85c61b56ddd900117fb247af04824

changelog: Fix [`ifs_same_cond`] false positive when using `option_env!` in if-let expressions.
2023-07-20 12:04:24 +02:00