let_and_return: avoid "does not live long enough" errors
EDIT: Add #3324 to the list of fixes
<details>
<summary>Description of old impl</summary>
<br>
Avoid suggesting turning the RHS expression of the last statement into the block tail expression if a temporary borrows from a local that would be destroyed before.
This is my first incursion into MIR so there's probably room for improvement!
</details>
Avoid linting if the return type of some method or function called in the last statement has a lifetime parameter.
changelog: Fix false positive in [`let_and_return`]
Fixes#3792Fixes#3324
New lint: `unnested_or_patterns`
changelog: Adds a lint `unnested_or_patterns`, suggesting `Some(0 | 2)` as opposed to `Some(0) | Some(2)`. The lint only fires on compilers capable of using `#![feature(or_patterns)]`.
- The lint is primarily encoded as a pure algorithm which to unnest or-patterns in an `ast::Pat` (`fn unnest_or_patterns`) through a `MutVisitor`. After that is done, and assuming that any change was detected, then `pprust::pat_to_string` is used to simply convert the transformed pattern into a suggestion.
- The PR introduces a module `utils::ast_utils` with a bunch of functions for spanless & nodeless equality comparisons of ASTs.
cc https://github.com/rust-lang/rust/issues/54883
Make `PolyTraitRef::self_ty` return `Binder<Ty>`
This came up during review of #71618. The current implementation is the same as a call to `skip_binder` but harder to audit. Make it preserve binding levels and add a call to `skip_binder` at all use sites so they can be audited as part of #72507.
Add doc for checking if type defines specific method
This PR adds documentation on how:
- check if a type defines a specific method
- check an expr is calling a specific method
closes: #3843
changelog: none
Cleanup: Use rustc's `same_type` for our `same_tys`
This delegates our `same_tys` to [ty::TyS::same_type][same_type] to
remove some duplication.
Our `same_tys` was introduced 4 years ago in #730. Before, it was
building an inference context to be able to call
`can_eq` to compare the types. The `rustc-dev-guide` has some more details
about `can_eq` in [Type Inference -> Trying equality][try_eq].
Now, using the rustc function, we are essentially comparing the `DefId`s
of the given types, which also makes more sense, IMO.
I also confirmed that the FIXME is resolved via a bit of `dbg!`, however
no UI tests seem to have been affected.
[same_type]: 659951c4a0/src/librustc_middle/ty/util.rs (L777)
[try_eq]: https://rustc-dev-guide.rust-lang.org/type-inference.html#trying-equality
---
changelog: none
Fix cargo tests when running inside the rustlang/rust repo
It seems we hit https://github.com/rust-lang/cargo/issues/5418, so I've applied the suggested solution. Also added some more info when cargo-metadata fails to execute.
(there was no open issue for this)
changelog: none
Replace all remaining occurrences of submodule with subtree
r? @phansch
I should have included this in #5686, but forgot about it, so here we go again.
changelog: none
Add regression test for `string_lit_as_bytes` issue
Closes#5619
Before the fix in https://github.com/rust-lang/rust/pull/72637, `string_lit_as_bytes` was incorrectly triggering on the `env!` macro. With the fix merged, this test makes sure that the lint is not triggering anymore.
changelog: none
Give corrected code
This PR adds corrected code for doc examples.
I did this in several commits to facilitate review.
Don't hesitate to tell me if I forgot some.
Also, sometimes I felt it was not necessary to give corrected code, but I maybe wrong.
fixes: #4829
changelog: Improve documentation examples across multiple lints.
New lint: iter_next_slice
Hello, this is a work-in-progress PR for issue: https://github.com/rust-lang/rust-clippy/issues/5572
I have implemented lint to replace `iter().next()` for `slice[index..]` and `array` with `get(index)` and `get(0)` respectively. However since I made a lot of changes, I would like to request some feedback before continuing so that I could fix mistakes.
Thank you!
---
changelog: implement `iter_next_slice` lint and test, and modify `needless_continues`, `for_loop_over_options_result` UI tests since they have `iter().next()`