Add new lint `doc_lazy_continuation`
changelog: [`doc_lazy_continuation`]: add lint that warns on so-called "lazy paragraph continuations"
This is a follow-up for https://github.com/rust-lang/rust/pull/121659, since most cases of unintended block quotes are lazy continuations. The lint is designed to be more generally useful than that, though, because it will also catch unintended list items and unintended block quotes that didn't coincidentally hit a pulldown-cmark bug.
The second commit is the result of running `cargo dev dogfood --fix`, and manually fixing anything that seems wrong. NOTE: this lint's suggestions should never change the parser's interpretation of the markdown, but in many cases, it seems that doc comments in clippy were written without regard for this feature of Markdown (which, I suppose, is why this lint should exist).
fix: use hir_with_context to produce correct snippets for assigning_clones
The `assigning_clones` lint is producing wrong output when the assignment is a macro call.
Since Applicability level `Unspecified` will never be changed inside `hir_with_applicability`, so it is safe here to replace `hir_with_applicability` with `hir_with_context` to generate snippets of the macro call instead of the expansion.
fixes#12776
changelog: [`assigning_clones`]: use `hir_with_context` to produce correct snippets
fix false positive in Issue/12098 because lack of consideration of mutable caller
fixes [Issue#12098](https://github.com/rust-lang/rust-clippy/issues/12098)
In issue#12098, the former code doesn't consider the caller for clone is mutable, and suggests to delete clone function.
In this change, we first get the inner caller requests for clone,
and if it's immutable, the following code will suggest deleting clone.
If it's mutable, the loop will check whether a borrow check violation exists,
if exists, the lint should not execute, and the function will directly return;
otherwise, the following code will handle this.
changelog: [`clippy::unnecessary_to_owned`]: fix false positive
This is a follow-up for https://github.com/rust-lang/rust/pull/121659,
since most cases of unintended block quotes are lazy continuations.
The lint is designed to be more generally useful than that, though,
because it will also catch unintended list items and unintended
block quotes that didn't coincidentally hit a pulldown-cmark bug.
Allow more attributes in `clippy::useless_attribute`
Fixes#12753Fixes#4467Fixes#11595Fixes#10878
changelog: [`useless_attribute`]: Attributes allowed on `use` items now include `ambiguous_glob_exports`, `hidden_glob_reexports`, `dead_code`, `unused_braces`, and `clippy::disallowed_types`.
Suggest collapsing nested or patterns if the MSRV allows it
Nested `or` patterns have been stable since 1.53, so we should be able to suggest `Some(1 | 2)` if the MSRV isn't set below that.
This change adds an msrv check and also moves it to `matches/mod.rs`, because it's also needed by `redundant_guards`.
changelog: [`collapsible_match`]: suggest collapsing nested or patterns if the MSRV allows it
fix suggestion error for [`manual_is_ascii_check`] with missing type
fixes: #11324fixes: #11776
changelog: improve [`manual_is_ascii_check`] to suggest labeling type in closure, fix FP with type generics, and improve linting on ref expressions.
suppress `readonly_write_lock` for underscore-prefixed bindings
Fixes#12733
Unsure if there's a better way to prevent this kind of false positive but this is the one that made most sense to me.
In my experience, prefixing bindings with an underscore is the usual way to name variables that aren't used and that exist purely for executing drop code at the end of the scope.
-------
changelog: suppress [`readonly_write_lock`] for underscore-prefixed bindings
check if closure as method arg has read access in [`collection_is_never_read`]
fixes: #11783
---
changelog: fix [`collection_is_never_read`] misfires when use `retain` for iteration
configurably allow `useless_vec` in tests
This adds a `àllow-useless-vec-in-test` configuration which, when set to `true` will allow the `useless_vec` lint in `#[test]` functions and code within `#[cfg(test)]`. It also moves a `is_in_test` helper to `clippy_utils`.
---
changelog: configurably allow [`useless_vec`] in test code
This adds a `àllow-useless-vec-in-test` configuration which, when set
to `true` will allow the `useless_vec` lint in `#[test]` functions and
code within `#[cfg(test)]`. It also moves a `is_in_test` helper to
`clippy_utils`.
fix [`large_stack_arrays`] linting in `vec` macro
fixes: #12586
this PR also adds a wrapper function `matching_root_macro_call` to `clippy_utils::macros`, considering how often that same pattern appears in the codebase.
(I'm always very indecisive towards naming, so, if anyone have better idea of how that function should be named, feel free to suggest it)
---
changelog: fix [`large_stack_arrays`] linting in `vec` macro; add `matching_root_macro_call` to clippy_utils
[`non_canonical_partial_ord_impl`]: Fix emitting warnings which conflict with `needless_return`
fixes#12683
---
changelog: fix [`non_canonical_partial_ord_impl`] emitting warnings which conflict with `needless_return`
Disallow ambiguous attributes on expressions
This implements the suggestion in [#15701](https://github.com/rust-lang/rust/issues/15701#issuecomment-2033124217) to disallow ambiguous outer attributes on expressions. This should resolve one of the concerns blocking the stabilization of `stmt_expr_attributes`.
reduce `single_char_pattern` to only lint on ascii chars
This should mostly fix the `single_char_pattern` lint, because with a single byte, the optimizer will usually see through the char-to-string-expansion and single loop iteration. This fixes#11675 and #8111.
Update: As per the meeting on November 28th, 2023, we voted to also downgrade the lint to pedantic.
---
changelog: downgrade [`single_char_pattern`] to `pedantic`
Fix `is_test_module_or_function`
The rustdoc comment for `is_test_module_or_function` states: 2795a60189/clippy_utils/src/lib.rs (L2561-L2566)
Given `item`, the function calls `is_in_test_function` with `item.hir_id()`. However, `is_in_test_function` considers only `item`'s parents, not `item` itself. This PR fixes the problem.
The `test_with_disallowed_name` test fails without the fix, but passes once applied.
changelog: none
Rework interior mutability detection
Replaces the existing interior mutability detection, the two main changes being
- It now follows references/pointers e.g. `struct S(&Cell)`
- `mutable_key_type` ignores pointers as it did before
- The `ignore_interior_mutability` config now applies to types containing the ignored type, e.g. `http::HeaderName`
Fixes https://github.com/rust-lang/rust-clippy/issues/7752
Fixes https://github.com/rust-lang/rust-clippy/issues/9776
Fixes https://github.com/rust-lang/rust-clippy/issues/9801
changelog: [`mutable_key_type`], [`declare_interior_mutable_const`]: now considers types that have references to interior mutable types as interior mutable
This commit introduces a check to ensure that the lint won't trigger when the initializer is
unreachable, such as:
```
thread_local! {
static STATE: Cell<usize> = panic!();
}
```
This is achieved by looking at the unpeeled initializer expression and ensuring that the parent
macro is not `panic!()`, `todo!()`, `unreachable!()`, `unimplemented!()`.
fixes#12637
changelog: [`threadlocal_initializer_can_be_made_const`] will no longer trigger on `unreachable` macros.
Emit the `needless_pass_by_ref_mut` lint on `self` arguments as well
Fixes https://github.com/rust-lang/rust-clippy/issues/12589.
Fixes https://github.com/rust-lang/rust-clippy/issues/9591.
The first commit fixes a bug I uncovered while working on this: sometimes, the mutable borrow "event" happens before the alias one, which makes some argument detected as not used mutably even if they are. The fix was simply to fill the map with the aliases afterwards.
The second commit removes the restriction to not run `self` argument for the `needless_pass_by_ref_mut` lint.
changelog: emit the `needless_pass_by_ref_mut` lint on `self` arguments as well
r? `@Manishearth`