Skip to content

Update Clippy #109566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 80 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
003a211
Improve diagnostic of `no_mangle_with_rust_abi`
Jarcho Feb 28, 2023
1a81a3e
Remove `snippet_with_macro_callsite`
Jarcho Mar 2, 2023
90afb20
Remove `identity_future` indirection
Swatinem Nov 24, 2022
e66e918
Fortify clippy tests.
cjgillot Mar 7, 2023
3d229d5
avoid reuse tripping over copyright notices
pietroalbini Nov 15, 2022
27910cb
Introduce a no-op PlaceMention statement for `let _ =`.
cjgillot Sep 6, 2022
cf8a67d
Merge commit '3c06e0b1ce003912f8fe0536d3a7fe22558e38cf' into clippyup
flip1995 Mar 10, 2023
c34d04a
Update changelog for beta-accepted labels
flip1995 Mar 10, 2023
b0e2e7b
Auto merge of #10475 - flip1995:beta-changelog, r=xFrednet
bors Mar 10, 2023
797d8bf
Don't lint `manual_clamp` in const contexts.
Jarcho Mar 10, 2023
8e1dd06
Auto merge of #10479 - Jarcho:issue_10474, r=flip1995
bors Mar 10, 2023
5c85cd9
Directly construct Inherited.
cjgillot Mar 9, 2023
15d7278
Auto merge of #108974 - flip1995:clippyup, r=Manishearth
bors Mar 10, 2023
0f1474e
Add `allow_attribute` lint
blyxyas Mar 10, 2023
5956896
Fix code fragment
blyxyas Mar 10, 2023
1cf7218
Add ignore flag to code fragments
blyxyas Mar 11, 2023
7333b36
Auto merge of #104527 - ferrocene:pa-more-licenses, r=pnkfelix
bors Mar 11, 2023
7449912
Rollup merge of #108950 - cjgillot:inherit-less, r=compiler-errors
matthiaskrgr Mar 11, 2023
2d572d4
Replace list indexing for `.get` (fail-safe)
blyxyas Mar 11, 2023
e426ba4
Auto merge of #10420 - Jarcho:no_mangle_diag, r=dswij
bors Mar 11, 2023
f19db28
Auto merge of #10434 - Jarcho:snip_context, r=dswij
bors Mar 11, 2023
d65c9a5
Extend tests + improve description + general improvement
blyxyas Mar 11, 2023
213a22e
Remove uses of `box_syntax` in rustc and tools
clubby789 Feb 27, 2023
15f2423
Remove `box_syntax` from AST and use in tools
clubby789 Feb 27, 2023
1c7048d
Add utility macros to help with writing tests.
Jarcho Mar 7, 2023
e65ad6f
Auto merge of #10453 - Jarcho:test_utils, r=dswij
bors Mar 12, 2023
e07c6b4
Auto merge of #108872 - cjgillot:simp-const-prop, r=oli-obk
bors Mar 12, 2023
ff23e48
Auto merge of #108471 - clubby789:unbox-the-syntax, r=Nilstrieb,est31
bors Mar 13, 2023
8a9492a
enhance [`ifs_same_cond`] to lint same immutable method calls as well
J-ZhengLi Feb 16, 2023
f0ae2b7
make [`ifs_same_cond`] use `ignore_interior_mutablility` configuration
J-ZhengLi Feb 24, 2023
f4ccb06
extract `is_interior_mutable_type` from [`mut_key`] to `clippy_utils:…
J-ZhengLi Mar 13, 2023
555f568
Fix semicolon insertion in `match_single_binding`
Alexendoo Mar 9, 2023
945e42f
Auto merge of #10470 - Alexendoo:match-single-binding-semicolon, r=gi…
bors Mar 13, 2023
6631480
Fix false positive with `a = a`
blyxyas Mar 13, 2023
011bb46
update lint configuration doc for [`ifs_same_cond`]
J-ZhengLi Mar 14, 2023
ff843ac
Auto merge of #10350 - J-ZhengLi:issue_10272, r=xFrednet
bors Mar 14, 2023
491f632
Auto merge of #104833 - Swatinem:async-identity-future, r=compiler-er…
bors Mar 14, 2023
5924b46
Fix documentation for `derived_hash_with_manual_eq`
nagisa Mar 14, 2023
5941616
Auto merge of #10500 - nagisa:docs-fix, r=Alexendoo
bors Mar 14, 2023
c465bf7
Auto merge of #10499 - blyxyas:fix-almost_swapped, r=giraffate
bors Mar 14, 2023
f2eddc5
Remove box expressions from HIR
clubby789 Mar 14, 2023
3eea494
Ignore external macros
blyxyas Mar 14, 2023
e2ba75d
Add macro test
blyxyas Mar 15, 2023
4b9cb85
Rename lint
blyxyas Mar 15, 2023
1cab0cb
Fix formatting, remove commented code, etc...
blyxyas Mar 15, 2023
5afa93b
Auto merge of #10481 - blyxyas:allow_attribute, r=xFrednet
bors Mar 16, 2023
d1b28f3
Fix clippy.
m-ou-se Mar 16, 2023
afe27ba
Issue function modifiers in the right order in manual_async_fn lint
samueltardieu Mar 5, 2023
9546517
Add external macro test + Now it works
blyxyas Mar 16, 2023
ffabdab
New lint to detect `&std::path::MAIN_SEPARATOR.to_string()`
samueltardieu Mar 11, 2023
5c4040e
Auto merge of #10502 - blyxyas:fix-almost_swapped, r=giraffate
bors Mar 17, 2023
60fe49c
Rollup merge of #108958 - clubby789:unbox-the-hir, r=compiler-errors
matthiaskrgr Mar 17, 2023
d3c8442
Auto merge of #10483 - samueltardieu:issue-10480, r=llogiq
bors Mar 17, 2023
e64c596
Auto merge of #10456 - samueltardieu:issue-10450, r=Manishearth
bors Mar 18, 2023
dec6ef8
Correct active members link in `CONTRIBUTING.md`
xFrednet Mar 19, 2023
0a77f4c
Auto merge of #10522 - xFrednet:10521-docs-and-triage, r=Manishearth
bors Mar 19, 2023
5810f1f
remove some trait solver helpers
lcnr Mar 14, 2023
6f62887
Use local key in providers
compiler-errors Mar 13, 2023
84b6049
Use uninit checking from rustc
Noratrieb Mar 18, 2023
7b3c4aa
Auto merge of #10520 - Nilstrieb:uninit, r=Alexendoo
bors Mar 21, 2023
728ee6f
Really dogfood clippy
samueltardieu Mar 21, 2023
6cebe58
Auto merge of #10526 - samueltardieu:dogfood-clippy, r=flip1995
bors Mar 21, 2023
3497086
Do not propose to remove `async move` if variables are captured by ref
samueltardieu Mar 12, 2023
b138bb5
Do not propose to simplify a not expression coming from a macro
samueltardieu Mar 21, 2023
6db2d59
Auto merge of #109119 - lcnr:trait-system-cleanup, r=compiler-errors
bors Mar 22, 2023
5839621
Auto merge of #10490 - samueltardieu:issue-10482, r=xFrednet
bors Mar 22, 2023
cae7b87
rustc: Remove unused `Session` argument from some attribute functions
petrochenkov Mar 19, 2023
1d1e723
Auto merge of #10527 - samueltardieu:issue-10523, r=dswij
bors Mar 22, 2023
966d5b0
Cache `has_sig_drop_attr` for `significant_drop_tightening`
Noratrieb Mar 22, 2023
8bdd54e
Add `CastKind::Transmute` to MIR
scottmcm Feb 25, 2023
b506eb5
Rename AliasEq -> AliasRelate
compiler-errors Mar 21, 2023
be01b98
Auto merge of #10533 - Nilstrieb:cache, r=dswij
bors Mar 23, 2023
f345904
Auto merge of #109517 - matthiaskrgr:rollup-m3orqzd, r=matthiaskrgr
bors Mar 23, 2023
58eb996
Auto merge of #108442 - scottmcm:mir-transmute, r=oli-obk
bors Mar 23, 2023
d7d3dbf
New lint: detect unnecessary struct building
samueltardieu Mar 11, 2023
c72c914
Auto merge of #10489 - samueltardieu:issue-10476, r=giraffate
bors Mar 24, 2023
62cba5d
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Mar 24, 2023
8134414
Bump nightly version -> 2023-03-24
flip1995 Mar 24, 2023
d5e2a7a
Auto merge of #10539 - flip1995:rustup, r=flip1995
bors Mar 24, 2023
50475e8
Merge commit 'd5e2a7aca55ed49fc943b7a07a8eba05ab5a0079' into clippyup
flip1995 Mar 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ Current stable, released 2023-03-09

* `SYSROOT` and `--sysroot` can now be set at the same time
[#10149](https://github.com/rust-lang/rust-clippy/pull/10149)
* Fix error when providing an `array-size-threshold` in `clippy.toml`
[#10423](https://github.com/rust-lang/rust-clippy/pull/10423)

## Rust 1.67

Expand Down Expand Up @@ -186,8 +188,6 @@ Released 2023-01-26

### Moves and Deprecations

* Moved [`uninlined_format_args`] to `style` (Now warn-by-default)
[#9865](https://github.com/rust-lang/rust-clippy/pull/9865)
* Moved [`needless_collect`] to `nursery` (Now allow-by-default)
[#9705](https://github.com/rust-lang/rust-clippy/pull/9705)
* Moved [`or_fun_call`] to `nursery` (Now allow-by-default)
Expand Down Expand Up @@ -423,7 +423,7 @@ Released 2022-12-15
[#9490](https://github.com/rust-lang/rust-clippy/pull/9490)
* [`almost_complete_letter_range`]: No longer lints in external macros
[#9467](https://github.com/rust-lang/rust-clippy/pull/9467)
* [`drop_copy`]: No longer lints on idiomatic cases in match arms
* [`drop_copy`]: No longer lints on idiomatic cases in match arms
[#9491](https://github.com/rust-lang/rust-clippy/pull/9491)
* [`question_mark`]: No longer lints in const context
[#9487](https://github.com/rust-lang/rust-clippy/pull/9487)
Expand Down Expand Up @@ -4382,6 +4382,7 @@ Released 2018-09-13
<!-- begin autogenerated links to lint list -->
[`absurd_extreme_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#absurd_extreme_comparisons
[`alloc_instead_of_core`]: https://rust-lang.github.io/rust-clippy/master/index.html#alloc_instead_of_core
[`allow_attributes`]: https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes
[`allow_attributes_without_reason`]: https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes_without_reason
[`almost_complete_letter_range`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_complete_letter_range
[`almost_complete_range`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_complete_range
Expand Down Expand Up @@ -4661,6 +4662,7 @@ Released 2018-09-13
[`manual_instant_elapsed`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_instant_elapsed
[`manual_is_ascii_check`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_ascii_check
[`manual_let_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else
[`manual_main_separator_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_main_separator_str
[`manual_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_map
[`manual_memcpy`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_memcpy
[`manual_non_exhaustive`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive
Expand Down Expand Up @@ -4985,6 +4987,7 @@ Released 2018-09-13
[`unnecessary_safety_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_safety_doc
[`unnecessary_self_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_self_imports
[`unnecessary_sort_by`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_sort_by
[`unnecessary_struct_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_struct_initialization
[`unnecessary_to_owned`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_to_owned
[`unnecessary_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_unwrap
[`unnecessary_wraps`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_wraps
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ a [developer guide] and is a good place to start your journey.
All issues on Clippy are mentored, if you want help simply ask someone from the
Clippy team directly by mentioning them in the issue or over on [Zulip]. All
currently active team members can be found
[here](https://github.com/rust-lang/highfive/blob/master/highfive/configs/rust-lang/rust-clippy.json#L3)
[here](https://github.com/rust-lang/rust-clippy/blob/master/triagebot.toml#L18)

Some issues are easier than others. The [`good-first-issue`] label can be used to find the easy
issues. You can use `@rustbot claim` to assign the issue to yourself.
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ for the generic parameters for determining interior mutability
**Default Value:** `["bytes::Bytes"]` (`Vec<String>`)

* [mutable_key_type](https://rust-lang.github.io/rust-clippy/master/index.html#mutable_key_type)
* [ifs_same_cond](https://rust-lang.github.io/rust-clippy/master/index.html#ifs_same_cond)


### allow-mixed-uninlined-format-args
Expand Down
71 changes: 71 additions & 0 deletions src/tools/clippy/clippy_lints/src/allow_attributes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use ast::AttrStyle;
use clippy_utils::diagnostics::span_lint_and_sugg;
use rustc_ast as ast;
use rustc_errors::Applicability;
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};

declare_clippy_lint! {
/// Detects uses of the `#[allow]` attribute and suggests replacing it with
/// the `#[expect]` (See [RFC 2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html))
///
/// The expect attribute is still unstable and requires the `lint_reasons`
/// on nightly. It can be enabled by adding `#![feature(lint_reasons)]` to
/// the crate root.
///
/// This lint only warns outer attributes (`#[allow]`), as inner attributes
/// (`#![allow]`) are usually used to enable or disable lints on a global scale.
///
/// ### Why is this bad?
///
/// `#[expect]` attributes suppress the lint emission, but emit a warning, if
/// the expectation is unfulfilled. This can be useful to be notified when the
/// lint is no longer triggered.
///
/// ### Example
/// ```rust,ignore
/// #[allow(unused_mut)]
/// fn foo() -> usize {
/// let mut a = Vec::new();
/// a.len()
/// }
/// ```
/// Use instead:
/// ```rust,ignore
/// #![feature(lint_reasons)]
/// #[expect(unused_mut)]
/// fn foo() -> usize {
/// let mut a = Vec::new();
/// a.len()
/// }
/// ```
#[clippy::version = "1.69.0"]
pub ALLOW_ATTRIBUTES,
restriction,
"`#[allow]` will not trigger if a warning isn't found. `#[expect]` triggers if there are no warnings."
}

declare_lint_pass!(AllowAttribute => [ALLOW_ATTRIBUTES]);

impl LateLintPass<'_> for AllowAttribute {
// Separate each crate's features.
fn check_attribute(&mut self, cx: &LateContext<'_>, attr: &ast::Attribute) {
if_chain! {
if cx.tcx.features().lint_reasons;
if let AttrStyle::Outer = attr.style;
if let Some(ident) = attr.ident();
if ident.name == rustc_span::symbol::sym::allow;
then {
span_lint_and_sugg(
cx,
ALLOW_ATTRIBUTES,
ident.span,
"#[allow] attribute found",
"replace it with",
"expect".into(),
Applicability::MachineApplicable,
);
}
}
}
}
25 changes: 13 additions & 12 deletions src/tools/clippy/clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,18 +495,19 @@ struct NotSimplificationVisitor<'a, 'tcx> {

impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind {
if let Some(suggestion) = simplify_not(self.cx, inner) {
span_lint_and_sugg(
self.cx,
NONMINIMAL_BOOL,
expr.span,
"this boolean expression can be simplified",
"try",
suggestion,
Applicability::MachineApplicable,
);
}
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind &&
!inner.span.from_expansion() &&
let Some(suggestion) = simplify_not(self.cx, inner)
{
span_lint_and_sugg(
self.cx,
NONMINIMAL_BOOL,
expr.span,
"this boolean expression can be simplified",
"try",
suggestion,
Applicability::MachineApplicable,
);
}

walk_expr(self, expr);
Expand Down
70 changes: 62 additions & 8 deletions src/tools/clippy/clippy_lints/src/copies.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_then};
use clippy_utils::source::{first_line_of_span, indent_of, reindent_multiline, snippet, snippet_opt};
use clippy_utils::ty::needs_ordered_drop;
use clippy_utils::ty::{is_interior_mut_ty, needs_ordered_drop};
use clippy_utils::visitors::for_each_expr;
use clippy_utils::{
capture_local_usage, eq_expr_value, get_enclosing_block, hash_expr, hash_stmt, if_sequence, is_else_clause,
is_lint_allowed, path_to_local, search_same, ContainsName, HirEqInterExpr, SpanlessEq,
capture_local_usage, def_path_def_ids, eq_expr_value, find_binding_init, get_enclosing_block, hash_expr, hash_stmt,
if_sequence, is_else_clause, is_lint_allowed, path_to_local, search_same, ContainsName, HirEqInterExpr, SpanlessEq,
};
use core::iter;
use core::ops::ControlFlow;
use rustc_errors::Applicability;
use rustc_hir::def_id::DefIdSet;
use rustc_hir::intravisit;
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, HirIdSet, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_middle::query::Key;
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::hygiene::walk_chain;
use rustc_span::source_map::SourceMap;
use rustc_span::{BytePos, Span, Symbol};
Expand Down Expand Up @@ -159,18 +161,40 @@ declare_clippy_lint! {
"`if` statement with shared code in all blocks"
}

declare_lint_pass!(CopyAndPaste => [
pub struct CopyAndPaste {
ignore_interior_mutability: Vec<String>,
ignored_ty_ids: DefIdSet,
}

impl CopyAndPaste {
pub fn new(ignore_interior_mutability: Vec<String>) -> Self {
Self {
ignore_interior_mutability,
ignored_ty_ids: DefIdSet::new(),
}
}
}

impl_lint_pass!(CopyAndPaste => [
IFS_SAME_COND,
SAME_FUNCTIONS_IN_IF_CONDITION,
IF_SAME_THEN_ELSE,
BRANCHES_SHARING_CODE
]);

impl<'tcx> LateLintPass<'tcx> for CopyAndPaste {
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
for ignored_ty in &self.ignore_interior_mutability {
let path: Vec<&str> = ignored_ty.split("::").collect();
for id in def_path_def_ids(cx, path.as_slice()) {
self.ignored_ty_ids.insert(id);
}
}
}
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if !expr.span.from_expansion() && matches!(expr.kind, ExprKind::If(..)) && !is_else_clause(cx.tcx, expr) {
let (conds, blocks) = if_sequence(expr);
lint_same_cond(cx, &conds);
lint_same_cond(cx, &conds, &self.ignored_ty_ids);
lint_same_fns_in_if_cond(cx, &conds);
let all_same =
!is_lint_allowed(cx, IF_SAME_THEN_ELSE, expr.hir_id) && lint_if_same_then_else(cx, &conds, &blocks);
Expand Down Expand Up @@ -547,9 +571,39 @@ fn check_for_warn_of_moved_symbol(cx: &LateContext<'_>, symbols: &[(HirId, Symbo
})
}

fn method_caller_is_mutable(cx: &LateContext<'_>, caller_expr: &Expr<'_>, ignored_ty_ids: &DefIdSet) -> bool {
let caller_ty = cx.typeck_results().expr_ty(caller_expr);
// Check if given type has inner mutability and was not set to ignored by the configuration
let is_inner_mut_ty = is_interior_mut_ty(cx, caller_ty)
&& !matches!(caller_ty.ty_adt_id(), Some(adt_id) if ignored_ty_ids.contains(&adt_id));

is_inner_mut_ty
|| caller_ty.is_mutable_ptr()
// `find_binding_init` will return the binding iff its not mutable
|| path_to_local(caller_expr)
.and_then(|hid| find_binding_init(cx, hid))
.is_none()
}

/// Implementation of `IFS_SAME_COND`.
fn lint_same_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>]) {
for (i, j) in search_same(conds, |e| hash_expr(cx, e), |lhs, rhs| eq_expr_value(cx, lhs, rhs)) {
fn lint_same_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>], ignored_ty_ids: &DefIdSet) {
for (i, j) in search_same(
conds,
|e| hash_expr(cx, e),
|lhs, rhs| {
// Ignore eq_expr side effects iff one of the expressin kind is a method call
// and the caller is not a mutable, including inner mutable type.
if let ExprKind::MethodCall(_, caller, _, _) = lhs.kind {
if method_caller_is_mutable(cx, caller, ignored_ty_ids) {
false
} else {
SpanlessEq::new(cx).eq_expr(lhs, rhs)
}
} else {
eq_expr_value(cx, lhs, rhs)
}
},
) {
span_lint_and_note(
cx,
IFS_SAME_COND,
Expand Down
3 changes: 3 additions & 0 deletions src/tools/clippy/clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::utils::internal_lints::produce_ice::PRODUCE_ICE_INFO,
#[cfg(feature = "internal")]
crate::utils::internal_lints::unnecessary_def_path::UNNECESSARY_DEF_PATH_INFO,
crate::allow_attributes::ALLOW_ATTRIBUTES_INFO,
crate::almost_complete_range::ALMOST_COMPLETE_RANGE_INFO,
crate::approx_const::APPROX_CONSTANT_INFO,
crate::as_conversions::AS_CONVERSIONS_INFO,
Expand Down Expand Up @@ -262,6 +263,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::manual_clamp::MANUAL_CLAMP_INFO,
crate::manual_is_ascii_check::MANUAL_IS_ASCII_CHECK_INFO,
crate::manual_let_else::MANUAL_LET_ELSE_INFO,
crate::manual_main_separator_str::MANUAL_MAIN_SEPARATOR_STR_INFO,
crate::manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE_INFO,
crate::manual_rem_euclid::MANUAL_REM_EUCLID_INFO,
crate::manual_retain::MANUAL_RETAIN_INFO,
Expand Down Expand Up @@ -616,6 +618,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::unnamed_address::VTABLE_ADDRESS_COMPARISONS_INFO,
crate::unnecessary_owned_empty_strings::UNNECESSARY_OWNED_EMPTY_STRINGS_INFO,
crate::unnecessary_self_imports::UNNECESSARY_SELF_IMPORTS_INFO,
crate::unnecessary_struct_initialization::UNNECESSARY_STRUCT_INITIALIZATION_INFO,
crate::unnecessary_wraps::UNNECESSARY_WRAPS_INFO,
crate::unnested_or_patterns::UNNESTED_OR_PATTERNS_INFO,
crate::unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME_INFO,
Expand Down
9 changes: 6 additions & 3 deletions src/tools/clippy/clippy_lints/src/default.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_sugg};
use clippy_utils::source::snippet_with_macro_callsite;
use clippy_utils::source::snippet_with_context;
use clippy_utils::ty::{has_drop, is_copy};
use clippy_utils::{
any_parent_is_automatically_derived, contains_name, get_parent_expr, is_from_proc_macro, match_def_path, paths,
Expand Down Expand Up @@ -160,6 +160,8 @@ impl<'tcx> LateLintPass<'tcx> for Default {
}
};

let init_ctxt = local.span.ctxt();

// find all "later statement"'s where the fields of the binding set as
// Default::default() get reassigned, unless the reassignment refers to the original binding
let mut first_assign = None;
Expand All @@ -169,7 +171,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
// find out if and which field was set by this `consecutive_statement`
if let Some((field_ident, assign_rhs)) = field_reassigned_by_stmt(consecutive_statement, binding_name) {
// interrupt and cancel lint if assign_rhs references the original binding
if contains_name(binding_name, assign_rhs, cx) {
if contains_name(binding_name, assign_rhs, cx) || init_ctxt != consecutive_statement.span.ctxt() {
cancel_lint = true;
break;
}
Expand Down Expand Up @@ -204,11 +206,12 @@ impl<'tcx> LateLintPass<'tcx> for Default {
.iter()
.all(|field| assigned_fields.iter().any(|(a, _)| a == &field.name));

let mut app = Applicability::Unspecified;
let field_list = assigned_fields
.into_iter()
.map(|(field, rhs)| {
// extract and store the assigned value for help message
let value_snippet = snippet_with_macro_callsite(cx, rhs.span, "..");
let value_snippet = snippet_with_context(cx, rhs.span, init_ctxt, "..", &mut app).0;
format!("{field}: {value_snippet}")
})
.collect::<Vec<String>>()
Expand Down
8 changes: 4 additions & 4 deletions src/tools/clippy/clippy_lints/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use rustc_span::sym;

declare_clippy_lint! {
/// ### What it does
/// Checks for deriving `Hash` but implementing `PartialEq`
/// explicitly or vice versa.
/// Lints against manual `PartialEq` implementations for types with a derived `Hash`
/// implementation.
///
/// ### Why is this bad?
/// The implementation of these traits must agree (for
Expand Down Expand Up @@ -54,8 +54,8 @@ declare_clippy_lint! {

declare_clippy_lint! {
/// ### What it does
/// Checks for deriving `Ord` but implementing `PartialOrd`
/// explicitly or vice versa.
/// Lints against manual `PartialOrd` and `Ord` implementations for types with a derived `Ord`
/// or `PartialOrd` implementation.
///
/// ### Why is this bad?
/// The implementation of these traits must agree (for
Expand Down
5 changes: 1 addition & 4 deletions src/tools/clippy/clippy_lints/src/functions/must_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
let attr = cx.tcx.get_attr(item.owner_id, sym::must_use);
if let Some(attr) = attr {
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr);
} else if is_public
&& !is_proc_macro(attrs)
&& trait_ref_of_method(cx, item.owner_id.def_id).is_none()
{
} else if is_public && !is_proc_macro(attrs) && trait_ref_of_method(cx, item.owner_id.def_id).is_none() {
check_must_use_candidate(
cx,
sig.decl,
Expand Down
Loading