From fea889985e06506558c2794e354e8667922438af Mon Sep 17 00:00:00 2001 From: Dinu Blanovschi Date: Sat, 18 Nov 2023 18:02:31 +0100 Subject: [PATCH] fix dogfood --- clippy_lints/src/endian_bytes.rs | 2 +- clippy_lints/src/fallible_impl_from.rs | 2 +- clippy_lints/src/lib.rs | 12 ++++++------ clippy_lints/src/loops/manual_memcpy.rs | 2 +- clippy_lints/src/needless_move.rs | 18 ++++++++++-------- clippy_lints/src/panic_in_result_fn.rs | 2 +- clippy_lints/src/unwrap_in_result.rs | 2 +- src/driver.rs | 2 +- 8 files changed, 22 insertions(+), 20 deletions(-) diff --git a/clippy_lints/src/endian_bytes.rs b/clippy_lints/src/endian_bytes.rs index 6f5a0cb8801b..a7baee4486c6 100644 --- a/clippy_lints/src/endian_bytes.rs +++ b/clippy_lints/src/endian_bytes.rs @@ -203,7 +203,7 @@ fn maybe_lint_endian_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, prefix: Prefix lint.as_name(prefix), if prefix == Prefix::To { " method" } else { "" }, ), - move |diag| { + |diag| { if let Some(help) = help { diag.help(help); } diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 753f75d83a84..6ee94ae5848e 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -116,7 +116,7 @@ fn lint_impl_body(cx: &LateContext<'_>, impl_span: Span, impl_items: &[hir::Impl FALLIBLE_IMPL_FROM, impl_span, "consider implementing `TryFrom` instead", - move |diag| { + |diag| { diag.help( "`From` is intended for infallible conversions only. \ Use `TryFrom` if there's a possibility for the conversion to fail", diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index d3ccb326317f..ab268c8edc47 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -685,7 +685,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(move |_| Box::new(from_over_into::FromOverInto::new(msrv()))); store.register_late_pass(move |_| Box::new(use_self::UseSelf::new(msrv()))); store.register_late_pass(move |_| Box::new(missing_const_for_fn::MissingConstForFn::new(msrv()))); - store.register_late_pass(move |_| Box::new(needless_question_mark::NeedlessQuestionMark)); + store.register_late_pass(|_| Box::new(needless_question_mark::NeedlessQuestionMark)); store.register_late_pass(move |_| Box::new(casts::Casts::new(msrv()))); store.register_early_pass(move || Box::new(unnested_or_patterns::UnnestedOrPatterns::new(msrv()))); store.register_late_pass(|_| Box::new(size_of_in_element_count::SizeOfInElementCount)); @@ -752,7 +752,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(|_| Box::new(mixed_read_write_in_expression::EvalOrderDependence)); store.register_late_pass(move |_| Box::new(missing_doc::MissingDoc::new(missing_docs_in_crate_items))); store.register_late_pass(|_| Box::new(missing_inline::MissingInline)); - store.register_late_pass(move |_| Box::new(exhaustive_items::ExhaustiveItems)); + store.register_late_pass(|_| Box::new(exhaustive_items::ExhaustiveItems)); store.register_late_pass(|_| Box::new(match_result_ok::MatchResultOk)); store.register_late_pass(|_| Box::new(partialeq_ne_impl::PartialEqNeImpl)); store.register_late_pass(|_| Box::new(unused_io_amount::UnusedIoAmount)); @@ -895,7 +895,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { store.register_late_pass(|_| Box::new(from_str_radix_10::FromStrRadix10)); store.register_late_pass(move |_| Box::new(if_then_some_else_none::IfThenSomeElseNone::new(msrv()))); store.register_late_pass(|_| Box::new(bool_assert_comparison::BoolAssertComparison)); - store.register_early_pass(move || Box::new(module_style::ModStyle)); + store.register_early_pass(|| Box::new(module_style::ModStyle)); store.register_late_pass(|_| Box::::default()); store.register_late_pass(move |_| Box::new(disallowed_types::DisallowedTypes::new(disallowed_types.clone()))); store.register_late_pass(move |_| { @@ -905,9 +905,9 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) { }); store.register_early_pass(move || Box::new(disallowed_script_idents::DisallowedScriptIdents::new(allowed_scripts))); store.register_late_pass(|_| Box::new(strlen_on_c_strings::StrlenOnCStrings)); - store.register_late_pass(move |_| Box::new(self_named_constructors::SelfNamedConstructors)); - store.register_late_pass(move |_| Box::new(iter_not_returning_iterator::IterNotReturningIterator)); - store.register_late_pass(move |_| Box::new(manual_assert::ManualAssert)); + store.register_late_pass(|_| Box::new(self_named_constructors::SelfNamedConstructors)); + store.register_late_pass(|_| Box::new(iter_not_returning_iterator::IterNotReturningIterator)); + store.register_late_pass(|_| Box::new(manual_assert::ManualAssert)); store.register_late_pass(move |_| { Box::new(non_send_fields_in_send_ty::NonSendFieldInSendTy::new( enable_raw_pointer_heuristic_for_send, diff --git a/clippy_lints/src/loops/manual_memcpy.rs b/clippy_lints/src/loops/manual_memcpy.rs index 40d56240b9de..decbd7669fd7 100644 --- a/clippy_lints/src/loops/manual_memcpy.rs +++ b/clippy_lints/src/loops/manual_memcpy.rs @@ -408,7 +408,7 @@ fn get_assignments<'a, 'tcx>( // just increases complexity. (cc #3188 and #4193) stmts .iter() - .filter_map(move |stmt| match stmt.kind { + .filter_map(|stmt| match stmt.kind { StmtKind::Local(..) | StmtKind::Item(..) => None, StmtKind::Expr(e) | StmtKind::Semi(e) => Some(e), }) diff --git a/clippy_lints/src/needless_move.rs b/clippy_lints/src/needless_move.rs index 39b1bf1ef717..47994e555b85 100644 --- a/clippy_lints/src/needless_move.rs +++ b/clippy_lints/src/needless_move.rs @@ -3,7 +3,7 @@ use clippy_utils::sugg::DiagnosticExt; use clippy_utils::ty::is_copy; use rustc_data_structures::fx::FxIndexMap; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{CaptureBy, Closure, Expr, ExprKind, HirId}; use rustc_hir_typeck::expr_use_visitor as euv; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; @@ -41,7 +41,7 @@ declare_clippy_lint! { declare_lint_pass!(NeedlessMove => [NEEDLESS_MOVE]); impl NeedlessMove { - fn check_closure<'tcx>(&self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, closure: &'tcx Closure<'tcx>) { + fn check_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, closure: &'tcx Closure<'tcx>) { let CaptureBy::Value { move_kw } = closure.capture_clause else { return; }; @@ -58,8 +58,8 @@ impl NeedlessMove { mut captured_vars, } = { let mut ctx = MovedVariablesCtxt { - captured_vars: Default::default(), - moved_vars: Default::default(), + captured_vars: FxIndexMap::default(), + moved_vars: FxIndexMap::default(), }; let body = cx.tcx.hir().body(closure.body); let infcx = cx.tcx.infer_ctxt().build(); @@ -70,7 +70,7 @@ impl NeedlessMove { // Remove the captured vars which were also `move`d. // See special case 1. below. - for (hir_id, _upvars) in moved_vars.iter() { + for (hir_id, _upvars) in &moved_vars { let Some(vars) = captured_vars.get_mut(hir_id) else { continue; }; @@ -99,9 +99,11 @@ impl NeedlessMove { }; match (moved_vars.is_empty(), captured_vars.is_empty()) { - (true, true) => lint("there were no captured variables, so the `move` is unnecessary"), + (true, true) => { + lint("there were no captured variables, so the `move` is unnecessary"); + }, (false, true) => { - lint("there were consumed variables, but no borrowed variables, so the `move` is unnecessary") + lint("there were consumed variables, but no borrowed variables, so the `move` is unnecessary"); }, (_, false) => { // captured_vars is not empty, so `move` actually makes a difference and we @@ -121,7 +123,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessMove { return; }; - self.check_closure(cx, expr, closure); + Self::check_closure(cx, expr, closure); } } diff --git a/clippy_lints/src/panic_in_result_fn.rs b/clippy_lints/src/panic_in_result_fn.rs index 6a760f9fe64a..0ed1cdc4da08 100644 --- a/clippy_lints/src/panic_in_result_fn.rs +++ b/clippy_lints/src/panic_in_result_fn.rs @@ -84,7 +84,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, body: &'tcx hir PANIC_IN_RESULT_FN, impl_span, "used `panic!()` or assertion in a function that returns `Result`", - move |diag| { + |diag| { diag.help( "`panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing", ); diff --git a/clippy_lints/src/unwrap_in_result.rs b/clippy_lints/src/unwrap_in_result.rs index df4b42133f8c..fb33d5462ecb 100644 --- a/clippy_lints/src/unwrap_in_result.rs +++ b/clippy_lints/src/unwrap_in_result.rs @@ -106,7 +106,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_item: &'tc UNWRAP_IN_RESULT, impl_span, "used unwrap or expect in a function that returns result or option", - move |diag| { + |diag| { diag.help("unwrap and expect should not be used in a function that returns result or option"); diag.span_note(result, "potential non-recoverable error(s)"); }, diff --git a/src/driver.rs b/src/driver.rs index 1ae8ac81695f..281fa20c61b2 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -186,7 +186,7 @@ pub fn main() { handler.note_without_error(format!("Clippy version: {version_info}")); }); - exit(rustc_driver::catch_with_exit_code(move || { + exit(rustc_driver::catch_with_exit_code(|| { let mut orig_args: Vec = env::args().collect(); let has_sysroot_arg = arg_value(&orig_args, "--sysroot", |_| true).is_some();