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 #114729

Merged
merged 79 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
50da775
Rename cast_ref_to_mut to invalid_reference_casting (clippy side)
Urgau Jun 8, 2023
d4f735c
redundant_type_annotations: only pass certain def kinds to type_of
Alexendoo Jul 19, 2023
1662fdb
fix
fee1-dead May 25, 2023
d94d85f
Perform OpaqueCast field projection on HIR, too.
oli-obk Jul 24, 2023
be0b4d5
Remove `constness` from `ParamEnv`
fee1-dead Jul 27, 2023
39fb315
bless clippy
fee1-dead Jul 27, 2023
e97a770
Auto merge of #114134 - fee1-dead-contrib:rm-constness-from-param-env…
bors Jul 28, 2023
4c9d68e
Make Clippy understand generic const items
fmease Jul 2, 2023
0c0026e
Auto merge of #111916 - fee1-dead-contrib:noop-method-call-warn, r=co…
bors Jul 29, 2023
436060f
Auto merge of #113422 - Urgau:cast_ref_to_mut-pre-beta, r=Nilstrieb
bors Jul 29, 2023
0c93e30
Mark `map_or` as `#[must_use]`
WaffleLapkin Jun 15, 2023
f54263a
Rollup merge of #112655 - WaffleLapkin:must_use_map_or, r=workingjubilee
matthiaskrgr Jul 30, 2023
9a0af82
Use builder pattern instead of lots of arguments for `EmitterWriter::…
oli-obk Jul 25, 2023
084c90a
Remove a `bool` for color in favor of the `WriteColor` trait wrapping…
oli-obk Jul 26, 2023
dc1e8b0
[`unnecessary_mut_passed`]: don't lint in macro expansions
y21 Jul 31, 2023
f9a6dfa
New lint `ignored_unit_patterns`
samueltardieu Jul 27, 2023
b0e64a9
Merge commit '5436dba826191964ac1d0dab534b7eb6d4c878f6' into clippyup
flip1995 Jul 31, 2023
588c1ab
Auto merge of #11269 - y21:issue11268, r=Centri3
bors Aug 1, 2023
7ef1a54
Rename incorrect_fn_null_checks to useless_ptr_null_checks (clippy side)
Urgau Jul 13, 2023
0ff6579
fix RedundantLocals clippy caused by async and await
chenyukang Aug 2, 2023
72074a0
Alphabetically order arms in methods/mod.rs match
Aug 2, 2023
78f5e0d
Auto merge of #11284 - lengyijun:reorder, r=blyxyas
bors Aug 2, 2023
b07de24
Remove constness from `TraitPredicate`
fee1-dead Jul 29, 2023
779e0f4
Do not lint unwrapping on `!` or never-like enums
Centri3 Jul 29, 2023
71c5413
Extract never-like into `clippy_utils`
Centri3 Aug 2, 2023
7af5ea1
Auto merge of #11252 - Centri3:#11245, r=xFrednet
bors Aug 2, 2023
4d49065
Suppress `question_mark` if `question_mark_used` is not allowed
Centri3 Aug 2, 2023
97d1cfa
Auto merge of #11286 - Centri3:#11283, r=Alexendoo
bors Aug 2, 2023
fef85c9
Take snippet instead of pretty printing type
Centri3 Aug 2, 2023
237dd59
Auto merge of #11288 - Centri3:#11278, r=Alexendoo
bors Aug 2, 2023
ff27f90
Auto merge of #107254 - chenyukang:yukang/fix-107113-wrong-sugg-in-ma…
bors Aug 2, 2023
1eb254e
Auto merge of #11242 - samueltardieu:issue-11238, r=Centri3,giraffate
bors Aug 3, 2023
85b5e98
Add `internal_features` lint
Noratrieb Mar 9, 2023
8f4f476
Rollup merge of #113657 - Urgau:expand-incorrect_fn_null_check-lint, …
matthiaskrgr Aug 3, 2023
3fb8441
Fix `suspicious_xor_used_as_pow.rs` performance
blyxyas Jul 29, 2023
5818225
Auto merge of #11255 - blyxyas:fix-perf-sus_xor_used_as_pow, r=xFrednet
bors Aug 3, 2023
d412b91
Auto merge of #108955 - Nilstrieb:dont-use-me-pls, r=oli-obk
bors Aug 3, 2023
1589759
Rollup merge of #114022 - oli-obk:tait_ice_alias_field_projection, r=…
matthiaskrgr Aug 4, 2023
ed0dfed
Improve spans for indexing expressions
Noratrieb Aug 3, 2023
1852200
Auto merge of #114104 - oli-obk:syn2, r=compiler-errors
bors Aug 4, 2023
878a87d
Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31
matthiaskrgr Aug 4, 2023
ec1d61e
Auto merge of #114481 - matthiaskrgr:rollup-58pczpl, r=matthiaskrgr
bors Aug 4, 2023
e5b0483
Small code style adjustments
lengyijun Aug 5, 2023
ab1281f
fix: Make ConstEvalLateContext::new() public, to match the 'constant_…
MortenLohne May 29, 2023
046d3df
New lints: `impossible_double_const_comparisons` and `ineffective_dou…
MortenLohne May 29, 2023
e16a2ac
Add descriptions for 'impossible_double_const_comparisons' and 'ineff…
MortenLohne May 29, 2023
08e1333
Add missing variable decl to doc comment
MortenLohne Jun 1, 2023
8f40d09
Add tests for const comparisons that compare two different types
MortenLohne Jun 3, 2023
b5ef66f
Optimize by doing a cheap check for double binary expression first
MortenLohne Jun 10, 2023
1d61fc1
Rename 'impossible_double_const_comparisons' -> 'impossible_compariso…
MortenLohne Jun 10, 2023
9646446
Add lifetime parameter to 'Constant', after rebasing on upstream
MortenLohne Aug 6, 2023
0e064d5
Replace ConstEvalLateContext::new() with two calls to constant() to s…
MortenLohne Aug 6, 2023
3157b96
Provide fallback code snippets, if the snippet is not available
MortenLohne Aug 6, 2023
44cd3bc
cleanup misinformation regarding has_deref
ouz-a Aug 5, 2023
261837c
Rollup merge of #114505 - ouz-a:cleanup_mir, r=RalfJung
matthiaskrgr Aug 6, 2023
d628046
Update clippy_lints/src/operators/mod.rs
Manishearth Aug 6, 2023
6a2c8a1
Auto merge of #10843 - MortenLohne:feat/double-const-comparisons, r=C…
bors Aug 6, 2023
526d115
Auto merge of #11191 - Alexendoo:redundant-type-annotations-ice, r=ll…
bors Aug 6, 2023
84d2896
Auto merge of #11295 - lengyijun:typo, r=Centri3
bors Aug 7, 2023
3ff6fd2
Store the laziness of type aliases in the DefKind
fmease Aug 6, 2023
5f86009
Rollup merge of #114566 - fmease:type-alias-laziness-is-crate-specifi…
matthiaskrgr Aug 8, 2023
f959ccc
[`redundant_guards`]: don't lint on floats
y21 Aug 8, 2023
b615650
document the new behavior and add test for float in struct
y21 Aug 8, 2023
7c595b4
Auto merge of #11305 - y21:issue11304, r=Centri3
bors Aug 8, 2023
830bac5
clarify why `Vec::new()` + resize is worse than `vec![0; N]`
y21 Aug 9, 2023
d2acfb3
Reword paragraph
y21 Aug 9, 2023
dd25cc3
Remove unnecessary paragraph, move examples
y21 Aug 9, 2023
add2722
Auto merge of #11310 - y21:slow_vector_initialization_doc, r=xFrednet…
bors Aug 9, 2023
17b9c42
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Aug 10, 2023
61e9b15
Bump nightly version -> 2023-08-10
flip1995 Aug 10, 2023
beb57f0
Don't ICE with late bound regions
Centri3 Aug 10, 2023
7b2fd81
Add test for `&mut`
Centri3 Aug 10, 2023
bd1554c
Auto merge of #11318 - Centri3:#11309, r=Manishearth
bors Aug 11, 2023
a5f62bd
redundant_locals: fix FPs on mutated shadows
max-niederman Aug 11, 2023
0fc051d
Fix redundant_locals for Async desugaring
flip1995 Aug 11, 2023
3927677
Dogfood and bless tests
flip1995 Aug 11, 2023
8703661
Auto merge of #11316 - flip1995:rustup, r=flip1995
bors Aug 11, 2023
1e8fdf4
Auto merge of #11320 - max-niederman:redundant_locals_shadow_mutated,…
bors Aug 11, 2023
852bf4e
Merge commit '1e8fdf492808a25d78a97e1242b835ace9924e4d' into clippyup
flip1995 Aug 11, 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
4 changes: 4 additions & 0 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4844,6 +4844,7 @@ Released 2018-09-13
[`field_reassign_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default
[`filetype_is_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#filetype_is_file
[`filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map
[`filter_map_bool_then`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_bool_then
[`filter_map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_identity
[`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next
[`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next
Expand Down Expand Up @@ -4889,12 +4890,14 @@ Released 2018-09-13
[`if_same_then_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else
[`if_then_some_else_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_then_some_else_none
[`ifs_same_cond`]: https://rust-lang.github.io/rust-clippy/master/index.html#ifs_same_cond
[`ignored_unit_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#ignored_unit_patterns
[`impl_trait_in_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#impl_trait_in_params
[`implicit_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_clone
[`implicit_hasher`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_hasher
[`implicit_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_return
[`implicit_saturating_add`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_add
[`implicit_saturating_sub`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_sub
[`impossible_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#impossible_comparisons
[`imprecise_flops`]: https://rust-lang.github.io/rust-clippy/master/index.html#imprecise_flops
[`inconsistent_digit_grouping`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_digit_grouping
[`inconsistent_struct_constructor`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_struct_constructor
Expand Down Expand Up @@ -5189,6 +5192,7 @@ Released 2018-09-13
[`redundant_closure`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
[`redundant_closure_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_call
[`redundant_closure_for_method_calls`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls
[`redundant_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_comparisons
[`redundant_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else
[`redundant_feature_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_feature_names
[`redundant_field_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn main() {
matches.get_one::<String>("type").map(String::as_str),
matches.get_flag("msrv"),
) {
Ok(_) => update_lints::update(update_lints::UpdateMode::Change),
Ok(()) => update_lints::update(update_lints::UpdateMode::Change),
Err(e) => eprintln!("Unable to create lint: {e}"),
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_dev/src/setup/vscode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn check_install_precondition(force_override: bool) -> bool {
}
} else {
match fs::create_dir(vs_dir_path) {
Ok(_) => {
Ok(()) => {
println!("info: created `{VSCODE_DIR}` directory for clippy");
},
Err(err) => {
Expand Down
64 changes: 35 additions & 29 deletions src/tools/clippy/clippy_lints/src/casts/ptr_as_ptr.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::borrow::Cow;

use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::msrvs::{self, Msrv};
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::sugg::Sugg;
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, Mutability, TyKind};
use rustc_lint::LateContext;
Expand All @@ -16,33 +14,41 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Msrv) {
return;
}

if_chain! {
if let ExprKind::Cast(cast_expr, cast_to_hir_ty) = expr.kind;
let (cast_from, cast_to) = (cx.typeck_results().expr_ty(cast_expr), cx.typeck_results().expr_ty(expr));
if let ty::RawPtr(TypeAndMut { mutbl: from_mutbl, .. }) = cast_from.kind();
if let ty::RawPtr(TypeAndMut { ty: to_pointee_ty, mutbl: to_mutbl }) = cast_to.kind();
if matches!((from_mutbl, to_mutbl),
(Mutability::Not, Mutability::Not) | (Mutability::Mut, Mutability::Mut));
if let ExprKind::Cast(cast_expr, cast_to_hir_ty) = expr.kind
&& let (cast_from, cast_to) = (cx.typeck_results().expr_ty(cast_expr), cx.typeck_results().expr_ty(expr))
&& let ty::RawPtr(TypeAndMut { mutbl: from_mutbl, .. }) = cast_from.kind()
&& let ty::RawPtr(TypeAndMut { ty: to_pointee_ty, mutbl: to_mutbl }) = cast_to.kind()
&& matches!((from_mutbl, to_mutbl),
(Mutability::Not, Mutability::Not) | (Mutability::Mut, Mutability::Mut))
// The `U` in `pointer::cast` have to be `Sized`
// as explained here: https://github.com/rust-lang/rust/issues/60602.
if to_pointee_ty.is_sized(cx.tcx, cx.param_env);
then {
let mut applicability = Applicability::MachineApplicable;
let cast_expr_sugg = Sugg::hir_with_applicability(cx, cast_expr, "_", &mut applicability);
let turbofish = match &cast_to_hir_ty.kind {
TyKind::Infer => Cow::Borrowed(""),
TyKind::Ptr(mut_ty) if matches!(mut_ty.ty.kind, TyKind::Infer) => Cow::Borrowed(""),
_ => Cow::Owned(format!("::<{to_pointee_ty}>")),
};
span_lint_and_sugg(
cx,
PTR_AS_PTR,
expr.span,
"`as` casting between raw pointers without changing its mutability",
"try `pointer::cast`, a safer alternative",
format!("{}.cast{turbofish}()", cast_expr_sugg.maybe_par()),
applicability,
);
}
&& to_pointee_ty.is_sized(cx.tcx, cx.param_env)
{
let mut app = Applicability::MachineApplicable;
let cast_expr_sugg = Sugg::hir_with_applicability(cx, cast_expr, "_", &mut app);
let turbofish = match &cast_to_hir_ty.kind {
TyKind::Infer => String::new(),
TyKind::Ptr(mut_ty) => {
if matches!(mut_ty.ty.kind, TyKind::Infer) {
String::new()
} else {
format!(
"::<{}>",
snippet_with_applicability(cx, mut_ty.ty.span, "/* type */", &mut app)
)
}
},
_ => return,
};

span_lint_and_sugg(
cx,
PTR_AS_PTR,
expr.span,
"`as` casting between raw pointers without changing its mutability",
"try `pointer::cast`, a safer alternative",
format!("{}.cast{turbofish}()", cast_expr_sugg.maybe_par()),
app,
);
}
}
4 changes: 4 additions & 0 deletions src/tools/clippy/clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::if_let_mutex::IF_LET_MUTEX_INFO,
crate::if_not_else::IF_NOT_ELSE_INFO,
crate::if_then_some_else_none::IF_THEN_SOME_ELSE_NONE_INFO,
crate::ignored_unit_patterns::IGNORED_UNIT_PATTERNS_INFO,
crate::implicit_hasher::IMPLICIT_HASHER_INFO,
crate::implicit_return::IMPLICIT_RETURN_INFO,
crate::implicit_saturating_add::IMPLICIT_SATURATING_ADD_INFO,
Expand Down Expand Up @@ -337,6 +338,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::methods::EXPECT_USED_INFO,
crate::methods::EXTEND_WITH_DRAIN_INFO,
crate::methods::FILETYPE_IS_FILE_INFO,
crate::methods::FILTER_MAP_BOOL_THEN_INFO,
crate::methods::FILTER_MAP_IDENTITY_INFO,
crate::methods::FILTER_MAP_NEXT_INFO,
crate::methods::FILTER_NEXT_INFO,
Expand Down Expand Up @@ -516,6 +518,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::operators::FLOAT_CMP_CONST_INFO,
crate::operators::FLOAT_EQUALITY_WITHOUT_ABS_INFO,
crate::operators::IDENTITY_OP_INFO,
crate::operators::IMPOSSIBLE_COMPARISONS_INFO,
crate::operators::INEFFECTIVE_BIT_MASK_INFO,
crate::operators::INTEGER_DIVISION_INFO,
crate::operators::MISREFACTORED_ASSIGN_OP_INFO,
Expand All @@ -524,6 +527,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::operators::NEEDLESS_BITWISE_BOOL_INFO,
crate::operators::OP_REF_INFO,
crate::operators::PTR_EQ_INFO,
crate::operators::REDUNDANT_COMPARISONS_INFO,
crate::operators::SELF_ASSIGNMENT_INFO,
crate::operators::VERBOSE_BIT_MASK_INFO,
crate::option_env_unwrap::OPTION_ENV_UNWRAP_INFO,
Expand Down
50 changes: 17 additions & 33 deletions src/tools/clippy/clippy_lints/src/derive.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
use clippy_utils::diagnostics::{
span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then,
};
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then};
use clippy_utils::ty::{implements_trait, implements_trait_with_env, is_copy};
use clippy_utils::{is_lint_allowed, match_def_path, paths};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, Visitor};
use rustc_hir::{
self as hir, BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, Impl, Item, ItemKind,
UnsafeSource, Unsafety,
self as hir, BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, Impl, Item, ItemKind, UnsafeSource, Unsafety,
};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::nested_filter;
use rustc_middle::traits::Reveal;
use rustc_middle::ty::{
self, ClauseKind, GenericArgKind, GenericParamDefKind, ImplPolarity, ParamEnv,
ToPredicate, TraitPredicate, Ty, TyCtxt,
self, ClauseKind, GenericArgKind, GenericParamDefKind, ImplPolarity, ParamEnv, ToPredicate, TraitPredicate, Ty,
TyCtxt,
};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::def_id::LocalDefId;
Expand Down Expand Up @@ -207,10 +204,13 @@ declare_lint_pass!(Derive => [

impl<'tcx> LateLintPass<'tcx> for Derive {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), .. }) = item.kind {
if let ItemKind::Impl(Impl {
of_trait: Some(ref trait_ref),
..
}) = item.kind
{
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
let is_automatically_derived =
cx.tcx.has_attr(item.owner_id, sym::automatically_derived);
let is_automatically_derived = cx.tcx.has_attr(item.owner_id, sym::automatically_derived);

check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);
check_ord_partial_ord(cx, item.span, trait_ref, ty, is_automatically_derived);
Expand Down Expand Up @@ -327,12 +327,7 @@ fn check_ord_partial_ord<'tcx>(
}

/// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint.
fn check_copy_clone<'tcx>(
cx: &LateContext<'tcx>,
item: &Item<'_>,
trait_ref: &hir::TraitRef<'_>,
ty: Ty<'tcx>,
) {
fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &hir::TraitRef<'_>, ty: Ty<'tcx>) {
let clone_id = match cx.tcx.lang_items().clone_trait() {
Some(id) if trait_ref.trait_def_id() == Some(id) => id,
_ => return,
Expand All @@ -350,9 +345,10 @@ fn check_copy_clone<'tcx>(
if !is_copy(cx, ty) {
if ty_subs.non_erasable_generics().next().is_some() {
let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(&copy_id).map_or(false, |impls| {
impls
.iter()
.any(|&id| matches!(cx.tcx.type_of(id).instantiate_identity().kind(), ty::Adt(adt, _) if ty_adt.did() == adt.did()))
impls.iter().any(|&id| {
matches!(cx.tcx.type_of(id).instantiate_identity().kind(), ty::Adt(adt, _)
if ty_adt.did() == adt.did())
})
});
if !has_copy_impl {
return;
Expand Down Expand Up @@ -431,14 +427,7 @@ struct UnsafeVisitor<'a, 'tcx> {
impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
type NestedFilter = nested_filter::All;

fn visit_fn(
&mut self,
kind: FnKind<'tcx>,
decl: &'tcx FnDecl<'_>,
body_id: BodyId,
_: Span,
id: LocalDefId,
) {
fn visit_fn(&mut self, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body_id: BodyId, _: Span, id: LocalDefId) {
if self.has_unsafe {
return;
}
Expand Down Expand Up @@ -474,12 +463,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
}

/// Implementation of the `DERIVE_PARTIAL_EQ_WITHOUT_EQ` lint.
fn check_partial_eq_without_eq<'tcx>(
cx: &LateContext<'tcx>,
span: Span,
trait_ref: &hir::TraitRef<'_>,
ty: Ty<'tcx>,
) {
fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_ref: &hir::TraitRef<'_>, ty: Ty<'tcx>) {
if_chain! {
if let ty::Adt(adt, args) = ty.kind();
if cx.tcx.visibility(adt.did()).is_public();
Expand Down
5 changes: 1 addition & 4 deletions src/tools/clippy/clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, span: Span) {
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let fallback_bundle =
rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
let emitter = EmitterWriter::new(
Box::new(io::sink()),
fallback_bundle,
);
let emitter = EmitterWriter::new(Box::new(io::sink()), fallback_bundle);
let handler = Handler::with_emitter(Box::new(emitter)).disable_warnings();
let sess = ParseSess::with_span_handler(handler, sm);

Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/eta_reduction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use rustc_hir::{BindingAnnotation, Expr, ExprKind, FnRetTy, Param, PatKind, QPat
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::{
self, Binder, ClosureArgs, ClosureKind, EarlyBinder, FnSig, GenericArg, GenericArgKind,
GenericArgsRef, ImplPolarity, List, Region, RegionKind, Ty, TypeVisitableExt, TypeckResults,
self, Binder, ClosureArgs, ClosureKind, EarlyBinder, FnSig, GenericArg, GenericArgKind, GenericArgsRef,
ImplPolarity, List, Region, RegionKind, Ty, TypeVisitableExt, TypeckResults,
};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::symbol::sym;
Expand Down
52 changes: 52 additions & 0 deletions src/tools/clippy/clippy_lints/src/ignored_unit_patterns.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use hir::PatKind;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};

declare_clippy_lint! {
/// ### What it does
/// Checks for usage of `_` in patterns of type `()`.
///
/// ### Why is this bad?
/// Matching with `()` explicitly instead of `_` outlines
/// the fact that the pattern contains no data. Also it
/// would detect a type change that `_` would ignore.
///
/// ### Example
/// ```rust
/// match std::fs::create_dir("tmp-work-dir") {
/// Ok(_) => println!("Working directory created"),
/// Err(s) => eprintln!("Could not create directory: {s}"),
/// }
/// ```
/// Use instead:
/// ```rust
/// match std::fs::create_dir("tmp-work-dir") {
/// Ok(()) => println!("Working directory created"),
/// Err(s) => eprintln!("Could not create directory: {s}"),
/// }
/// ```
#[clippy::version = "1.73.0"]
pub IGNORED_UNIT_PATTERNS,
pedantic,
"suggest replacing `_` by `()` in patterns where appropriate"
}
declare_lint_pass!(IgnoredUnitPatterns => [IGNORED_UNIT_PATTERNS]);

impl<'tcx> LateLintPass<'tcx> for IgnoredUnitPatterns {
fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx hir::Pat<'tcx>) {
if matches!(pat.kind, PatKind::Wild) && cx.typeck_results().pat_ty(pat).is_unit() {
span_lint_and_sugg(
cx,
IGNORED_UNIT_PATTERNS,
pat.span,
"matching over `()` is more explicit",
"use `()` instead of `_`",
String::from("()"),
Applicability::MachineApplicable,
);
}
}
}
2 changes: 2 additions & 0 deletions src/tools/clippy/clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ mod future_not_send;
mod if_let_mutex;
mod if_not_else;
mod if_then_some_else_none;
mod ignored_unit_patterns;
mod implicit_hasher;
mod implicit_return;
mod implicit_saturating_add;
Expand Down Expand Up @@ -1093,6 +1094,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
})
});
store.register_late_pass(|_| Box::new(redundant_locals::RedundantLocals));
store.register_late_pass(|_| Box::new(ignored_unit_patterns::IgnoredUnitPatterns));
// add lints here, do not remove this comment, it's used in `new_lint`
}

Expand Down
4 changes: 3 additions & 1 deletion src/tools/clippy/clippy_lints/src/loops/never_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ fn never_loop_expr<'tcx>(
ExprKind::Binary(_, e1, e2)
| ExprKind::Assign(e1, e2, _)
| ExprKind::AssignOp(_, e1, e2)
| ExprKind::Index(e1, e2, _) => never_loop_expr_all(cx, &mut [e1, e2].iter().copied(), ignore_ids, main_loop_id),
| ExprKind::Index(e1, e2, _) => {
never_loop_expr_all(cx, &mut [e1, e2].iter().copied(), ignore_ids, main_loop_id)
},
ExprKind::Loop(b, _, _, _) => {
// Break can come from the inner loop so remove them.
absorb_break(never_loop_block(cx, b, ignore_ids, main_loop_id))
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/manual_float_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
if !in_external_macro(cx.sess(), expr.span)
&& (
matches!(cx.tcx.constness(cx.tcx.hir().enclosing_body_owner(expr.hir_id)), Constness::NotConst)
matches!(cx.tcx.constness(cx.tcx.hir().enclosing_body_owner(expr.hir_id)), Constness::NotConst)
|| cx.tcx.features().active(sym!(const_float_classify))
) && let ExprKind::Binary(kind, lhs, rhs) = expr.kind
&& let ExprKind::Binary(lhs_kind, lhs_lhs, lhs_rhs) = lhs.kind
Expand Down
Loading
Loading