Commit graph

10009 commits

Author SHA1 Message Date
bors
fc1152abf6 Auto merge of #11359 - Alexendoo:unwrap-or-default-check-suggestion, r=dswij
Check that the suggested method exists in unwrap_or_default

Fixes #11355

changelog: none
2023-08-20 15:26:33 +00:00
Alex Macleod
8f2d47ea72 Check that the suggested method exists in unwrap_or_default 2023-08-19 20:22:45 +00:00
lengyijun
e440065a0f [iter_overeager_cloned]: detect .cloned().map() and .cloned().for_each()
key idea:
for `f` in `.map(f)` and `.for_each(f)`:
1. `f` must be a closure with one parameter
2. don't lint if mutable paramter in clsure `f`: `|mut x| ...`
3. don't lint if parameter is moved
2023-08-19 21:18:14 +08:00
y21
e52bd6f850 new lint: should_panic_without_expect 2023-08-18 18:57:14 +02:00
xFrednet
41570c1ee7
Update version attribute for 1.72 lints 2023-08-18 18:27:10 +02:00
bors
1698ce0ba1 Auto merge of #11280 - samueltardieu:issue-11267, r=Centri3
[new_without_default]: include `where` clause in suggestions, make applicable

changelog: [`new_without_default`]: include `where` clause in suggestions
2023-08-18 15:55:40 +00:00
bors
d5298bea7f Auto merge of #11314 - GuillaumeGomez:needless_ref_mut_async_block, r=Centri3
Correctly handle async blocks for NEEDLESS_PASS_BY_REF_MUT

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

The problem was that the `async block`s are popping a closure which we didn't go into, making it miss the mutable access to the variables.

cc `@Centri3`

changelog: none
2023-08-17 15:55:23 +00:00
Guillaume Gomez
5875bd2b5f Use HirId from PlaceWithHirId rather than using the one provided to the function 2023-08-17 17:45:17 +02:00
bors
701e77c87f Auto merge of #11070 - y21:issue11065, r=flip1995
[`useless_conversion`]: only lint on paths to fn items and fix FP in macro

Fixes #11065 (which is actually two issues: an ICE and a false positive)

It now makes sure that the function call path points to a function-like item (and not e.g. a `const` like in the linked issue), so that calling `TyCtxt::fn_sig` later in the lint does not ICE (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616836099).
It *also* makes sure that the expression is not part of a macro call (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616919639). ~~I'm not sure if there's a better way to check this other than to walk the parent expr chain and see if any of them are expansions.~~ (edit: it doesn't do this anymore)

changelog: [`useless_conversion`]: fix ICE when call receiver is a non-fn item
changelog: [`useless_conversion`]: don't lint if argument is a macro argument (fixes a FP)

r? `@llogiq` (reviewed #10814, which introduced these issues)
2023-08-17 14:41:46 +00:00
J-ZhengLi
aa8995e589 allow calling to_owned with borrowed value for [implicit_clone] 2023-08-15 09:41:15 +08:00
y21
f47165c703 find expansions more efficiently 2023-08-14 16:50:31 +02:00
y21
2820d980cb [useless_conversion]: fix FP in macro and add test 2023-08-14 16:28:04 +02:00
y21
34348f72f4 [useless_conversion]: make sure path points to fn-like item 2023-08-14 16:28:04 +02:00
lengyijun
fc061890d6 [iter_overeager_cloned]: detect .cloned().filter() and .cloned().find()
Key idea:
```
// before
iter.cloned().filter(|x| unimplemented!() )
// after
iter.filter(|&x| unimplemented!() ).cloned()

// before
iter.cloned().filter( foo )
// after
iter.filter(|&x| foo(x) ).cloned()
```
2023-08-14 09:13:01 +08: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
Samuel Tardieu
f9b22e7b84 [new_without_default]: make the suggestion machine-applicable
Now that generics and lifetimes are output as expected, the lint
should be applicable.
2023-08-11 21:16:56 +02:00
Samuel Tardieu
621e76d252 [new_without_default]: include where clauses in suggestion
Fix #11267
2023-08-11 21:10:18 +02:00
bors
1e8fdf4928 Auto merge of #11320 - max-niederman:redundant_locals_shadow_mutated, r=Alexendoo
redundant_locals: fix FPs on mutated shadows

Fixes #11290.

When a mutable binding is shadowed by
a mutable binding of the same name in a different scope, mutations in that scope have different meaning.
This PR fixes spurious `redundant_locals` emissions on such locals.

cc `@Centri3,` `@flip1995`

changelog: [`redundant_locals`]: fix false positives on mutated shadows
2023-08-11 10:58:13 +00:00
bors
8703661a9a Auto merge of #11316 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

cc `@max-niederman` With the latest sync, I'm getting a lot of FP in the `redundant_locals` lint you recently added. Any ideas where this could come from?

changelog: none
2023-08-11 08:54:35 +00:00
Philipp Krones
0fc051ddba
Fix redundant_locals for Async desugaring 2023-08-11 10:51:18 +02:00
Max Niederman
a5f62bdfcd
redundant_locals: fix FPs on mutated shadows
When a mutable binding is shadowed by
a mutable binding of the same name in a different scope,
mutations in that scope have different meaning.
This commit fixes spurious `redundant_locals` emissions
on such locals.
2023-08-10 19:53:45 -07:00
bors
bd1554c425 Auto merge of #11318 - Centri3:#11309, r=Manishearth
[`filter_map_bool_then`]: Don't ICE on late bound regions

Fixes #11309

Also lints `&NonCopy` now, since any `&` is `Copy`. That was accidental, but it seems that this is a consequence (or improvement!) of this fix.

r? `@Jarcho`

changelog: [`filter_map_bool_then`]: Don't ICE on late bound regions
2023-08-11 00:17:15 +00:00
Catherine Flores
beb57f074e Don't ICE with late bound regions 2023-08-10 16:26:22 -05:00
Philipp Krones
17b9c42572
Merge remote-tracking branch 'upstream/master' into rustup 2023-08-10 21:15:24 +02:00
Guillaume Gomez
42186af21e Correctly handle async blocks for NEEDLESS_PASS_BY_REF_MUT 2023-08-10 16:23:27 +02:00
y21
dd25cc349b Remove unnecessary paragraph, move examples 2023-08-09 14:48:31 +02:00
Timo
d2acfb37b3
Reword paragraph
Co-authored-by: Dirkjan Ochtman <dirkjan@ochtman.nl>
2023-08-09 14:44:42 +02:00
y21
830bac5548 clarify why Vec::new() + resize is worse than vec![0; N] 2023-08-09 14:08:48 +02:00
bors
7c595b4599 Auto merge of #11305 - y21:issue11304, r=Centri3
[`redundant_guards`]: don't lint on float literals

Fixes #11304

changelog: [`redundant_guards`]: don't lint on float literals

r? `@Centri3` i figured you are probably a good reviewer for this since you implemented the lint ^^
2023-08-08 16:18:06 +00:00
y21
b6156502af document the new behavior and add test for float in struct 2023-08-08 18:04:57 +02:00
y21
f959ccc09b [redundant_guards]: don't lint on floats 2023-08-08 17:19:53 +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
bors
84d2896747 Auto merge of #11295 - lengyijun:typo, r=Centri3
Small code style adjustments

changelog: none
2023-08-07 03:23:23 +00:00
bors
526d1156bd Auto merge of #11191 - Alexendoo:redundant-type-annotations-ice, r=llogiq
redundant_type_annotations: only pass certain def kinds to type_of

Fixes #11190
Fixes rust-lang/rust#113516

Also adds an `is_lint_allowed` check to skip the lint when it's not needed

changelog: none
2023-08-06 18:45:38 +00:00
Manish Goregaokar
d628046244
Update clippy_lints/src/operators/mod.rs
Co-authored-by: Catherine Flores <catherine.3.flores@gmail.com>
2023-08-06 17:19:43 +00:00
Matthias Krüger
261837c841 Rollup merge of #114505 - ouz-a:cleanup_mir, r=RalfJung
Add documentation to has_deref

Documentation of `has_deref` needed some polish to be more clear about where it should be used and what's it's purpose.

cc https://github.com/rust-lang/rust/issues/114401

r? `@RalfJung`
2023-08-06 17:26:29 +02:00
ouz-a
44cd3bcbba cleanup misinformation regarding has_deref 2023-08-06 17:29:09 +03:00
Morten Lohne
3157b96a5b Provide fallback code snippets, if the snippet is not available 2023-08-06 13:49:17 +02:00
Morten Lohne
0e064d5d04 Replace ConstEvalLateContext::new() with two calls to constant() to simplify the code, after PR suggestion 2023-08-06 13:48:28 +02:00
Morten Lohne
9646446923 Add lifetime parameter to 'Constant', after rebasing on upstream 2023-08-06 13:29:50 +02:00
Morten Lohne
1d61fc1b0a Rename 'impossible_double_const_comparisons' -> 'impossible_comparisons' and 'ineffective_double_const_comparisons' -> 'redundant_comparisons', after discussion on Zulip 2023-08-05 21:28:08 +02:00
Morten Lohne
b5ef66f442 Optimize by doing a cheap check for double binary expression first 2023-08-05 21:28:08 +02:00
Morten Lohne
08e1333fa6 Add missing variable decl to doc comment 2023-08-05 21:28:08 +02:00
Morten Lohne
e16a2ac0c6 Add descriptions for 'impossible_double_const_comparisons' and 'ineffective_double_const_comparisons' 2023-08-05 21:28:08 +02:00
Morten Lohne
046d3df35e New lints: impossible_double_const_comparisons and ineffective_double_const_comparisons 2023-08-05 21:28:08 +02:00
lengyijun
e5b0483c85 Small code style adjustments 2023-08-05 12:41:20 +08:00
bors
ec1d61e064 Auto merge of #114481 - matthiaskrgr:rollup-58pczpl, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #113945 (Fix wrong span for trait selection failure error reporting)
 - #114351 ([rustc_span][perf] Remove unnecessary string joins and allocs.)
 - #114418 (bump parking_lot to 0.12)
 - #114434 (Improve spans for indexing expressions)
 - #114450 (Fix ICE failed to get layout for ReferencesError)
 - #114461 (Fix unwrap on None)
 - #114462 (interpret: add mplace_to_ref helper method)
 - #114472 (Reword `confusable_idents` lint)
 - #114477 (Account for `Rc` and `Arc` when suggesting to clone)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-08-04 20:31:40 +00: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
bors
18522006a1 Auto merge of #114104 - oli-obk:syn2, r=compiler-errors
Lots of tiny incremental simplifications of `EmitterWriter` internals

ignore the first commit, it's https://github.com/rust-lang/rust/pull/114088 squashed and rebased, but it's needed to use to use `derive_setters`, as they need a newer `syn` version.

Then this PR starts out with removing many arguments that are almost always defaulted to `None` or `false` and replace them with builder methods that can set these fields in the few cases that want to set them.

After that it's one commit after the other that removes or merges things until everything becomes some very simple trait objects
2023-08-04 18:46:19 +00:00