Skip to content
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

Update Clippy #106780

Merged
merged 85 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
0cd9b06
Small code style adjustments
Niki4tap Dec 22, 2022
a935826
Fix the actual bug
Niki4tap Dec 22, 2022
9ff868c
test test test
Niki4tap Dec 22, 2022
0e5fcb7
move mutex_atomic to clippy::restriction
Dec 25, 2022
c617a8e
Rename `Rptr` to `Ref` in AST and HIR
Noratrieb Dec 28, 2022
4ccafea
Merge commit '4f3ab69ea0a0908260944443c739426cc384ae1a' into clippyup
flip1995 Dec 29, 2022
315bb10
Account for multiple multiline spans with empty padding
estebank Dec 27, 2022
d8365f9
Rollup merge of #106259 - flip1995:clippyup, r=matthiaskrgr
matthiaskrgr Dec 29, 2022
cd579d6
Auto merge of #106266 - matthiaskrgr:rollup-cxrdbzy, r=matthiaskrgr
bors Dec 29, 2022
0298095
add comment about mutex_atomic issue to description
Dec 29, 2022
6ccd4eb
Auto merge of #10115 - rdrpenguin04:master, r=flip1995
bors Dec 30, 2022
7a64a51
Fix typo
ardislu Dec 31, 2022
da7c99b
Fix typo in `unused_self` diagnostic message
smoelius Jan 1, 2023
a85e480
Auto merge of #10110 - Niki4tap:needless_anyhow_return, r=Alexendoo
bors Jan 1, 2023
5b46f2d
chore: fix identation of `if_chain` in `filter_map`
chansuke Dec 22, 2022
6145194
chore: add simple comment for `get_enclosing_block`
chansuke Dec 22, 2022
8de011f
don't lint field_reassign when field in closure
ericwu17 Jan 2, 2023
01a2a9d
[`drop_ref`]: don't lint idiomatic in match arm
ericwu17 Jan 2, 2023
7a1a9c8
empty_structs_with_brackets: not MachineApplicable anymore
FoseFx Jan 2, 2023
9aef1a2
reword dbg_macro labels
euclio Jan 1, 2023
f53c6e2
Correct Gankra's name in the linkedlist lint
Noratrieb Jan 2, 2023
3006c7c
Auto merge of #10146 - Nilstrieb:💀, r=llogiq
bors Jan 2, 2023
653f5d9
Auto merge of #10139 - chansuke:chore/fix-if_chain_ident, r=Jarcho
bors Jan 2, 2023
1a46dc0
Auto merge of #10138 - smoelius:unused_self-typo, r=xFrednet
bors Jan 2, 2023
bd83650
Suggest using Path for comparing extensions
tylerjw Dec 21, 2022
0aa7d73
Only remove method from end of recv, indent suggestion source
tylerjw Jan 2, 2023
cf4e981
use OnlyBodies instead of All
ericwu17 Jan 2, 2023
0cee2c5
Don't trigger lint if last method is to_lower/upper
tylerjw Jan 2, 2023
4334919
Auto merge of #10143 - EricWu2003:field_reassign_with_default-FP, r=M…
bors Jan 3, 2023
8b1ac45
Auto merge of #10141 - FoseFx:fosefx/9887, r=Jarcho
bors Jan 3, 2023
0bca8dd
Auto merge of #10135 - ardislu:fix-typo, r=giraffate
bors Jan 3, 2023
d3a50d2
trim paths in `box_default`
llogiq Jan 3, 2023
73d293f
rename get_parent_node to parent_id
compiler-errors Jan 3, 2023
bd1d897
rename find_parent_node to opt_parent_id
compiler-errors Jan 3, 2023
70f6c47
get_parent and find_parent
compiler-errors Jan 3, 2023
ea6ff7e
Apply changes suggested in review
tylerjw Jan 4, 2023
a385d34
Auto merge of #10107 - tylerjw:suggest_path, r=Alexendoo
bors Jan 4, 2023
d39dd86
Auto merge of #10140 - chansuke:chore/add-comment-for-enclosing-block…
bors Jan 4, 2023
d0c1605
Make the iter_kv_map lint handle ref/mut annotations.
khuey Jan 4, 2023
05ba519
trim paths in `default_trait_access`/`clone_on_copy` suggestions
llogiq Jan 4, 2023
755ae3f
Fix spelling while we're in the neighborhood.
khuey Jan 4, 2023
d5d8ef1
Auto merge of #10159 - khuey:iter_kv_map_ref_mut, r=llogiq
bors Jan 4, 2023
1c42dbb
Expand derivable-impls to cover enums with a default unit variant.
khuey Jan 5, 2023
61ff54e
Auto merge of #10161 - khuey:default_enum_unit_variant, r=llogiq
bors Jan 5, 2023
79ed23f
fix
tamaroning Jan 5, 2023
6433d79
Restrict suggestion of deriving Default for enums to MSRV 1.62.
khuey Jan 5, 2023
4f4c961
Auto merge of #10142 - EricWu2003:drop_ref-FP, r=llogiq
bors Jan 5, 2023
e443604
unused_self: Don't trigger if the method body contains todo!()
sulami Jan 6, 2023
3816f9a
Auto merge of #10137 - euclio:dbg-macro, r=giraffate
bors Jan 6, 2023
3f48ed5
Auto merge of #10160 - llogiq:default-trim-paths, r=dswij
bors Jan 6, 2023
179a22f
Auto merge of #10153 - llogiq:box-default-trim-paths, r=Jarcho
bors Jan 6, 2023
1b9a25e
[#10167] Clarify that the lint only works if x eq. y in a `for` loop.
blyxyas Jan 6, 2023
4262aeb
[arithmetic-side-effects] Consider negative numbers and add more tests
c410-f3r Jan 6, 2023
3f0d0c1
Auto merge of #10112 - c410-f3r:arith, r=xFrednet
bors Jan 6, 2023
fb34fbf
[arithmetic_side_effects] Add more tests related to custom types
c410-f3r Jan 6, 2023
19b79c4
Auto merge of #10168 - blyxyas:fix_reversed_empty_ranges, r=dswij
bors Jan 6, 2023
ef5a545
Auto merge of #10164 - khuey:default_enum_unit_variant_msrv, r=llogiq
bors Jan 7, 2023
ce56cf7
chore
tamaroning Jan 7, 2023
cf1d3d0
Auto merge of #10162 - tamaroning:fix10018, r=xFrednet
bors Jan 7, 2023
d8877bb
hotfix: remove `ITER_COUNT` since it is not called
chansuke Jan 7, 2023
d29c4c9
Auto merge of #10174 - chansuke:hotfix/remove-paths, r=dswij
bors Jan 8, 2023
d23dce5
add a test against #100898
llogiq Jan 8, 2023
46981dc
Auto merge of #10181 - llogiq:test-box-default-10089, r=flip1995
bors Jan 9, 2023
41b2a3d
Auto merge of #10170 - c410-f3r:arith, r=dswij
bors Jan 9, 2023
53c12e0
hash xor peq
robertbastian Jan 9, 2023
8ca900b
rename
robertbastian Jan 10, 2023
15226f9
Auto merge of #10166 - sulami:master, r=giraffate
bors Jan 11, 2023
5f8686e
Change `src/test` to `tests` in source files, fix tidy and tests
albertlarsan68 Jan 5, 2023
bd76d91
trim paths in `suspicious_to_owned`
llogiq Jan 8, 2023
34024ad
expl_impl_clone_on_copy: ignore packed structs with type/const params
Alexendoo Jan 11, 2023
a95286b
Auto merge of #10189 - Alexendoo:copy-packed-struct, r=giraffate
bors Jan 12, 2023
7c01721
Auto merge of #10179 - llogiq:trim-suspicious-to-owned-paths, r=xFrednet
bors Jan 12, 2023
9206332
fix
robertbastian Jan 12, 2023
decaba9
Auto merge of #10184 - robertbastian:master, r=xFrednet
bors Jan 12, 2023
321c530
Don't pass `--sysroot` twice if SYSROOT is set
jyn514 Jan 3, 2023
fe00717
Add cargo-clippy sysroot test
flip1995 Jan 12, 2023
f9ca9d4
Auto merge of #10149 - jyn514:duplicate-sysroot, r=flip1995
bors Jan 12, 2023
631481f
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Jan 12, 2023
616b6d2
Bump nightly version -> 2023-01-12
flip1995 Jan 12, 2023
cd76d57
Also add rustc_driver to clippy_utils
flip1995 Jan 12, 2023
0b8ee70
Auto merge of #10191 - flip1995:rustup, r=flip1995
bors Jan 12, 2023
5eed9c6
Revert 4dbd8ad34e7f6820f6e9e99531353e7ffe37b76a, c7dc96155853a3919b97…
Jarcho Jan 12, 2023
757e944
Adjust old code for newer rustc version.
Jarcho Jan 12, 2023
7f27e2e
Auto merge of #10192 - Jarcho:revert_9701, r=flip1995
bors Jan 12, 2023
01c7584
Merge commit '7f27e2e74ef957baa382dc05cf08df6368165c74' into clippyup
flip1995 Jan 12, 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
7 changes: 7 additions & 0 deletions src/tools/clippy/.github/driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ test "$sysroot" = $desired_sysroot
sysroot=$(SYSROOT=$desired_sysroot ./target/debug/clippy-driver --print sysroot)
test "$sysroot" = $desired_sysroot

# Check that the --sysroot argument is only passed once (SYSROOT is ignored)
(
cd rustc_tools_util
touch src/lib.rs
SYSROOT=/tmp RUSTFLAGS="--sysroot=$(rustc --print sysroot)" ../target/debug/cargo-clippy clippy --verbose
)

# Make sure this isn't set - clippy-driver should cope without it
unset CARGO_MANIFEST_DIR

Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4137,6 +4137,7 @@ Released 2018-09-13
[`derive_hash_xor_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq
[`derive_ord_xor_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord
[`derive_partial_eq_without_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_partial_eq_without_eq
[`derived_hash_with_manual_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derived_hash_with_manual_eq
[`disallowed_macros`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_macros
[`disallowed_method`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_method
[`disallowed_methods`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/book/src/installation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Installation

If you're using `rustup` to install and manage you're Rust toolchains, Clippy is
If you're using `rustup` to install and manage your Rust toolchains, Clippy is
usually **already installed**. In that case you can skip this chapter and go to
the [Usage] chapter.

Expand Down
3 changes: 3 additions & 0 deletions src/tools/clippy/clippy_dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// warn on lints, that are included in `rust-lang/rust`s bootstrap
#![warn(rust_2018_idioms, unused_lifetimes)]

// The `rustc_driver` crate seems to be required in order to use the `rust_lexer` crate.
#[allow(unused_extern_crates)]
extern crate rustc_driver;
extern crate rustc_lexer;

use std::path::PathBuf;
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/box_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_hir::{
Block, Expr, ExprKind, Local, Node, QPath, TyKind,
};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::{lint::in_external_macro, ty::print::with_forced_trimmed_paths};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::sym;

Expand Down Expand Up @@ -59,7 +59,7 @@ impl LateLintPass<'_> for BoxDefault {
if is_plain_default(arg_path) || given_type(cx, expr) {
"Box::default()".into()
} else {
format!("Box::<{arg_ty}>::default()")
with_forced_trimmed_paths!(format!("Box::<{arg_ty}>::default()"))
},
Applicability::MachineApplicable
);
Expand Down
6 changes: 5 additions & 1 deletion src/tools/clippy/clippy_lints/src/copies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,11 @@ fn check_for_warn_of_moved_symbol(cx: &LateContext<'_>, symbols: &[(HirId, Symbo
.iter()
.filter(|&&(_, name)| !name.as_str().starts_with('_'))
.any(|&(_, name)| {
let mut walker = ContainsName { name, result: false };
let mut walker = ContainsName {
name,
result: false,
cx,
};

// Scan block
block
Expand Down
10 changes: 5 additions & 5 deletions src/tools/clippy/clippy_lints/src/dbg_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use rustc_span::sym;

declare_clippy_lint! {
/// ### What it does
/// Checks for usage of dbg!() macro.
/// Checks for usage of the [`dbg!`](https://doc.rust-lang.org/std/macro.dbg.html) macro.
///
/// ### Why is this bad?
/// `dbg!` macro is intended as a debugging tool. It
/// should not be in version control.
/// The `dbg!` macro is intended as a debugging tool. It should not be present in released
/// software or committed to a version control system.
///
/// ### Example
/// ```rust,ignore
Expand Down Expand Up @@ -91,8 +91,8 @@ impl LateLintPass<'_> for DbgMacro {
cx,
DBG_MACRO,
macro_call.span,
"`dbg!` macro is intended as a debugging tool",
"ensure to avoid having uses of it in version control",
"the `dbg!` macro is intended as a debugging tool",
"remove the invocation before committing it to a version control system",
suggestion,
applicability,
);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::dereference::NEEDLESS_BORROW_INFO,
crate::dereference::REF_BINDING_TO_REFERENCE_INFO,
crate::derivable_impls::DERIVABLE_IMPLS_INFO,
crate::derive::DERIVE_HASH_XOR_EQ_INFO,
crate::derive::DERIVED_HASH_WITH_MANUAL_EQ_INFO,
crate::derive::DERIVE_ORD_XOR_PARTIAL_ORD_INFO,
crate::derive::DERIVE_PARTIAL_EQ_WITHOUT_EQ_INFO,
crate::derive::EXPL_IMPL_CLONE_ON_COPY_INFO,
Expand Down
7 changes: 3 additions & 4 deletions src/tools/clippy/clippy_lints/src/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rustc_hir::def::Res;
use rustc_hir::{Block, Expr, ExprKind, PatKind, QPath, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
use rustc_middle::ty::print::with_forced_trimmed_paths;
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::Span;
Expand Down Expand Up @@ -98,9 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
if let ty::Adt(def, ..) = expr_ty.kind();
if !is_from_proc_macro(cx, expr);
then {
// TODO: Work out a way to put "whatever the imported way of referencing
// this type in this file" rather than a fully-qualified type.
let replacement = format!("{}::default()", cx.tcx.def_path_str(def.did()));
let replacement = with_forced_trimmed_paths!(format!("{}::default()", cx.tcx.def_path_str(def.did())));
span_lint_and_sugg(
cx,
DEFAULT_TRAIT_ACCESS,
Expand Down Expand Up @@ -170,7 +169,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) {
if contains_name(binding_name, assign_rhs, cx) {
cancel_lint = true;
break;
}
Expand Down
8 changes: 4 additions & 4 deletions src/tools/clippy/clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,10 +1282,10 @@ fn referent_used_exactly_once<'tcx>(
possible_borrowers.push((body_owner_local_def_id, PossibleBorrowerMap::new(cx, mir)));
}
let possible_borrower = &mut possible_borrowers.last_mut().unwrap().1;
// If `place.local` were not included here, the `copyable_iterator::warn` test would fail. The
// reason is that `PossibleBorrowerVisitor::visit_terminator` considers `place.local` a possible
// borrower of itself. See the comment in that method for an explanation as to why.
possible_borrower.at_most_borrowers(cx, &[local, place.local], place.local, location)
// If `only_borrowers` were used here, the `copyable_iterator::warn` test would fail. The reason is
// that `PossibleBorrowerVisitor::visit_terminator` considers `place.local` a possible borrower of
// itself. See the comment in that method for an explanation as to why.
possible_borrower.bounded_borrowers(&[local], &[local, place.local], place.local, location)
&& used_exactly_once(mir, place.local).unwrap_or(false)
} else {
false
Expand Down
161 changes: 117 additions & 44 deletions src/tools/clippy/clippy_lints/src/derivable_impls.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::msrvs::{self, Msrv};
use clippy_utils::source::indent_of;
use clippy_utils::{is_default_equivalent, peel_blocks};
use rustc_errors::Applicability;
use rustc_hir::{
def::{DefKind, Res},
Body, Expr, ExprKind, GenericArg, Impl, ImplItemKind, Item, ItemKind, Node, PathSegment, QPath, TyKind,
def::{CtorKind, CtorOf, DefKind, Res},
Body, Expr, ExprKind, GenericArg, Impl, ImplItemKind, Item, ItemKind, Node, PathSegment, QPath, Ty, TyKind,
};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_middle::ty::{AdtDef, DefIdTree};
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::sym;

declare_clippy_lint! {
Expand Down Expand Up @@ -51,7 +54,18 @@ declare_clippy_lint! {
"manual implementation of the `Default` trait which is equal to a derive"
}

declare_lint_pass!(DerivableImpls => [DERIVABLE_IMPLS]);
pub struct DerivableImpls {
msrv: Msrv,
}

impl DerivableImpls {
#[must_use]
pub fn new(msrv: Msrv) -> Self {
DerivableImpls { msrv }
}
}

impl_lint_pass!(DerivableImpls => [DERIVABLE_IMPLS]);

fn is_path_self(e: &Expr<'_>) -> bool {
if let ExprKind::Path(QPath::Resolved(_, p)) = e.kind {
Expand All @@ -61,6 +75,98 @@ fn is_path_self(e: &Expr<'_>) -> bool {
}
}

fn check_struct<'tcx>(
cx: &LateContext<'tcx>,
item: &'tcx Item<'_>,
self_ty: &Ty<'_>,
func_expr: &Expr<'_>,
adt_def: AdtDef<'_>,
) {
if let TyKind::Path(QPath::Resolved(_, p)) = self_ty.kind {
if let Some(PathSegment { args: Some(a), .. }) = p.segments.last() {
for arg in a.args {
if !matches!(arg, GenericArg::Lifetime(_)) {
return;
}
}
}
}
let should_emit = match peel_blocks(func_expr).kind {
ExprKind::Tup(fields) => fields.iter().all(|e| is_default_equivalent(cx, e)),
ExprKind::Call(callee, args) if is_path_self(callee) => args.iter().all(|e| is_default_equivalent(cx, e)),
ExprKind::Struct(_, fields, _) => fields.iter().all(|ef| is_default_equivalent(cx, ef.expr)),
_ => false,
};

if should_emit {
let struct_span = cx.tcx.def_span(adt_def.did());
span_lint_and_then(cx, DERIVABLE_IMPLS, item.span, "this `impl` can be derived", |diag| {
diag.span_suggestion_hidden(
item.span,
"remove the manual implementation...",
String::new(),
Applicability::MachineApplicable,
);
diag.span_suggestion(
struct_span.shrink_to_lo(),
"...and instead derive it",
"#[derive(Default)]\n".to_string(),
Applicability::MachineApplicable,
);
});
}
}

fn check_enum<'tcx>(cx: &LateContext<'tcx>, item: &'tcx Item<'_>, func_expr: &Expr<'_>, adt_def: AdtDef<'_>) {
if_chain! {
if let ExprKind::Path(QPath::Resolved(None, p)) = &peel_blocks(func_expr).kind;
if let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const), id) = p.res;
if let variant_id = cx.tcx.parent(id);
if let Some(variant_def) = adt_def.variants().iter().find(|v| v.def_id == variant_id);
if variant_def.fields.is_empty();
if !variant_def.is_field_list_non_exhaustive();

then {
let enum_span = cx.tcx.def_span(adt_def.did());
let indent_enum = indent_of(cx, enum_span).unwrap_or(0);
let variant_span = cx.tcx.def_span(variant_def.def_id);
let indent_variant = indent_of(cx, variant_span).unwrap_or(0);
span_lint_and_then(
cx,
DERIVABLE_IMPLS,
item.span,
"this `impl` can be derived",
|diag| {
diag.span_suggestion_hidden(
item.span,
"remove the manual implementation...",
String::new(),
Applicability::MachineApplicable
);
diag.span_suggestion(
enum_span.shrink_to_lo(),
"...and instead derive it...",
format!(
"#[derive(Default)]\n{indent}",
indent = " ".repeat(indent_enum),
),
Applicability::MachineApplicable
);
diag.span_suggestion(
variant_span.shrink_to_lo(),
"...and mark the default variant",
format!(
"#[default]\n{indent}",
indent = " ".repeat(indent_variant),
),
Applicability::MachineApplicable
);
}
);
}
}
}

impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
if_chain! {
Expand All @@ -83,49 +189,16 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
if !attrs.iter().any(|attr| attr.doc_str().is_some());
if let child_attrs = cx.tcx.hir().attrs(impl_item_hir);
if !child_attrs.iter().any(|attr| attr.doc_str().is_some());
if adt_def.is_struct();
then {
if let TyKind::Path(QPath::Resolved(_, p)) = self_ty.kind {
if let Some(PathSegment { args: Some(a), .. }) = p.segments.last() {
for arg in a.args {
if !matches!(arg, GenericArg::Lifetime(_)) {
return;
}
}
}
}
let should_emit = match peel_blocks(func_expr).kind {
ExprKind::Tup(fields) => fields.iter().all(|e| is_default_equivalent(cx, e)),
ExprKind::Call(callee, args)
if is_path_self(callee) => args.iter().all(|e| is_default_equivalent(cx, e)),
ExprKind::Struct(_, fields, _) => fields.iter().all(|ef| is_default_equivalent(cx, ef.expr)),
_ => false,
};

if should_emit {
let struct_span = cx.tcx.def_span(adt_def.did());
span_lint_and_then(
cx,
DERIVABLE_IMPLS,
item.span,
"this `impl` can be derived",
|diag| {
diag.span_suggestion_hidden(
item.span,
"remove the manual implementation...",
String::new(),
Applicability::MachineApplicable
);
diag.span_suggestion(
struct_span.shrink_to_lo(),
"...and instead derive it",
"#[derive(Default)]\n".to_string(),
Applicability::MachineApplicable
);
}
);
then {
if adt_def.is_struct() {
check_struct(cx, item, self_ty, func_expr, adt_def);
} else if adt_def.is_enum() && self.msrv.meets(msrvs::DEFAULT_ENUM_ATTRIBUTE) {
check_enum(cx, item, func_expr, adt_def);
}
}
}
}

extract_msrv_attr!(LateContext);
}
Loading